[antlr-interest] ANTLR grammar: Clarifications needed

Anakreon anakreonmejdi at yahoo.gr
Wed Apr 28 14:48:18 PDT 2004


Bharath S wrote:
> Hi Antlers,
> 
> I have a rule of the form: 
> **
> Statements: (statement)* ;
> **
> and I get a warning "Non-determinism between Alt 1 and exit branch of
> block". If I use the "warnWhenFollowAmbig = false" command, I still get the
> error. Any ideas?
> 
> Also, I am wondering how to differenciate between two rules, BOOLEAN and
> INTEGER in the lexer. They are of the form:
> 
> BOOLEAN: '1'|'0';
> INTEGER: ('0'..'9')+(UNDERSCORE ('0'..'9')+ )?;
> 
> Can I differenciate these rules without making them "protected"?
> 
> Thanks!!
> 
> Bharath.

I would declare only rule NUMBER in the lexer.
Then I would have a rule lat's call it bool_rule
bool_rule
   :
   n:NUMBER {
    int val = Integer.parseInt(#n.getText());
    if (val < 0 || val > 1) {
       throw new ANTLRException(...);
    }
    #n.setType(BOOLEAN);
   }
   ;
Then whenever a boolean is expected I'd call the bool_rule.
Perhaps a decendant of ANTLRException should be thrown.


 
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