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*} \]
Rewrite the following grammar to eliminate left recursion:
\[S \rightarrow Sa \mid Sb \mid AB \mid C \mid \epsilon\]
Rewrite the following grammar to eliminate left recursion (note that \(\_\), digits \(0-9\), and \(+, -, *\) and \(/\) are terminals in this grammar): \[ \begin{align*} S &\rightarrow \_ S \mid SP \mid NS \mid E\\ N &\rightarrow ND \mid D\\ D &\rightarrow 0 \mid 1 \mid \cdots \mid 9\\ P &\rightarrow + \mid - \mid * \mid / \end{align*} \]
Consider the following grammar, in which \(+\), \(*\), and \(a\) are terminals: \[ S \rightarrow S S + \mid SS * \mid a \]
\[ \begin{align*} E &\rightarrow E + T \mid T\\ T &\rightarrow T F \mid F\\ F &\rightarrow F * \mid P\\ P &\rightarrow a \mid b \end{align*} \]