value ::= TRUE, FALSE, 0, 1, 2, 3, ...
term ::= value | (term) | term + term | term - term | term < term | if term then term else term
The objective of this project is to define an abstract syntax data structure, define an evaluation function, and define a type checking function.
- Define an abstract syntax data structure using Scheme, ML, or Haskell.
- Define an evaluation function over your abstract syntax data structure. It should take an arbitrary abstract syntax structure and return either the value resulting from its evaluaton or a simple run-time error. You do not need to deal with ill-formed abstract syntax structures. Assume your AST structures are produced by a valid parser.
- Define a type checking function over your abstract syntax data structure. It should take an arbitrary abstract syntax structure and return a Boolean true if the AST structure is well-typed or false if it is not. Report any errors to the screen.
- Combine your solutions to problems 2 and 3 to construct a type checking evaluator. This evaluator should first call the type checking routine. If the input AST is not well-typed, then the evaluator should fail. If the input AST is well-typed, the evaluation function from Problem 2 should be called on the result.
- Can you guarantee that any AST structure that passes type checking will not crash when evaluated? Please explain