Lecture 24 - Exercises
Grammar 1: \(\Sigma = \{a,
b\}, V = \{S\}, S = S\) \[
\begin{align*}
S &\rightarrow \epsilon\\
S &\rightarrow aSa\\
S &\rightarrow bSb
\end{align*}
\]
Grammar 2: \(\Sigma = \{a,
b\}, V = \{S\}, S = S\) \[
\begin{align*}
S &\rightarrow \epsilon\\
S &\rightarrow aSbS\\
S &\rightarrow bSaS\\
\end{align*}
\]
Part
A - Leftmost, Rightmost Derivations; Ambiguous Grammars
- Give a leftmost derivation of \(abab\) in Grammar 2 above.
- Give a rightmost derivation of \(abab\) in Grammar 2 above.
- Are their parse trees the same?
- Show that Grammar 2 above is ambiguous by finding more than one
left-most derivation for the string \(abaabb\).
Part B - Parsing and Left
Recursion
- Consider the grammar \(S \rightarrow aS
\mid bS \mid \epsilon\). Find a derivation for the string \(aabb\). At each step, how many characters
of the input string did you need to look at to know which rule to
apply?
- Repeat the same exercise for the grammar \(S \rightarrow Sa \mid Sb \mid
\epsilon\).