Programming Languages: Chapter 10: Local Binding and Conditional Evaluation



Recap

  • preliminaries (Chapter 1)
  • language definition and description methods (BNF); can use these to define/describe more than just language (e.g., data structures) (Chapter 2)
  • scanning and parsing (Chapter 3)
  • language implementation strategies (Chapter 4)
  • recursive programming in Scheme and λ-calculus (Chapter 5)
  • (static and dynamic) binding times and bindings (e.g., scope) (Chapter 6)
  • strong typing and type inference (Chapter 7)
  • currying and higher-order functions (Chapter 8)
  • datatypes (Chapter 9)
    • definition (through define-datatype)
    • pattern matching (through cases)
  • data abstraction (Chapter 9)
    • interface, implementation, application
    • multiple representations (list, abstract-syntax, and procedural)


Plan

  • now we use these fundamentals, to build data-driven interpreters (in the style of occurs-free?, parse-expression, and unparse-expression)
  • we will progressively add features such as conditional evaluation, local binding, statements, and recursion


Preliminaries

  • set of values a programming language manipulates:
    • expressed values: possible values of expressions (e.g., in Scheme: numbers, pairs, characters, strings)
    • denoted values: values bound to variables (e.g., in Scheme: locations containing expressed values (or pointers))
  • in our first language:
    • expressed value = number
    • denoted value = number
  • two languages
    • defined language (or source language): language specified by the interpreter (here, ChAmElEoN)
    • defining language (or host language): language in which we write the interpreter (here, Scheme)


More SLLGEN

  • what do we need before we can test our interpreter? a front end
  • the sllgen:make-define-datatypes procedure is used to automatically generate the define-datatype declarations from the grammar (or we can code them up by hand)
  • read-eval-print interactive toplevel loop


A simple interpreter

  • grammar on p. 71
  • sample expressions in this language on p. 72
  • necessary datatypes on p. 72
  • simple interpreter in Figure 3.2 on p. 74


Conditional evaluation

  • how can we add conditional evaluation to our interpreter?
  • new production rule and constructor on p. 80
  • let us avoid boolean for now by associating 0 with false and anything else with true, true-value? predicate on p. 80
  • sample conditional expressions on p. 80
  • augmented eval-expression procedure


Local binding

  • how can we add local binding to our interpreter?
  • sample expressions on p. 82
  • scope holes
  • new production rule and constructor on p. 82
  • must take care to evaluate operands using passed environment and body using extending environment
  • augmented eval-expression procedure in Figure 3.6 on p. 83


References

    [EOPL2] D.P. Friedman, M. Wand, and C.T. Haynes. Essentials of Programming Languages. MIT Press, Cambridge, MA, Second edition, 2001.

Return Home