吉大编译课件编译器开发3.pptVIP

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  4. 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  5. 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  6. 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  7. 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
编译程序的面向对象设计与实现 Dr. Zheng Xiaojuan Associate Professor Software College of Northeast Normal University April. 2009 阶段三:语法分析器开发 项目需求 读入词法分析的输出结果token序列; 对token序列进行语法分析生成语法正确的与源程序结构相对应的语法分析树; 能够指出语法错误所在位置。 一、编译原理内容 语法分析程序的功能 所需编译知识关联图 所需编译知识关联图 一、Context Free Grammar CFG 定义为四元组 VT,VN,S,P VT是有限的终极符集合 VN是有限的非终极符集合 S是开始符,S? VN P是产生式的集合,且具有下面的形式: A?X1X2…Xn 其中A?VN,Xi? VT?VN ,右部可空。 二、Top-down parsing 自顶向下语法分析方法的前提条件 G VT, VN, S, P For any A? VN, For any two productions of A, Predict A ? ?1 ? Predict A ? ?2 ? 同一个非终极符的任意两个产生式的predict集合互不相交 这个条件保证:针对当前的符号和当前的非终极符,可以选择唯一的产生式来进行推导; 三、 Grammar Transformation 消除公共前缀 left factoring 公共前缀 A ? ??1 | … | ??n| ?1|…| ?m 提取公因子 A ? ?A’| ?1|…| ?m A’ ? ?1 | … | ?n 消除左递归 left recursion 直接左递归:A ? A ?1 | … | ? n | ?1|…| ?m 消除方法: A ? ?1|…| ?m A’ A’ ? ?1| … | ?n A’|? 消除左递归 left recursion 间接左递归: 消除方法: Pre-conditions Algorithm 四、Three Important Sets First Set first集 for a string ? with non-terminal and terminal symbols; First ? Follow Set follow集 for a non-terminal symbol A; Follow A Predict Set 预测集 for a production; Predict A? ? 1 First Set first集 Definition: First ? a | ??*a?, a?VT , if ??*? then First ? First ? ? ? For each symbol X, calculate First X Example 2 Follow Set follow集 Example 3 Predict Set predict集 Definition: Predict A ? ? first ? , if ? ? first ? ; Predict A ? ? first ? - ? ? follow A , if ? ? first ? ; Example 五、 Recursive-Descent Parsing The goal of parsing Check whether the input string belongs to the language of CFG; Two actions match a : to check current symbol, if match, read next symbol; Derivation: select the production General Process G VT, VN, S, P Predefined function: void match a: VT Global variable: token: VT Input string: str General Process void match a: VT if token a token readNext str ; else error ; Example Building Parse Tree Data structure ParseTree Operations ParseTree BuildRoot symbol: VT ? VN ; ParseTree BuildOneNode symbol:

文档评论(0)

lyxbb + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档