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

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

The exercises of Chapter Four

4.2

Grammar: A → ( A ) A | ε

Assume we have lookahead of one token as in the example on p. 144 in the text book. Procedure A()

if (LookAhead() ∈ {‘(‘}) then

Call Expect(‘(‘) Call A()

Call Expect (‘)’) Call A() else

if (LookAhead()∈ {‘)‘, $}) then

return()

else

/* error */ fi fi

end

4.3 Given the grammar statement→ assign-stmt|call-stmt|other assign-stmt→identifier:=exp call-stmt→identifier(exp-list) [Solution] First, convert the grammar into following forms: statement→ identifier:=exp | identifier(exp-list)|other Then, the pseudocode to parse this grammar: Procedure statement Begin Case token of ( identifer : match(identifer); case token of ( := : match(:=); exp; ( (: match((); exp-list; match()); else error; endcase

第1页

你可能喜欢

热门文档

相关文档

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