吉大编译课件Parsing.ppt

  1. 1、本文档共67页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
吉大编译课件Parsing.ppt

Compiler Construction Principles Implementation Techniques Dr. Zheng Xiaojuan Professor Software College of Northeast Normal University March. 2010 Role of Parsing in a Compiler What will be introduced About Parsing General information about a Parser (parsing) Functional requirement (input, output, main function) Process General techniques in developing a Parser How to define the syntax of a programming language? Why not regular expressions? (not enough) Context free grammar (上下文无关文法) How to implement a parser with respect to its definition of syntax? Top-down Parsing Bottom-up Parsing Knowledge Relation Graph § 3 Context Free Grammar Parsing 3.1 The Parsing Process (语法分析过程) 3.2 Context-free Grammars (上下文无关文法) 3.3 Parse Trees and Abstract Syntax Tree (语法分析树和抽象语法树) 3.4 Ambiguous (二义性) 3.5 Syntax of C0 Language (简单语言的语法) 3.1 The Parsing Process Function of a Parser Input : Token / TokenList Output: internal representation of syntactic structure Process Read tokens Establish syntactic structure – parse tree/syntax tree, according to the syntax definition (context free grammar); Check syntactical errors Syntactic Structures Rules for describing the structure of a well-defined program Syntax Errors Different Types of Syntax Errors Following token for a syntactic structure is wrong (后继单词错) Identifier/constant error (标识符或者常量错) Keyword error(关键字错) Start token for a syntactic structure is wrong(开始单词错) Unbalanced parentheses(括号配对错) Syntax Errors Dealing with Errors Once an error is detected, how to deal with it? Quit immediately, not practical Error recovery Error repair Error correction There is no “perfect” way to do it! Different Types of Parsing Methods Universal parsing methods for any grammars Cocke-Younger-Kasami algorithm Earley’s algorithm Top-down parsing methods (limited grammars)- predictive Recursive descendent parsing (递归下降法) LL(k) -- k=1 Bottom-up parsing methods (limited grammars) – shift-reduce SLR(k) LR(k) LALR(k) Operator-precedence

文档评论(0)

000 + 关注
实名认证
内容提供者

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

1亿VIP精品文档

相关文档