Question 1
Consider the following grammar:
S→aBS∣aa∣a
B→a
Which of the following is true of the SLR(1) parsing strategy for this grammar?
Remember that an additional production S′→S is added as part of the parsing automaton's construction.
Question 2
Consider the grammar in last question (Question 1), what is true of the SLR(0) parsing strategy for the grammar?
Question 3
Consider the following lexical specification, which of the following are true?
- /* rule 1 */
ab*c*a* /* rule 2 */
a /* rule 3 */
abc /* rule 4 */
b*c*a*a /* rule 5 */
c.*c /* rule 6 */
[Choose all that apply]
Question 4
Consider the following grammar:
S→bAb∣bBa
A→aS∣CB
B→b∣Bc
C→c∣cC
Which of the following is a reason why this grammar cannot be LL(1)?
[Choose all that apply]
Question 5
Consider the grammar:
S→TaT
T→ϵ∣bbT
Which of the following is a state in the SLR(1) parsing automaton for this grammar?
[Check all that apply]
Question 6
Consider the following two grammars:
Grammar 1:
S→(T)
T→T+int∣int
Grammar 2:
S→(T)
T→int+T∣int
Use shift-reduce parsing on the string '( int + int + … int )' which is the sum of n 'int', assuming n>3.
[Choose all that apply]
Question 7
The following state table describes a finite automaton.
The automaton initially begins in state 1. State 5 is the only accepting state. Entries labelled with an 'E' are errors (i.e. there is no valid transition on that input).
| state\input |
a |
b |
c |
d |
| 1 |
E |
E |
3 |
4 |
| 2 |
E |
1 |
E |
4 |
| 3 |
2 |
E |
5 |
E |
| 4 |
5 |
E |
E |
E |
| 5 |
E |
E |
5 |
E |
Which of the following is true of the strings accepted by this automaton?
[Choose all that apply]
Question 8
Consider the following grammar:
S→baSab∣baS∣b
Which of the following is true?
[Choose all that apply]
Question 9
Consider again the grammar in last question (Question 8), augmented with a new start symbol and a production that includes an end-of-input marker:
S′→S$
S→baSab∣baS∣b
Recall that the algorithm for constructing a simple recursive descent parser given in the lecture videos tries the productions in a particular order when trying to parse an input string. What order of the S productions results in the fastest time to parse the string 'babab' using the simple recursive descent strategy? Assume that the input is appended with an end-of-input marker $.