CSCI 312 Assignment #4

Assignment #4: Parsing 

(Modified from Prof. Greenberg’s Homework #4).

For this assignment you will add to the parser that we discussed in class.  As usual, you will proceed in stages:

    1. Test the existing parser code for arithmetic expressions, by simply running the program you downloaded.
    2. Add the tokens, lexer rules, and parsing functions to support parsing Boolean expressions. 
    3. Add the tokens, lexer rules, and parsing functions to support the parsing of statements.
    4. Add a function run :: Store -> String -> Store that accepts a store (set of variable assignments) and a string (the text of a program) and returns the modified store made by parsing the statement. If you copy/paste your eval code from the previous assignment, this function ends up being just one line of code.

Here are some hints that may save you time and frustration:

    1. The existing lexer rules have a single character (e.g., lexer ('+':s) = TPlus:lexer s).  To support rules that use strings (multiple characters), you can chain characters together using a colon:  lexer ('f':'a':'l':'s':'e':s) = TFalse:lexer s
    2. To keep the code a little smaller, I’ve used the names AExp and BExp instead of ArithExp and BoolExp.
    3. Remember that the type for BExp includes an AExp, and the type for Stmt includes an AExp and a BExp.  Looking at your evaluator code for the previous assignment will help you see what I mean.