[antlr-interest] "No viable alternative" error

Benjamin S Wolf jokeserver at gmail.com
Sun Mar 25 09:54:53 PDT 2012


Probably your rule of

ID  :	('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'.')*

is matching 'lt', and the same with the other ones, so you aren't
getting LT tokens, but ID tokens. You might be able to fix this by
moving the ID rule after the LT, etc. rules; otherwise you'll need to
otherwise prevent ID from matching on that input.

On Sat, Mar 24, 2012 at 8:03 PM, Todd Nine <tnine at apigee.com> wrote:
> Hi guys,
>  I've attached my grammer file.  I'm getting the "no viable alternative"
> error when parsing.
>
> This statement works.
>
> "select * where a < 5"
>
> This one fails
>
> "select * where a lt 5"
>
>
> I'm a bit lost as to why, my rule for expression is defined in this way.
>
> //mathmatical equality operations
>
> equalityop :
>
>  property LT<LessThan>^ value
>
>  |property LTE<LessThanEqual>^ value
>
>  |property EQ<Equal>^ value
>
>  |property GT<GreaterThan>^ value
>
>  |property GTE<GreaterThanEqual>^ value
>
>  ;
>
>
> Then LT is this in my tokens
>
>
> LT : '<' | 'lt';
>
>
> Any help would be greatly appreciated!  All my operations for equality ops
> do it, so I know I've defined something incorrectly in my grammer.
>
>
> Thanks,
>
> Todd
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list