Interpreter This lecture discusses how we can write an "interpreter" for a language. The interpreter main function is "eval" which will walk into a parse tree and "execute" the operator. It did this by recursively "evaluate" the input. Hence, the interpreter is mostly a highly recursive function. How we represent the program. A program is stored as a list. The first element is an operator, the rest is its arguments. This form is also suitable for representing a parse tree. A simple expression 1+2+3 can be written as: ("+" ("+" 1 2) 3) The "eval" function is as follow: eval( L ) if L == nil ret 0 if isatom(L) ret evalatom(L) // now L must be a list, head(L) is an operator if head(L) == "+" ret eval(second(L)) + eval(third(L)) if head(L) == ... eval walks into L. If head(L) is an atom, it can be only two things: a constant (number 1,2...) or a name (variable). We use "evalatom" to interpret them. evalatom(A) if isnumber(A) ret tail(A) // get value of a name if isname(A) ret lookup(a, vlist) lookup searches a "dictionary" of names to get its value.