Skip to main content



      Home
Home » Modeling » TMF (Xtext) » problem with references
problem with references [message #1706321] Tue, 25 August 2015 13:26 Go to next message
Eclipse UserFriend
No Message Body

[Updated on: Mon, 23 November 2015 04:29] by Moderator

Re: problem with references [message #1706322 is a reply to message #1706321] Tue, 25 August 2015 13:44 Go to previous messageGo to next message
Eclipse UserFriend
hi the grammar you posted makes not much sense to me.
you can only (cross) reference objects, not parts of objects.
and the things you can reference need (by default) have to have an attribute named name

can you give us a example model?
Re: problem with references [message #1706369 is a reply to message #1706322] Wed, 26 August 2015 06:20 Go to previous messageGo to next message
Eclipse UserFriend
No Message Body

[Updated on: Mon, 23 November 2015 04:29] by Moderator

Re: problem with references [message #1706371 is a reply to message #1706369] Wed, 26 August 2015 06:43 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

first of all you should stick to the Xtext Naming Conventions:

Rules: Camel Case
Attribute: Lower Case
Terminal: Upper Case

then something like this should work

Model:
	(material+=Materials)*(matetrial_transfr+=Material_transformations)
	
	*(final_product+=FinalProduct)*(caracteristiques+=Caracteristique);
	
	
Materials:
	'Materials''=''{'(numberofmaterials+=Numberofmaterial)+'}'
;

Numberofmaterial:
	
	name=ID;	
	
Material_transformations:
	
		
immediate_Material_A=Immediate_Material_A
	
		

immediate_Material_B=Immediate_Material_B;

Immediate_Material_A:
	name=ID '=' '{'(((numberofmaterials+=Numberofmaterial))'[''{'(mixtures+=Mixture)'}'']' ',')+ '}' '[' '{' 'Homogeneity''=' homogeneity=Boolean'}'']' 
;

Immediate_Material_B:
	name=ID '=''{'ref=[Immediate_Material_A] '}''[''Temperature'':' temperatur=INT('°c')']'
;
	
 
 FinalProduct:
	
	Final_Product=ID '=' '{' ref=[Immediate_Material_B]'}''[' 'Porduct_Category' ':' "Food" ']';
	
	
Caracteristique:
	Production_Requirements=ID '=''{''Space_Required'':' value0=INT'm' '*' value1=INT'm' '*' value2=INT'm''}';
	
	
Mixture:
	'Mixture_portion'':' qunatity=DOUBLE '%';	
	
DOUBLE returns ecore :: EDouble:'-'?INT ('.'INT)?;

Boolean:
	'true'|'false';
Re: problem with references [message #1706373 is a reply to message #1706371] Wed, 26 August 2015 07:05 Go to previous messageGo to next message
Eclipse UserFriend
No Message Body

[Updated on: Mon, 23 November 2015 04:30] by Moderator

Re: problem with references [message #1706376 is a reply to message #1706373] Wed, 26 August 2015 07:28 Go to previous messageGo to next message
Eclipse UserFriend
isnt that possible right now?
Re: problem with references [message #1706378 is a reply to message #1706376] Wed, 26 August 2015 07:50 Go to previous messageGo to next message
Eclipse UserFriend
@christian I guess Sonia is asking how to do Validation.

@sonia You don't specify value ranges and other validation rules in the grammar. Instead, you implement it in your language's validator.

Also, your grammar currently looks like it is only modeling one special case. You don't want to hardcode that there are products A and B, you probably want to have arbitrary products and intermediate products.
Re: problem with references [message #1706382 is a reply to message #1706378] Wed, 26 August 2015 08:31 Go to previous messageGo to next message
Eclipse UserFriend
No Message Body

[Updated on: Mon, 23 November 2015 04:30] by Moderator

Re: problem with references [message #1706411 is a reply to message #1706382] Wed, 26 August 2015 12:50 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

this depends on your semantics. if your FinalProduct should reference any material you could do


Immediate_Material:

Immediate_Material_A|
Immediate_Material_B;

FinalProduct:

Final_Product=ID '=' '{' ref=[Immediate_Material]'}''[' 'Porduct_Category' ':' "Food" ']';
Re: problem with references [message #1706419 is a reply to message #1706411] Wed, 26 August 2015 13:47 Go to previous messageGo to next message
Eclipse UserFriend
@christian I'm sure Material_A and Material_B are just examples. Sonnias domain has three concepts:

1. initial materials (like water, noodles and sauce)
2. intermediate materials (like boiled noodles)
3. final products (like yummy pasta)

Materials = {water, noodles, sauce}

Transformations = {
  boiledNoodles = {noodles [{portion:30%}], water[{portion: 70%}]} [{temp: 90°C}]
  yummyPasta = {boiledNoodles[{portion: 90%}], sauce[{portion:10%}]}
}
Product = {yummyPasta}[{category:Food}]


So you can drastically simplify the grammar by just having "Material" which can either just have a name or a name and a composition rule. Materials can reference other Materials. Products can also reference Materials and have additional constraints.
Re: problem with references [message #1706494 is a reply to message #1706419] Thu, 27 August 2015 07:15 Go to previous messageGo to next message
Eclipse UserFriend
No Message Body

[Updated on: Mon, 23 November 2015 04:30] by Moderator

Re: problem with references [message #1706508 is a reply to message #1706494] Thu, 27 August 2015 08:45 Go to previous messageGo to next message
Eclipse UserFriend
something like

Model:
    'Materials' '=' '{' (materials+=Material (','materials+=Material)*)? '}'
    'Transformations' '=' '{'
        transformedMaterials+=TransformedMaterial*
    '}'
    'Product' '=' '{' material=[AbstractMaterial]  '}'('[' attributes=Attributes']')?
;

AbstractMaterial:
    Material | TransformedMaterial
;

TransformedMaterial:
    name=ID '=' '{' (parts+=TransformationPart (','parts+=TransformationPart)*)? '}'  ('['attributes=Attributes ']')?
;

TransformationPart:
    material=[AbstractMaterial] ('['attributes=Attributes ']')?
;
    
Material: name=ID;    

Attributes:
   {Attributes} '{' (attributes+=Attribute(','ttributes+=Attribute)*)? '}'
; 

Attribute:
    name=ID ":" value=Value
;

Value:
    IdValue | NumericValue
;

IdValue:
    value=ID
;

NumericValue:
    value=INT unit=("°C"|"%")?
;
Re: problem with references [message #1706521 is a reply to message #1706494] Thu, 27 August 2015 09:31 Go to previous messageGo to next message
Eclipse UserFriend
Hey Sonnia,

please be sure to follow at least the 15 min tutorial, it will answer a lot of your questions. Below I sketched a grammar that you can use as a starting point.

You should reduce the noise in your language. All those [] and {} make it pretty badly readable.

Cheers,
Stefan

Model:
	{Model}
	'Materials' '{' initialMaterials += InitialMaterial* '}'
	'Transformations' '{'
		intermediateMaterials += IntermediateMaterial*
	'}'
	//product left as an exercise
;

Material:
  InitialMaterial | IntermediateMaterial
;

InitialMaterial:
	name = ID
;

IntermediateMaterial:
	name = ID '=' productionRule = ProductionRule
;

ProductionRule:
  CompositeRule | AtomicRule
;

CompositeRule:
	//you might want to allow nested ProductionRules here. I only allowed one level of nesting by referencing the AtomicRule 
  '{' parts += AtomicRule+ '}' ('[' properties += Property* ']')?
;

AtomicRule:
  '{' material = [Material] '}' ('[' properties += Property* ']')?
;


//properties left as an exercise
Property:
	'{' 'hot' '}'
;
Re: problem with references [message #1711372 is a reply to message #1706521] Thu, 15 October 2015 07:54 Go to previous message
Eclipse UserFriend
No Message Body

[Updated on: Mon, 23 November 2015 04:30] by Moderator

Previous Topic:Xtext 2.9.0 beta - "Build system" is disabled
Next Topic:2.5.0: Problems using Standalone Xtend with Xpand code
Goto Forum:
  


Current Time: Sat Nov 08 13:40:44 EST 2025

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

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

Back to the top