Due Date: Mon 29 NovIn this project, you will extend project 1c to include a very simple, general mechanism for expressing nonlinear data structures. To implement this mechanism, you will first add three branches to your abstract syntax:
Next you will extend your evaluation function to support the additional syntax as follows:
Exampleseval (Cell(Plus(Const 3, Const 7), Const 5)) Map.empty -> Cell(Const 10, Const 5) eval (Cell(Const 1, Cell(Const 2, Cell(Const 3, Const 0)))) Map.empty -> Cell(Const 1, Cell(Const 2, Cell(Const 3, Const 0))) eval (Car(Cell(Const 10, Const 5))) Map.empty -> Const 10 eval (Cdr(Cell(Const 10, Const 5))) Map.empty -> Const 5 eval (Cdr(Const 10)) Map.empty -> error eval (Cdr(Fun("x", Var "x", Map.empty))) Map.empty -> error eval (Cdr(Cell(Const 10, Fun("x", Var "x", Map.empty)))) Map.empty -> Fun("x", Var "x", Map.empty) Additional examples will be available shortly. |
Teaching > Comp 371/471: Theory (and Practice) of Programming Languages > Projects > Fall 2010 >