Bladeren bron

created transformation environmetn

Jeremy Siek 4 jaren geleden
bovenliggende
commit
ec59799c87
2 gewijzigde bestanden met toevoegingen van 20 en 36 verwijderingen
  1. 13 36
      book.tex
  2. 7 0
      defs.tex

+ 13 - 36
book.tex

@@ -5,6 +5,7 @@
 \usepackage[T1]{fontenc}
 \usepackage[utf8]{inputenc}
 \usepackage{listings}
+\usepackage{verbatim}
 \usepackage{amsmath}
 \usepackage{amsthm}
 \usepackage{amssymb}
@@ -99,7 +100,7 @@ Cambridge, Massachusetts\\
 London, England}
 
 \begin{copyrightpage}
-  \textcopyright\ [2021] Jeremy G. Siek.  Available for free viewing
+  \textcopyright\ 2021 Jeremy G. Siek.  Available for free viewing
   or personal downloading under the
   \href{https://creativecommons.org/licenses/by-nc-nd/2.0/uk/}{CC-BY-NC-ND}
   license.
@@ -2108,27 +2109,19 @@ in the program below. This is accomplished by introducing a new
 variable, and then using the new variable in place of the complex
 operand, as shown in the output of \code{remove-complex-opera*} on the
 right.
-\begin{center}
-\begin{tabular}{lll}
-\begin{minipage}{0.4\textwidth}
+\begin{transformation}
 % var_test_19.rkt
 \begin{lstlisting}
 (let ([x (+ 42 (- 10))])
   (+ x 10))
 \end{lstlisting}
-\end{minipage}
-&
-$\Rightarrow$
-&
-\begin{minipage}{0.4\textwidth}
+\compilesto
 \begin{lstlisting}
 (let ([x (let ([tmp.1 (- 10)])
             (+ 42 tmp.1))])
    (+ x 10))
 \end{lstlisting}
-\end{minipage}
-\end{tabular}
-\end{center}
+\end{transformation}
 
 \begin{figure}[tp]
 \centering
@@ -2179,50 +2172,34 @@ Returning to the example program with the expression \code{(+ 42 (-
 \code{rco-atom} function because it is an argument of the \code{+} and
 therefore needs to become atomic.  The output of \code{rco-atom}
 applied to \code{(- 10)} is as follows.
-\begin{center}
-\begin{tabular}{lll}
-\begin{minipage}{0.4\textwidth}
+\begin{transformation}
 \begin{lstlisting}
-(- 10)
+  (- 10)
 \end{lstlisting}
-\end{minipage}
-&
-$\Rightarrow$
-&
-\begin{minipage}{0.4\textwidth}
+\compilesto
 \begin{lstlisting}
 tmp.1
 ((tmp.1 . (- 10)))
 \end{lstlisting}
-\end{minipage}
-\end{tabular}
-\end{center}
+\end{transformation}
 
 Take special care of programs such as the following that bind a
 variable to an atomic expression. You should leave such variable
 bindings unchanged, as shown in the program on the right \\
-\begin{center}
-\begin{tabular}{lll}
-\begin{minipage}{0.4\textwidth}
+\begin{transformation}
 % var_test_20.rkt
 \begin{lstlisting}
 (let ([a 42])
   (let ([b a])
     b))
 \end{lstlisting}
-\end{minipage}
-&
-$\Rightarrow$
-&
-\begin{minipage}{0.4\textwidth}
+\compilesto
 \begin{lstlisting}
 (let ([a 42])
   (let ([b a])
     b))
 \end{lstlisting}
-\end{minipage}
-\end{tabular} 
-\end{center}
+\end{transformation}
 A careless implementation of \key{rco-exp} and \key{rco-atom} might
 produce the following output with unnecessary temporary variables.
 \begin{center}
@@ -2253,7 +2230,7 @@ list of \code{passes} and then run the script to test your compiler.
 \end{lstlisting}
 While debugging your compiler, it is often useful to see the
 intermediate programs that are output from each pass. To print the
-intermediate programs, place the \lstinline{(debug-level 1)} before the call to
+intermediate programs, place \lstinline{(debug-level 1)} before the call to
 \code{interp-tests} in \code{run-tests.rkt}.
 \end{exercise}
 

+ 7 - 0
defs.tex

@@ -201,3 +201,10 @@
 
 \newcommand{\TTKEY}[1]{{\normalfont\tt #1}}
 
+\newenvironment{transformation}{
+  \newcommand{\compilesto}{%
+    \end{minipage}&$\Rightarrow$&\begin{minipage}{0.4\textwidth}}
+  \begin{center}\begin{tabular}{lll}\begin{minipage}{0.4\textwidth}
+  }{%
+  \end{minipage}\end{tabular}\end{center}%
+}