[antlr-interest] SQL grammar, keywords that can be identifiers

Pete Forman pete.forman at westerngeco.com
Fri Jul 23 02:23:15 PDT 2004


At 2004-07-22 22:33 +0300, Ruslan Zasukhin wrote:
>join_type
>     :    ("left" | "right" | "full" ) ( "outer"! )?
>
>
>But SQL grammar still must accept the next query
>
>     WHERE left(fld,5) = "Peter"
>           ^^^^^

So the problem is that a token may be a keyword or not depending on
the context.

This might be soluble in the lexer using either lexer states or lexer
switching.  However that is moving rather a lot of the logic from the
parser to the lexer and does not look to be a promising approach.

I would have the lexer aggressively return tokens whenever a keyword
might be valid.  The parser would then accept keywords in places where
identifiers are expected and call setType to make them into
identifiers.

join_type
   : (LEFT | RIGHT | FULL) (OUTER!)?;

where_clause
   : WHERE identifier LPAREN ...

identifier
   : IDENTIFIER
   | (LEFT | RIGHT | FULL | OUTER) {##.setType(IDENTIFIER);};

My syntax is not checked but hopefully you'll get the idea.

-- 
Pete Forman                -./\.-  Disclaimer: This post is originated
WesternGeco                  -./\.-   by myself and does not represent
pete.forman at westerngeco.com    -./\.-   opinion of Schlumberger, Baker
http://petef.port5.com           -./\.-   Hughes or their divisions.



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

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



More information about the antlr-interest mailing list