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

thrutchy eric_mahurin at yahoo.com
Fri Jul 23 12:31:44 PDT 2004


Here is another solution: don't use keywords.  Use semantic predicates
to determine if an identifier matches a "keyword" only when you are in
the context to find that keyword.  I'm doing something similar in a
lexer, but I see no reason why you couldn't do this in a parser:

join_type : lrf:ID {
    lrf.getText().equals("left") || 
    lrf.getText().equals("right") || 
    lrf.getText().equals("full")
}? ( outer:ID { outer.getText().equals("outer") }? )? ;

I haven't tried this out in a parser, so be warned.

- Eric

--- In antlr-interest at yahoogroups.com, Ruslan Zasukhin <sunshine at p...>
wrote:
> Hi All,
> 
> It seems in the past we have discuss this, but I want ask once again.
> 
> We have SQL grammar.
> 
> We have for example the next rule
> 
> join_type
>     :    ("left" | "right" | "full" ) ( "outer"! )?
> 
> 
> But SQL grammar still must accept the next query
> 
>     WHERE left(fld,5) = "Peter"
>           ^^^^^  
> 
> 
> As you see problem is that 'left' is keyword.
> ANTLR mark it as token in Lexer.
> 
> So our function left() simple return error.
> 
> --------------
> Another example of problem. SQL by standard allow to use field and table
> names as key words.
> 
>     SELECT *
>     FROM references
>     
> Here "references" is name of table.
> But SQL also have key word 'references'.
> So we get conflict.
> 
> 
> -------------
> 1) Can anybody explain to __as child__
> 
>     how this can be resolved in ANTLR ?
> 
> 
> 2) does exists in ANTLR at least one example which demonstrate such hard
> grammars?  If no then, Terrence, may be there is sense to add one?
> May be some mini-SQL ?
> 
> Thank you in advance.
> 
> 
> -- 
> Best regards,
> Ruslan Zasukhin      [ I feel the need...the need for speed ]
> -------------------------------------------------------------
> e-mail: ruslan at p...
> web: http://www.paradigmasoft.com
> 
> To subscribe to the Valentina mail list go to:
> http://lists.macserve.net/mailman/listinfo/valentina
> -------------------------------------------------------------



 
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