Decorating a Parse Tree Using Attribute Grammar

Given the following grammar of attributes for type declarations, I need to be able to create a parse tree for any string, such as "A, B: C;", and then decorate the tree.

Usually I can do this for simple attribute grammars and when it is obvious what attributes are, but I cannot decrypt what out_tab and in_tab . Yes, this is my homework, and I do not ask permission, I ask for instructions on what these attributes and possible examples mean to help me.

 decl -> ID decl_tail decl.t := decl_tail.t decl_tail.in_tab := insert(decl,in_tab, ID.n, decl_tail.t) decl.out_tab := decl_tail.out_tab decl_tail -> , decl decl_tail.t := decl.t decl.in_tab := decl_tail.in_tab decl_tail.out_tab := decl.out_tab decl_tail -> : ID ; decl_tail.t := ID.n decl_tail.out_tab := decl_tail.in_tab 
+4
source share
1 answer

A few years later, I hope you did a good job in your homework :)

about your exercise:

decl.t and decl_tail.t are synthesized attributes that copy the type name ( ID.n ) and pass it on for each parent production in the parsing tree

when the achievement of decl -> ID decl_tail , the in_tab attribute stores a kind of list of relations between identifiers and types (the in_tab type is not clear, but we can take a list of tuples (identifier; type) ). This attribute is inherited, so the list will begin to be built in the highest release (the leftmost identifier) ​​and continue to build it from left to right and complete it in the rightmost identifier.

Then the list ends when decl_tail -> : ID; is created decl_tail -> : ID; so that the synthesized attribute ( out_tab ) is used to re-synthesize the result on the start character.

this drawing was the best I could do to draw a decorated tree and graphic dependency:

enter image description here

The blue arrows are the synthesis of the t attribute, the green arrows are the way the in list is created, and the red arrows are the way the result is synthesized with the starting character

+2
source

All Articles