Practical difference between parser rules and lexer rules in ANTLR?

… what are the practical differences between these two statements in ANTLR … MY_RULE will be used to tokenize your input source. It represents a fundamental building block of your language. my_rule is called from the parser, it consists of zero or more other parser rules or tokens produced by the lexer. That’s the difference. … Read more

When do we use ANTLR

The Antlr package is used by the WebGrease package. The WebGrease package is used by the ASP.NET Web Optimization package. If you want to remove Antlr, remove the ASP.NET Web Optimization package. It will in turn remove the other 2 packages. It does not affect performance much, provided that you designed your application properly.

ANTLR 4 $channel = HIDDEN and options

The v4 equivalent would look like: COMMENT : ( ‘//’ ~[\r\n]* ‘\r’? ‘\n’ | ‘/*’ .*? ‘*/’ ) -> channel(HIDDEN) ; which will put all single- and multi line comment on the HIDDEN channel. However, if you’re not doing anything with these HIDDEN-tokens, you could also skip these tokens, which would look like this: COMMENT … Read more

Is “Implicit token definition in parser rule” something to worry about?

I highly recommend correcting all instances of this warning in code of any importance. This warning was created (by me actually) to alert you to situations like the following: shiftExpr : ID ((‘<<‘ | ‘>>’) ID)?; Since ANTLR 4 encourages action code be written in separate files in the target language instead of embedding them … Read more

Once grammar is complete, what’s the best way to walk an ANTLR v4 tree?

I wouldn’t walk this manually if I were you. After generating a lexer and parser, ANTLR would also have generated a file called CfscriptBaseListener that has empty methods for all of your parser rules. You can let ANTLR walk your tree and attach a custom tree-listener in which you override only those methods/rules you’re interested … Read more