AST 树语义分析器
AST树的最后一个节点必须有语义分析器的翻译信息,还是非最后一个节点也可以有这个信息?
The last nodes of an AST tree must have the information of the traduction of the semantic analyzer or the non-last nodes also can have this information?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的问题似乎不太好。
假设您指的是“最后一个节点”所在的“叶子节点”,是的,您不仅可以将语义信息与叶子相关联,还可以与内部节点相关联。
一个简单的例子是“这个表达式的类型”。很明显,包含文字 TRUE 的叶节点将具有与其关联的表达式类型“boolean”。表达式“if e then 2.7 else 9.3 endif”具有对应的 AST,并且与 if 表达式对应的内部节点将具有关联的“float”类型。
人们可以提出很多“语义”属性:“使用变量 X、Y、Z”、“无副作用”、“分叉并行子进程”等。其中任何一个都可能适用于内部树节点。
Your question seems not quite well formed.
Under the assumption you mean "leaf nodes" where you wrote "last nodes", yes, you can associate semantic information not only with leaves but with interior nodes.
A simple example would be "the type of this expression". It is clear that leaf node containing the literal TRUE would have an expression type "boolean" associated with it. The expression "if e then 2.7 else 9.3 endif" has a corresponding AST, and the internal node corresponding to the if-expression would have an associated type of "float".
There are lots of "semantic" properties one could propose: "uses variables X, Y, Z", "side effect-free", "forks parallel subprocesses", etc. any of which might apply to interior tree nodes.
如果我正确理解你的问题,在 AST 中,内部节点也可以携带语义信息,就像叶节点一样。
If I understand your question correctly, in an AST, interior nodes can also carry semantic information, as well as the leaf nodes.
所有 AST 树都必须存储语义信息。
但是,“叶节点”(引用变量、值、操作数的节点)确实可以存储一些与“分支节点”或“非叶节点”不同的信息。
All AST trees have to store semantic information.
But, its true that the "leaf nodes", (nodes that reference variables, values, operands), may store some additional or different information than "branch-nodes" or "non leaf nodes".