[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.modeling.tmf] Re: Removing left recursion...
|
Thanks for the tips! I managed to get a bit further :p
I managed to come to the arithmetic expression part of the grammar. I tried to use your tips but I still got some left recursion that I can't remove.
Here's the full grammar:
grammar SvtObjSpec with org.eclipse.xtext.common.Terminals
generate svtObjSpec "http://SvtObjSpec"
Spec:
'#definitions'
(definitions+=Definition ';')*
'#assumptions'
(assumptions+=LogicExpression ';')*
'#requirements'
(requirements+=LogicExpression ';')*
;
Definition:
atom=ID
expression=LogicExpression;
LogicExpression :
(TerminalBinaryExpression ({Operation.left=current} op=LogicBinOperator)?)
| (TerminalArithmeticExpression ({Operation.left=current} op=CompareOperation)?)
;
TerminalBinaryExpression returns LogicExpression:
'(' LogicExpression ')'
| atom=ID
| "TRUE"
| "FALSE"
;
LogicBinOperator:
'&'
| '#'
| '->'
| '<->'
| '<-'
| '#!';
LogicUnOperator :
'~'
| '@';
TerminalArithmeticExpression returns LogicExpression:
var=ID
| number=INT
| BinaryArithmeticExpression
| UnaryArithmeticExpression
| '(' TerminalArithmeticExpression ')'
;
BinaryArithmeticExpression:
expression=TerminalArithmeticExpression ({Operation.left=current} op=ArithmeticBinOperator)?;
ArithmeticExpressionList :
expression=TerminalArithmeticExpression
(',' expressionList=ArithmeticExpressionList)?;
UnaryArithmeticExpression:
op=ArithmeticUnOperator expression=TerminalArithmeticExpression;
MinMaxExpression:
('MIN' | 'MAX') '(' ArithmeticExpressionList ')';
ArithmeticBinOperator:
'+'
| '-'
| '*'
| '/'
| '%';
ArithmeticUnOperator: '-';
CompareOperation:
'<'
| '<='
| '>'
| '>='
| '<>'
| '=';
And these are the errors I get:
error(210): The following sets of rules are mutually left-recursive [ruleTerminalArithmeticExpression, ruleBinaryArithmeticExpression]
error(210): The following sets of rules are mutually left-recursive [ruleTerminalArithmeticExpression, rule__BinaryArithmeticExpression__Group__0, rule__BinaryArithmeticExpression__ExpressionAssignment_0, rule__TerminalArithmeticExpression__Alternatives] and [ruleTerminalArithmeticExpression, ruleBinaryArithmeticExpression, rule__BinaryArithmeticExpression__Group__0, rule__BinaryArithmeticExpression__ExpressionAssignment_0, rule__TerminalArithmeticExpression__Alternatives]
I'm thankful for any tips!
Best regards
Henrik