Copyright © 2006 Gradiance Corporation.
Bottom-Up Parsing
shift-reduce parsing, viable prefixes.
1.
Consider the grammar:
S → aSa | bSb | aa | bb
A shift-reduce parser works by identifying the handle of each right-sentential form and replacing it by the head of the corresponding production. In this question, we indicate the handle of a right-sentential form by surrounding it by square brackets [...]. Which of the following shows a right-sentential form of the above grammar with the handle properly marked?
a)
abab[aababa]
b)
ababaS[ababa]
c)
ababbS[bbaba]
d)
abab[bSb]baba
2.
Perform a shift-reduce parse of the input aaa+a*+ according to the grammar:
S → SS+ | SS* | a
Show the stack and remaining input at each stage, using the form ($stack, input$). Then, identify the pair that is NOT a stage of the shift-reduce parse.
($SS, a+a*+$)
($a, aa+a*+$)
($SS+, $)
($SSa*, +$)
3.
Perform a shift-reduce parse of the input aa+aa*+ according to the grammar:
($Sa, +aa*+$)
($Sa+, aa*+$)
($SS, +aa*+$)
($Sa, a*+$)
4.
Consider the augmented grammar:
S' → S S → aSb | ab
Describe the set of viable prefixes for this grammar. Then, identify one of the viable prefixes from the following list:
aaabb
aa
aSbbb
aaaSbb
5.
S → aSb | ab
[aaaaab]bbbb
aaaa[abbbbb]
aaaaa[S]bbbbb
aaaa[aSb]bbbb