How to control switching Antlr
lexer modes from parser actions?
I extended the generated Parser and Lexer so I can call pushMode
and popMode
from parser witch in turn call suitable pushMode
and popMode
of lexer but with no effect. Is there any thing I can do to activate this functionality?
Asked
Active
Viewed 1,311 times
7

Angie
- 319
- 3
- 12
-
I suspect by the time the parser-rules are being hit, the lexer has already gone to work making tokens past the point where you want the switch-over to occur... Is it possible to determine the switch-over points using *only* lexer rules? If not, perhaps there is some way to re-wind the lexer's token stream and discard the tokens you don't trust. – Darien Sep 25 '13 at 16:36
1 Answers
8
Your lexer should be written such that the input can be completely tokenized before the parser is even created. Even though the token stream is lazily filled, ANTLR 4 is not guaranteed to correctly parse the input if your lexer does not meet this requirement.

Sam Harwell
- 97,721
- 20
- 209
- 280