i'm learning ANTLR right now. Let's say, I have a VHDL code and would like to do some processing on the PROCESS blocks. The rest should be completely ignored. I don't want to describe the whole VHDL language, since I'm interested only in the process blocks. So I could write a rule that matches process blocks. But how do I tell ANTLR to match only the process block rule and ignore anything else?
相关问题
- Using Antlr to get identifiers and function names
- boolean and arithmetic expression grammar in ANTLR
- antlr 4.2.2 output to console warning (157)
- What happened to options in rules in ANTLR 4?
- ANTLR How to use lexer rules having same starting?
相关文章
- In ANTLR, how do you specify a specific number of
- Slow ANTLR4 generated Parser in Python, but fast i
- Ignore some part of input when parsing with ANTLR
- Working example of wikitext-to-HTML in ANTLR 3
- How to parse a parenthesized hierarchy root?
- Interpreting custom language
- Two basic ANTLR questions
- How to deal with list return values in ANTLR
In the upcoming ANTLR v4, you can do fuzzy parsing. take a look at
http://www.antlr.org/wiki/display/ANTLR4/Wildcard+Operator+and+Nongreedy+Subrules
You can get the beta software here:
http://antlr.org/download/antlr-4.0b3-complete.jar
Terence
I know next to no VHDL, so let's say you want to replace all single line comments in a (Java) source file with multi-line comments:
should become:
You need to let the lexer match single line comments, of course. But you should also make sure it recognizes multi-line comments because you don't want
//bar
to be recognized as a single line comment in:The same goes for string literals:
Finally, you should create some sort of catch-all rule in the lexer that will match any character.
A quick demo:
If you now parse input like this:
the following will be printed to your console:
Note that this is just a quick demo: a string literal in Java could contain Unicode escapes, which my demo doesn't support, and my demo also does not handle char-literals (the char literal
char c = '"';
would break it). All of these things are quite easy to fix, of course.