|
abstract class Expression extends TreeNode { |
|
protected Expression(int lineNumber) {super(lineNumber);} |
|
private AbstractSymbol type = null; |
|
public AbstractSymbol get_type() { return type; } |
|
public Expression set_type(AbstractSymbol s) { type = s; return this; } |
|
public abstract void dump_with_types(PrintStream out, int n); |
|
public void dump_type(PrintStream out, int n) { |
|
if (type != null) { out.println(Utilities.pad(n) + ": " + type.getString()); } |
|
else { out.println(Utilities.pad(n) + ": _no_type"); } |
|
} |
|
} |
|
|
|
class assign extends Expression { |
|
protected AbstractSymbol name; |
|
protected Expression expr; |
|
public assign(int lineNumber, AbstractSymbol a1, Expression a2) { |
|
super(lineNumber); |
|
name = a1; |
|
expr = a2; |
|
} |
|
public TreeNode copy() { |
|
return new assign(lineNumber, copy_AbstractSymbol(name), (Expression)expr.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "assign\n"); |
|
dump_AbstractSymbol(out, n+2, name); |
|
expr.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_assign"); |
|
dump_AbstractSymbol(out, n + 2, name); |
|
expr.dump_with_types(out, n + 2); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class static_dispatch extends Expression { |
|
protected Expression expr; |
|
protected AbstractSymbol type_name; |
|
protected AbstractSymbol name; |
|
protected Expressions actual; |
|
public static_dispatch(int lineNumber, Expression a1, AbstractSymbol a2, AbstractSymbol a3, Expressions a4) { |
|
super(lineNumber); |
|
expr = a1; |
|
type_name = a2; |
|
name = a3; |
|
actual = a4; |
|
} |
|
public TreeNode copy() { |
|
return new static_dispatch(lineNumber, (Expression)expr.copy(), copy_AbstractSymbol(type_name), copy_AbstractSymbol(name), (Expressions)actual.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "static_dispatch\n"); |
|
expr.dump(out, n+2); |
|
dump_AbstractSymbol(out, n+2, type_name); |
|
dump_AbstractSymbol(out, n+2, name); |
|
actual.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_static_dispatch"); |
|
expr.dump_with_types(out, n + 2); |
|
dump_AbstractSymbol(out, n + 2, type_name); |
|
dump_AbstractSymbol(out, n + 2, name); |
|
out.println(Utilities.pad(n + 2) + "("); |
|
for (Enumeration e = actual.getElements(); e.hasMoreElements();) { |
|
((Expression)e.nextElement()).dump_with_types(out, n + 2); |
|
} |
|
out.println(Utilities.pad(n + 2) + ")"); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class dispatch extends Expression { |
|
protected Expression expr; |
|
protected AbstractSymbol name; |
|
protected Expressions actual; |
|
public dispatch(int lineNumber, Expression a1, AbstractSymbol a2, Expressions a3) { |
|
super(lineNumber); |
|
expr = a1; |
|
name = a2; |
|
actual = a3; |
|
} |
|
public TreeNode copy() { |
|
return new dispatch(lineNumber, (Expression)expr.copy(), copy_AbstractSymbol(name), (Expressions)actual.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "dispatch\n"); |
|
expr.dump(out, n+2); |
|
dump_AbstractSymbol(out, n+2, name); |
|
actual.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_dispatch"); |
|
expr.dump_with_types(out, n + 2); |
|
dump_AbstractSymbol(out, n + 2, name); |
|
out.println(Utilities.pad(n + 2) + "("); |
|
for (Enumeration e = actual.getElements(); e.hasMoreElements();) { |
|
((Expression)e.nextElement()).dump_with_types(out, n + 2); |
|
} |
|
out.println(Utilities.pad(n + 2) + ")"); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class cond extends Expression { |
|
protected Expression pred; |
|
protected Expression then_exp; |
|
protected Expression else_exp; |
|
public cond(int lineNumber, Expression a1, Expression a2, Expression a3) { |
|
super(lineNumber); |
|
pred = a1; |
|
then_exp = a2; |
|
else_exp = a3; |
|
} |
|
public TreeNode copy() { |
|
return new cond(lineNumber, (Expression)pred.copy(), (Expression)then_exp.copy(), (Expression)else_exp.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "cond\n"); |
|
pred.dump(out, n+2); |
|
then_exp.dump(out, n+2); |
|
else_exp.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_cond"); |
|
pred.dump_with_types(out, n + 2); |
|
then_exp.dump_with_types(out, n + 2); |
|
else_exp.dump_with_types(out, n + 2); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class loop extends Expression { |
|
protected Expression pred; |
|
protected Expression body; |
|
public loop(int lineNumber, Expression a1, Expression a2) { |
|
super(lineNumber); |
|
pred = a1; |
|
body = a2; |
|
} |
|
public TreeNode copy() { |
|
return new loop(lineNumber, (Expression)pred.copy(), (Expression)body.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "loop\n"); |
|
pred.dump(out, n+2); |
|
body.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_loop"); |
|
pred.dump_with_types(out, n + 2); |
|
body.dump_with_types(out, n + 2); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class typcase extends Expression { |
|
protected Expression expr; |
|
protected Cases cases; |
|
public typcase(int lineNumber, Expression a1, Cases a2) { |
|
super(lineNumber); |
|
expr = a1; |
|
cases = a2; |
|
} |
|
public TreeNode copy() { |
|
return new typcase(lineNumber, (Expression)expr.copy(), (Cases)cases.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "typcase\n"); |
|
expr.dump(out, n+2); |
|
cases.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_typcase"); |
|
expr.dump_with_types(out, n + 2); |
|
for (Enumeration e = cases.getElements(); e.hasMoreElements();) { |
|
((Case)e.nextElement()).dump_with_types(out, n + 2); |
|
} |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class block extends Expression { |
|
protected Expressions body; |
|
public block(int lineNumber, Expressions a1) { |
|
super(lineNumber); |
|
body = a1; |
|
} |
|
public TreeNode copy() { |
|
return new block(lineNumber, (Expressions)body.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "block\n"); |
|
body.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_block"); |
|
for (Enumeration e = body.getElements(); e.hasMoreElements();) { |
|
((Expression)e.nextElement()).dump_with_types(out, n + 2); |
|
} |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
|
|
class let extends Expression { |
|
protected AbstractSymbol identifier; |
|
protected AbstractSymbol type_decl; |
|
protected Expression init; |
|
protected Expression body; |
|
public let(int lineNumber, AbstractSymbol a1, AbstractSymbol a2, Expression a3, Expression a4) { |
|
super(lineNumber); |
|
identifier = a1; |
|
type_decl = a2; |
|
init = a3; |
|
body = a4; |
|
} |
|
public TreeNode copy() { |
|
return new let(lineNumber, copy_AbstractSymbol(identifier), copy_AbstractSymbol(type_decl), (Expression)init.copy(), (Expression)body.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "let\n"); |
|
dump_AbstractSymbol(out, n+2, identifier); |
|
dump_AbstractSymbol(out, n+2, type_decl); |
|
init.dump(out, n+2); |
|
body.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_let"); |
|
dump_AbstractSymbol(out, n + 2, identifier); |
|
dump_AbstractSymbol(out, n + 2, type_decl); |
|
init.dump_with_types(out, n + 2); |
|
body.dump_with_types(out, n + 2); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
|
|
class plus extends Expression { |
|
protected Expression e1; |
|
protected Expression e2; |
|
public plus(int lineNumber, Expression a1, Expression a2) { |
|
super(lineNumber); |
|
e1 = a1; |
|
e2 = a2; |
|
} |
|
public TreeNode copy() { |
|
return new plus(lineNumber, (Expression)e1.copy(), (Expression)e2.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "plus\n"); |
|
e1.dump(out, n+2); |
|
e2.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_plus"); |
|
e1.dump_with_types(out, n + 2); |
|
e2.dump_with_types(out, n + 2); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class sub extends Expression { |
|
protected Expression e1; |
|
protected Expression e2; |
|
public sub(int lineNumber, Expression a1, Expression a2) { |
|
super(lineNumber); |
|
e1 = a1; |
|
e2 = a2; |
|
} |
|
public TreeNode copy() { |
|
return new sub(lineNumber, (Expression)e1.copy(), (Expression)e2.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "sub\n"); |
|
e1.dump(out, n+2); |
|
e2.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_sub"); |
|
e1.dump_with_types(out, n + 2); |
|
e2.dump_with_types(out, n + 2); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class mul extends Expression { |
|
protected Expression e1; |
|
protected Expression e2; |
|
public mul(int lineNumber, Expression a1, Expression a2) { |
|
super(lineNumber); |
|
e1 = a1; |
|
e2 = a2; |
|
} |
|
public TreeNode copy() { |
|
return new mul(lineNumber, (Expression)e1.copy(), (Expression)e2.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "mul\n"); |
|
e1.dump(out, n+2); |
|
e2.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_mul"); |
|
e1.dump_with_types(out, n + 2); |
|
e2.dump_with_types(out, n + 2); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class divide extends Expression { |
|
protected Expression e1; |
|
protected Expression e2; |
|
public divide(int lineNumber, Expression a1, Expression a2) { |
|
super(lineNumber); |
|
e1 = a1; |
|
e2 = a2; |
|
} |
|
public TreeNode copy() { |
|
return new divide(lineNumber, (Expression)e1.copy(), (Expression)e2.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "divide\n"); |
|
e1.dump(out, n+2); |
|
e2.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_divide"); |
|
e1.dump_with_types(out, n + 2); |
|
e2.dump_with_types(out, n + 2); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class neg extends Expression { |
|
protected Expression e1; |
|
public neg(int lineNumber, Expression a1) { |
|
super(lineNumber); |
|
e1 = a1; |
|
} |
|
public TreeNode copy() { |
|
return new neg(lineNumber, (Expression)e1.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "neg\n"); |
|
e1.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_neg"); |
|
e1.dump_with_types(out, n + 2); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class lt extends Expression { |
|
protected Expression e1; |
|
protected Expression e2; |
|
public lt(int lineNumber, Expression a1, Expression a2) { |
|
super(lineNumber); |
|
e1 = a1; |
|
e2 = a2; |
|
} |
|
public TreeNode copy() { |
|
return new lt(lineNumber, (Expression)e1.copy(), (Expression)e2.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "lt\n"); |
|
e1.dump(out, n+2); |
|
e2.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_lt"); |
|
e1.dump_with_types(out, n + 2); |
|
e2.dump_with_types(out, n + 2); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class eq extends Expression { |
|
protected Expression e1; |
|
protected Expression e2; |
|
public eq(int lineNumber, Expression a1, Expression a2) { |
|
super(lineNumber); |
|
e1 = a1; |
|
e2 = a2; |
|
} |
|
public TreeNode copy() { |
|
return new eq(lineNumber, (Expression)e1.copy(), (Expression)e2.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "eq\n"); |
|
e1.dump(out, n+2); |
|
e2.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_eq"); |
|
e1.dump_with_types(out, n + 2); |
|
e2.dump_with_types(out, n + 2); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class leq extends Expression { |
|
protected Expression e1; |
|
protected Expression e2; |
|
public leq(int lineNumber, Expression a1, Expression a2) { |
|
super(lineNumber); |
|
e1 = a1; |
|
e2 = a2; |
|
} |
|
public TreeNode copy() { |
|
return new leq(lineNumber, (Expression)e1.copy(), (Expression)e2.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "leq\n"); |
|
e1.dump(out, n+2); |
|
e2.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_leq"); |
|
e1.dump_with_types(out, n + 2); |
|
e2.dump_with_types(out, n + 2); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class comp extends Expression { |
|
protected Expression e1; |
|
public comp(int lineNumber, Expression a1) { |
|
super(lineNumber); |
|
e1 = a1; |
|
} |
|
public TreeNode copy() { |
|
return new comp(lineNumber, (Expression)e1.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "comp\n"); |
|
e1.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_comp"); |
|
e1.dump_with_types(out, n + 2); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
|
|
class int_const extends Expression { |
|
protected AbstractSymbol token; |
|
public int_const(int lineNumber, AbstractSymbol a1) { |
|
super(lineNumber); |
|
token = a1; |
|
} |
|
public TreeNode copy() { |
|
return new int_const(lineNumber, copy_AbstractSymbol(token)); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "int_const\n"); |
|
dump_AbstractSymbol(out, n+2, token); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_int"); |
|
dump_AbstractSymbol(out, n + 2, token); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class bool_const extends Expression { |
|
protected Boolean val; |
|
public bool_const(int lineNumber, Boolean a1) { |
|
super(lineNumber); |
|
val = a1; |
|
} |
|
public TreeNode copy() { |
|
return new bool_const(lineNumber, copy_Boolean(val)); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "bool_const\n"); |
|
dump_Boolean(out, n+2, val); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_bool"); |
|
dump_Boolean(out, n + 2, val); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
|
|
class string_const extends Expression { |
|
protected AbstractSymbol token; |
|
public string_const(int lineNumber, AbstractSymbol a1) { |
|
super(lineNumber); |
|
token = a1; |
|
} |
|
public TreeNode copy() { |
|
return new string_const(lineNumber, copy_AbstractSymbol(token)); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "string_const\n"); |
|
dump_AbstractSymbol(out, n+2, token); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_string"); |
|
out.print(Utilities.pad(n + 2) + "\""); |
|
Utilities.printEscapedString(out, token.getString()); |
|
out.println("\""); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class new_ extends Expression { |
|
protected AbstractSymbol type_name; |
|
public new_(int lineNumber, AbstractSymbol a1) { |
|
super(lineNumber); |
|
type_name = a1; |
|
} |
|
public TreeNode copy() { |
|
return new new_(lineNumber, copy_AbstractSymbol(type_name)); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "new_\n"); |
|
dump_AbstractSymbol(out, n+2, type_name); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_new"); |
|
dump_AbstractSymbol(out, n + 2, type_name); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class isvoid extends Expression { |
|
protected Expression e1; |
|
public isvoid(int lineNumber, Expression a1) { |
|
super(lineNumber); |
|
e1 = a1; |
|
} |
|
public TreeNode copy() { |
|
return new isvoid(lineNumber, (Expression)e1.copy()); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "isvoid\n"); |
|
e1.dump(out, n+2); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_isvoid"); |
|
e1.dump_with_types(out, n + 2); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class no_expr extends Expression { |
|
public no_expr(int lineNumber) { |
|
super(lineNumber); |
|
} |
|
public TreeNode copy() { |
|
return new no_expr(lineNumber); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "no_expr\n"); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_no_expr"); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
class object extends Expression { |
|
protected AbstractSymbol name; |
|
public object(int lineNumber, AbstractSymbol a1) { |
|
super(lineNumber); |
|
name = a1; |
|
} |
|
public TreeNode copy() { |
|
return new object(lineNumber, copy_AbstractSymbol(name)); |
|
} |
|
public void dump(PrintStream out, int n) { |
|
out.print(Utilities.pad(n) + "object\n"); |
|
dump_AbstractSymbol(out, n+2, name); |
|
} |
|
|
|
|
|
public void dump_with_types(PrintStream out, int n) { |
|
dump_line(out, n); |
|
out.println(Utilities.pad(n) + "_object"); |
|
dump_AbstractSymbol(out, n + 2, name); |
|
dump_type(out, n); |
|
} |
|
|
|
} |
|
|
|
|