[antlr-interest] languages without reserved words

Martin Probst mail at martin-probst.com
Tue Mar 7 13:45:50 PST 2006

> identifier { lexer.testLiterals = false; } 
>     : NCNAME 
>      { lexer.testLiterals = true; }  // should be an "exit-action"
>     ;

The problem is that every parser would first need to know if an NCNAME
comes up to decide to enter the identifier rules. That's always a
problem with state switching in the parser - lookahead stops working
predictably. There is no way around that - you can't decide to enter the
identifier rule before you know there's an identifier coming up, for
which you need to know whether you're in the identifier rule ...

> Does anyone have an idea of how to do the above in ANTLR? Not possible...?

Not possible, but not only not possible in ANTLR, but impossible in the
general sense.


More information about the antlr-interest mailing list