2020/1/23 HW2: WHILE interpreter
HW2: WHILE interpreter
Submit Assignment
Due Friday by 11:59pm Points 100 Submitting a file upload
Programming Assignment 2 – The WHILE language:
In Haskell, or the language of your choice, write an interpreter for the WHILE language. Your program should consist of:
A data structure for the abstract syntax tree (AST) of WHILE. You can decide on an appropriate representation (e.g. strings) for variables.
A parser for WHILE. You may use external libraries when writing the parser. Remember to cite any code you take from elsewhere.
Do NOT use regular expressions for parsing. (If you try it, you’ll quickly see why it doesn’t work.)
Unlike in hw1, you may NOT assume that there is always exactly one space between terms.
An interpreter for this AST. You should choose a suitable representation for stores. Your interpreter should include functions to evaluate arithmetic expressions, boolean expressions, and commands.
Remember that stores—state—only exist during evaluation, not during parsing. Your AST should not store any state that is not present in the syntax.
Variables do not need to be declared. A reference to an unset variable returns 0.
Test cases which show that your AST, parser, and interpreter work. These test cases should show good code coverage (i.e. test all cases).
Finally, add a feature to your language, like arrays, ternary operators as expressions, or (if you’re feeling ambitious!!) functions. This addition will involve modifying the AST, parser, and interpreter to support this new feature. You should also write new tests for this new feature.
The WHILE slides (course webpage » resources » slides (https://classes.soe.ucsc.edu/cse210a/Winter20/04-while-bigstep.pdf) ) should be a good starting point for the data structure and interpreter. The parsing resources (course webpage » resources » parsing (https://classes.soe.ucsc.edu/cse210a/Winter20/links.html) ) should provide a good starting point for the parser.
Your code will be tested via this testing script (https://github.com/SohumB/cse210A-asgtest/tree/hw2- while) , so please ensure your submission also satisfies the following technical requirements:
It contains a Makefile, such that running make in the root directory of your submission produces a file in the root directory called while.
This file, when executed as “./while”, reads the WHILE language via stdin, parses it to an AST, evaluates the resulting AST with an empty state, and writes the result to stdout.
Your submission will be merged with this repository during testing, so ensure there are no filename conflicts.
You may write your test cases by following the pattern in that repository; if you do, place them in the tests directory. You may execute all tests in the tests directory by running test.sh in the root directory, after merging. Good test cases should make you (and me, the grader) feel confident that your program works. However, the provided test cases in the tests directory are not the only ones you will be tested on.
https://canvas.ucsc.edu/courses/29855/assignments/106557 1/2
2020/1/23 HW2: WHILE interpreter
You will receive extra credit for hw2, if you use a language that you did not use for hw1. To receive this extra credit, please note in your README what language you used for each homework.
Good luck!
https://canvas.ucsc.edu/courses/29855/assignments/106557
2/2