|
|
|
|
|
Re: Xtext grammar [message #1731522 is a reply to message #1731446] |
Fri, 06 May 2016 12:47 |
RamaRao Nandamuri Messages: 120 Registered: April 2016 |
Senior Member |
|
|
Model:
(variables+=Variable)*
;
Variable:
name=ID '=' expression=Expression
;
Expression:
BooleanExpression;
BooleanExpression returns Expression:
Comparison
(({AndOrExpression.left=current} op=("||"|"&&")) right=Comparison)*;
Comparison returns Expression:
Equals
(({Comparison.left=current} op=("<") ) right=Equals)*;
Equals returns Expression:
Addition
(({Equals.left=current} op=("==") ) right=Addition)*;
Addition returns Expression:
Multiplication
(({Plus.left=current} '+' | {Minus.left=current} '-')
right=Multiplication)*;
Multiplication returns Expression:
Prefixed (({MultiOrDiv.left=current} op=("*"|"/")) right=Prefixed)*;
Prefixed returns Expression:
{BooleanNegation} =>"!" expression=Atomic | /* right associativity */
{ArithmeticSigned} =>"-" expression=Atomic | /* right associativity */
Atomic;
Atomic returns Expression:
'(' Expression ')' |
{NumberLiteral} value=INT |
{StringLiteral} value=STRING |
{BooleanLiteral} value=('true'|'false') |
{VariableReference} ref=[Variable]
;
// the types will be used only internally by the type system
Type:
{IntType} 'int' |
{StringType} 'string' |
{BooleanType} 'boolean'
;
[Updated on: Fri, 06 May 2016 13:38] Report message to a moderator
|
|
|
|
Re: Xtext grammar [message #1731526 is a reply to message #1731523] |
Fri, 06 May 2016 13:29 |
|
well i had hoped for a minimal reproducable example not 200 lines of grammar.
the there is a question you have to answer: a assignment can start with a assignment?
Assignment: ('math')? (expression+=Expression '=' expression+=Expression) (',' expression+=Expression'=' expression+=Expression)*;
Expression:
Primary
;
Primary returns Expression: value+=NUMBER |assignment+=Assignment
;
i dont know if that is intended
thats the point of the left recusion.
what should happen here ?!?
and it makes no sense to me since this is already handled on assignmentlevel ?!?
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.03647 seconds