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.

Do they result in different AST trees? Different performance? …

The parser builds the AST using tokens produced by the lexer, so the questions make no sense (to me). A lexer merely “feeds” the parser a 1 dimensional stream of tokens.

Leave a Comment