S属性和L属性语法是什么意思?

发布于 2024-08-25 05:20:26 字数 73 浏览 6 评论 0原文

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

I'm reading a compiler book and kinda confused when it says "a S-attribute grammar is also a L-attribute grammar". Couldn't understand. Can someone make it clear (an example should be great). Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

明媚殇 2024-09-01 05:20:26

L 属性语法

L-属性语法是一种特殊类型的属性语法。它们允许在抽象语法树的一次从左到右的遍历中评估属性。因此,L-属性语法中的属性评估可以方便地合并到自上而下的语法分析中。许多编程语言都是 L 属性的。特殊类型的编译器(狭义编译器)基于某种形式的 L 属性语法。这些与 S 属性语法相当。用于代码合成。

S 属性语法

S-属性语法是一类属性语法,其特征是没有继承的属性。在解析过程的语义分析过程中,继承属性必须从抽象语法树的父节点向下传递到子节点,这对于自底向上解析来说是一个问题,因为在自下而上解析中,抽象语法的父节点树是在其所有子节点创建之后创建的。 S属性语法中的属性评估可以方便地结合到自上而下的解析和自下而上的解析中。 Yacc 基于 S 属性方法。

任何 S 属性语法也是 L 属性语法。

在L-属性语法中,属性评估可以通过从左到右的遍历来执行。由于在 S 属性语法中属性不是继承的,因此它不会阻止您这样做。因此,您可以说 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.

In L-attributed grammars attribute evaluation can be performed in left-to-right traversal. Since in S-attributed grammars attributes are not inherited, it does not prevent you from doing just that. As such, you can say an S-attributed grammar conforms to that characteristic of an L-grammar.

碍人泪离人颜 2024-09-01 05:20:26

简单的S属性语法是一种具有严格综合类型语法的语法,意味着在整个解析树中仅具有值属性,

而L属性语法可以同时具有综合语法和继承语法,其中一些规则例如具有传递继承总是从左到右。
我想这会对你有所帮助。

Simply S-attributed Grammar is the Grammar who has strictly Synthesized type of grammar means Only having Value attribute throughout the parse tree

where as L-Attributed grammar can have both synthesized as well as Inherited grammar with some of the rules like one having the transfer of inheritance from always left to right.
I think it will help you out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文