4.5 Exercise: Dragon Book Exercise Answers
4.5 Exercise: Dragon Book Exercise Answers
Searchortypeacommand
Thisrepository
Explore
Features
Enterprise
Blog
fool2fish/Dragonbookexerciseanswers
Dragonbookexerciseanswers/CH04/4.5/4.5.md
branch:master
Signup
Star
167
Signin
Fork
86
fool2fishayearagoaddanwsers
1Contributor
file
216lines(198sloc) 4.326kb
Edit
Raw
Blame
History
Delete
4.5Exercise
4.5.1
Forexercise4.2.2(a)ofthegrammarS>0S1|01,therightmostpointouteachsentencebelowthehandle.
1. 000111
2. 00S11
Answer
1. 01
2. 0S1
4.5.2
Forgrammarexercises4.2.1S>SS+|SS*|aandrightmostbeloweachsentence,repeattheexercise4.5.1.
1. SSS+a*+
2. SS+a*a+
3. aaa*a++
Answer
1. SS+
2. SS+
3. a
4.5.3
Forthefollowinginputsymbolstringandgrammar,indicatingthecorrespondingbottomupparsingprocess.
1. 4.5.1grammarexercisesstring000111.
2. 4.5.2grammarexercisesstringaaa*a++.
Answer
1,000111
Stack
Enter
Handle
Action
000111$
Shifted
$0
00111$
Shifted
$00
0111$
Shifted
$000
$111
$0001
$11
$00S
$11
$00S1
1$
$0S
1$
$0S1
$S
Shifted
01
Statute:S>01
Shifted
0S1
Statute:S>0S1
Shifted
0S1
Statute:S>0S1
Accepted
2,aaa*a++
Stack
Enter
aaa*a++$
$A
aa*a++$
$S
aa*a++$
$Sa
a*a++$
$SS
a*a++$
$SSa
*A++$
$SSS
*A++$
$SSS*
a++$
$SS
a++$
$SSa
++$
$SSS
++$
$SSS+
+$
$SS
+$
$SS+
$S
Handle
Action
Shifted
Statute:S>a
Shifted
Statute:S>a
Shifted
Statute:S>a
Shifted
SS*
Statute:S>SS*
Shifted
Statute:S>a
Shifted
SS+
Statute:S>SS+
Shifted
SS+
Statute:S>SS+
Accepted