Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Scoping for variables
Scoping for variables [message #991061] Mon, 17 December 2012 04:01
Eclipse UserFriend
Good week everyone,
I've got a scoping problem.

Here are relevant parts of my grammar:
NewType:
	'TYPE' {NewType} name=NotPrimitiveType
		struct=Struct
	'END_TYPE'			
;

Struct:
	'STRUCT'
		variables+=Variable+
	'END_STRUCT'';'
;

Type:
	IntType | BoolType | RealType | SIntType | DIntType | UIntType | USIntType | UDIntType | 
	TimeType | DateType | DateAndTimeType | string=StringDefinition | notprimitivetype=[NotPrimitiveType]
;

NotPrimitiveType:
	name=ID
;

Variable:
	(variable=VariableDefinition|array=ArrayDefinition)';'
;

VariableDefinition:
	name=ID ':' type=Type
;


Program:
   'PROGRAM'
   'DEF'
   definitions+=Variable*;
   'ASS'
	assignments+=Assignment*;

Assignment:
variableStructOrFB=[VariableDefinition]'.'internal=InternalRecursive'=0;';

InternalRecursive:
	((internalVariable=[VariableDefinition])|(internalArray=[ArrayDefinition]'['index=ExpressionIndex']'))('.'otherInternal=InternalRecursive)? 
;


Now, the problem is on InternalRecursive rule. As you can see, I can define some structs with NewType rule and they contain some variables.
In assignment, I've got an external variable (variableStructOrFB) and internal.
I want the internal variable is chosen from the definitions that reside in external struct, but I have visibility on all variables of all struct.

For example, something like this is accepted:

TYPE type1
	STRUCT
		i : INT;
	END_STRUCT;
END_TYPE

TYPE type2
	STRUCT
		j : INT;
	END_STRUCT;
END_TYPE

PROGRAM
	DEF
		t2 : type2;
	ASS
               t2.i:=0;
	


How can I implement scope for this situation?
Previous Topic:XText implicitly set rule assignment
Next Topic:Spell checking for custom construct - DocumentPartitioner is confused
Goto Forum:
  


Current Time: Thu Nov 06 06:03:31 EST 2025

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

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

Back to the top