20 \texttt{comb2.sc} uploaded to KEATS. Make sure your parser combinators |
20 \texttt{comb2.sc} uploaded to KEATS. Make sure your parser combinators |
21 process list of tokens as input, not strings. Feel free to use the ``hack'' |
21 process list of tokens as input, not strings. Feel free to use the ``hack'' |
22 explained during the lectures. This might make your grammar |
22 explained during the lectures. This might make your grammar |
23 simpler. However, make sure you understand the code involved in the |
23 simpler. However, make sure you understand the code involved in the |
24 ``hack'' because if you just do ``mix-and-match'' you will receive |
24 ``hack'' because if you just do ``mix-and-match'' you will receive |
25 strange errors. The main function that will be tested is called |
25 strange error messages. The main function that will be tested is called |
26 \texttt{eval} and \texttt{Stmts.parse\_all}. The latter expects a list |
26 \texttt{eval} and \texttt{Stmts.parse\_all}. The latter expects a list |
27 of tokens as input and generates an AST. The former expects an AST and |
27 of tokens as input and generates an AST. The former expects an AST and |
28 ``runs'' the program. The marks will be distributed such that 6 marks |
28 ``runs'' the program. The marks will be distributed such that 6 marks |
29 are given for the correct grammar (and parsers); 4 marks for the correct |
29 are given for the correct grammar (and parsers); 4 marks for the correct |
30 \texttt{eval} function. You should use the lexer from CW2 for the |
30 \texttt{eval} function. You should use the lexer from CW2 for the |
31 parser - you potentially need to make additions for CW3. |
31 parser - you potentially need to make modifications to the regular |
|
32 expressions for CW3. |
32 |
33 |
33 \subsection*{Disclaimer\alert} |
34 \subsection*{Disclaimer\alert} |
34 |
35 |
35 It should be understood that the work you submit represents your own |
36 It should be understood that the work you submit represents your own |
36 effort. You have not copied from anyone else. An exception is the |
37 effort. You have not copied from anyone else. An exception is the |
37 Scala code I showed during the lectures or uploaded to KEATS, which |
38 Scala code I showed during the lectures or uploaded to KEATS, which |
38 you can both use. You can also use your own code from the CW~1 and |
39 you can both use. You can also use your own code from CW~1 and |
39 CW~2. |
40 CW~2. |
40 %But do not |
41 %But do not |
41 %be tempted to ask Github Copilot for help or do any other |
42 %be tempted to ask Github Copilot for help or do any other |
42 %shenanigans like this! |
43 %shenanigans like this! |
43 |
44 |
131 |
132 |
132 In addition to the simple assignments of the form \code{... := ...} |
133 In addition to the simple assignments of the form \code{... := ...} |
133 from Task 1, parse the assignments of the form |
134 from Task 1, parse the assignments of the form |
134 |
135 |
135 \begin{quote} |
136 \begin{quote} |
136 \texttt{... += ...} \;\;and\;\; \texttt{... *= ...} |
137 \texttt{... += ...} \;\;, \texttt{... -= ...} \;\; and\;\; \texttt{... *= ...} |
137 \end{quote} |
138 \end{quote} |
138 |
139 |
|
140 \noindent |
139 and translate them into simple assignments. For example |
141 and translate them into simple assignments. For example |
140 |
142 |
141 \begin{quote} |
143 \begin{quote} |
142 \texttt{cnt += 1} |
144 \texttt{cnt += 1} |
143 \end{quote} |
145 \end{quote} |
144 |
146 |
145 should give the assignment \texttt{cnt := cnt + 1}. Similarly |
147 \noindent |
146 for \texttt{*=}. |
148 should produce the assignment \texttt{cnt := cnt + 1}. Similarly |
|
149 for \texttt{-=} and \texttt{*=}. Be careful to \emph{translate} these |
|
150 assignments---they should not produce a separate AST-node. |
147 |
151 |
148 \subsection*{Task 4} |
152 \subsection*{Task 4} |
149 |
153 |
150 Implement an interpreter for the WHILE language you designed |
154 Implement an interpreter for the WHILE language you designed |
151 and parsed in Tasks 1 and 2. This interpreter should take |
155 and parsed in Tasks 1 and 2. This interpreter should take |