[antlr-interest] some questions

Balvinder Singh bals1978 at hotmail.com
Wed Jun 12 11:12:42 PDT 2002


I want max matching as flex does.

eg

MUL : '*' ;
EXP : "**" ;

so on seeing "**" lexer should return EXP rather than MUL MUL


balvinder



>From: Greg Lindholm <glindholm at yahoo.com>
>Reply-To: antlr-interest at yahoogroups.com
>To: antlr-interest at yahoogroups.com
>Subject: Re: [antlr-interest] some questions
>Date: Wed, 12 Jun 2002 11:02:19 -0700 (PDT)
>
>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/




_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com


 

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



More information about the antlr-interest mailing list