|How to process unary minus for constants by other way than expressions firstname.lastname@example.org (Marek Peca) (2007-03-14)|
|Re: How to process unary minus for constants by other way than express email@example.com (Sylvain Schmitz) (2007-03-14)|
|From:||Sylvain Schmitz <firstname.lastname@example.org>|
|Date:||14 Mar 2007 23:25:04 -0400|
|Posted-Date:||14 Mar 2007 23:25:04 EDT|
Marek Peca wrote:
> [...] then, I changed to
> expr: NUMBER
> | expr_nonnum
> expr_nonnum: '(' expr ')'
> | '(' expr ')'
> | expr '+' expr
> | expr '-' expr
> | expr '^' expr
> | '-' NUMBER %prec UNNUM
> | '-' expr_nonnum %prec UNEXP
> but without success.
What about the following? Unary minus has a stronger precedence anyhow.
expr: expr '+' expr
| expr '-' expr
| expr '^' expr
expr_unary: '-' NUMBER
| '-' expr_unary
| '(' expr ')'
I am afraid it won't solve all your issues, since "------3" will not
evaluate to a single "3" tree node. I didn't see any variables in your
syntax, and thus I do not quite understand why you should evaluate your
AST several times, as the result ought to remain the same.
On the other hand, if you do have variables in your expressions, then
you could distinguish variable expressions from constant ones in your
grammar with the same kind of trick. Nonetheless, I would favor
evaluating the constant parts of the expression AST over obfuscating
Hope that helps,
Return to the
Search the comp.compilers archives again.