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

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

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

4.12 a. Can an LL(1) grammar be ambigous? Why or Why not?

b. Can an ambigous grammar be LL(1)? Why or Why not? c. Must an unambigous grammar be LL(1)? Why or Why not? [Solution] Defination of an ambiguous grammar: A grammar that generates a string with two distinct parse trees. (Page 116) Defination of an LL(1) grammar: A grammar is an LL(1) grammar if the associatied LL(1) parsing table has at most one priduction in each table entry.

a. An LL(1) grammar can not be ambiguous, since the defination implies that an unambiguous parse can

be constructed using the LL(1) parsing table

b. An ambiguous grammar can not be LL(1) grammar, but can be convert to be ambiguous by using

disambiguating rule.

c. An unambiguous grammar may be not an LL(1) grammar, since some ambiuous grammar can be

parsed using LL(K) table, where K>1. 4.13

Left recursive grammars can not be LL(1):

Consider a grammar with a production A → A β with symbol t in its first set. IF A is on the top of the stack and the current look-ahead token is t, A will be popped off the stack and then β will be pushed onto the stack followed by A. A will again be the top of the stack and the look-ahead token will still be t, so it will repeat again, and again, infinitely, or until you get a stack overflow.

Note: The first set for the recursive production will have a non-empty intersection with the first set for the terminating production, which will lead to a conflict when creating the LL(1) table.

上一页第6页

你可能喜欢

热门文档

相关文档

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