Allow negative unary expression in combination with subtraction [message #1782285] |
Wed, 21 February 2018 10:10 |
Chris X Messages: 60 Registered: November 2017 |
Member |
|
|
Hi guys,
in my grammar I have the following expression rules:
Expression returns Expression :
Assignment;
Assignment returns Expression :
{Assignment} feature=[ecore::EObject|ID] OpSingleAssign value=Assignment |
OrExpression;
OpSingleAssign:
"="
;
OrExpression returns Expression:
AndExpression (=>({BinaryOperation.left=current} op=OpOr) right=AndExpression)*;
OpOr:
'||';
AndExpression returns Expression:
EqualityExpression (=>({BinaryOperation.left=current} op=OpAnd) right=EqualityExpression)*;
OpAnd:
'&&';
EqualityExpression returns Expression:
RelationalExpression (=>({BinaryOperation.left=current} op=OpEquality)
right=RelationalExpression)*
;
OpEquality:
'==' | '!=' ;
RelationalExpression returns Expression:
AdditiveExpression (
=>({InstanceOfExpression.left=current} 'instanceof' type=[ecore::EObject|ID]) |
=>({BinaryOperation.left=current} op=OpCompare) right=AdditiveExpression
)*
;
OpCompare:
'>=' | '<' '=' | '>' | '<' ;
AdditiveExpression returns Expression:
MultiplicativeExpression (=>({BinaryOperation.left=current} op=OpAdd) right=MultiplicativeExpression)*
;
OpAdd:
'+' | '-'
;
MultiplicativeExpression returns Expression:
ExponentExpression (=>({BinaryOperation.left=current} op=OpMul) right=ExponentExpression)*
;
OpMul:
'*' | '/'
;
ExponentExpression returns Expression:
UnaryOrPrimitivExpression
(=>({BinaryOperation.left=current} op=OpExponent) right=ExponentExpression)?;
OpExponent:
'**';
UnaryOrPrimitivExpression returns Expression
: PostfixOperation
| UnaryOperation
;
UnaryOperation returns Expression:
({UnaryOperation} op=OpUnary operand=PrimitivExpression)
;
OpUnary:
'!' | '-'
;
PostfixOperation returns Expression:
PrimitivExpression =>({PostfixOperation.operand=current} op=OpPostfix)?
;
OpPostfix:
'++' | '--'
;
PrimitivExpression returns Expression:
LiteralExpression |
ParenthesizedExpression
;
...
With this grammar it's not possible to parse expressions like -6-7 and so far I have no idea how to solve this issue.
Has someone an idea to fix this?
I also had a look to the b3-project (https://github.com/eclipse/b3/blob/master/org.eclipse.b3.beelang/src/org/eclipse/b3/BeeLang.xtext), maybe I'm wrong, but I would say this grammar has the same problem or not?
Many thanks and have a nice day!
[Updated on: Wed, 21 February 2018 10:17] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03401 seconds