[antlr-interest] Again Infinite recursion on SQL table_ref <-> join_table

John B. Brodie jbb at acm.org
Fri Aug 30 10:12:49 PDT 2002


>   >> joined_table
>   >>     :    table_reference "join" table_reference
>   >>     ;
>   >> 
>   >> 

Observe that the "join" keyword is *required* here - the "join" must
appear 1 or more times in any valid statement containing a joined_table.

>   >> table_reference
>   >>     :    table_name             // IDENT
>   >>     |    subquery               // '(' query ')'
>   >>     |    joined_table
>   >>     ;
>   >> 
>   >> This 2 rules give this error: infinite recursion.
>   >> 
>   >> Anybody know how this can be resolved ?

Observe that the "join" keyword is optional here - the "join" may
appear 0 or more times in any valid statement containing a table_reference.

>   > 
>   > I don't know much about SQL, but try this:
>   > 
>   > primitive_element
>   >   :    table_name             // IDENT
>   >   |    subquery               // '(' query ')'
>   >   ;
>   > 
>   > table_reference
>   >   :    primitive_element ( "join" primitive_element )*
>   >   ;
>
>   Or in other words:
>
>   joined_table
>       :    table_reference ("join" table_reference)*
>       ;
>
>   table_reference
>       :    table_name             // IDENT
>       |    subquery               // '(' query ')'
>       ;
>
>   Wow, it looks this must work.  Thank you very much, Bogdan!  :-)
>

The last two rules do not correctly capture the facts that at least 1
"join" is required for a joined_table and is optional in a
table_reference. But maybe this doesn't really matter, would need to
analyze the usage of the joined_table and table_reference rules in the
rest of your grammar.

Bogdan's solution appears to be better, with the addition of a rule

joined_table : primitive_element ( "join" primitive_element )+ ;

to his rules, which are

primitive_element
  :    table_name             // IDENT
  |    subquery               // '(' query ')'
  ;

table_reference
  :    primitive_element ( "join" primitive_element )*
  ;

Hope this helps...

 

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



More information about the antlr-interest mailing list