1 / 18

北京化工大学 信息科学与技术学院计算机系

计科 0601~0605 编译原理. 编译原理复习. 北京化工大学 信息科学与技术学院计算机系. ● 内容简介. 参考书籍 考试时间 考试题型 考试范围 内容概述 例题解答. Compilers:Principles, Techniques,and tools 编译原理 Compiler Construction Principle and Pratice 编译原理及实践. 2007 年 12 月 31 日 8:00~10:00 计科 0501 教 102 计科 0502 教 102 计科 0503 教 103

feo
Download Presentation

北京化工大学 信息科学与技术学院计算机系

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 计科0601~0605 编译原理 编译原理复习 北京化工大学 信息科学与技术学院计算机系

  2. ●内容简介 • 参考书籍 • 考试时间 • 考试题型 • 考试范围 • 内容概述 • 例题解答 Compilers:Principles, Techniques,and tools 编译原理 Compiler Construction Principle and Pratice 编译原理及实践 2007年12月31日 8:00~10:00 计科0501 教102 计科0502 教102 计科0503 教103 计科0504 教103 计科0505 教201 卷面题型: • 证明题 • 计算题 平时成绩: • 上机 • 考勤 考试时间 • 词法分析 • 上下文无关文法及分析 • 自顶向下的分析方法 • 自底向上的分析方法 • 语义分析 • 中间代码生成 • 代码优化 考试题型 考试范围 内容简介 内容概述 例题解答

  3. 内容概述 ●内容概述

  4. 符 号 处 理 前 端 后 端 错 误 处 理 ●编译器的功能组织结构图 ●内容概述 词 法 分 析 语 法 分 析 语 义 分 析 中 间 代 码 生 成 中 间 代 码 优 化 目 标 代 码 生 成 源 程 序 目 标 程 序

  5. 例题解答 编译程序的功能组织结构图 词法分析(正则表达式→NFA → DFA → DFA 最小化) 句型→推导的语法树 文法←→语言←→句子 自顶向下语法分析 (LL(1)) 自底向上语法分析 (LR(0)、SLR(1)、LR(1)、LALR(1)) 语义分析 中间代码 中间代码优化

  6. 1 . 编译程序的功能和组织结构 符 号 处 理 前 端 后 端 错 误 处 理 词 法 分 析 语 法 分 析 语 义 分 析 中 间 代 码 生 成 中 间 代 码 优 化 目 标 代 码 生 成 源 程 序 目 标 程 序

  7. 2.请构造与正则式R=(a*b)*ba(a|b)* 等价的状态最少的DFA(确定有限自动机)。 解: (1) NFA (2) NFA → DFA (3) DFA 最小化

  8. E E + T T F T * F F i ( E ) E + T 3.有文法G[E]:ET | E+T| E-T TF | T*F | T/F Fi | (E) 请判断(E+T)*i+F是G的一句型吗? 如果是,请画出它的推导的语法树。

  9. 4.(1)设有文法G[S]=({b},{S,B},S, {S →b|bB,B→bS}),该文法所描述的语言是_________。(2)已知语言L={anbbn|n ≥1},则_______文法可以产生语言L。(3)设有文法G[I]:I→I1 | I0 | Ic | a | b | c 该文法的句子有________ ①ab0 ②a0c01 ③aaa ④bc10

  10. 4.(1)设有文法G[S]=({b},{S,B},S, {S →b|bB,B→bS}),该文法所描述的语言是L(G[S]={b2i+1|i ≥0} (2)已知语言L={anbbn|n ≥1},则 Z → aAb A → aAb | b 上述文法可以产生语言L。 (3)设有文法G[I]:I→I1 | I0 | Ic | a | b | c 该文法的句子有 ②④ 。 ①ab0 ②a0c01 ③aaa ④bc10

  11. 5.设有文法G[S]:S→EE→Aa | bBA→cA|dB→cB|d构造其LR(0)分析表并利用分析表判断bccd是否为文法G[S]的句子。 

  12. 6.(1)设有文法exp → exp + term | exp - term | term该文法消除左递归后为 _________。(2)LALR(1)文法均为LR(1)文法(T/F?)

  13. 7. 对于文法lexp→atom|listatom→number|identifierlist→(lexp-seq)lexp-seq→lexp-seq lexp | lexp1) 消除左递归。2) 为得出的文法的非终结符构造First集合和Follow集合。 解:lexp-seq->lexp lexp-seq’ lexp-seq’->lexp lexp-seq’| ε First(lexp) = { n, i, ( } ,Follow = { $,n,i,(,) } First(atom) = { n, i } ,Follow = { $,n,i,(,) } First(list) = {(} ,Follow = { $,n,i,(,) } First(lexp-seq) = { n,i,( } ,Follow = { ) } First(lexp-seq’) = {ε,n,i,( } ,Follow = { ) }

  14. 8.说明以下的文法是LR(1)文法但不是LALR(1)文法:S → a A d | b B d | a B e | b A eA→ cB→ c

  15. 9.在一个移入-规约的分析中采用以下的语法制导的翻译模式,在按一产生式规约时,立即执行括号中的动作。A → aB {print “0”}A → c {print “1”}B→ Ab {print “2”}当分析器的输入为aacbb时,打印的字符串是什么?

  16. A A → aB {print “0”}A → c {print “1”}B→ Ab {print “2”} B a ⑤ 分析器输入为aacbb,打印的字符为 12020 b A ④ a B ③ b A ② c ①

  17. 10. 请写出TINY program三地址码及其四元式表示。 read x ; { input an integer } if 0 < x then { don’t compute if x <= 0 } fact:=1; repeat fact:=fact*x; x:=x-1 until x=0; write fact { output factorial of x } ends

  18. 三地址码 read xt1=x>0 if_false t1 goto L1 fact=1 label L2 t2=fact*x fact=t2 t3=x-1 x=t3 t4= x= =0 if_false t4 goto L2 write fact label L1 halt 四元式 (sub, x, 1, t3 ) (asn, t3, x, _ ) (eq, x, 0, t4 ) (if_f, t4, L2, _) (wri, fact, _, _ ) (lab, L1, _ , _ ) halt, _, _, _ ) (rd, x , _ , _ ) (gt, x, 0, t1 ) (if_f, t1, L1, _ ) (asn, 1,fact, _ ) (lab, L2, _ , _ ) (mul, fact, x, t2 ) (asn, t2, fact, _ )

More Related