CS 342 Lecture -*- Outline -*-
* core interpreter structure
** how to read the code
generally organized around kinds of data (ADTs)
run the program, put in print statements, see what happens
it's just a program
flip back and forth between appendix and description
description is the comments
look for errors!
check boundary cases especially
check for initializations
look for invariant properties of data structures
write in comments
what abstract concept corresponds to each type of data?
** syntax-directed intrpretation
read ()-balanced input into userinput array.
parse it
evaluate it
*** reading
read until get some non blanks, a whole line,
and a parenthesis balanced string.
*** parsing is "recursive descent" (top-down)
::= |
so 2 cases: function def's recognized by (define ...
handled by parseDef
::= (define )
so after finding (define ,
parseDef looks for , then ,
then , then ).
note: formal vs. actual parameter
has several alternatives, so have several cases.
parseExp (bottom of 488) checks for applications: (...
or values or names, etc.
example: follow parse of (+ x 2)
result of parse is a syntax tree (or function def tree)
draw expression tree for (+ x 2) see page 11
(apexp: + ((varexp: y) (valexp: 3)))
*** evaluation of expressions
**** data structures
***** environments
def: environment = a mapping from variables to values
def: x is bound to 3, 3 is the binding of x
rep: pair of lists of same length (invariant)
names and values
used for: global variables, parameters
changed by: set, function call, see eval (p. 13)
***** syntax trees
see page 9
explain variant records
data structure grammar code
variant A ::= B|C if then ..B.. else ..C
record A ::= B C parseB; parseC
***** function defs
name, formals, body (exp)
**** some questions about the interpreter
what does / mean?
what happens to syntax tress after they are evaluated (no g.c.?)
what happens if one redefines a function
what does while return?
what changes could we make to set?