使用属性语法装饰解析树
给定类型声明的以下属性语法,我需要能够为任何给定字符串生成解析树,例如“A,B : C;”,然后装饰该树。
对于简单的属性语法,当属性显而易见时,我通常可以这样做,但我无法破译 out_tab
和 in_tab
是什么。是的,这是我的作业,我不是在寻求解决方案,我是在寻求有关这些属性含义的指导以及可能的示例来帮助我。
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
Given the following attribute grammar for type declarations, I need to be able to produce a parse tree for any given string, for example "A, B : C;", and then decorate the tree.
I can generally do this for simple attribute grammars and when its obvious what the attributes are, but I can not decipher what out_tab
and in_tab
are. Yes, this is my homework and I am not asking for the solution, I am asking for guidance on what these attributes mean and possible examples to assist 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几年后,我希望你很好地完成了你的家庭作业:)
关于你的练习:
decl.t
和decl_tail.t
是复制类型名称的综合属性(将其传递给解析树中的每个父产生式
>ID.n) 并在产生式
decl -> 时 。 ID decl_tail
到达后,in_tab
属性保存了一种标识符和类型之间的关系列表(尚不清楚in_tab
的类型,但我们可以假设元组列表(标识符;类型)
)。该属性是继承的,因此列表将从最顶部的产生式(最左边的标识符)开始构建,并继续从左到右构建,并在最右边的标识符完成。当
decl_tail ->
decl_tail -> 时,链表构建完成。 : ID;
到达,因此使用合成属性 (out_tab
) 将结果再次合成到起始符号。这张图是我能做的最好的绘制装饰树和图依赖关系的图:
蓝色箭头是
t
属性的合成,绿色箭头是t
属性的合成>in 列表已构建红色箭头是如何将结果合成到初始符号Several years after, I hope you finished well your home work :)
about your exercise:
decl.t
anddecl_tail.t
are synthetized atributes that copy the Type name (ID.n
) and pass it for each parent production in the parsing treewhen a production
decl -> ID decl_tail
is reached, thein_tab
attributte keeps a kind of list of relationship between identifiers and types (it is not clear the type ofin_tab
but we can assume a list of tuples(identifier; type)
). This attribute is inherited, so the list will start to be constructed in the top most production (leftmost identifier), and continue constructing it from left to right and finish it in the rightmost identifier.Then the list is finished to be constructed when
decl_tail -> : ID;
is reached so a synthesised attribute (out_tab
) is used to synthesise the result again to the starting symbol.this drawing was the best I could do for drawing the decorated tree and graph dependence:
Blue arrows are the synthetizing of the
t
attribute, the green arrows are how thein
list is constructed and the red arrows are how the result is synthesized to the initial symbol