61a lecture 27 announcements interpreting scheme the
play

61A Lecture 27 Announcements Interpreting Scheme The Structure of - PowerPoint PPT Presentation

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:


  1. 61A Lecture 27

  2. Announcements

  3. Interpreting Scheme

  4. The Structure of an Interpreter 4

  5. The Structure of an Interpreter Eval Apply 4

  6. The Structure of an Interpreter Eval Base cases: Apply 4

  7. The Structure of an Interpreter Eval Base cases: • Primitive values (numbers) Apply 4

  8. The Structure of an Interpreter Eval Base cases: • Primitive values (numbers) Recursive calls: Apply 4

  9. The Structure of an Interpreter Eval Base cases: • Primitive values (numbers) Recursive calls: • Eval(operator, operands) of call expressions Apply 4

  10. The Structure of an Interpreter Eval Base cases: • Primitive values (numbers) Recursive calls: • Eval(operator, operands) of call expressions • Apply(procedure, arguments) Apply 4

  11. 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

  12. 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

  13. 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

  14. 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

  15. 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

  16. 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

  17. 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

  18. 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

  19. Special Forms

  20. Scheme Evaluation 6

  21. Scheme Evaluation The scheme_eval function choose behavior based on expression form: 6

  22. Scheme Evaluation The scheme_eval function choose behavior based on expression form: • Symbols are looked up in the current environment 6

  23. 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

  24. 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

  25. 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

  26. 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

  27. 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

  28. 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

  29. 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

  30. 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

  31. 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

  32. 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

  33. 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

  34. Logical Forms

  35. Logical Special Forms 8

  36. Logical Special Forms Logical forms may only evaluate some sub-expressions 8

Recommend


More recommend