On Tue, 2011-03-22 at 14:40 -0700, Hiten R wrote:
> John/All
>
> I followed 'antlr wiki' example but then it stopped working
> completely. Previous way it was complaining about the second line but
> after the change it could not get past the first line 'funny boys are
> Tom Hardy Donald '.
>
> Exception
> line 1:0 no viable alternative at input 'funny'
>
> I am not much familiar with ANTLR but can you give me another example
> or point me to getting quoted string resolved.
>
> Thx
> Hitender
>
> BEFORE [ignore caps please]
> start
> : 'funny' call_funny_parse
> | 'serious' call_serious_parse
> ;
>
> AFTER - ANTLR WIKI [ignore caps please]
> start
> : lexer_funny
> | lexer_serious
> ;
>
> lexer_funny : {input.LT(1).getText().equals("funny")}?
> call_funny_parse;
> lexer_serious : {input.LT(1).getText().equals("serious")}?
> call_serious_parse;
i have not used token look ahead very much so I am fuzzy about this.
but i think LT(1) looks ahead 1 token without actually consuming any
token. so after your predicate the token stream is still positioned at
the "funny" token so you need to consume it before the call_funny_parse.
something like (very much untested!!!)
start
: {input.LT(1).getText().equals("funny")}? TOKEN call_funny_parse
| {input.LT(1).getText().equals("serious")}? TOKEN call_serious_parse
| /* whatever is appropriate if neither funny nor serious is present*/
;
hope this helps...
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.