[antlr-interest] One more ambig in SQL grammar

Ruslan Zasukhin sunshine at public.kherson.ua
Mon Sep 2 07:25:32 PDT 2002


Hi All,

I have meet last and hardest ambig warn, that I cannot resolve after 5-6
hours of working. The following are rules of interest:

//-------------------------------------------------------------------------
from_clause
    :    "from"^ table_reference ( COMMA table_reference )*
    ;

subquery
    :    LPAREN query_expression RPAREN
    ;

//-------------------------------------------------------------------------
query_expression
    :    query_term (( "union"^ | "except"^ ) ( "all" )? query_term)*
    ;
    
query_term
    :    query_primary ("intersect"^ ( "all" )?  query_primary)*
    ;

query_primary
    :    "values"^ table_value_constructor_list
    |    "table"^ table_name
    |    "select"^ ( set_quantifier )? select_list table_expression
    |    table_reference
    ;
    
//-------------------------------------------------------------------------
table_reference
    :    non_join_table
          ( (join_type)? "join"^ table_reference ( join_specification )? )*
    ;
    
non_join_table
    :    (table_name ("as")? correlation_name) => table_name ("as")?
correlation_name
    |    table_name
    |    (subquery ("as")? correlation_name) => subquery ("as")?
correlation_name
    |    subquery
    ;

join_specification
    :    "on" search_condition
    |    "using" LPAREN column_name_list RPAREN
    ;

join_type!
    :    ("left" | "right" | "full" ) ( "outer" )?
    |    "inner"
    |     "union"           <<<<<< LINE:  LL44
    ;
//-------------------------------------------------------------------------

Offended is rule table_reference and its line
          ( (join_type)? "join"^ table_reference ( join_specification )? )*

ANTLR give warn:
    "ambiguity on k=1 "union" between branch 1 and exit branch."

1) Yes, I see *why* thi warn comes.

2) if comment line {LINE:  LL44}  then no warn, and I get CORRECTLY working
grammar. I have check on tests.

3) PROBLEM is that I cannot find NOT syntax predicate, not semantic
predicate that can resolve this warning.

For example I have try the next

//-------------------------------------------------------------------------
table_reference
    :    non_join_table
         ( ((join_type)? "join") =>
                (join_type)? "join"^ table_reference ( join_specification )?
         |  /* nothing */
         )*
    ;


//-------------------------------------------------------------------------
table_reference
    :    non_join_table
         ( ((join_type)? "join") =>
                (join_type)? "join"^ table_reference ( join_specification )?
         |  ("values"|"table"|"select"|LPAREN) => /* exit, do nothing */
         )*
    ;



 

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



More information about the antlr-interest mailing list