Lisp/Scheme Project George Kraft, Arash Ghoreyshi

advertisement
Lisp/Scheme
Project
George Kraft, Arash Ghoreyshi
Grammar & Abstract Syntax Tree
•
•
•
•
•
•
•
number(), symbol(), list()
lambda(), let()
car(), cdr(), cons()
add(), subtract(), multiply(), divide()
eq(), _if()
app()
expr()
Each non-terminal has a corresponding node type, e.g.
ASTNumber, ASTSymbol, etc.
Visiting the Abstract Syntax Tree
•
•
An initial AST is created using the expr()
non-terminal.
expr is then fed into the Visitor class' eval
method, which evaluates the expression,
building up the environment as it goes. It
returns an ASTExpr that represents the final
result.
Environment
•
•
•
Each Environment object represents a
particular scope.
An Environment object consists of a
HashMap, and a reference to the parent
environment.
Closures are used to provide static scoping.
Features/Requirements
•
•
•
•
•
•
•
Multiple binding instances in "lets"
Multiple parameters in lambdas
Support for recursion
Support for lists: car, cdr, cons
Whole number combinators
List combinators
foldr using combinators
Download