[antlr-interest] NON-reserved Words

John Allen Green greenj at ix.netcom.com
Mon Apr 28 20:14:29 PDT 2003


--On 4/28/2003 11:53 PM +0000 Brian Hagenbuch wrote:

> I started down this road, but found it to be complicated to
> implement and hard/impossible to remove non-determinism.  So I'm 
> considering a different approach:
> 
> - Have the lexer treat non-reserved words as keywords and collect
>   them under a parser rule such as maybeIdentifier.
> 
> - In the parser, include maybeIdentifer in the rule for variable.
> 
> - Use syntactic predicates to distinguish the cases.


That's basically how I do it. I have an "identifier" rule in the parser,
which could be any ID token or unreserved keyword. (I have one rule with a
huge list of unreserved keywords.)  For the most part, a syntactic
predicate is not even needed - most of the time you know based on the
syntax when the next token needs to be an identifier.

I do one more thing too... if I consume an unreserved keyword (say, from
your example, CASE) when I was expecting an identifier, then I change the
node type to ID, to make subsequent tree parsers easier to use.

hth,
John
john at joanju dot com
www.joanju.com


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list