Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Comparison!!!(create a boolean expression combined with arthmetic operations)
Comparison!!! [message #818337] Sun, 11 March 2012 12:44 Go to next message
fay ab is currently offline fay abFriend
Messages: 1
Registered: March 2012
Junior Member
Hello,
first, excuse me for my English if you find some wrong sentenses.

I must write Xtext grammar for a project, and I'm jammed at some boolean expression,
this is the problem:

transition NomOfTransition [ Guard ] {
...
}

my problem is the Guard.

the grammar is:

System :
('System' name=ID '{'
(variables+=VariableDeclaration)*
transitions+=Transition+
'}'
)?
;

VariableDeclaration returns Variable:
name=ID '=' initVal=INT ';'|
aname=ID'['index=Addition']' '=' initVal=INT ';' //array
;

Transition:
'transition' name=ID '[' garde=(Or) ']' ('label' label=STRING)? '{'
(assignments+=Assignment )+
'}'
;



Assignment :
var=VariableRef '=' expr=Addition';'
;

Addition returns IntExpression:
Multiplication (
({Addition.left=current} '+' | {Subtraction.left=current} '-' )
right=Multiplication
)*
;

Multiplication returns IntExpression :
UnitaryMinus
(
({Multiplication.left=current} '*' | {Division.left=current} '/' | {Modulo.left=current} '%')
right=UnitaryMinus
)*
;

UnitaryMinus returns IntExpression :
('-'? Power {UnitaryMinus.val=current})
;


Power returns IntExpression:
Primary ({Power.left=current} '**' right=Primary)*
;

Primary returns IntExpression :
VariableRef | Constante | '(' Addition ')'
;

Constante:
val=INT
;

VariableRef :
var=[Variable]
;


Or returns BooleanExpression :
And ({Or.left=current} '||' right=And)*
;


And returns BooleanExpression:
Not ({And.left=current} '&&' right=Not)*
;


Not returns BooleanExpression :
('!' ? PrimaryBool {Not.val=current})
;


PrimaryBool returns BooleanExpression:
True | False | '(' Or ')'
;

Comparison return BooleanExpression:
Addition ({Comparison.left=current} op=BoolOperator right=Addition}
;

BoolOperator:
'>' | '<' | '<=' | '>=' | '==' | '!='


True:
value='True'
;

False:
value='False'
;


I must respect some meta-model, Comparison must have 2 IntExpression and an operator

Thank you so much!
Re: Comparison!!! [message #820569 is a reply to message #818337] Wed, 14 March 2012 09:40 Go to previous message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
We're still trying to understand what your exact problem is here, I guess.

How about adding
IntExpression:
  Addition;

and changing
Comparison return BooleanExpression:
IntExpression ({Comparison.left=current} op=BoolOperator right=IntExpression}

?


Previous Topic:DSL Generation and Validation
Next Topic:Validation just for the changed elements?
Goto Forum:
  


Current Time: Sun Mar 29 23:45:30 GMT 2020

Powered by FUDForum. Page generated in 0.08547 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top