61A Lecture 27
Announcements
Interpreting Scheme
The Structure of an Interpreter 4
The Structure of an Interpreter Eval Apply 4
The Structure of an Interpreter Eval Base cases: Apply 4
The Structure of an Interpreter Eval Base cases: • Primitive values (numbers) Apply 4
The Structure of an Interpreter Eval Base cases: • Primitive values (numbers) Recursive calls: Apply 4
The Structure of an Interpreter Eval Base cases: • Primitive values (numbers) Recursive calls: • Eval(operator, operands) of call expressions Apply 4
The Structure of an Interpreter Eval Base cases: • Primitive values (numbers) Recursive calls: • Eval(operator, operands) of call expressions • Apply(procedure, arguments) Apply 4
The Structure of an Interpreter Eval Base cases: • Primitive values (numbers) Recursive calls: • Eval(operator, operands) of call expressions • Apply(procedure, arguments) Apply Base cases: • Built-in primitive procedures 4
The Structure of an Interpreter Eval Base cases: • Primitive values (numbers) • Look up values bound to symbols Recursive calls: • Eval(operator, operands) of call expressions • Apply(procedure, arguments) Apply Base cases: • Built-in primitive procedures 4
The Structure of an Interpreter Eval Base cases: • Primitive values (numbers) • Look up values bound to symbols Recursive calls: • Eval(operator, operands) of call expressions • Apply(procedure, arguments) Apply Base cases: • Built-in primitive procedures 4
The Structure of an Interpreter Eval Base cases: • Primitive values (numbers) • Look up values bound to symbols Recursive calls: • Eval(operator, operands) of call expressions • Apply(procedure, arguments) • Eval(sub-expressions) of special forms Apply Base cases: • Built-in primitive procedures 4
The Structure of an Interpreter Eval Base cases: • Primitive values (numbers) • Look up values bound to symbols Recursive calls: • Eval(operator, operands) of call expressions • Apply(procedure, arguments) • Eval(sub-expressions) of special forms Apply Base cases: • Built-in primitive procedures Recursive calls: • Eval(body) of user-defined procedures 4
The Structure of an Interpreter Eval Base cases: • Primitive values (numbers) • Look up values bound to symbols Recursive calls: • Eval(operator, operands) of call expressions • Apply(procedure, arguments) • Eval(sub-expressions) of special forms Apply Base cases: • Built-in primitive procedures Recursive calls: • Eval(body) of user-defined procedures 4
The Structure of an Interpreter Eval Base cases: • Primitive values (numbers) • Look up values bound to symbols Recursive calls: • Eval(operator, operands) of call expressions • Apply(procedure, arguments) • Eval(sub-expressions) of special forms Requires an environment for symbol Apply Base cases: lookup • Built-in primitive procedures Recursive calls: • Eval(body) of user-defined procedures 4
The Structure of an Interpreter Eval Base cases: • Primitive values (numbers) • Look up values bound to symbols Recursive calls: • Eval(operator, operands) of call expressions • Apply(procedure, arguments) • Eval(sub-expressions) of special forms Requires an environment for symbol Apply Base cases: lookup • Built-in primitive procedures Recursive calls: • Eval(body) of user-defined procedures Creates a new environment each time a user-defined procedure is applied 4
Special Forms
Scheme Evaluation 6
Scheme Evaluation The scheme_eval function choose behavior based on expression form: 6
Scheme Evaluation The scheme_eval function choose behavior based on expression form: • Symbols are looked up in the current environment 6
Scheme Evaluation The scheme_eval function choose behavior based on expression form: • Symbols are looked up in the current environment • Self-evaluating expressions are returned as values 6
Scheme Evaluation The scheme_eval function choose behavior based on expression form: • Symbols are looked up in the current environment • Self-evaluating expressions are returned as values • All other legal expressions are represented as Scheme lists, called combinations 6
Scheme Evaluation The scheme_eval function choose behavior based on expression form: • Symbols are looked up in the current environment • Self-evaluating expressions are returned as values • All other legal expressions are represented as Scheme lists, called combinations ( if <predicate> <consequent> <alternative>) 6
Scheme Evaluation The scheme_eval function choose behavior based on expression form: • Symbols are looked up in the current environment • Self-evaluating expressions are returned as values • All other legal expressions are represented as Scheme lists, called combinations ( if <predicate> <consequent> <alternative>) ( lambda (<formal-parameters>) <body>) 6
Scheme Evaluation The scheme_eval function choose behavior based on expression form: • Symbols are looked up in the current environment • Self-evaluating expressions are returned as values • All other legal expressions are represented as Scheme lists, called combinations ( if <predicate> <consequent> <alternative>) ( lambda (<formal-parameters>) <body>) ( define <name> <expression>) 6
Scheme Evaluation The scheme_eval function choose behavior based on expression form: • Symbols are looked up in the current environment • Self-evaluating expressions are returned as values • All other legal expressions are represented as Scheme lists, called combinations ( if <predicate> <consequent> <alternative>) ( lambda (<formal-parameters>) <body>) ( define <name> <expression>) (<operator> <operand 0> ... <operand k>) 6
Scheme Evaluation The scheme_eval function choose behavior based on expression form: • Symbols are looked up in the current environment • Self-evaluating expressions are returned as values • All other legal expressions are represented as Scheme lists, called combinations ( if <predicate> <consequent> <alternative>) ( lambda (<formal-parameters>) <body>) Special forms are identified ( define <name> <expression>) by the first list element (<operator> <operand 0> ... <operand k>) 6
Scheme Evaluation The scheme_eval function choose behavior based on expression form: • Symbols are looked up in the current environment • Self-evaluating expressions are returned as values • All other legal expressions are represented as Scheme lists, called combinations ( if <predicate> <consequent> <alternative>) ( lambda (<formal-parameters>) <body>) Special forms are identified ( define <name> <expression>) by the first list element (<operator> <operand 0> ... <operand k>) 6
Scheme Evaluation The scheme_eval function choose behavior based on expression form: • Symbols are looked up in the current environment • Self-evaluating expressions are returned as values • All other legal expressions are represented as Scheme lists, called combinations ( if <predicate> <consequent> <alternative>) ( lambda (<formal-parameters>) <body>) Special forms Any combination are identified that is not a ( define <name> <expression>) by the first known special list element form is a call (<operator> <operand 0> ... <operand k>) expression 6
Scheme Evaluation The scheme_eval function choose behavior based on expression form: • Symbols are looked up in the current environment • Self-evaluating expressions are returned as values • All other legal expressions are represented as Scheme lists, called combinations ( if <predicate> <consequent> <alternative>) ( lambda (<formal-parameters>) <body>) Special forms Any combination are identified that is not a ( define <name> <expression>) by the first known special list element form is a call (<operator> <operand 0> ... <operand k>) expression (define (demo s) (if (null? s) '(3) (cons (car s) (demo (cdr s))) )) 6
Scheme Evaluation The scheme_eval function choose behavior based on expression form: • Symbols are looked up in the current environment • Self-evaluating expressions are returned as values • All other legal expressions are represented as Scheme lists, called combinations ( if <predicate> <consequent> <alternative>) ( lambda (<formal-parameters>) <body>) Special forms Any combination are identified that is not a ( define <name> <expression>) by the first known special list element form is a call (<operator> <operand 0> ... <operand k>) expression (define (demo s) (if (null? s) '(3) (cons (car s) (demo (cdr s))) )) (demo (list 1 2)) 6
Logical Forms
Logical Special Forms 8
Logical Special Forms Logical forms may only evaluate some sub-expressions 8
Recommend
More recommend