|
@@ -1807,7 +1807,7 @@ instructor solution for the \LangVar{} compiler is approximately
|
|
|
|
|
|
The \LangVar{} language extends the \LangInt{} language with
|
|
|
variables. The concrete syntax of the \LangVar{} language is defined
|
|
|
-by the grammar presented in figure~\ref{fig:Lvar-concrete-syntax} and
|
|
|
+by the grammar presented in figure~\ref{fig:Lvar-concrete-syntax}, and
|
|
|
the abstract syntax is presented in figure~\ref{fig:Lvar-syntax}. The
|
|
|
nonterminal \Var{} may be any \racket{Racket}\python{Python}
|
|
|
identifier. As in \LangInt{}, \READOP{} is a nullary operator,
|
|
@@ -1923,10 +1923,10 @@ evaluates the body \code{(+ 10 x)}, producing $42$.
|
|
|
%
|
|
|
{\if\edition\pythonEd\pythonColor
|
|
|
%
|
|
|
-The \LangVar{} language includes assignment statements, which define a
|
|
|
+The \LangVar{} language includes an assignment statement, which defines a
|
|
|
variable for use in later statements and initializes the variable with
|
|
|
the value of an expression. The abstract syntax for assignment is
|
|
|
-defined in Figure~\ref{fig:Lvar-syntax}. The concrete syntax for
|
|
|
+defined in figure~\ref{fig:Lvar-syntax}. The concrete syntax for
|
|
|
assignment is \index{subject}{Assign@\texttt{Assign}}
|
|
|
\begin{lstlisting}
|
|
|
|$\itm{var}$| = |$\itm{exp}$|
|
|
@@ -2064,7 +2064,7 @@ method overriding to interpret \LangInt{} and \LangVar{} using
|
|
|
%
|
|
|
\racket{the
|
|
|
\href{https://docs.racket-lang.org/guide/classes.html}{\code{class}}
|
|
|
- \index{subject}{class} feature of Racket.}
|
|
|
+ \index{subject}{class} feature of Racket.}%
|
|
|
%
|
|
|
\python{a Python \code{class} definition.}
|
|
|
%
|
|
@@ -2136,7 +2136,7 @@ def InterpLvar(InterpLint):
|
|
|
\end{minipage}
|
|
|
\fi}
|
|
|
\end{center}
|
|
|
-Getting back to the troublesome example, repeated here:
|
|
|
+We return to the troublesome example, repeated here:
|
|
|
{\if\edition\racketEd
|
|
|
\begin{lstlisting}
|
|
|
(Let 'y (Int 10) (Prim '- (Var 'y)))
|
|
@@ -2148,9 +2148,9 @@ y = 10
|
|
|
print(-y)
|
|
|
\end{lstlisting}
|
|
|
\fi}
|
|
|
-\noindent We can invoke the \code{interp\_exp} method for \LangVar{}
|
|
|
+\noindent We can invoke the \code{interp\_exp} method for \LangVar{}%
|
|
|
\racket{on this expression,}
|
|
|
-\python{on the \code{-y} expression,}%
|
|
|
+\python{on the \code{-y} expression,}
|
|
|
%
|
|
|
which we call \code{e0}, by creating an object of the \LangVar{} class
|
|
|
and calling the \code{interp\_exp} method
|
|
@@ -3390,7 +3390,7 @@ variables with their initializing expressions.
|
|
|
|
|
|
{\if\edition\racketEd
|
|
|
%
|
|
|
-Returning to the example program with the expression \code{(+ 42 (-
|
|
|
+In the example program with the expression \code{(+ 42 (-
|
|
|
10))}, the subexpression \code{(- 10)} should be processed using the
|
|
|
\code{rco\_atom} function because it is an argument of the \code{+}
|
|
|
operator and therefore needs to become atomic. The output of
|
|
@@ -3411,7 +3411,7 @@ tmp.1
|
|
|
%
|
|
|
Returning to the example program with the expression \code{42 + -10},
|
|
|
the subexpression \code{-10} should be processed using the
|
|
|
-\code{rco\_exp} function with \code{True} as the second argument
|
|
|
+\code{rco\_exp} function with \code{True} as the second argument,
|
|
|
because \code{-10} is an argument of the \code{+} operator and
|
|
|
therefore needs to become atomic. The output of \code{rco\_exp}
|
|
|
applied to \code{-10} is as follows.
|
|
@@ -3517,8 +3517,8 @@ programs, place \lstinline{(debug-level 1)} before the call to
|
|
|
{\if\edition\pythonEd\pythonColor
|
|
|
Implement the \code{remove\_complex\_operands} pass in
|
|
|
\code{compiler.py}, creating auxiliary functions for each
|
|
|
- nonterminal in the grammar, i.e., \code{rco\_exp}
|
|
|
- and \code{rco\_stmt}. We recommend you use the function
|
|
|
+ nonterminal in the grammar, that is, \code{rco\_exp}
|
|
|
+ and \code{rco\_stmt}. We recommend that you use the function
|
|
|
\code{utils.generate\_name()} to generate fresh names from a stub string.
|
|
|
\fi}
|
|
|
\end{exercise}
|
|
@@ -3835,7 +3835,7 @@ recursively and then append the resulting instructions.
|
|
|
We recommend that you use the function \code{utils.label\_name()} to
|
|
|
transform strings into labels, for example, in
|
|
|
the target of the \code{callq} instruction. This practice makes your
|
|
|
-compiler portable across Linus and Mac OS X, which requires an underscore
|
|
|
+compiler portable across Linux and Mac OS X, which requires an underscore
|
|
|
prefixed to all labels.
|
|
|
\fi}
|
|
|
\begin{exercise}
|
|
@@ -3855,7 +3855,7 @@ list of \code{passes} and then run the script to test your compiler.
|
|
|
Implement the \key{select\_instructions} pass in
|
|
|
\code{compiler.py}. Create three new example programs that are
|
|
|
designed to exercise all the interesting cases in this pass.
|
|
|
-Run the \code{run-tests.py} script to to check
|
|
|
+Run the \code{run-tests.py} script to check
|
|
|
whether the output programs produce the same result as the input
|
|
|
programs.
|
|
|
\fi}
|
|
@@ -3958,7 +3958,7 @@ list of \code{passes} and then run the script to test your compiler.
|
|
|
\end{lstlisting}
|
|
|
\fi}
|
|
|
{\if\edition\pythonEd\pythonColor
|
|
|
-Run the \code{run-tests.py} script to to check
|
|
|
+Run the \code{run-tests.py} script to check
|
|
|
whether the output programs produce the same result as the input
|
|
|
programs.
|
|
|
\fi}
|
|
@@ -4038,7 +4038,7 @@ list of \code{passes} and then run the script to test your compiler.
|
|
|
\end{lstlisting}
|
|
|
\fi}
|
|
|
{\if\edition\pythonEd\pythonColor
|
|
|
-Run the \code{run-tests.py} script to to check
|
|
|
+Run the \code{run-tests.py} script to check
|
|
|
whether the output programs produce the same result as the input
|
|
|
programs.
|
|
|
\fi}
|
|
@@ -4062,8 +4062,9 @@ all labels (for example, changing \key{main} to \key{\_main}).
|
|
|
returns \code{'macosx}, \code{'unix}, or \code{'windows}.}
|
|
|
%
|
|
|
\python{The Python \code{platform} library includes a \code{system()}
|
|
|
- function that returns \code{'Linux'}, \code{'Windows'}, or
|
|
|
- \code{'Darwin'} (for Mac).}
|
|
|
+ function that returns \code{\textquotesingle Linux\textquotesingle},
|
|
|
+ \code{\textquotesingle Windows\textquotesingle}, or
|
|
|
+ \code{\textquotesingle Darwin\textquotesingle} (for Mac).}
|
|
|
|
|
|
\begin{exercise}\normalfont\normalsize
|
|
|
%
|
|
@@ -4088,7 +4089,7 @@ the provided \key{runtime.c} file to \key{runtime.o} using
|
|
|
\fi}
|
|
|
{\if\edition\pythonEd\pythonColor
|
|
|
%
|
|
|
-Run the \code{run-tests.py} script to to check whether the output
|
|
|
+Run the \code{run-tests.py} script to check whether the output
|
|
|
programs produce the same result as the input programs. That script
|
|
|
translates the x86 AST that you produce into a string by invoking the
|
|
|
\code{repr} method that is implemented by the x86 AST classes in
|
|
@@ -6656,7 +6657,7 @@ Run the script to test the register allocator.
|
|
|
\fi}
|
|
|
%
|
|
|
{\if\edition\pythonEd\pythonColor
|
|
|
-Run the \code{run-tests.py} script to to check whether the
|
|
|
+Run the \code{run-tests.py} script to check whether the
|
|
|
output programs produce the same result as the input programs.
|
|
|
\fi}
|
|
|
\end{exercise}
|