\documentstyle[code,11pt]{article}	%
\textheight 9.25in
\textwidth 6.25in
\oddsidemargin 0in
\topmargin -0.5in
\renewcommand{\baselinestretch}{1.1}
\newcommand{\bnf}[1]{$\langle{}$#1$\rangle$}
\newcommand{\lexp}{\langle exp \rangle}
\newcommand{\makeline}{\mbox{$\left\{\hspace*{4in}\right\}$}}

\newcommand{\boolean}{\mbox{\sf boolean}}
\newcommand{\intg}{\mbox{\sf integer}}
\newcommand{\listtype}{\mbox{\sf list}}
\newcommand{\type}{\langle\mbox{\it type}\rangle}
\newcommand{\swhile}{\mbox{\sf while}}
\newcommand{\senddo}{\mbox{\sf end do}}
\newcommand{\sdo}{\mbox{\sf do}}
\newcommand{\divline}{\cline{2-2}}


\begin{document}
\begin{center} \large
Solution to Midterm \#1
\end{center}

\begin{enumerate}

%%% #1 Grammars %%%
\item  
\begin{enumerate}
  \item i, ii, iii, iv
  \item i, iii, iv
\end{enumerate}
%%% #2 Partial Correctness %%%
\item 
\newcommand{\noteq}{$\neq$}
\newcommand{\precon}{$(\forall i\in 1..n-1. A[i] \le A[i+1])  \wedge 
   (\exists k\in 1..n-1. A[k] = A[k+1])$}
\newcommand{\invar}{$(\forall i\in 1..j. A[i] < A[i+1])$}
\newcommand{\postcon}{$(\forall i\in 1..j. A[i] < A[i+1]) \wedge A[j] = A[j+1]$}
\begin{code}

\{ \precon \}

j := 1;
\swhile\ A[j] \noteq A[j+1] do

\{ \invar \}

    j := j+1;
\senddo

\{ \postcon \}
\end{code}

%%% #3 Types & Type Checking %%%
\item  

  \begin{enumerate}
        \item static scoping: 5 8 3 4 1 8 
        \item dynamic scoping 7 11 3 11 1 3

  \end{enumerate}



%%% #4 Parameter Passing %%%
\item 
  \begin{enumerate}
        \item call-by-value: 4 5 1 3 
        \item call-by-value-result: 4 5 4 3  or 4 5 5 3, depending
		on whether parameters are copied back left-to-right or
		right-to-left 
        \item call-by-reference: 8 8 8 3 
  \end{enumerate}

%%% #5 Activation Records %%%
\item \mbox{}

{\large
\begin{tabular}{ll@{\hspace{9ex}}ll@{\hspace{9ex}}ll}
 $AR_1$: & SL = $GL$ & $AR_3$: & SL = $AR_2$ & $AR_5$: & SL = $GL$\\[3ex]
	 & DL = $GL$ &         & DL = $AR_2$ &         & DL = $AR_4$  \\[3ex]
 $AR_2$: & SL = $GL$ & $AR_4$: & SL = $AR_2$  \\[3ex]
	 & DL = $AR_1$ &       & DL = $AR_3$   
\end{tabular}
}

  

\end{enumerate}
\end{document}


 