Skip to content
Snippets Groups Projects
Verified Commit 540daa29 authored by Sankalp Gambhir's avatar Sankalp Gambhir
Browse files

Ex review: fixes from discussion session

parent 8debe626
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
......@@ -26,17 +26,30 @@
\end{solution}
\item Explain why the grammar is not LL(1).
\begin{solution}
\(IDs\) has two rules with the same \(\first\) set.
\(decl\), \(IDs\), and \(type\) each have two rules with the same
\(\first\) set.
\end{solution}
\item Give an LL(1) grammar describing the same sequences of tokens as the
previous grammar.
\begin{solution}
We can remove the common prefix from \(decl\):
\begin{gather*}
decl = type~\lstinline|ID|~decl' \\
decl' = \lstinline|;| \mid \lstinline|(| ~optIDs~\lstinline|);|
\end{gather*}
We can remove the left recursion from the \(IDs\) rule:
\begin{gather*}
IDs = \lstinline|ID| ~IDs' \\
IDs' = \epsilon \mid \lstinline|ID| ~IDs'
\end{gather*}
We can also remove the left recursion from the \(type\) rule:
\begin{gather*}
type = \lstinline|int| ~type' \\
type' = \epsilon \mid \lstinline|*| ~type'
\end{gather*}
Note that \(IDs\) can be followed only by a closing parenthesis.
\end{solution}
\end{enumerate}
......
......@@ -5,7 +5,7 @@
concatenation is given by:
%%
\begin{gather*}
L_1L_1 = \{u_1u_2 \mid u_1 \in L_1 \land u_2 \in L_2\}
L_1L_2 = \{u_1u_2 \mid u_1 \in L_1 \land u_2 \in L_2\}
\end{gather*}
%%
We that a language \(L\) left-cancels if and only if for every \(L_1, L_2\):
......@@ -15,7 +15,7 @@
\end{gather*}
\begin{enumerate}
\item Does \(L = \empty\) left-cancel? \ifAns{No}
\item Does \(L = \emptyset\) left-cancel? \ifAns{No}
\item Does \(L = \epsilon\) left-cancel? \ifAns{Yes}
\item Give a regular expression describing an infinite language \(L\) that left-cancels. \ifAns{\(a^*b\)}
\item Give a context-free grammar for another language \(L\) that
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment