[antlr-interest] Warning/ambiguity suppression

Nigel Sheridan-Smith nbsherid at secsme.org.au
Fri Jul 22 05:21:19 PDT 2005



> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Olivier Dragon
> Sent: Friday, 22 July 2005 10:06 PM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Warning/ambiguity suppression
> 
> You could use predicates and match a non-identifier character after the
> word (you could have a variable named trueThat or falseData).
> 
> TRUE:
> 	("true" ~(IDENTCHAR))=> "true" ;
> FALSE:
> 	("false" ~(IDENTCHAR))=> "false" ;
> 
> protected IDENTCHAR:
> 	('a'..'z'|'A'..'Z'|'0'..'9'|'_') ;
> 

Alternatively, you could make "true" and "false" literals to be tested, by
moving them out of the lexer and into the parser.

Remove these from lexer:

TRUE:"true";
FALSE:"false";


And modify this in parser:

primaryExpression
	:	"true"
	  | "false"
    | constant
    |	identPrimary
	  |	LPAREN! logicalOrExpression RPAREN!
	;


They will be treated as IDENT tokens until the test for literals, and then
converted to "literal_TRUE" and "literal_FALSE" tokens. Consequently, you
might need to modify the tokens{} section of your parser accordingly, since
you are generating a Heterogeneous AST.

Nigel

--
Nigel Sheridan-Smith
PhD research student

Faculty of Engineering
University of Technology, Sydney
Phone: 02 9514 7946
Fax: 02 9514 2435




More information about the antlr-interest mailing list