Programming Languages: Optional Homework Assignment 2
G22.2110
Notes:
-
Due on May 2, 2000, 6:00pm (late homeworks will not be accepted).
- Electronic submissions only.
To be sent by email to crutcher@cs.nyu.edu.
- Send only a single text (ASCII) file as an email message.
- You are required to include a printout of a session
showing a run of your program(s) on some general test data.
For those who did the first optional homework assignment, the best
score between both assignments will be used to complement the mid-term
grade.
This homework can be implemented indifferently in Java or C++.
Consider a simple language for arithmetic expressions, defined as:
Exp ::= Int | Exp + Exp | Exp - Exp | Exp * Exp | Exp / Exp
Problem 1
Represent each kind of arithmetic expression using classes and objects. For
example, the expression (3+(5+6)) would be created by writing
(in Java):
new AddExp(new IntExp(3), new AddExp(new IntExp(5), new IntExp(6)))
Problem 2
Write an evaluator that takes such an expression, and computes its
value (of type int). Particular care should be taken with
division by 0.
This document was translated from LATEX by HEVEA.