CSC 330 Lecture Notes Week 5
A Tree Interpreter for Pascal -- Phase 1
Relevant reading -- Chapters 3 and 4 of the book; Assignment 4 support files
and related documentation
Comparing Pascal and EJay semantics.
The two languages are quite similar semantically.
Both have the same fundamental control and expression constructs.
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).
Both have the same fundamental semantics of function call, including call-by-
reference parameter passing (it's called "call-by-var" in Pascal).
Neither has higher-level modularization constructs, such as classes.
Significant semantic differences include:
Pascal uses name type equivalencing, EJay uses structural.
Pascal uses identifiers for atomic types, EJay uses keywords.
Pascal has one top-level program body to begin program execution; EJay has a
method named "main".
Pascal passes composite values (arrays and records) by value, whereas EJay
passes them by reference.
In these notes, we'll examine an initial Pascal interpreter example.
It's at about Phase 1.25 in the 5-phase testing plan for Assignment 4.
The interpreter does assignment statements and simple integer-valued
expressions.
It provides a good working example for you to get started with the assignment.
The attached listings are these
PascalInterpreter.java -- the tree interpreter
PascalInterpreterTest.java -- the test driver program
Memory.java -- a support file for dealing with program memory used in
the interpreter
Value.java -- a small support file that defines the tagged r-values
passed around in the interpreter
LValue.java -- a small support file that defines the tagged l-values
passed around in the interpreter
Types.java -- a class with static methods used in runtime type
checking
TypeNode.java -- an extension of TreeNode for representing
data types used at runtime