[antlr-interest] ANTLR 3 newbie question: Decision can match using multiple alternatives

David Holroyd dave at badgers-in-foil.co.uk
Fri Apr 27 04:11:38 PDT 2007


On Fri, Apr 27, 2007 at 02:51:46AM -0700, Ivo Jimenez wrote:
> The rules I have for these are the following:
> 
> predicate
>   : row_value_constructor ( comparison_predicate | in_predicate |
> null_predicate )
>   | exists_predicate
>   ;
> 
> comparison_predicate
>   : ( '=' | '<>' | '<' | '<=' | '>' | '>=' ) ( quantifier )?
>            ( row_value_constructor | '(' subquery ')' )
>   ;
> 
> in_predicate
>   : ('not')? 'in' '(' subquery ')'
>   ;
> 
> null_predicate
>   : 'is' ('not')? 'null'
>   ;
> 
> exists_predicate
>   : 'exists' '(' subquery ')'
>   ;
> 
> row_value_constructor
>   : expression_list
>   ;
> 
> quantifier
>   : 'any' | 'some' | 'all'
>   ;
> 
> expression_list
>   : expression ( ',' expression )*
>   ;
> 
> expression
>   : character_expression
>   | numeric_expression
>   ;
> 
> character_expression
>   : atom ( '|' '|' atom )*
>   ;
> 
> numeric_expression
>   : numeric_term ( ( '+' | '-' ) numeric_term )*
>   ;
> 
> numeric_term
>   : numeric_factor ( ( '*' | '\\' ) numeric_factor )*
>   ;
> 
> numeric_factor
>   : ( '+' | '-' )? atom
>   ;
> 
> atom
>   : NUMBER
>   | STRING
>   | column_reference
>   | aggregate_function
>   | other_function
>   | '(' expression ')'
>   ;
> 
> // Lexer
> WS    : (' ' |'\t' |'\n' |'\r' )+ { skip(); } ;
> NL    : '\r' ? '\n';
> NUMBER: ( '0'..'9' )+ ( '.' ( '0'..'9' )+ )?;
> STRING: '\'' ( LETTER | '0'..'9' | '_' | '\\' | ' ' | '-' | '>' | '='
> | '<' | '+' )+ '\'';
> ID    : LETTER ( LETTER | '0'..'9' | '_' )*;
> LETTER: ('a'..'z' | 'A'..'Z');
> 
> When I call ANTLR I get the following:
> 
> ANTLR Parser Generator  Version 3.0b7 (April 12, 2007)  1989-2007
> warning(200): SqlV3.g:248:34: Decision can match input such as "','
> {ID, 'avg'..'nullifzero'}" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> warning(208): SqlV3.g:842:1: The following token definitions are
> unreachable: NL,LETTER
> 
> Where line 248 is the expression_list: expression ( ',' expression )*;
> line and 842 the LETTER line. I've even bought the ANTLR 3 book in
> search of an answer and I know it is there (section 11.5 Ambiguities
> and Non-determinisms) but I can't see it.

Is ',' allowed elsewhere in your grammar?  I can't see the problem in
the snippet given (could just be that I missed it ;) so maybe more
context is needed.

Have you tried using the grammar visualisation tools in ANTLRWorks to
debug the issue?


ta,
dave

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list