[antlr-interest] How to tell assignment from equal?

me 262 me262c at gmail.com
Wed May 2 08:36:10 PDT 2007


Thanks Miguel,

  It works as you pointed out.

  ASSIGN :	'=' ('='{$setType(COMPARE);})? ;

ME

On 5/2/07, Miguel Ping <miguel.ping at gmail.com> wrote:
> Hi,
>
> You can use a predicate to check for an '=' after the first '=' and
> then change the token type:
>
>
> ASSIGN : '=' ('=' {$type = COMPARE;} ) ? ;
>
> the ('=') ? rule checks for existence of the '=' in the ASSIGN token,
> after reading the first '='. The action {$type = COMPARE;} sets the
> token type >only< if the predicate is true, that is only if the lexer
> found a '=' after the first '='.
>
> Hope it helps,
> Miguel Ping
>
> On 5/2/07, me 262 <me262c at gmail.com> wrote:
> > Hi,
> >
> >   I am having problem with equal "==" and assign "=" in my grammar file.
> >
> > .......
> >       ASSIGN          : '='   ;
> > .......
> >
> >       COMPARE :
> >                       ( '<'
> >                       | "<="
> >                       | '>'
> >                       | ">="
> >                       | "=="
> >                       | "!="
> >                       );
> >
> > I get message:
> >
> > my.g: warning:lexical nondeterminism between rules ASSIGN and COMPARE upon
> > script.g:     k==1:'='
> > script.g:     k==2:<end-of-token>
> >
> > It must be a very common problem.
> > Thanks in advance!
> >
>


More information about the antlr-interest mailing list