equal
deleted
inserted
replaced
235 Explain your decision and indicate what this program would |
235 Explain your decision and indicate what this program would |
236 print out. |
236 print out. |
237 |
237 |
238 \subsection*{Question 4} |
238 \subsection*{Question 4} |
239 |
239 |
240 Extend the lexer and parser to add a \texttt{break} keyword. Modify |
240 Extend the lexer and parser to add a \textcolor{codepurple}{\pcode{break}} keyword. Modify |
241 the compiler such that when a \texttt{break}-statement is encountered |
241 the compiler (including lexer and parser) such that when a \textcolor{codepurple}{\texttt{break}}-statement is encountered |
242 the code should jump out of the ``enclosing'' for-loop, or in case it |
242 the code should jump out of the ``enclosing'' for-loop, or in case it |
243 is not inside a for-loop to the end of the program. For example the |
243 is not inside a for-loop to the end of the program. For example the |
244 program |
244 program |
245 |
245 |
246 \begin{center} |
246 \begin{center} |
247 \begin{minipage}{12cm} |
247 \begin{minipage}{12cm} |
248 \begin{lstlisting}[language=While, numbers=none] |
248 \begin{lstlisting}[language=While, numbers=none] |
|
249 // should print 0 .. 10 |
249 for i := 0 upto 10 do { |
250 for i := 0 upto 10 do { |
250 write i; |
251 write i; |
251 write "\n" |
252 write "\n" |
252 }; |
253 }; |
253 |
254 |
|
255 // should print 0 .. 4 |
254 for i := 0 upto 10 do { |
256 for i := 0 upto 10 do { |
255 if i > 4 then break else skip; |
257 if i > 4 then break else skip; |
256 write i; |
258 write i; |
257 write "\n" |
259 write "\n" |
258 }; |
260 }; |