[antlr-interest] Re: Multiple nondeterminism between lexer rules. (Ignore previous mail)

micheal_jor open.zone at virgin.net
Fri Apr 2 12:21:00 PST 2004


--- In antlr-interest at yahoogroups.com, Bharath S <payasam79 at y...> wrote:
> Hi Grp,
> 
> If I have lexer rules of this form:
> -----------------
> R1: A|B; 
> R2: C|D;
> 
> A: INT 'a'; 
> B: REAL 'a'; 
> 
> C: INT 'c';
> D: REAL 'd';
> -----------------
> 
> Here, I have to resolve nondeterminism betwee A and C
> and also between B and D. I tried to have two separate
> rules to handle both but it doesnt work. I can only
> handle one of them at a time but not both. Any ideas
> on how ANTLR handles this?
> 
> My determinism resolving rules:
> --------------------------------
> R1: (INT 'c') => R2 {$setType(R2);}
>     | (INT 'a') => R1 {$setType(R1);}
> 
> R2: (REAL 'a') => R1 {$setType(R1);}
>     | (REAL 'd') => R2 {$setType(R2);}
> 
> ---------------------------------------------

You should merge those rules into a single one like this:

R1 : INT 
    ( 'c'   { $setType(R2); }
    | 'a'
    )
  | REAL
    ( 'a'
    | 'd'  { $setType(R2); }
    )
  ;

Cheers,

Micheal
ANTLR/C#



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

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



More information about the antlr-interest mailing list