| Scoping for variables [message #991061] |
Mon, 17 December 2012 04:01 |
Eclipse User |
|
|
|
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?
|
|
|
Powered by
FUDForum. Page generated in 0.04000 seconds