[antlr-interest] Found an error with UNARY_MINUS and typecast in java.g

Terence Parr parrt at cs.usfca.edu
Mon Jun 6 18:13:56 PDT 2005


On Jun 6, 2005, at 5:59 PM, Mark Bednarczyk wrote:

> I found an error in the logic of java.g when it comes to parsing
> UNARY_MINUS and UNARY_PLUS after a typecast. Who do I report the
> problem to?
>
> Here is an example:
> -(int)2 != (int)-2;
>
> Generates this AST tree:
> ( [AST ROOT,<<0>>] ( EXPR ( [!=,<NOT_EQUAL>] ( [-,<UNARY_MINUS>]
> ( [(,<TYPECAST] ( TYPE [int,<IDENT>] ) [2,<NUM_INT>] ) ) (
> [-,<MINUS>] [int,<IDENT>] [2,<NUM_NT>] ) ) ) )
>
> You can see that on the lefthand side of the expression it
> generates the correct tree, UNARY_MINUS, TYPECAST , IDENT and
> the NUM_INT. Then on the right things go wrong, I get a MINUS
> instead of UNARY_MINUS, a IDENT instead of a TYPECAST with
> IDENT.
>
> I don't mind creating a patch for this and submitting it, as I
> would like this problem fixed in the java.g grammar instead of
> in my NPL.g file as I'm just inheriting and would like to be
> upgradable to new versions of java.g and keep number of
> overrides of underlying java grammar in my NPL grammar to a
> minimum.

Hi Mark,

Send me the tweak to the rule and I'll update the grammar.

Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com



More information about the antlr-interest mailing list