[antlr-interest] greedy vs nongreedy lexer rules

Terence Parr parrt at cs.usfca.edu
Sun Apr 18 16:53:15 PDT 2010


On Apr 18, 2010, at 4:50 PM, Cliff Hudson wrote:

> You wrote:
> 
> Well, imagine that you are modifying "global" state as you match characters in identifier; this is something done in actions that ANTLR can analyze. There is no way to "roll this back".
> 
> The 'global' state you are talking about is state the DFA is modifying but which an action in a rule could examine?  Is the amount of state visible to actions too much to store while alternatives are being evaulated?

It's state you set up and modify then ref:

@members {
int i = 0;
}

...

ID : ('a'..'z' {i++;})+ {System.out.println(i);} ;

ANTLR can't save i for you each char iteration.

Ter


More information about the antlr-interest mailing list