Csc 4330/6330, Programming Language Concepts (Spring 2020)

Homework 1 (Due: 28 January (Tuesday))

Extend the WAE PLY implementation in include the following tpyes of expressions:
  1. Single With Expressions: These expressions allow the possibility of evaluating a WAE expression that contains variables, given values for these variables. Some valid "single with expressions" are shown below:
    {with {x 3} {+ x x}}  should evaluate to 6
    {with {x 3} {with {y 4} {+ x y}}} should evaluate to 7
    {with {x {with {x 3} {+ x x}}} {* x x }} should evaluate to 36
    
  2. Multi With Expressions: These generalize the single with expressions by allowing multiple variables to be assigned values in the same with expression. Some examples are:
    {with {{x 3} {y 4} {z 5}} {+ x {* y z}}} should evaluate to 23
    {with {{x 3} {y 4} {z 5}} {+ {with {{x 10} {z 20}} x} {* {+ x y} z}}} should evaluate to 45
    {with {{x 3} {y 4} {z 5} {y 3}} {+ x {* y z}}} # note this is syntactically valid
                                                   # but should not be evaluated
                                                   # (semantic error should be printed)
    
    Submit the following files: WAE.py, WAELexer.py, WAEParser.py, and README
Parse trees for above with-expressions