递归下降分析 (42).ppt
《递归下降分析 (42).ppt》由会员分享,可在线阅读,更多相关《递归下降分析 (42).ppt(11页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、CompilerS1Synthesized AttributesAn attribute is synthesized if all its dependencies point from child to parent in the parse tree.Equivalently,an attribute a is synthesized if,given a grammar rule A X1 X2,Xn the only associated attribute equation with an a on the left-hand side is of the form A.a=f(X
2、1.a1,X1.ak,Xn.a1,Xn.ak)An attribute grammar in which all the attributes are synthesized is called an S-attributed grammar.CompilerS2Attribute Values of S-Attributed GrammarGiven a parse tree or a syntax tree constructed by a parser,the attribute values of S-attributed grammar can be computed by a si
3、ngle bottom-up,or postorder,traversal of the tree.procedure PostEval(T:treenode);for each child C of T do PostEval(C);compute all synthesized attributes of TCompilerS3Examplenumber1.valnumber2.valdigit.valnumber.valdigit.valCompilerS4Inherited AttributeAn attribute that is not synthesized is called
4、an inherited attribute.Example:decltypevar-listid(x),var-listid(y)floatdtypedtypedtypedtypedtypeCompilerS5Inherited Attribute(cont)Dependencies flow either from parent to children or from sibling to sibling.Inherited attributes can be computed by a preorder traversal,or combined preorder/inorder tra
5、versal of the syntax tree.a Aa Ba Ca Aa Ba Cprocedure PreEval(T:treenode);for each child C of T do compute all inherited attributes of C PreEval(C);CompilerS6Example 6.12decl type var-listtype int|floatvar-list id,var-list|iddecltypevar-listid(x),var-listid(y)floatdtypedtypedtypedtypedtype12345Compi
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 递归下降分析 42 递归 下降 分析 42
限制150内