Loading ...
Sorry, an error occurred while loading the content.
 

One more ambig in SQL grammar

Expand Messages
  • Ruslan Zasukhin
    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:
    Message 1 of 1 , Sep 2, 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 message has been successfully submitted and would be delivered to recipients shortly.