Question 1
Consider the following grammar:
S → A ( S ) B ∣ ϵ
A → S ∣ S B ∣ x ∣ ϵ
B → S B ∣ y
What are the first and follow sets of S?
First: {x, y, '(', ϵ }, Follow: {$, '(', y}
First: {x, y, '(', ϵ }, Follow: {$, y, x, '(', ')'}
First: {x, ϵ }, Follow: {$, y, x, '(', ')'}
First: {x, y, '(', ϵ }, Follow: {y, x, '(', ')'}
First: {x, y, '('}, Follow: {$, y, x, '(', ')'}
First: {x, '('}, Follow: {$, y, x}
Question 2
What are the items in the initial state of the SLR(1) parsing automaton for the grammar in last question(Question 1)?
Do not add an extra symbol to the grammar; just use the grammar as is.
[Choose all that apply]
Question 3
Which of the following are true of the initial state of the SLR(1) parsing automaton from the last question (Question 2)?
[Choose all that apply]
Question 4
Consider grammars G1, G2, and G3.
G1: E → idT ∣ (E)T
T → + id ∣ * id
G2:
S → bSb ∣ A ∣ ϵ
A → aA ∣ ϵ
G3:
R → aR' ∣ (R)R'
R' → ϵ ∣ XR'
X → . R ∣ + R ∣ *
The number of symbols in the first sets for the *non-terminals* are:
Question 5
Given the following grammar,
stmt→ var | if_stmt
if_stmt→ if var then stmt | if var then stmt else stmt
var→ a | b | win | loss
Which of the following series is a valid bottom-up parsing for the string:
if a then if b then win else loss
[Choose all that apply]
Question 6
For the grammar in last question (Question 5), when applying shift-reduce parsing to the same string:
if a then if b then win else loss
What kind of conflicts will we have?
Question 7
Consider the following grammar:
E → T * E ∣ T
T → int + T ∣ int \mid (E)
Using shift-reduce parsing, how many shift and how many reduce moves does it take to accept the input string:
((int + int)*int)
Question 8
Consider the following grammar:
S \rightarrow Sb \mid a
This grammar is:
Question 9
Consider the following grammar:
S \rightarrow SbS \mid a
This grammar is:
Question 10
Consider the following grammar:
S \rightarrow bS \mid a
This grammar is:
Question 11
Which of the following statements are true about this grammar:
S \rightarrow aTUb \mid \epsilon
T \rightarrow cUc \mid bUb \mid aUa
U \rightarrow Sb \mid cc