Adjust presentation theme to suit projector:
Black (default) -
White -
League -
Sky -
Beige -
Simple
Serif -
Blood -
Night -
Moon -
Solarized
Reads a character and decides what action to take:
Of course, this is a simple representation and we haven't taken other considerations, such as escape characters (e.g. \), line continuation characters (e.g. \ or 1, 2 etc.), complex numbers etc. into account. Again, a lot of these depend on the language features that we are designing.
As you can see, the parser recursively descends into each stage. It also checks types and syntax rules as it goes.
Why design your own?
Scanner?? We don't need no steenkin' scanner for our language. We'll just pass it straight to the lexer to sort it out.
If the first item is 'quote', simply return the list unevaluated.
(quote 1 2 ax)
If the first item is 'define', then it is of the form:
(define var expression)
Pop the var and expression from the array. Recursively evaluate expression and then set var in the symbol table
to the result of the expression.
If the first item is 'set!', then it is of the form:
(set! var expression)
Similar to handling define, except that it doesn't create a new variable in the symbol table, only replaces an
existing symbol.
If the first item is 'if', then it is of the form:
(if condition true_exp false_exp)
Pop the condition, true_exp and false_exp from the array. Then, recursively evaluate the value of condition and
depending on the return value, evaluate true_exp or false_exp.
If the first item is 'begin', then it is of the form:
(begin exp exp ...)
Simply read the rest of the array items in a for loop and evaluate each one, then return the value of the last one.
If the first item is 'lambda', then it is of the form:
(lambda (args) exp)
Return an anonymous subroutine that creates a new symbol table based on the args and evaluates the expression.
If the first item is none of the above, then it is of the form:
(proc_name arg1 arg2 ...)
Evaluate this recursively (which will fetch it out of the symbol table) and pass it the arguments.
This is implemented as a linked list of objects, each of which has a couple of member variables and methods.
The find() method works like this: