CS 250 - Programming Languages
Spring 2001
Assignment 3 -- Due February 26
Read chapters 3 and 4 of the book, and answer the following questions.
I need hard-copy of everything, and electronic copy of your program(s).
- Answer question 3-7 in your book (you may use Java
if you wish, but please specify what language you used).
- Answer question 4-7 in your book.
- Answer question 4-8 in your book.
-
Design a recursive descent parser for the syntactic class
Statements in language Jay, using the Abstract and Concrete
Syntax of Jay in Appendix B of your book and your TokenStream
class from Assignment 2 as a basis. The output of this
parser should be an abstact syntax tree for an instance of
Statements (You may work in teams of two on this question).
A skeleton version of the parser and a
simple driver program are available in the directory
~echown/courses/250/interpreter. Copy the files
ConcreteSyntax0.java, Program0.java, and
Interpreter0.java to your working directory before starting
this program.
-
Is Jay a statically typed or dynamically typed language?
Explain.
-
Extra credit: Add a display method to the appropriate abstract
syntax classes so that an abstract syntax tree for Assignment can
be displayed in indented notation. That is, the Assignment z
= 2*x + 3/y - 4; should be displayed by your methods as follows when
its abstract representation is passed to the display method:
-
Assignment:
-
Target: Variable: z
-
Source: Binary:
-
Operator: -
-
Binary:
-
Operator: +
-
Binary:
-
Operator: *
-
Value: 2
-
Variable: x
-
Binary:
-
Operator: /
-
Value: 3
-
Variable: y
-
Value: 4
-
Note that the indented notation represents a tree in which the root of
each subtree is at one tab position and the descendents are indented one
tab position to the right of that root on subsequent lines.