Réf. : RE: [antlr-interest] Warning/ambiguity suppression
loic.lefevre at bnpparibas.com
loic.lefevre at bnpparibas.com
Fri Jul 22 05:31:24 PDT 2005
Indeed, the grammar was like that at the beginning.
After the changes, I had to change the primaryExpression rule to:
// the basic element of an expression
primaryExpression
: !"true" { #primaryExpression=#[TRUE,"TRUE"]; }
| !"false" { #primaryExpression=#[FALSE,"FALSE"]; }
| constant
| identPrimary
| LPAREN! logicalOrExpression RPAREN!
;
And now everything works perfectly.
Thanks Nigel and Oli.
Loïc
Internet
nbsherid at secsme.org.au@antlr.org - 22/07/2005 14:21
Envoyé par : antlr-interest-bounces at antlr.org
Pour : antlr-interest
cc :
Objet : RE: [antlr-interest] Warning/ambiguity suppression
> -----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
This message and any attachments (the "message") is
intended solely for the addressees and is confidential.
If you receive this message in error, please delete it and
immediately notify the sender. Any use not in accord with
its purpose, any dissemination or disclosure, either whole
or partial, is prohibited except formal approval. The internet
can not guarantee the integrity of this message.
BNP PARIBAS (and its subsidiaries) shall (will) not
therefore be liable for the message if modified.
---------------------------------------------
Ce message et toutes les pieces jointes (ci-apres le
"message") sont etablis a l'intention exclusive de ses
destinataires et sont confidentiels. Si vous recevez ce
message par erreur, merci de le detruire et d'en avertir
immediatement l'expediteur. Toute utilisation de ce
message non conforme a sa destination, toute diffusion
ou toute publication, totale ou partielle, est interdite, sauf
autorisation expresse. L'internet ne permettant pas
d'assurer l'integrite de ce message, BNP PARIBAS (et ses
filiales) decline(nt) toute responsabilite au titre de ce
message, dans l'hypothese ou il aurait ete modifie.
More information about the antlr-interest
mailing list