ATNState states[] = g.atn.ruleToStartState;
Rule r = g.getRule(startRule);
index = r.index;
state = states[index];
Maybe it's too easy, but I simply can't find how can I get the state index given a token name.For the parser rules I useATNState states[] = g.atn.ruleToStartState;
Rule r = g.getRule(startRule);
index = r.index;
state = states[index];
But I can't use this in the lexer grammar because the only existing rules are the parser rules.Thanks a lot.
There is no direct relation between token types and lexer rule indexes (and thus no relation to states in the ATN). Lexer rules frequently contain the type, more, or skip commands, or even custom embedded actions to alter the type produced for a rule.
Depending on what you are trying to accomplish (you didn’t specify), you’ll need to do things some other way.
Sam
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.