Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Ocl grammar and a temporal extension of it
Ocl grammar and a temporal extension of it [message #71409] Mon, 15 June 2009 13:48 Go to next message
Cosmin Ciuraru is currently offline Cosmin CiuraruFriend
Messages: 16
Registered: July 2009
Junior Member
Hello,

I would like to extend the current OCL grammair in order to add some
temporal operators to it. In order to do that, I intend to write an OCL
grammar that takes into account these operators and for that I use the
XText tool provided by oaw (I really don't know if I should ask this in
the tmf newsgroup) in order to have a parser and a metamodel generated.
After some search and adaptation, I ended up using this grammar:

OclFile
: mm = Model (expressions += OclExpression)+
;

Model
: "MainModel : http://SimplePDL"
;

OclExpression
: contextDecl = ContextDeclaration stereotype = Stereotype ( name = Name
)? ":" exp = Expression ";"
;

ContextDeclaration
: "context" contextName = TypeName
;

Stereotype
: "inv"
;

Expression
: logExp = LogicalExpression
;

IfExpression
: "if" ifExp = Expression
"then" theExp = Expression
"else" elseExp = Expression
"endif"
;

LogicalExpression
: relExp = RelationalExpression (logOp = LogicalOperator sub =
RelationalExpression)*
;

RelationalExpression
: tempExp = TemporalExpression | addExp = AdditiveExpression
( relOp = RelationalOperator sub = AdditiveExpression )?
;


TemporalExpression
: UnaryTemporalExpression
| BinaryTemporalExpression
;

UnaryTemporalExpression
: UnaryTemporalOperator LogicalExpression
;

BinaryTemporalExpression
: LogicalExpression BinaryTemporalOperator LogicalExpression
;
AdditiveExpression
: MultiplicativeExpression ( AddOperator MultiplicativeExpression )*
;

MultiplicativeExpression
: UnaryExpression ( MultiplyOperator UnaryExpression )*
;

UnaryExpression
: ( UnaryOperator PostfixExpression )
| PostfixExpression
;

PostfixExpression
: PrimaryExpression ( ("." | "->") FeatureCall )*
;

PrimaryExpression
: LiteralCollection
| Literal
| PathExp
| "(" Expression ")"
| IfExpression
;

PathExp
: PathName TimeExpression? Qualifiers? FeatureCallParameters?
;

FeatureCallParameters
: "(" ( Declarator )? ( ActualParameterList )? ")"
;

Literal
: STRING | Number | "#" Name | Name
;

EnumerationType
: "enum" "{" "#" Name ( "," "#" Name )* "}"
;

SimpleTypeSpecifier
: PathTypeName
| EnumerationType
;

LiteralCollection
: CollectionKind "{" ExpressionListOrRange? "}"
;

ExpressionListOrRange
: Expression ( ( "," Expression )+ | ( ".." Expression ))?
;

FeatureCall
: PathName TimeExpression? Qualifiers? FeatureCallParameters?
;

Qualifiers
: "[" ActualParameterList "]"
;

Declarator
: Name ( "," Name )* ( ":" SimpleTypeSpecifier )? "|"
;

PathTypeName
: TypeName ( "::" TypeName )*
;

PathName
: ( TypeName | Name ) ( "::" ( TypeName | Name ) )*
;

TimeExpression
: "@" Name
;

ActualParameterList
: Expression ( "," Expression )*
;

Native LogicalOperator
: "'and' | 'or' | 'xor' | 'implies'"
;

Native CollectionKind
: "'Set' | 'Bag' | 'Sequence' | 'Collection'"
;

RelationalOperator
: "=" | ">" | "<" | ">=" | "<=" | "<>"
;

AddOperator
: "+" | "-"
;

Native MultiplyOperator
: "'*' | '/'"
;

Native UnaryOperator
: "'-' | 'not'"
;

UnaryTemporalOperator
: SOMETIME_PAST
| ALWAYS_PAST
| SOMETIME
| ALWAYS
| INITIALLY
;

Native SOMETIME_PAST
: "'sometime_past'"
;

Native ALWAYS_PAST
: "'always_past'"
;

Native SOMETIME
: "'sometime'"
;

Native ALWAYS
: "'always'"
;

Native INITIALLY
: "'initially'"
;

BinaryTemporalOperator
: SOMETIME_SINCE_LAST
| ALWAYS_SINCE_LAST
| UNTIL
| BEFORE
;

Native SOMETIME_SINCE_LAST
: "'sometime_since_last'"
;

Native ALWAYS_SINCE_LAST
: "'always_since_last'"
;

Native UNTIL
: "'until'"
;

Native BEFORE
: "'before'"
;


Native Name
: "'a'..'z' ( 'a'..'z' | '0'..'9' | 'A'..'Z' | '_')*"
;

Native TypeName
: "'A'..'Z' ( 'a'..'z' | '0'..'9' | 'A'..'Z' | '_')*"
;

Native Number
: "'0'..'9' ('0'..'9')*"
;

I thought first to give it a try with just an ocl file, having the form:


MainModel : http://SimplePDL

context Process
inv start_all:
self.processElement->forAll(wd:WorkDefinition|wd.name.size() = 1 implies
wd.name="3");

After running the parser on this file I get the errors:

no viable alternative at input 'self' (line:5, start:61, length:3)
no viable alternative at input 'wd' (line:5, start:134, length:1)

My question to you is whether you see something wrong with the grammar or
it's all about the way XText generates the parser. Thank you!

Regards,
Cosmin
Re: Ocl grammar and a temporal extension of it [message #71448 is a reply to message #71409] Wed, 17 June 2009 05:50 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Cosmin

Your grammar does not use OCL and does not use the LPG tooling used by the
MDT-OCL project, so I suggest that you ask for grammar help on a group that has
some relevance.

If you want to re-use the MDT-OCL grammar, you can do that by exploiting
the LPG include capabilities. If you examine the MDT-OCL sources you will
see that it does this internally to promote EssentialOCL into Complete OCL.
The QVT Declarative project does the same to extend EssentialOCL to QVTr
or QVTc.

Regards

Ed Willink

Cosmin Ciuraru wrote:
> Hello,
>
> I would like to extend the current OCL grammair in order to add some
> temporal operators to it. In order to do that, I intend to write an OCL
> grammar that takes into account these operators and for that I use the
> XText tool provided by oaw (I really don't know if I should ask this in
> the tmf newsgroup) in order to have a parser and a metamodel generated.
> After some search and adaptation, I ended up using this grammar:
>
> OclFile : mm = Model (expressions += OclExpression)+ ;
>
> Model
> : "MainModel : http://SimplePDL" ;
>
> OclExpression : contextDecl = ContextDeclaration stereotype =
> Stereotype ( name = Name )? ":" exp = Expression ";"
> ;
>
> ContextDeclaration
> : "context" contextName = TypeName
> ;
>
> Stereotype
> : "inv"
> ;
>
> Expression
> : logExp = LogicalExpression
> ;
>
> IfExpression : "if" ifExp = Expression "then" theExp =
> Expression "else" elseExp = Expression
> "endif"
> ;
> LogicalExpression : relExp = RelationalExpression (logOp =
> LogicalOperator sub = RelationalExpression)*
> ;
>
> RelationalExpression : tempExp = TemporalExpression | addExp =
> AdditiveExpression ( relOp = RelationalOperator sub =
> AdditiveExpression )?
> ;
>
>
> TemporalExpression : UnaryTemporalExpression
> | BinaryTemporalExpression
> ;
>
> UnaryTemporalExpression
> : UnaryTemporalOperator LogicalExpression
> ;
>
> BinaryTemporalExpression
> : LogicalExpression BinaryTemporalOperator LogicalExpression
> ;
> AdditiveExpression : MultiplicativeExpression ( AddOperator
> MultiplicativeExpression )*
> ;
>
> MultiplicativeExpression : UnaryExpression ( MultiplyOperator
> UnaryExpression )*
> ;
>
> UnaryExpression : ( UnaryOperator PostfixExpression )
> | PostfixExpression
> ;
>
> PostfixExpression : PrimaryExpression ( ("." | "->") FeatureCall )*
> ;
>
> PrimaryExpression : LiteralCollection
> | Literal
> | PathExp
> | "(" Expression ")"
> | IfExpression
> ;
>
> PathExp : PathName TimeExpression? Qualifiers? FeatureCallParameters?
> ;
>
> FeatureCallParameters : "(" ( Declarator )? ( ActualParameterList )?
> ")"
> ;
>
> Literal : STRING | Number | "#" Name | Name
> ;
>
> EnumerationType : "enum" "{" "#" Name ( "," "#" Name )* "}"
> ;
>
> SimpleTypeSpecifier : PathTypeName
> | EnumerationType
> ;
>
> LiteralCollection : CollectionKind "{" ExpressionListOrRange? "}"
> ;
>
> ExpressionListOrRange : Expression ( ( "," Expression )+ | ( ".."
> Expression ))?
> ;
>
> FeatureCall : PathName TimeExpression? Qualifiers?
> FeatureCallParameters?
> ;
>
> Qualifiers : "[" ActualParameterList "]"
> ;
>
> Declarator : Name ( "," Name )* ( ":" SimpleTypeSpecifier )? "|"
> ;
>
> PathTypeName : TypeName ( "::" TypeName )*
> ;
>
> PathName : ( TypeName | Name ) ( "::" ( TypeName | Name ) )*
> ;
>
> TimeExpression : "@" Name
> ;
>
> ActualParameterList : Expression ( "," Expression )*
> ;
>
> Native LogicalOperator : "'and' | 'or' | 'xor' | 'implies'"
> ;
>
> Native CollectionKind : "'Set' | 'Bag' | 'Sequence' | 'Collection'"
> ;
>
> RelationalOperator : "=" | ">" | "<" | ">=" | "<=" | "<>"
> ;
>
> AddOperator : "+" | "-"
> ;
>
> Native MultiplyOperator : "'*' | '/'"
> ;
>
> Native UnaryOperator : "'-' | 'not'"
> ;
>
> UnaryTemporalOperator : SOMETIME_PAST
> | ALWAYS_PAST
> | SOMETIME
> | ALWAYS
> | INITIALLY
> ;
>
> Native SOMETIME_PAST
> : "'sometime_past'"
> ;
>
> Native ALWAYS_PAST
> : "'always_past'"
> ;
> Native SOMETIME
> : "'sometime'"
> ;
>
> Native ALWAYS
> : "'always'"
> ;
>
> Native INITIALLY
> : "'initially'"
> ;
>
> BinaryTemporalOperator : SOMETIME_SINCE_LAST | ALWAYS_SINCE_LAST
> | UNTIL | BEFORE
> ;
>
> Native SOMETIME_SINCE_LAST
> : "'sometime_since_last'"
> ;
>
> Native ALWAYS_SINCE_LAST
> : "'always_since_last'"
> ;
>
> Native UNTIL
> : "'until'"
> ;
>
> Native BEFORE
> : "'before'"
> ;
>
>
> Native Name : "'a'..'z' ( 'a'..'z' | '0'..'9' | 'A'..'Z' | '_')*"
> ;
>
> Native TypeName : "'A'..'Z' ( 'a'..'z' | '0'..'9' | 'A'..'Z' | '_')*"
> ;
>
> Native Number : "'0'..'9' ('0'..'9')*"
> ;
>
> I thought first to give it a try with just an ocl file, having the form:
>
>
> MainModel : http://SimplePDL
>
> context Process
> inv start_all:
> self.processElement->forAll(wd:WorkDefinition|wd.name.size() = 1 implies
> wd.name="3");
>
> After running the parser on this file I get the errors:
>
> no viable alternative at input 'self' (line:5, start:61, length:3)
> no viable alternative at input 'wd' (line:5, start:134, length:1)
>
> My question to you is whether you see something wrong with the grammar
> or it's all about the way XText generates the parser. Thank you!
>
> Regards,
> Cosmin
>
Previous Topic:[Announce] MDT OCL 1.3.0RC5 is available
Next Topic:[Announce] MDT OCL 1.3.0 is available
Goto Forum:
  


Current Time: Fri Apr 26 03:00:23 GMT 2024

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

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

Back to the top