--- a/hws/hw09.tex Wed Dec 21 14:33:05 2022 +0000
+++ b/hws/hw09.tex Tue Apr 04 22:31:09 2023 +0100
@@ -2,6 +2,7 @@
\usepackage{../style}
\usepackage{../graphics}
\usepackage{../langs}
+\usepackage{../grammar}
\begin{document}
@@ -92,6 +93,25 @@
}
\end{lstlisting}
+\item As an optimisation technique, a compiler might want to detect `dead code' and
+ not generate anything for this code. Why does this optimisation technique have the
+ potential of speeding up the run-time of a program? (Hint: On what CPUs are programs
+ run nowadays?)
+
+\item In an earlier question, we analysed the advantages of having a lexer-phase
+ before running the parser (having a lexer is definitely a good thing to have). But you
+ might wonder if a lexer can also be implemented by a parser and some simple
+ grammar rules. Consider for example:
+
+ \begin{plstx}[margin=1cm]
+ : \meta{S\/} ::= (\meta{Kw\/}\mid \meta{Id\/}\mid \meta{Ws\/}) \cdot \meta{S\/} \;\mid\; \epsilon\\
+ : \meta{Kw\/} ::= \texttt{if} \mid \texttt{then} \mid \ldots\\
+ : \meta{Id\/} ::= (\texttt{a} \mid\ldots\mid \texttt{z}) \cdot \meta{Id\/} \;\mid\; \epsilon\\
+ : \meta{Ws\/} ::= \ldots\\
+ \end{plstx}
+
+ What is wrong with implementing a lexer in this way?
+
\item What is the difference between a parse tree and an abstract
syntax tree? Give some simple examples for each of them.