Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.4.1 第6题答案有误 #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions ch04/4.4/4.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</table>

2. S -> + S S | \* S S | a

step1. 无左公因子

step2. 无左递归
Expand Down Expand Up @@ -90,7 +90,7 @@

S -> A
A -> (S) S A | ε

step3. 预测分析表

<table>
Expand Down Expand Up @@ -127,13 +127,13 @@

S -> SA | (S) | a
A -> +S | S | *

进一步提取终结符

S -> SA | T
A -> +S | S | *
T -> (S) | a

step2. 消除左递归(根据 p135 的算法 4.19)

i = 1
Expand All @@ -149,7 +149,7 @@
无需处理
j = 2
无需处理

得到最终的产生式

S -> TB
Expand All @@ -163,7 +163,7 @@
first(A) = [+, *] + first(T) =[+, *, (, a]
first(B) = [ε] + first(A) = [ε, +, *, (, a]
first(S) = first(T) = [(, a]

follow(T) = [$, +, *, (, a]
follow(A) = [$, +, *, (, ), a]
follow(B) = [$]
Expand Down Expand Up @@ -268,7 +268,7 @@
follow(bexpr) = follow(bexpr') = [), $]
follow(bterm) = follow(bterm') = [or, $]
follow(bfactor) = [and, $]

````

step4. 预测分析表
Expand Down Expand Up @@ -326,8 +326,8 @@
</tr>
<tr>
<th>bterm'</th>
<td></td>
<td>bterm' -> and bfactor bterm'</td>
<td>bterm' -> ε</td>
<td></td>
<td></td>
<td>bterm' -> ε</td>
Expand All @@ -349,21 +349,22 @@
</tbody>
</table>


### 4.4.2 !!

有没有可能通过某种方法修改练习 4.2.1 中的文法,构造出一个与该练习中的语言(运算分量为 a 的后缀表达式)对应的预测分析器?

#### 解答

S -> SS+ | SS* | a

step1. 提取左公因子

S -> SSA | a
A -> + | *

step2. 消除左递归

i = 1
S -> aB
B -> SAB | ε
Expand All @@ -373,7 +374,7 @@ step2. 消除左递归
S -> aB
B -> aBAB | ε
A -> + | *

step3. 预测分析表

<table>
Expand Down Expand Up @@ -413,7 +414,7 @@ step3. 预测分析表
</tr>
</tbody>
</table>


### 4.4.3

Expand Down Expand Up @@ -472,7 +473,7 @@ step3. 预测分析表
以下题目请参考 Aho 本人的讲义:[Aho: Properties of Context-Free Languages](http://www.cs.columbia.edu/~aho/cs3261/lectures/12-10-08.htm),[本地副本](cs.columbia.edu-aho-cs3261-properties-of-cfl-121008.html)

此外还有[另一篇内容相似的文章](http://courses.engr.illinois.edu/cs373/Lectures/lec14.pdf),[本地副本](courses.engr.illinois.edu-cs373-lec14.pdf)

关于 CNF 和 CYK 算法,有较多相关资料,自行搜索

### 4.4.6 !
Expand Down