Write Java classes that define Abstract Syntax Trees (ASTs) for the following grammar:
E → id | int | E opr E | id ( L ) | id ( ) | ( E ) L → E | L , E opr → + | - | * | /where id is an identifier and int is an integer. Your classes should have attributes, constructor(s), and must redefine the methods equals and toString. Do not write any other methods. Hint: You need to write an abstract class for any kind of expression and then write one subclass of this class for each different expression (identifier, integer, binary operation, and function call). You should also have a class that contains your main program. You are free to define additional classes, if needed. Do not write any parser, scanner, or evaluator. Your main program should construct the AST for the expression g(h(),y*f(x*3)) using your class constructors and should print it to the output. Your output should look like this:
Use the form below to submit your programming assignment. We do not accept email or hardcopy submissions. The only acceptable file format for your submitted file is plain text (you source file pa4.java). You may submit your file as many times as you like, but only the most recently submitted file will be retained and evaluated.
Last modified: 04/18/11 by Leonidas Fegaras