文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > 高等教育 > 理学 > 编译原理与实践 第四章 答案
侵权投诉

编译原理与实践 第四章 答案

(other: match(other); else error; endcase; end statement

4.7 a

Grammar: A → ( A ) A | ε

First(A)={(,ε } Follow(A)={$,)} 4.7 b

See theorem on P.178 in the text book 1. First{(}∩First{ε}=Φ

2. ε∈Fist(A), First(A) ∩Follow(A)= Φ

both conditions of the theorem are satisfied, hence grammar is LL(1)

4.9 Consider the following grammar: lexp→atom|list atom→number|identifier list→(lexp-seq) lexp-seq→lexp, lexp-seq|lexp a. Left factor this grammar.

b. Construct First and Follow sets for the nonterminals of the resulting grammar. c. Show that the resulting grammar is LL(1).

d. Construct the LL(1) parsing table for the resulting grammar.

e. Show the actions of the corresponding LL(1) parser, given the input string (a,(b,(2)),(c)). [Solution] a. lexp→atom|list atom→number|identifier list→(lexp-seq) lexp-seq→lexp lexp-seq’ lexp-seq’→, lexp-seq|ε b. First(lexp)={number, identifier, ( } First(atom)={number, identifier} First(list)={( } First(lexp-seq)={ number, identifier, ( } First(lexp-seq’)={, , ε} Follow(lexp)={, $, } } Follow(atom)= {, $, } } Follow(list)= {, $, } } Follow(lexp-seq)={$, } }

上一页第2页

你可能喜欢

热门文档

相关文档

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email