Assignment #5: Parsing with Applicative Combinators
(Modified from Prof. Greenberg’s Homework #4).
For this assignment you will use Haskell’s Applicative Combinators to simplify your parser from the previous assignment, making the parsing rules much shorter and more grammar-like . Because I have already done some of the work required in Greenberg’s version of the assignment and wish to keep this code private, I will be mailing you the zipfile this time instead of posting it on our course webpage. As usual, you will proceed in stages:
-
- Test the existing parser code for arithmetic expressions without variables, by simply running the program you downloaded.
- Modify the
Parser AExp
code and add any other code necessary to support variables. - Add support for Boolean keywords (
"true"
,"false"
,"AND"
,"OR"
). - Add support for parsing Boolean constants
true
,false
. - Add support for parsing entire Boolean expressions.
- Add support for parsing statements
For extra credit, you might attempt the following:
-
- As you’ll see, my handling of keywords has quite a bit of redundancy, requiring both a lexer-like rule and a call to the
kw
function. Although I was unable to make this code any less redundant, I suspect that there is a way to do it with more sophisticated kw function. - There should also be a way to parse
Skip
statements. Can you figure it out? - As in the previous assignment, I have not included a test for sequences, where a sequences is syntactically a pair of statements separated by a semicolon; e.g.,
x = 5; y = 3
. Can you modify yourstmt
parser to handle such forms?
- As you’ll see, my handling of keywords has quite a bit of redundancy, requiring both a lexer-like rule and a call to the