CSC 330 Lecture Notes Week 5

CSC 330 Lecture Notes Week 5
A Tree Interpreter for Pascal -- Phase 1



  1. Relevant reading -- Chapters 3 and 4 of the book; Assignment 4 support files and related documentation

  2. Comparing Pascal and EJay semantics.
    1. The two languages are quite similar semantically.
      1. Both have the same fundamental control and expression constructs.
      2. Both have the same fundamental atomic and composite data types (although the Pascal subset in the examples does not implement record types, which are the equivalent of EJay structs).
      3. Both have the same fundamental semantics of function call, including call-by- reference parameter passing (it's called "call-by-var" in Pascal).
      4. Neither has higher-level modularization constructs, such as classes.

    2. Significant semantic differences include:
      1. Pascal uses name type equivalencing, EJay uses structural.
      2. Pascal uses identifiers for atomic types, EJay uses keywords.
      3. Pascal has one top-level program body to begin program execution; EJay has a method named "main".
      4. Pascal passes composite values (arrays and records) by value, whereas EJay passes them by reference.

  3. In these notes, we'll examine an initial Pascal interpreter example.
    1. It's at about Phase 1.25 in the 5-phase testing plan for Assignment 4.
    2. The interpreter does assignment statements and simple integer-valued expressions.
    3. It provides a good working example for you to get started with the assignment.

  4. The attached listings are these
    1. PascalInterpreter.java -- the tree interpreter
    2. PascalInterpreterTest.java -- the test driver program
    3. Memory.java -- a support file for dealing with program memory used in the interpreter
    4. Value.java -- a small support file that defines the tagged r-values passed around in the interpreter
    5. LValue.java -- a small support file that defines the tagged l-values passed around in the interpreter
    6. Types.java -- a class with static methods used in runtime type checking
    7. TypeNode.java -- an extension of TreeNode for representing data types used at runtime




index | lectures | handouts | assignments | examples | doc | solutions | bin