What I am trying to do is allowing expression like 8 - - - 2 + 3.
program ::= expr:e
{: RESULT = ...; :}
;
expr ::= INTCONST:c
{: RESULT = ...; :}
| binaryExpr:e
{: RESULT = e; :}
| LPAREN expr:e RPAREN
{: RESULT = e; :}
| MINUS expr:e
{: RESULT = - e; :}
%prec UMINUS
;
binaryExpr ::= expr:e1 PLUS expr:e2
{: RESULT = ... :}
expr:e1 MINUS expr:e2
{: RESULT = ... :}
For the unary negation, I tried this
| MINUS expr:e
{: RESULT = - e; :}
%prec UMINUS
, but it says that the negative sign is a bad operand type.
Is there any tips to do unary negation?