/* * Abstract Syntax Tree data structures for the Straightline language, * "Modern Compiler Implementation in Java", Appel (w/ Palsberg), * Program 1.5. */ abstract class Stm {} class CompoundStm extends Stm { Stm stm1, stm2; CompoundStm(Stm s1, Stm s2) { stm1 = s1; stm2 = s2; } } class AssignStm extends Stm { String id; Exp exp; AssignStm(String i, Exp e) { id = i; exp = e; } } class PrintStm extends Stm { ExpList exps; PrintStm(ExpList e) { exps = e; } } abstract class Exp {} class IdExp extends Exp { String id; IdExp(String i) {id = i;} } class NumExp extends Exp { int num; NumExp(int n) {num = n;} } class OpExp extends Exp { Exp left, right; int oper; final static int PLUS = 1, MINUS = 2, TIMES = 3, DIV = 4; OpExp(Exp l, int o, Exp r) { left = l; oper = o; right = r; } } class EseqExp extends Exp { Stm stm; Exp exp; EseqExp(Stm s, Exp e) { stm = s; exp = e; } } abstract class ExpList {} class PairExpList extends ExpList { Exp head; ExpList tail; public PairExpList(Exp h, ExpList t) { head = h; tail = t; } } class LastExpList extends ExpList { Exp head; public LastExpList(Exp h) {head = h;} }