Expression Language Problem [message #686037] |
Tue, 21 June 2011 09:19  |
Eclipse User |
|
|
|
Hi,
I want to create a grammar which combines bool and arithmetic expressions with grouping (parenthesis) like:
( 1 == 2 and ( 1 < ( 1+2) ) and not(2 > 3) ).
My actual grammar (based on the example in the docu for Expression + Expression) has the problem that '1 AND 2' would be valid, too.
Is there a way to fix this in the grammar or is an additional validation like the IConcretSytaxValidator required? What about the content-proposal if the 'additional' validator must be used?
I found several similar grammars in the forum but it seems they have the same 'problem'...
//
//short version with combined expressions for and|or and +|-|*|/ ...
//
ExpressionBoolBinary returns OperationBool:
ExpressionBoolUnary ({OperationBool.left=current}
op=('AND'|'OR')
right=ExpressionBoolBinary)?
;
ExpressionBoolUnary returns OperationBool:
('NOT')? unary=TerminalExpressionBool
;
//would be the terminal if bool only...
TerminalExpressionBool returns Operation:
ExpressionBoolCompare |
{BoolLiteral} value = ('TRUE'|'FALSE')
;
ExpressionBoolCompare returns Operation:
Expression ({Operation.left=current}
op=('=='|'<'|'>')
right=ExpressionBoolCompare)?
;
Expression returns Operation:
TerminalExpression ({Operation.left=current}
op=('+'|'-'|'*'|'/')
right=Expression)?
;
TerminalExpression returns Operation:
'(' ExpressionBoolBinary ')' |
{Function} func=('sin'|'cos') '(' param=IntLiteral ')'|
literal=IntLiteral
;
IntLiteral: value = INT;
many thanks
gerit
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05598 seconds