Set type for a node

Hello dear MPS experts !

I have a problem with defining a type for a node. My situation:

I have a node called "assignmentNode" with two child-nodes "leftSide" and "rightSide" to define assignent expressions. On the leftSide I can only use AttributeReferences (which refer to nodes of type VariableDeclaration) and on the rightSide I can have expressions.

I have a typesystem inference rule to make sure that the type of the <Expression> on the right side corresponds to the type of the <AttributeReference> on the left side.

<assignmentNode> looks like: <AttributeReference> = <Expression>   (e.g.  myIntAttribute = 2 + 4 + 1)

 

On the rightSide I also want to use a node "<complexNode>" which has two child-nodes nodeX and attributeReference.

<complexNode> looks like: <nodeX>.<attributeReference> (e.g.  someNodeName.myIntAttribute)

This attributeReference refers to a VariableDeclaration and since has a type, nodeX is a custom node, its type should be ignored.

I now want to be able to use <complexNode> on the rightSide of my <assignmentNode> like this:

<attributeReference> = <complexNode>  (or... <attributeReference> = <nodeX>.<attributeReference>)

 

My problem:

I get a type-error since MPS and my typesystem inference rule say that the type of <complexNode> on the rightSide does not equal the type of the <attributeReference>  on the leftSide

Is it possible to manually define the type of <complexNode> to ensure that the leftSide of <assignmentNode> has the same type as its rightSide?

I want to set the "overall" type of <complexNode> to the type of its child node called <attributeReference>.

E.g. typeof(complexNode) = complexNode.attributeReference.type

 

Thanks a lot!

0
3 comments

Unless I misunderstood something fundamental in your example, I believe that an inference rule:

typeof(complexNode) = typeof(complexNode.attributeReference) would do the trick. (Here I assume you already have an inference rule that compares the type of an AttributeReference and the actual Attribute that it refers to.)

Vaclav

 

0
Avatar
Permanently deleted user

Did you maybe mean "typeof(complexNode) :==: typeof(complexNode.attributeReference)" ? The normal "=" operator threw me an error so I changed it to the ":==:" operator.

Now it is working!

Thanks again, Vaclav!

0

Good to hear that! Yes I meant :==:, sorry for puzzling you.

Vaclav

 

0

Please sign in to leave a comment.