Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Nested Struct with Qualified Name
Nested Struct with Qualified Name [message #1074230] Fri, 26 July 2013 06:24 Go to next message
kamo cuvao is currently offline kamo cuvao
Messages: 11
Registered: July 2013
Junior Member
Hello!

I'm trying to make C-like structs with xtext, but I face a problem with qualified names:
The struct IS a type, and a type can have another type as its type. (that sounds weird ^^)

So now i want to create a qualified name that looks something like this:

variable.substruct.subsubstruct.variable
x.struct1.struct2.y //for example


Example:
TYPE
	koords : STRUCT
		x : INT;
		y : INT;
		z : INT;
	END_STRUCT;
	
	koords2 : STRUCT
		x : koords;
		y : koords;
		z : koords;
	END_STRUCT;
END_TYPE

VAR PRIVATE
	myWorld : koords;
	myOtherWorld: koords2;
END_VAR

ROUTINE main
	//Should not work
	myWorld.koords.integer := 5;
	myWorld.koords2.koords := 5;
	
	
	//Should work
//	myWorld.x :=5;
//	myOtherWorld.x.x := 5;
END_ROUTINE


Grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "..."

Model:
	(elements+=AbstractElement)*
;
	
AbstractElement:
	types += TypeBlock | routines += RoutineBlock | variables += VariableBlock
;

TypeBlock: {TypeBlock}
	'TYPE'
		(types+=Type)*
	'END_TYPE'
;
Type: name=ID ':' (type=SimpleType | struct=Struct | typeRef=[Type]) ';';
	
Struct: {Struct}
	'STRUCT'
		(variables+=Variable)*
	'END_STRUCT'
;

VariableBlock: {VariableBlock}
	'VAR' (isGlobal?='GLOBAL' |  isPrivate?='PRIVATE')
		(variables+=Variable)*
	'END_VAR'
;
Variable: name=ID ':' (typeRef=[Type] | type=SimpleType) ';';
	
RoutineBlock:
	'ROUTINE' name=ID
		(statements+=Statement)*
	'END_ROUTINE'
;
Statement: DotExpression;


DotExpression returns Ref:
    VariableRef ({DotExpression.ref=current}  "." tail=[SuperRef])* ':=' INT ';'
;
 
VariableRef returns Ref:
    {EntityRef} entity=[Variable]
; 

SuperRef: Variable|Type;

//Allocation:
//	ref=[SuperRef | QualifiedName] ':=' INT ';'
//;
//SuperRef: variable=Variable|type=Type;
//QualifiedName:
//	ID ('.' ID)*
//;

SimpleType:
	(IntType | BoolType | RealType)
;

IntType:  {IntType}  "INT";
BoolType: {BoolType} "BOOL";
RealType: {RealType} "REAL";


I tried it with [xxx | QualifiedName] and left factoring, but i just cant figure it out.

Thanks for your help!
Re: Nested Struct with Qualified Name [message #1074301 is a reply to message #1074230] Fri, 26 July 2013 09:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6233
Registered: July 2009
Senior Member
Hi did you have a look at
http://christiandietrich.wordpress.com/2013/05/18/xtext-and-dot-express
ions/

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Nested Struct with Qualified Name [message #1074695 is a reply to message #1074301] Sat, 27 July 2013 09:44 Go to previous messageGo to next message
kamo cuvao is currently offline kamo cuvao
Messages: 11
Registered: July 2013
Junior Member
Yes, I have. The problem I have is that i dont have the same entity in a row, but i have a variable which can have a type which has other variables in it. (type of struct)

so its not "entity.entity.entity"

its "variable.variable"
or "variable.substruct.variable"
or "variable.substruct.subsubstruct.variable"
Re: Nested Struct with Qualified Name [message #1074699 is a reply to message #1074695] Sat, 27 July 2013 09:54 Go to previous message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6233
Registered: July 2009
Senior Member
Hi i dont get this Point. An entity ref is the Same as a vAr
Previous Topic:Auto edit strategy with ID's
Next Topic:validation order
Goto Forum:
  


Current Time: Sat Aug 30 20:29:55 EDT 2014

Powered by FUDForum. Page generated in 0.01611 seconds