Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross reference - not sure how to do it here
Cross reference - not sure how to do it here [message #685997] Tue, 21 June 2011 10:36 Go to next message
john doe is currently offline john doeFriend
Messages: 74
Registered: June 2011
Member
Hi there. I did some reading up on cross references in the Xtext user guide.
However, I'm unsure how to build up a grammar rule for my language. The end result is this:

properties {
   cpu : long;
}

definitions {
   cpu > 20000 && cpu < 40000
}


And so far I have the following grammar rules
//============= PROPERTY GRAMMAR ==================
Property :
	"properties" "{"
		(propertyDefs+=PropertyDefinition)+
	"}" 
;

PropertyDefinition :
	name=PropertyName ":" type=typeDef
;

PropertyName :
	name=ID
;

typeDef :
	"int"
	| "double"
	| "long"
;

//============= DEFINITION GRAMMAR ================
Definition :
	"definitions" "{"
		(profiles+=ProfileSpecification)+
	"}"
;

ProfileSpecification :
	ID "{"
		(conditions+=Condition)+
	"}"
;

Condition :
	propertyName=[PropertyName] ComparisonOperation 
        (('&&' | '||') propertyName=[PropertyName] ComparisonOperation)*
;

ComparisonOperation :
	('!=' (INT | DOUBLE | STRING)
	| '==' (INT | DOUBLE | STRING)
	| '>' (INT | DOUBLE)
	| '>=' (INT | DOUBLE)
	| '<' (INT | DOUBLE)
	| '<=' (INT | DOUBLE))
;

terminal DOUBLE :
	INT '.' (INT)+
;


The issue is that I'm not sure how to cross-reference the rule 'PropertyName' from my rule 'Condition', as from my example you can see that a condition could end up looking like

cpu > 20000 && cpu < 40000


The problem is that in the 'Condition' rule, the attribute 'propertyName' could be overridden. Could anyone point me in the right direction as to how I may solve this because I'm stuck and Xtext is new to me. Thanks for the help!
Re: Cross reference - not sure how to do it here [message #685999 is a reply to message #685997] Tue, 21 June 2011 10:52 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

the short answer is use

Condition :
propertyName+=[PropertyName] ComparisonOperation
(('&&' | '||') propertyName+=[PropertyName] ComparisonOperation)*
;

However, the grammar would have to be modified substantially if you really want to do something with your model, as from the model you won't be able to retrieve the comparators or the values you compare against.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Cross reference - not sure how to do it here [message #686006 is a reply to message #685999] Tue, 21 June 2011 11:13 Go to previous messageGo to next message
john doe is currently offline john doeFriend
Messages: 74
Registered: June 2011
Member
Thanks for that Alex.

Ultimately, within a template at a later stage, I would like to assign the entire conditional statement to a variable and retrieve it within a template. But I can't do this with my current approach. Have you any suggestions for how I could improve the conditional rule? If I'm asking too much, don't worry about it.

Cheers
Re: Cross reference - not sure how to do it here [message #686022 is a reply to message #686006] Tue, 21 June 2011 12:01 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

the short answer is Expressions. Have a look at the arithmetics example from Xtext 1.0.x, Svens blog, Xbase, anything else to be found on the web on Xtext and expressions.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Cross reference - not sure how to do it here [message #686024 is a reply to message #686022] Tue, 21 June 2011 12:30 Go to previous message
john doe is currently offline john doeFriend
Messages: 74
Registered: June 2011
Member
Will do. Thanks
Previous Topic:data type rule - list
Next Topic:[Xbase] Operator Overloading
Goto Forum:
  


Current Time: Fri Apr 26 22:08:30 GMT 2024

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

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

Back to the top