[antlr-interest] Cannot explain "no viable alternative at input" - antlr 3.0.1
John B. Brodie
jbb at acm.org
Wed Mar 10 19:42:42 PST 2010
Greetings!
On Thu, 2010-03-11 at 14:01 +1100, J. Matthew Pryor wrote:
> I am a total ANTLR newbie,
Welcome to the crowd!
...stuff snipped...
> so when I give it the input
>
> true && true
>
> despite the fact that I get the following consle messages
>
> line 1:5 no viable alternative at input '&&'
> line 0:-1 no viable alternative at input '<EOF>'
>
> My method band() gets called with 2 Boolean, both set to true
>
... more snipped, sorry, trying to trim to the essence of my reply...
> relExpr returns [Object value]
> : e=expr {$value = $e.value;}
> ( '>' e=expr {$value = gt($value,$e.value);}
> | '<' e=expr {$value = lt($value,$e.value);}
> | '>=' e=expr {$value = gte($value,$e.value);}
> | '<=' e=expr {$value = lte($value,$e.value);}
> | '==' e=expr {$value = eq($value,$e.value);}
> | '!=' e=expr {$value = neq($value,$e.value);}
> )
> ;
>
the second operand of relExpr is not optional. so `true` all by itself
is NOT a valid relExpr.
I think you want to add a `?` meta-operator to make the second operand
optional.
Hope this helps...
-jbb
More information about the antlr-interest
mailing list