[antlr-interest] ANTLR grammar: Clarifications needed

Mark Lentczner markl at glyphic.com
Wed Apr 28 14:24:33 PDT 2004


> 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"?

Well, that depends on what you mean by these rules.  How should these 
parse? :
	" 1 " ==> BOOLEAN<1> or NUMBER<1> ?
	" 10 " ==> NUMBER<10> or BOOLEAN<1>, BOOLEAN<0> ?
If the answer depends on the parsing context, then no, you generally 
cannot differentiate these rules in the lexer.  (Actually you can, by 
having the parser set state back in the lexer, but that should be 
considered a last-resort sort of solution.)

Typically, the lexer would simply tokenize these as all NUMBER, and 
then it the parser, which knows when it is in a boolean context, can 
place a constraint on the values of NUMBER that it accepts.

	- Mark



 
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