Hi John,
In order to implement unary expressions I used a grammar structured like
the following:
AdditiveExpression = MultiplicativeExpression AdditiveExpressionTail* ;
AdditiveExpressionTail = (ADD | SUB) MultiplicativeExpression ;
MultiplicativeExpression = UnaryExpression MultiplicativeExpressionTail* ;
MultiplicativeExpressionTail = (MUL | DIV) UnaryExpression ;
UnaryExpression = SUB ConstantOrPostfixExpression
| ConstantOrPostfixExpression ;
Which, for a simple expression like -4 + 5 gives a parse tree of
AdditiveExpression
|->MultiplicativeExpression
|->UnaryExpression
|->SUB
|->ConstantOrPostfixExpression (4)
|->AdditiveExpressionTail
|->ADD
|->MultiplicativeExpression
|->UnaryExpression
|->ConstantOrPostfixExpression (5)
It's been a while since I've touched this stuff but that's the gist of it.
Cheers,
Iain
John Ledbetter wrote:
Hello,
I am working with a grammar for a simple mathematical language, and I
am having trouble implementing a unary minus sign.
In flex/bison, I would do something like...
%left PLUS MINUS
%nonassoc UNARY
// ....
somerule : expr MINUS expr
| MINUS expr %prec UNARY
What is the equivalent construct in grammatica?
Thanks,
John.
________________________________________________________________________
This email (and any attachments) is private and confidential, and is
intended solely for the
addressee. If you have received this communication in error please
remove it and inform us via
telephone or email. Although we take all possible steps to ensure mail
and attachments
are free from malicious content, malware and viruses, we cannot accept
any responsibility
whatsoever for any changes to content outwith our administrative bounds.
The views represented
within this mail are solely the view of the author and do not reflect
the views of the organisation
as a whole.
________________________________________________________________________
Graham Technology plc
http://www.grahamtechnology.com
________________________________________________________________________
_______________________________________________
Grammatica-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/grammatica-users