Frage

As part of a course in my university, I have to build a simple DSL using XText. Currently I am having a problem with static type checking. Lets suppose I have two types of variables in my language, circle and triangle. Both have their own set of parameters like e.g. radius or height/width. However, both do have common parameters like x/y (position). Therefore, I have to following xtext code:

//CircleAttributesInit makes sure, that the correct parameter are used
CircleDecl:
    'circle' name = ID '(' (attributes += CircleAttributesInit)* ')'
;

//triangleAttributesInit makes sure, that the correct parameter are used
TriangleDecl:
    'triangle' name = ID '(' (attributes += triangleAttributesInit)* ')'
;

CircleAccess returns INT:
    circle = [CircleDecl] '.' ('radius') 
;

TriangleAccess returns INT:
    triangle = [TriangleDecl] '.' ('height' | 'width') 
;

ObjectDecl:
    name = (CircleDecl | TriangleDecl)
;

ObjectAccess returns INT:
    objName = [ObjectDecl] '.' ('x' | 'y')
;

In my simple program, I can now type something like:

triangle tri (...)
circle  c (...)
tri.height = ...
c.radius = ...

but access on the super type variables like :

tri.x = ....
c.y =....

does not work. The error message is: "Couldn't resolve reference to ObjectDecl 'tri/c'." This kind of makes sense to me, since I never told xtext, that each TriangleDecl/CircleDecl object is also a ObjectDecl. But how do I do this?

War es hilfreich?

Lösung

it looks like you mix up some metalevels. as long as the attributes exist only on syntax level you have to take care yourself

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top