gpt4 book ai didi

compiler-theory - S-attributed 和 L-attributed 语法是什么意思?

转载 作者:行者123 更新时间:2023-12-04 01:53:12 24 4
gpt4 key购买 nike

我正在阅读一本编译器书,当它说“S 属性文法也是 L 属性文法”时有点困惑。无法理解。有人可以说清楚吗(一个例子应该很好)。谢谢。

最佳答案

L-attributed grammar

L-attributed grammars are a special type of attribute grammars. They allow the attributes to be evaluated in one left-to-right traversal of the abstract syntax tree. As a result, attribute evaluation in L-attributed grammars can be incorporated conveniently in top-down parsing. Many programming languages are L-attributed. Special types of compilers, the narrow compilers, are based on some form of L-attributed grammar. These are comparable with S-attributed grammars. Used for code synthesis.


S-attributed grammar

S-Attributed Grammars are a class of attribute grammars characterized by having no inherited attributes. Inherited attributes, which must be passed down from parent nodes to children nodes of the abstract syntax tree during the semantic analysis of the parsing process, are a problem for bottom-up parsing because in bottom-up parsing, the parent nodes of the abstract syntax tree are created after creation of all of their children. Attribute evaluation in S-attributed grammars can be incorporated conveniently in both top-down parsing and bottom-up parsing. Yacc is based on the S-attributed approach.

Any S-attributed grammar is also an L-attributed grammar.


在 L 属性语法中,属性评估可以在从左到右的遍历中执行。由于在 S 属性文法中,属性不是继承的,因此不会阻止您这样做。因此,您可以说 S 属性文法符合 L 文法的特征。

关于compiler-theory - S-attributed 和 L-attributed 语法是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2458558/

24 4 0
文章推荐: svn 分支提交 - 实验性提交
文章推荐: Rpmbuild - 创建的 .rpm 的设置名称
文章推荐: javascript -