equal
deleted
inserted
replaced
95 to submit the source code with which you answered the questions. However, the coursework |
95 to submit the source code with which you answered the questions. However, the coursework |
96 will \emph{only} be judged according to the answers. You can submit your answers |
96 will \emph{only} be judged according to the answers. You can submit your answers |
97 in a txt-file or as pdf.\bigskip |
97 in a txt-file or as pdf.\bigskip |
98 |
98 |
99 |
99 |
100 \subsection*{Question 1 (marked with 1\%)} |
100 \subsection*{Question 1 (marked with 2\%)} |
101 |
101 |
102 You need to lex and parse WHILE programs and submit the assembler |
102 You need to lex and parse WHILE programs and submit the assembler |
103 instructions for the Fibonacci program and for the program you submitted |
103 instructions for the Fibonacci program and for the program you submitted |
104 in Coursework 2 in Question 3. The latter should be so modified that |
104 in Coursework 2 in Question 3. The latter should be so modified that |
105 a user can input the upper bound on the console (in the original question |
105 a user can input the upper bound on the console (in the original question |
111 |
111 |
112 \begin{center} |
112 \begin{center} |
113 \texttt{for} \;\textit{Id} \texttt{:=} \textit{AExp}\; \texttt{upto} \;\textit{AExp}\; \texttt{do} \textit{Block} |
113 \texttt{for} \;\textit{Id} \texttt{:=} \textit{AExp}\; \texttt{upto} \;\textit{AExp}\; \texttt{do} \textit{Block} |
114 \end{center} |
114 \end{center} |
115 |
115 |
|
116 \noindent |
|
117 The intended meaning is to first assign the variable \textit{Id} the value of the first arithmetic |
|
118 expression, then go through the loop, at the end increase the value of the variable by 1, |
|
119 and finally test wether the value is not less or equal anymore to the value of the second |
|
120 arithmetic expression. For example the following instance of a \texttt{for}-loop |
|
121 is supposed to print out the numbers \texttt{2}, \texttt{3}, \texttt{4}. |
|
122 |
|
123 |
|
124 \begin{center} |
|
125 \begin{minipage}{6cm} |
|
126 \begin{lstlisting}[language=While,basicstyle=\ttfamily, numbers=none] |
|
127 for i := 2 upto 4 do { |
|
128 write i |
|
129 } |
|
130 \end{lstlisting} |
|
131 \end{minipage} |
|
132 \end{center} |
|
133 |
|
134 \noindent |
|
135 There are two ways how this can be implemented: one is to adapt the code generation |
|
136 part of the compiler and generate specific code for \texttt{for}-loops; the other is to |
|
137 translate the abstract syntax tree of \texttt{for}-loops into an abstract syntax tree using |
|
138 existing language constructs (for example while loops). |
|
139 |
|
140 |
|
141 |
116 \end{document} |
142 \end{document} |
117 |
143 |
118 %%% Local Variables: |
144 %%% Local Variables: |
119 %%% mode: latex |
145 %%% mode: latex |
120 %%% TeX-master: t |
146 %%% TeX-master: t |