January 2013
Intermediate to advanced
328 pages
8h 5m
English
A lexer grammar is composed of lexer rules, optionally broken into multiple modes, as we saw in Issuing Context-Sensitive Tokens with Lexical Modes. Lexical modes allow us to split a single lexer grammar into multiple sublexers. The lexer can return only those tokens matched by rules from the current mode.
Lexer rules specify token definitions and more or less follow the syntax of parser rules except that lexer rules cannot have arguments, return values, or local variables. Lexer rule names must begin with an uppercase letter, which distinguishes them from parser rule names.
| | /** Optional document comment */ |
| | TokenName : alternative1 | ... | alternativeN ; |
You can also define rules that are not tokens but rather ...
Read now
Unlock full access