[antlr-interest] Re: SQL grammar, keywords that can be identifiers
olejohnaske
ole.john.aske at sun.com
Mon Jul 26 03:03:43 PDT 2004
--- 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.
>
Are you sure this is a real problem?
At least according to the SQL92 standard, <reserved words> are not
allowed as identifiers: My copy of ISO/IEC9075:1992 (SQL92), chapter
5.2, Part 11) in the 'Syntax rule' states:
11)
The <identifier body> of a <regular identifier> .... shall not be
equal according to the comparison rules in Subclause 8.2 ... to any
<reserved words> ....
(Removed some lengthy sql92 phrases where '....' is inserted)
Both Table name and column names are defined as <identifiers> which
has an <identifier body>. According to this, your examples above are
not correct SQL92 syntax. (However, it may be allowed by some
implementation which extends the standard... )
Note: Identifier can be a <non-reserved words>. I handle this in my
SQL92 parser by:
nonReservedWords :
CATALOG_NAME | CHARACTER_SET_CATALOG | .... lots more... ;
identifier :
IDENT
| DELIMITED_IDENT
| nonReservedWord
;
Ole John Aske
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