- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
lecture04-Top-Down Parsing I
Lecture 4
Top-Down Parsing
Where We Are
Lexical Analysis
Syntax Analysis
Semantic Analysis
IR Generation
IR Optimization
Code Generation
Optimization
Source
Code
Machine
Code
Review from Last Time
Goal of syntax analysis: recover the intended structure of the program.
Idea: Use a context-free grammar to describe the programming language.
Given a sequence of tokens, look for a parse tree that generates those tokens.
Recovering this syntax tree is called parsing.
Different Types of Parsing
Top-Down Parsing
Beginning with the start symbol, try to guess the productions to apply to end up at the users program.
Bottom-Up Parsing
Beginning with the users program, try to apply productions in reverse to convert the program back into the start symbol
Top-Down Parsing
int +
( int + int )
T
E
T
E
T
T
E
E
Challenges in Top-Down Parsing
Top-down parsing begins with virtually no information.
Begins with just the start symbol, which matches every program
How can we know which productions to apply?
In general, we cant.
There are some grammars for which the best we can do is guess and backtrack if were wrong
If we have to guess, how do we do it?
Parsing as a Search
An idea: treat parsing as a graph search
Each node is a sentential form (a string of terminals and nonterminals derivable from the start symbol).
There is an edge from node α to node β iff α ? β.
Parsing as a Search
E
T
T+E
int
int + E
T+T+E
T+T
(E)
int + T
int + (E)
(T)
(T + E)
…
…
…
…
int + T + E
T + (E)
int + int
…
…
…
…
…
E
T
T+E
int
int + E
T+T+E
T+T
(E)
int + T
int + (E)
(T)
(T + E)
…
…
…
…
int + T + E
T + (E)
int + int
…
…
…
…
…
Parsing as a Search
Our First Top-Down Algorithm
Breadth-First Search
Maintain a worklist of sentential forms, nitially just the start symbol S.
While the worklist isnt empty:
Remove an element from the worklist.
If it matches the target string, youre done.
Otherwise, for each possible string that can be
derived in one step, add that string to the
您可能关注的文档
- chapter2 strategy analysis-outside environment-201203.ppt
- Chapter3the+dark+ages.ppt
- Chap_03 Interdependence and the Gains from Trade.ppt
- chapter11 solidarity.pptx
- Chargepump Introduction.ppt
- chemical or organic farming1.ppt
- CHECK BOM程序简介.doc
- checkout time & letter time.ppt
- chp5 酒店财务会计完成会计循环.ppt
- cisco交换机端口镜像.ppt
- Lesson 10:Plant parts.ppt
- Lesson 34 On the Farm 课件.ppt
- Lesson 1 Welcome to the World of Marketing.ppt
- Lesson1 On the Farm课件.ppt
- Lecture3 - Plan of Urban Road.ppt
- Lesson_1 We can dance 课件 2.ppt.ppt
- Let’s send an email..ppt
- lidar_and_images_Istambul_1.ppt
- LINUX下I2C框架.doc
- Longman welcome to English 1A chapter 5 A复习.ppt
文档评论(0)