[antlr-interest] some questions

Greg Lindholm glindholm at yahoo.com
Wed Jun 12 11:02:19 PDT 2002


Q1) Ask yourself this; if you have a single digit say '5' do you want
the lexer to return an Integer token or a Digit token?  In a context
free lexer you have to decide which you want. Normally you
would expect to see the Digit rule "protected" so it can be used in
other rules but never returned.

If your context isn't free then you probably should have different
lexers and switch between them as your context changes.  This is
discussed in the ANLTR docs in the section on Token Streams and
Multiplexing.

Q2) No, but the multiple lexer solution might work for this as well.

Greg


--- Balvinder Singh <bals1978 at hotmail.com> wrote:
> Hi...
> 
> Question 1
> 
> I have following lexer, in which I want both Digit and Integer to be
> accesed 
> from parser, but obiviously these two rule have conflict.
> 
> Can't we do some kind of maximum matching as we can do in Flex.
> 
> class Test extends Lexer;
> options{
> k=2;
> }
> 
> Digit : '0' .. '9' { System.out.println("Digit "+ $getText);}
>       ;
> 
> Integer : ( options {greedy=true;} :Digit)+ {
> System.out.println("Integer "+ 
> $getText);}
>         ;
> 
> 
> Question 2
> 
> During parsing I want some token, and this token may have some
> conflicts 
> with other tokens , is there any way that parser could tell lexer
> that first 
> search the desired token and if not found then search for others.
> 
> 
> thanx
> 
> balvinder
> 
> 
> 
> 
> _________________________________________________________________
> Send and receive Hotmail on your mobile device: http://mobile.msn.com
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/ 
> 
> 


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list