[antlr-interest] "No viable alternative" error

Todd Nine tnine at apigee.com
Sun Mar 25 11:10:18 PDT 2012


Sorry, I forgot to send this to the list.

On Sun, Mar 25, 2012 at 10:46 AM, Todd Nine <tnine at apigee.com> wrote:

> Thanks Karol, that fixed it!
>
> On Sun, Mar 25, 2012 at 7:12 AM, Karol Młot <karol.mlot at gmail.com> wrote:
>
>> Hi Todd,
>>
>> From what I can see in your grammar, your first lexer rule is ID and
>> it happends to match 'lt', so lexer returns token ID and not LT, as
>> you expect. Why? Because ID comes first, and lexer rules are processed
>> top to bottom. Solution would be moving ID rule down, after LT rule.
>> Hope that helps.
>>
>> Kind regards,
>> Karol
>>
>> On Sun, Mar 25, 2012 at 5:03 AM, 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