Antlr - Lexical mode

Card Puncher Data Processing


Lexical mode in Antlr

Lexical modes allow to split a single lexer grammar file into multiple sublexers.

The lexer can then only return tokens matched by rules from the current mode.

Lexers start out in the so-called default mode.

All rules are considered to be within the default mode unless you specify a mode command.

Modes are not allowed within combined grammars, just lexer grammars.


rules in default mode
/** ... **/
mode MODE1;
rules in MODE1
/** ... **/
mode MODEN;
rules in MODEN
/** ... **/


Documentation / Reference

Discover More
Card Puncher Data Processing
Antlr - Lexer Grammar

The grammar file of the lexer is composed of lexer rule, optionally broken into multiple lexical modes grammar file Only lexer grammars can contain: mode specifications. custom channels specifications...

Share this page:
Follow us:
Task Runner