CSE 4310 - CD - Assignment II
CSE 4310 - CD - Assignment II
Instruction: Attempt the following questions and prepare your assignment report handwritten
which you can submit as softcopy either by scanning or capturing. The report should be well
organized and submitted in a *.pdf format.
𝑆 → (𝐿 )| 𝑎
𝐿 → 𝐿, 𝑆| 𝑆
a. What are the terminals, nonterminals, and start symbol?
b. Find parse trees for the following sentences:
i. (𝑎, 𝑎)
ii. (𝑎, (𝑎, 𝑎))
iii. (𝑎, ((𝑎, 𝑎), (𝑎, 𝑎)))
c. Construct a leftmost derivation for each of the sentences in (b)
d. Construct a rightmost derivation for each of the sentences in (b)
e. What language does this grammar generate?
2. Consider the grammar
𝑆 → 𝑎𝑆𝑏𝑆 | 𝑏𝑆𝑎𝑆 | 𝜆
a. Show that this grammar is ambiguous by constructing two different leftmost
derivations for the sentence 𝒂𝒃𝒂𝒃.
b. Construct the corresponding rightmost derivations for 𝒂𝒃𝒂𝒃.
c. Construct the corresponding parse trees for 𝒂𝒃𝒂𝒃.
d. What language does this grammar generate?
3. Consider the grammar
𝑆 → 𝐴𝑆 | 𝑏
𝐴 → 𝑆𝐴 | 𝑏
a. Construct the collection of sets of 𝑳𝑹(𝟎) items for this grammar.
b. Construct a DFA in which each state is an 𝑳𝑹(𝟎) item from (a).
c. Construct the parsing table using the SLR algorithm.
d. Show all the moves allowed by the table from (c) on the input 𝒂𝒃𝒂𝒃.
e. Construct the canonical parsing table.
f. Construct the parsing table using the LALR algorithm.
8. Construct an SLR parsing table for the grammar in question number 3.
9. Construct a canonical LR parsing table for the following expression grammar:
E → E + E | E ∗ E | (E) | id
Obtain the sequence of configurations of the parser for the input string
w = 𝑖𝑑 ∗ (𝑖𝑑 + 𝑖𝑑).