Switch to generic visitor pattern.

main
Deryck Brown 3 years ago
parent 1db90b20a8
commit 55f6b2d105
  1. 201
      Triangle.AbstractMachine.Disassembler/src/main/java/Triangle/AbstractMachine/Disassembler.java
  2. 180
      Triangle.AbstractMachine.Interpreter/src/main/java/Triangle/AbstractMachine/Interpreter.java
  3. 45
      Triangle.AbstractMachine/src/main/java/Triangle/AbstractMachine/Instruction.java
  4. 17
      Triangle.AbstractMachine/src/main/java/Triangle/AbstractMachine/Machine.java
  5. 5
      Triangle.AbstractMachine/src/main/java/Triangle/AbstractMachine/OpCode.java
  6. 6
      Triangle.AbstractMachine/src/main/java/Triangle/AbstractMachine/Primitive.java
  7. 5
      Triangle.AbstractMachine/src/main/java/Triangle/AbstractMachine/Register.java
  8. 16
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/AbstractSyntaxTree.java
  9. 12
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Actuals/ActualParameter.java
  10. 12
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Actuals/ActualParameterSequence.java
  11. 11
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Actuals/ConstActualParameter.java
  12. 8
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Actuals/EmptyActualParameterSequence.java
  13. 11
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Actuals/FuncActualParameter.java
  14. 12
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Actuals/MultipleActualParameterSequence.java
  15. 11
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Actuals/ProcActualParameter.java
  16. 10
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Actuals/SingleActualParameterSequence.java
  17. 11
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Actuals/VarActualParameter.java
  18. 12
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Aggregates/ArrayAggregate.java
  19. 13
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Aggregates/MultipleArrayAggregate.java
  20. 19
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Aggregates/MultipleRecordAggregate.java
  21. 13
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Aggregates/RecordAggregate.java
  22. 11
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Aggregates/SingleArrayAggregate.java
  23. 14
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Aggregates/SingleRecordAggregate.java
  24. 14
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Commands/AssignCommand.java
  25. 14
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Commands/CallCommand.java
  26. 12
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Commands/Command.java
  27. 8
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Commands/EmptyCommand.java
  28. 13
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Commands/IfCommand.java
  29. 13
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Commands/LetCommand.java
  30. 10
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Commands/SequentialCommand.java
  31. 13
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Commands/WhileCommand.java
  32. 14
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Declarations/BinaryOperatorDeclaration.java
  33. 14
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Declarations/ConstDeclaration.java
  34. 12
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Declarations/Declaration.java
  35. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Declarations/FuncDeclaration.java
  36. 17
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Declarations/ProcDeclaration.java
  37. 10
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Declarations/SequentialDeclaration.java
  38. 17
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Declarations/UnaryOperatorDeclaration.java
  39. 12
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Declarations/VarDeclaration.java
  40. 11
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Expressions/ArrayExpression.java
  41. 13
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Expressions/BinaryExpression.java
  42. 14
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Expressions/CallExpression.java
  43. 11
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Expressions/CharacterExpression.java
  44. 8
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Expressions/EmptyExpression.java
  45. 13
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Expressions/Expression.java
  46. 10
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Expressions/IfExpression.java
  47. 11
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Expressions/IntegerExpression.java
  48. 13
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Expressions/LetExpression.java
  49. 11
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Expressions/RecordExpression.java
  50. 13
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Expressions/UnaryExpression.java
  51. 11
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Expressions/VnameExpression.java
  52. 21
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Formals/ConstFormalParameter.java
  53. 8
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Formals/EmptyFormalParameterSequence.java
  54. 9
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Formals/FormalParameter.java
  55. 12
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Formals/FormalParameterSequence.java
  56. 14
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Formals/FuncFormalParameter.java
  57. 15
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Formals/MultipleFormalParameterSequence.java
  58. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Formals/ProcFormalParameter.java
  59. 13
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Formals/SingleFormalParameterSequence.java
  60. 19
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Formals/VarFormalParameter.java
  61. 15
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Program.java
  62. 15
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Terminals/CharacterLiteral.java
  63. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Terminals/Identifier.java
  64. 15
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Terminals/IntegerLiteral.java
  65. 15
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Terminals/Operator.java
  66. 5
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Terminals/Terminal.java
  67. 8
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Types/AnyTypeDenoter.java
  68. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Types/ArrayTypeDenoter.java
  69. 13
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Types/BoolTypeDenoter.java
  70. 13
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Types/CharTypeDenoter.java
  71. 8
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Types/ErrorTypeDenoter.java
  72. 5
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Types/FieldTypeDenoter.java
  73. 13
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Types/IntTypeDenoter.java
  74. 14
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Types/MultipleFieldTypeDenoter.java
  75. 15
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Types/RecordTypeDenoter.java
  76. 11
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Types/SimpleTypeDenoter.java
  77. 14
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Types/SingleFieldTypeDenoter.java
  78. 12
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Types/TypeDeclaration.java
  79. 11
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Types/TypeDenoter.java
  80. 154
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitor.java
  81. 15
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitors/ActualParameterSequenceVisitor.java
  82. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitors/ActualParameterVisitor.java
  83. 12
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitors/ArrayAggregateVisitor.java
  84. 27
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitors/CommandVisitor.java
  85. 30
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitors/DeclarationVisitor.java
  86. 39
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitors/ExpressionVisitor.java
  87. 12
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitors/FieldTypeDenoterVisitor.java
  88. 15
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitors/FormalParameterSequenceVisitor.java
  89. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitors/FormalParameterVisitor.java
  90. 9
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitors/IdentifierVisitor.java
  91. 12
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitors/LiteralVisitor.java
  92. 9
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitors/OperatorVisitor.java
  93. 9
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitors/ProgramVisitor.java
  94. 12
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitors/RecordAggregateVisitor.java
  95. 30
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitors/TypeDenoterVisitor.java
  96. 15
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitors/VnameVisitor.java
  97. 13
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Vnames/DotVname.java
  98. 11
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Vnames/SimpleVname.java
  99. 13
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Vnames/SubscriptVname.java
  100. 13
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Vnames/Vname.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -50,62 +50,18 @@ public class Disassembler {
* @param r the number of the register. * @param r the number of the register.
* @param rightbracket the character to print after the register. * @param rightbracket the character to print after the register.
*/ */
private static void writeR(char leftbracket, int r, char rightbracket) { private static void writeR(char leftbracket, Register r, char rightbracket) {
System.out.print(leftbracket); System.out.print(leftbracket);
switch (r) { System.out.print(r.toString());
case Machine.CBr:
System.out.print("CB");
break;
case Machine.CTr:
System.out.print("CT");
break;
case Machine.PBr:
System.out.print("PB");
break;
case Machine.PTr:
System.out.print("PT");
break;
case Machine.SBr:
System.out.print("SB");
break;
case Machine.STr:
System.out.print("ST");
break;
case Machine.HBr:
System.out.print("HB");
break;
case Machine.HTr:
System.out.print("HT");
break;
case Machine.LBr:
System.out.print("LB");
break;
case Machine.L1r:
System.out.print("L1");
break;
case Machine.L2r:
System.out.print("L2");
break;
case Machine.L3r:
System.out.print("L3");
break;
case Machine.L4r:
System.out.print("L4");
break;
case Machine.L5r:
System.out.print("L5");
break;
case Machine.L6r:
System.out.print("L6");
break;
case Machine.CPr:
System.out.print("CP");
break;
}
System.out.print(rightbracket); System.out.print(rightbracket);
} }
private static void writeR(char leftBracket, int r, char rightBracket) {
var register = Register.values()[r];
writeR(leftBracket, register, rightBracket);
}
/** /**
* Writes a void n-field of an instruction. * Writes a void n-field of an instruction.
*/ */
@ -142,89 +98,90 @@ public class Disassembler {
* @param d the displacment of the primitive routine. * @param d the displacment of the primitive routine.
*/ */
private static void writePrimitive(int d) { private static void writePrimitive(int d) {
switch (d) { var primitive = Primitive.values()[d];
case Machine.idDisplacement: switch (primitive) {
case ID:
System.out.print("id "); System.out.print("id ");
break; break;
case Machine.notDisplacement: case NOT:
System.out.print("not "); System.out.print("not ");
break; break;
case Machine.andDisplacement: case AND:
System.out.print("and "); System.out.print("and ");
break; break;
case Machine.orDisplacement: case OR:
System.out.print("or "); System.out.print("or ");
break; break;
case Machine.succDisplacement: case SUCC:
System.out.print("succ "); System.out.print("succ ");
break; break;
case Machine.predDisplacement: case PRED:
System.out.print("pred "); System.out.print("pred ");
break; break;
case Machine.negDisplacement: case NEG:
System.out.print("neg "); System.out.print("neg ");
break; break;
case Machine.addDisplacement: case ADD:
System.out.print("add "); System.out.print("add ");
break; break;
case Machine.subDisplacement: case SUB:
System.out.print("sub "); System.out.print("sub ");
break; break;
case Machine.multDisplacement: case MULT:
System.out.print("mult "); System.out.print("mult ");
break; break;
case Machine.divDisplacement: case DIV:
System.out.print("div "); System.out.print("div ");
break; break;
case Machine.modDisplacement: case MOD:
System.out.print("mod "); System.out.print("mod ");
break; break;
case Machine.ltDisplacement: case LT:
System.out.print("lt "); System.out.print("lt ");
break; break;
case Machine.leDisplacement: case LE:
System.out.print("le "); System.out.print("le ");
break; break;
case Machine.geDisplacement: case GE:
System.out.print("ge "); System.out.print("ge ");
break; break;
case Machine.gtDisplacement: case GT:
System.out.print("gt "); System.out.print("gt ");
break; break;
case Machine.eqDisplacement: case EQ:
System.out.print("eq "); System.out.print("eq ");
break; break;
case Machine.neDisplacement: case NE:
System.out.print("ne "); System.out.print("ne ");
break; break;
case Machine.eolDisplacement: case EOL:
System.out.print("eol "); System.out.print("eol ");
break; break;
case Machine.eofDisplacement: case EOF:
System.out.print("eof "); System.out.print("eof ");
break; break;
case Machine.getDisplacement: case GET:
System.out.print("get "); System.out.print("get ");
break; break;
case Machine.putDisplacement: case PUT:
System.out.print("put "); System.out.print("put ");
break; break;
case Machine.geteolDisplacement: case GETEOL:
System.out.print("geteol "); System.out.print("geteol ");
break; break;
case Machine.puteolDisplacement: case PUTEOL:
System.out.print("puteol "); System.out.print("puteol ");
break; break;
case Machine.getintDisplacement: case GETINT:
System.out.print("getint "); System.out.print("getint ");
break; break;
case Machine.putintDisplacement: case PUTINT:
System.out.print("putint "); System.out.print("putint ");
break; break;
case Machine.newDisplacement: case NEW:
System.out.print("new "); System.out.print("new ");
break; break;
case Machine.disposeDisplacement: case DISPOSE:
System.out.print("dispose "); System.out.print("dispose ");
break; break;
} }
@ -237,98 +194,98 @@ public class Disassembler {
*/ */
private static void writeInstruction(Instruction instr) { private static void writeInstruction(Instruction instr) {
switch (instr.op) { switch (instr.opCode) {
case Machine.LOADop: case LOAD:
System.out.print("LOAD "); System.out.print("LOAD ");
writeN(instr.n); writeN(instr.length);
writeD(instr.d); writeD(instr.operand);
writeR('[', instr.r, ']'); writeR('[', instr.register, ']');
break; break;
case Machine.LOADAop: case LOADA:
System.out.print("LOADA "); System.out.print("LOADA ");
blankN(); blankN();
writeD(instr.d); writeD(instr.operand);
writeR('[', instr.r, ']'); writeR('[', instr.register, ']');
break; break;
case Machine.LOADIop: case LOADI:
System.out.print("LOADI "); System.out.print("LOADI ");
writeN(instr.n); writeN(instr.length);
break; break;
case Machine.LOADLop: case LOADL:
System.out.print("LOADL "); System.out.print("LOADL ");
blankN(); blankN();
writeD(instr.d); writeD(instr.operand);
break; break;
case Machine.STOREop: case STORE:
System.out.print("STORE "); System.out.print("STORE ");
writeN(instr.n); writeN(instr.length);
writeD(instr.d); writeD(instr.operand);
writeR('[', instr.r, ']'); writeR('[', instr.register, ']');
break; break;
case Machine.STOREIop: case STOREI:
System.out.print("STOREI"); System.out.print("STOREI");
writeN(instr.n); writeN(instr.length);
break; break;
case Machine.CALLop: case CALL:
System.out.print("CALL "); System.out.print("CALL ");
if (instr.r == Machine.PBr) { if (instr.register == Register.PB) {
blankN(); blankN();
writePrimitive(instr.d); writePrimitive(instr.operand);
} else { } else {
writeR('(', instr.n, ')'); writeR('(', instr.length, ')');
System.out.print(" "); System.out.print(" ");
writeD(instr.d); writeD(instr.operand);
writeR('[', instr.r, ']'); writeR('[', instr.register, ']');
} }
break; break;
case Machine.CALLIop: case CALLI:
System.out.print("CALLI "); System.out.print("CALLI ");
break; break;
case Machine.RETURNop: case RETURN:
System.out.print("RETURN"); System.out.print("RETURN");
writeN(instr.n); writeN(instr.length);
writeD(instr.d); writeD(instr.operand);
break; break;
case Machine.PUSHop: case PUSH:
System.out.print("PUSH "); System.out.print("PUSH ");
blankN(); blankN();
writeD(instr.d); writeD(instr.operand);
break; break;
case Machine.POPop: case POP:
System.out.print("POP "); System.out.print("POP ");
writeN(instr.n); writeN(instr.length);
writeD(instr.d); writeD(instr.operand);
break; break;
case Machine.JUMPop: case JUMP:
System.out.print("JUMP "); System.out.print("JUMP ");
blankN(); blankN();
writeD(instr.d); writeD(instr.operand);
writeR('[', instr.r, ']'); writeR('[', instr.register, ']');
break; break;
case Machine.JUMPIop: case JUMPI:
System.out.print("JUMPI "); System.out.print("JUMPI ");
break; break;
case Machine.JUMPIFop: case JUMPIF:
System.out.print("JUMPIF"); System.out.print("JUMPIF");
writeN(instr.n); writeN(instr.length);
writeD(instr.d); writeD(instr.operand);
writeR('[', instr.r, ']'); writeR('[', instr.register, ']');
break; break;
case Machine.HALTop: case HALT:
System.out.print("HALT "); System.out.print("HALT ");
} }
} }

@ -40,41 +40,46 @@ public class Interpreter {
static long accumulator; static long accumulator;
static int content(int r) { static int content(int r) {
var register = Register.values()[r];
return content(register);
}
static int content(Register r) {
// Returns the current content of register r, // Returns the current content of register r,
// even if r is one of the pseudo-registers L1..L6. // even if r is one of the pseudo-registers L1..L6.
switch (r) { switch (r) {
case Machine.CBr: case CB:
return CB; return CB;
case Machine.CTr: case CT:
return CT; return CT;
case Machine.PBr: case PB:
return Machine.PB; return Machine.PB;
case Machine.PTr: case PT:
return Machine.PT; return Machine.PT;
case Machine.SBr: case SB:
return SB; return SB;
case Machine.STr: case ST:
return ST; return ST;
case Machine.HBr: case HB:
return HB; return HB;
case Machine.HTr: case HT:
return HT; return HT;
case Machine.LBr: case LB:
return LB; return LB;
case Machine.L1r: case L1:
return data[LB]; return data[LB];
case Machine.L2r: case L2:
return data[data[LB]]; return data[data[LB]];
case Machine.L3r: case L3:
return data[data[data[LB]]]; return data[data[data[LB]]];
case Machine.L4r: case L4:
return data[data[data[data[LB]]]]; return data[data[data[data[LB]]]];
case Machine.L5r: case L5:
return data[data[data[data[data[LB]]]]]; return data[data[data[data[data[LB]]]]];
case Machine.L6r: case L6:
return data[data[data[data[data[data[LB]]]]]]; return data[data[data[data[data[data[LB]]]]]];
case Machine.CPr: case CP:
return CP; return CP;
default: default:
return 0; return 0;
@ -85,7 +90,6 @@ public class Interpreter {
static void dump() { static void dump() {
// Writes a summary of the machine state. // Writes a summary of the machine state.
int addr, staticLink, dynamicLink, localRegNum;
System.out.println(""); System.out.println("");
System.out.println("State of data store and registers:"); System.out.println("State of data store and registers:");
@ -95,7 +99,7 @@ public class Interpreter {
else { else {
System.out.println(" HB-->"); System.out.println(" HB-->");
System.out.println(" |--------|"); System.out.println(" |--------|");
for (addr = HB - 1; addr >= HT; addr--) { for (var addr = HB - 1; addr >= HT; addr--) {
System.out.print(addr + ":"); System.out.print(addr + ":");
if (addr == HT) if (addr == HT)
System.out.print(" HT-->"); System.out.print(" HT-->");
@ -110,41 +114,43 @@ public class Interpreter {
if (ST == SB) if (ST == SB)
System.out.println(" |--------| (stack is empty)"); System.out.println(" |--------| (stack is empty)");
else { else {
dynamicLink = LB; var dynamicLink = LB;
staticLink = LB; var staticLink = LB;
localRegNum = Machine.LBr; var localRegNum = Register.LB;
System.out.println(" ST--> |////////|"); System.out.println(" ST--> |////////|");
System.out.println(" |--------|"); System.out.println(" |--------|");
for (addr = ST - 1; addr >= SB; addr--) { for (var addr = ST - 1; addr >= SB; addr--) {
System.out.print(addr + ":"); System.out.print(addr + ":");
if (addr == SB) if (addr == SB)
System.out.print(" SB-->"); System.out.print(" SB-->");
else if (addr == staticLink) { else if (addr == staticLink) {
switch (localRegNum) { switch (localRegNum) {
case Machine.LBr: case LB:
System.out.print(" LB-->"); System.out.print(" LB-->");
break; break;
case Machine.L1r: case L1:
System.out.print(" L1-->"); System.out.print(" L1-->");
break; break;
case Machine.L2r: case L2:
System.out.print(" L2-->"); System.out.print(" L2-->");
break; break;
case Machine.L3r: case L3:
System.out.print(" L3-->"); System.out.print(" L3-->");
break; break;
case Machine.L4r: case L4:
System.out.print(" L4-->"); System.out.print(" L4-->");
break; break;
case Machine.L5r: case L5:
System.out.print(" L5-->"); System.out.print(" L5-->");
break; break;
case Machine.L6r: case L6:
System.out.print(" L6-->"); System.out.print(" L6-->");
break; break;
default:
break;
} }
staticLink = data[addr]; staticLink = data[addr];
localRegNum = localRegNum + 1; localRegNum = Register.values()[localRegNum.ordinal() + 1];
} else } else
System.out.print(" "); System.out.print(" ");
if ((addr == dynamicLink) && (dynamicLink != SB)) if ((addr == dynamicLink) && (dynamicLink != SB))
@ -277,45 +283,46 @@ public class Interpreter {
int addr, size; int addr, size;
char ch; char ch;
switch (primitiveDisplacement) { var primitive = Primitive.values()[primitiveDisplacement];
case Machine.idDisplacement: switch (primitive) {
case ID:
break; // nothing to be done break; // nothing to be done
case Machine.notDisplacement: case NOT:
data[ST - 1] = toInt(!isTrue(data[ST - 1])); data[ST - 1] = toInt(!isTrue(data[ST - 1]));
break; break;
case Machine.andDisplacement: case AND:
ST = ST - 1; ST = ST - 1;
data[ST - 1] = toInt(isTrue(data[ST - 1]) & isTrue(data[ST])); data[ST - 1] = toInt(isTrue(data[ST - 1]) & isTrue(data[ST]));
break; break;
case Machine.orDisplacement: case OR:
ST = ST - 1; ST = ST - 1;
data[ST - 1] = toInt(isTrue(data[ST - 1]) | isTrue(data[ST])); data[ST - 1] = toInt(isTrue(data[ST - 1]) | isTrue(data[ST]));
break; break;
case Machine.succDisplacement: case SUCC:
data[ST - 1] = overflowChecked(data[ST - 1] + 1); data[ST - 1] = overflowChecked(data[ST - 1] + 1);
break; break;
case Machine.predDisplacement: case PRED:
data[ST - 1] = overflowChecked(data[ST - 1] - 1); data[ST - 1] = overflowChecked(data[ST - 1] - 1);
break; break;
case Machine.negDisplacement: case NEG:
data[ST - 1] = -data[ST - 1]; data[ST - 1] = -data[ST - 1];
break; break;
case Machine.addDisplacement: case ADD:
ST = ST - 1; ST = ST - 1;
accumulator = data[ST - 1]; accumulator = data[ST - 1];
data[ST - 1] = overflowChecked(accumulator + data[ST]); data[ST - 1] = overflowChecked(accumulator + data[ST]);
break; break;
case Machine.subDisplacement: case SUB:
ST = ST - 1; ST = ST - 1;
accumulator = data[ST - 1]; accumulator = data[ST - 1];
data[ST - 1] = overflowChecked(accumulator - data[ST]); data[ST - 1] = overflowChecked(accumulator - data[ST]);
break; break;
case Machine.multDisplacement: case MULT:
ST = ST - 1; ST = ST - 1;
accumulator = data[ST - 1]; accumulator = data[ST - 1];
data[ST - 1] = overflowChecked(accumulator * data[ST]); data[ST - 1] = overflowChecked(accumulator * data[ST]);
break; break;
case Machine.divDisplacement: case DIV:
ST = ST - 1; ST = ST - 1;
accumulator = data[ST - 1]; accumulator = data[ST - 1];
if (data[ST] != 0) if (data[ST] != 0)
@ -323,7 +330,7 @@ public class Interpreter {
else else
status = failedZeroDivide; status = failedZeroDivide;
break; break;
case Machine.modDisplacement: case MOD:
ST = ST - 1; ST = ST - 1;
accumulator = data[ST - 1]; accumulator = data[ST - 1];
if (data[ST] != 0) if (data[ST] != 0)
@ -331,41 +338,41 @@ public class Interpreter {
else else
status = failedZeroDivide; status = failedZeroDivide;
break; break;
case Machine.ltDisplacement: case LT:
ST = ST - 1; ST = ST - 1;
data[ST - 1] = toInt(data[ST - 1] < data[ST]); data[ST - 1] = toInt(data[ST - 1] < data[ST]);
break; break;
case Machine.leDisplacement: case LE:
ST = ST - 1; ST = ST - 1;
data[ST - 1] = toInt(data[ST - 1] <= data[ST]); data[ST - 1] = toInt(data[ST - 1] <= data[ST]);
break; break;
case Machine.geDisplacement: case GE:
ST = ST - 1; ST = ST - 1;
data[ST - 1] = toInt(data[ST - 1] >= data[ST]); data[ST - 1] = toInt(data[ST - 1] >= data[ST]);
break; break;
case Machine.gtDisplacement: case GT:
ST = ST - 1; ST = ST - 1;
data[ST - 1] = toInt(data[ST - 1] > data[ST]); data[ST - 1] = toInt(data[ST - 1] > data[ST]);
break; break;
case Machine.eqDisplacement: case EQ:
size = data[ST - 1]; // size of each comparand size = data[ST - 1]; // size of each comparand
ST = ST - 2 * size; ST = ST - 2 * size;
data[ST - 1] = toInt(equal(size, ST - 1, ST - 1 + size)); data[ST - 1] = toInt(equal(size, ST - 1, ST - 1 + size));
break; break;
case Machine.neDisplacement: case NE:
size = data[ST - 1]; // size of each comparand size = data[ST - 1]; // size of each comparand
ST = ST - 2 * size; ST = ST - 2 * size;
data[ST - 1] = toInt(!equal(size, ST - 1, ST - 1 + size)); data[ST - 1] = toInt(!equal(size, ST - 1, ST - 1 + size));
break; break;
case Machine.eolDisplacement: case EOL:
data[ST] = toInt(currentChar == '\n'); data[ST] = toInt(currentChar == '\n');
ST = ST + 1; ST = ST + 1;
break; break;
case Machine.eofDisplacement: case EOF:
data[ST] = toInt(currentChar == -1); data[ST] = toInt(currentChar == -1);
ST = ST + 1; ST = ST + 1;
break; break;
case Machine.getDisplacement: case GET:
ST = ST - 1; ST = ST - 1;
addr = data[ST]; addr = data[ST];
try { try {
@ -375,12 +382,12 @@ public class Interpreter {
} }
data[addr] = currentChar; data[addr] = currentChar;
break; break;
case Machine.putDisplacement: case PUT:
ST = ST - 1; ST = ST - 1;
ch = (char) data[ST]; ch = (char) data[ST];
System.out.print(ch); System.out.print(ch);
break; break;
case Machine.geteolDisplacement: case GETEOL:
try { try {
while ((currentChar = System.in.read()) != '\n') while ((currentChar = System.in.read()) != '\n')
; ;
@ -388,10 +395,10 @@ public class Interpreter {
status = failedIOError; status = failedIOError;
} }
break; break;
case Machine.puteolDisplacement: case PUTEOL:
System.out.println(""); System.out.println("");
break; break;
case Machine.getintDisplacement: case GETINT:
ST = ST - 1; ST = ST - 1;
addr = data[ST]; addr = data[ST];
try { try {
@ -401,18 +408,18 @@ public class Interpreter {
} }
data[addr] = (int) accumulator; data[addr] = (int) accumulator;
break; break;
case Machine.putintDisplacement: case PUTINT:
ST = ST - 1; ST = ST - 1;
accumulator = data[ST]; accumulator = data[ST];
System.out.print(accumulator); System.out.print(accumulator);
break; break;
case Machine.newDisplacement: case NEW:
size = data[ST - 1]; size = data[ST - 1];
checkSpace(size); checkSpace(size);
HT = HT - size; HT = HT - size;
data[ST - 1] = HT; data[ST - 1] = HT;
break; break;
case Machine.disposeDisplacement: case DISPOSE:
ST = ST - 1; // no action taken at present ST = ST - 1; // no action taken at present
break; break;
} }
@ -422,7 +429,6 @@ public class Interpreter {
// Runs the program in code store. // Runs the program in code store.
Instruction currentInstr; Instruction currentInstr;
int op, r, n, d, addr, index;
// Initialize registers ... // Initialize registers ...
ST = SB; ST = SB;
@ -434,65 +440,67 @@ public class Interpreter {
// Fetch instruction ... // Fetch instruction ...
currentInstr = Machine.code[CP]; currentInstr = Machine.code[CP];
// Decode instruction ... // Decode instruction ...
op = currentInstr.op; var op = currentInstr.opCode;
r = currentInstr.r; var r = currentInstr.register;
n = currentInstr.n; var n = currentInstr.length;
d = currentInstr.d; var d = currentInstr.operand;
int addr;
// Execute instruction ... // Execute instruction ...
switch (op) { switch (op) {
case Machine.LOADop: case LOAD:
addr = d + content(r); addr = d + content(r);
checkSpace(n); checkSpace(n);
for (index = 0; index < n; index++) for (var index = 0; index < n; index++)
data[ST + index] = data[addr + index]; data[ST + index] = data[addr + index];
ST = ST + n; ST = ST + n;
CP = CP + 1; CP = CP + 1;
break; break;
case Machine.LOADAop: case LOADA:
addr = d + content(r); addr = d + content(r);
checkSpace(1); checkSpace(1);
data[ST] = addr; data[ST] = addr;
ST = ST + 1; ST = ST + 1;
CP = CP + 1; CP = CP + 1;
break; break;
case Machine.LOADIop: case LOADI:
ST = ST - 1; ST = ST - 1;
addr = data[ST]; addr = data[ST];
checkSpace(n); checkSpace(n);
for (index = 0; index < n; index++) for (var index = 0; index < n; index++)
data[ST + index] = data[addr + index]; data[ST + index] = data[addr + index];
ST = ST + n; ST = ST + n;
CP = CP + 1; CP = CP + 1;
break; break;
case Machine.LOADLop: case LOADL:
checkSpace(1); checkSpace(1);
data[ST] = d; data[ST] = d;
ST = ST + 1; ST = ST + 1;
CP = CP + 1; CP = CP + 1;
break; break;
case Machine.STOREop: case STORE:
addr = d + content(r); addr = d + content(r);
ST = ST - n; ST = ST - n;
for (index = 0; index < n; index++) for (var index = 0; index < n; index++)
data[addr + index] = data[ST + index]; data[addr + index] = data[ST + index];
CP = CP + 1; CP = CP + 1;
break; break;
case Machine.STOREIop: case STOREI:
ST = ST - 1; ST = ST - 1;
addr = data[ST]; addr = data[ST];
ST = ST - n; ST = ST - n;
for (index = 0; index < n; index++) for (var index = 0; index < n; index++)
data[addr + index] = data[ST + index]; data[addr + index] = data[ST + index];
CP = CP + 1; CP = CP + 1;
break; break;
case Machine.CALLop: case CALL:
addr = d + content(r); addr = d + content(r);
if (addr >= Machine.PB) { if (addr >= Machine.PB) {
callPrimitive(addr - Machine.PB); callPrimitive(addr - Machine.PB);
CP = CP + 1; CP = CP + 1;
} else { } else {
checkSpace(3); checkSpace(3);
if ((0 <= n) && (n <= 15)) if (0 <= n && n <= 15)
data[ST] = content(n); // static link data[ST] = content(n); // static link
else else
status = failedInvalidInstruction; status = failedInvalidInstruction;
@ -503,7 +511,7 @@ public class Interpreter {
CP = addr; CP = addr;
} }
break; break;
case Machine.CALLIop: case CALLI:
ST = ST - 2; ST = ST - 2;
addr = data[ST + 1]; addr = data[ST + 1];
if (addr >= Machine.PB) { if (addr >= Machine.PB) {
@ -518,43 +526,43 @@ public class Interpreter {
CP = addr; CP = addr;
} }
break; break;
case Machine.RETURNop: case RETURN:
addr = LB - d; addr = LB - d;
CP = data[LB + 2]; CP = data[LB + 2];
LB = data[LB + 1]; LB = data[LB + 1];
ST = ST - n; ST = ST - n;
for (index = 0; index < n; index++) for (var index = 0; index < n; index++)
data[addr + index] = data[ST + index]; data[addr + index] = data[ST + index];
ST = addr + n; ST = addr + n;
break; break;
case Machine.PUSHop: case PUSH:
checkSpace(d); checkSpace(d);
ST = ST + d; ST = ST + d;
CP = CP + 1; CP = CP + 1;
break; break;
case Machine.POPop: case POP:
addr = ST - n - d; addr = ST - n - d;
ST = ST - n; ST = ST - n;
for (index = 0; index < n; index++) for (var index = 0; index < n; index++)
data[addr + index] = data[ST + index]; data[addr + index] = data[ST + index];
ST = addr + n; ST = addr + n;
CP = CP + 1; CP = CP + 1;
break; break;
case Machine.JUMPop: case JUMP:
CP = d + content(r); CP = d + content(r);
break; break;
case Machine.JUMPIop: case JUMPI:
ST = ST - 1; ST = ST - 1;
CP = data[ST]; CP = data[ST];
break; break;
case Machine.JUMPIFop: case JUMPIF:
ST = ST - 1; ST = ST - 1;
if (data[ST] == n) if (data[ST] == n)
CP = d + content(r); CP = d + content(r);
else else
CP = CP + 1; CP = CP + 1;
break; break;
case Machine.HALTop: case HALT:
status = halted; status = halted;
break; break;
} }

@ -21,13 +21,6 @@ import java.io.IOException;
public class Instruction { public class Instruction {
public Instruction() {
op = 0;
r = 0;
n = 0;
d = 0;
}
// Java has no type synonyms, so the following representations are // Java has no type synonyms, so the following representations are
// assumed: // assumed:
// //
@ -37,26 +30,36 @@ public class Instruction {
// Operand = -32767..+32767; {16 bits signed} // Operand = -32767..+32767; {16 bits signed}
// Represents TAM instructions. // Represents TAM instructions.
public int op; // OpCode final OpCode opCode;
public int r; // RegisterNumber final Register register;
public int n; // Length final int length;
public int d; // Operand int operand; // Not final to allow for patching jump address
public Instruction(OpCode opcode, Register register, int length, int operand) {
this.opCode = opcode;
this.register = register;
this.length = length;
this.operand = operand;
}
public void setOperand(int operand) {
this.operand = operand;
}
public void write(DataOutputStream output) throws IOException { public void write(DataOutputStream output) throws IOException {
output.writeInt(op); output.writeInt(opCode.ordinal());
output.writeInt(r); output.writeInt(register.ordinal());
output.writeInt(n); output.writeInt(length);
output.writeInt(d); output.writeInt(operand);
} }
public static Instruction read(DataInputStream input) throws IOException { public static Instruction read(DataInputStream input) throws IOException {
Instruction inst = new Instruction();
try { try {
inst.op = input.readInt(); var opCode = OpCode.values()[input.readInt()];
inst.r = input.readInt(); var register = Register.values()[input.readInt()];
inst.n = input.readInt(); var length = input.readInt();
inst.d = input.readInt(); var operand = input.readInt();
return inst; return new Instruction(opCode, register, length, operand);
} catch (EOFException s) { } catch (EOFException s) {
return null; return null;
} }

@ -31,10 +31,6 @@ public final class Machine {
// INSTRUCTIONS // INSTRUCTIONS
// Operation codes
public final static int LOADop = 0, LOADAop = 1, LOADIop = 2, LOADLop = 3, STOREop = 4, STOREIop = 5, CALLop = 6,
CALLIop = 7, RETURNop = 8, PUSHop = 10, POPop = 11, JUMPop = 12, JUMPIop = 13, JUMPIFop = 14, HALTop = 15;
// CODE STORE // CODE STORE
public static Instruction[] code = new Instruction[1024]; public static Instruction[] code = new Instruction[1024];
@ -46,9 +42,6 @@ public final class Machine {
// REGISTER NUMBERS // REGISTER NUMBERS
public final static int CBr = 0, CTr = 1, PBr = 2, PTr = 3, SBr = 4, STr = 5, HBr = 6, HTr = 7, LBr = 8,
L1r = LBr + 1, L2r = LBr + 2, L3r = LBr + 3, L4r = LBr + 4, L5r = LBr + 5, L6r = LBr + 6, CPr = 15;
// DATA REPRESENTATION // DATA REPRESENTATION
public final static int booleanSize = 1, characterSize = 1, integerSize = 1, addressSize = 1, public final static int booleanSize = 1, characterSize = 1, integerSize = 1, addressSize = 1,
@ -58,14 +51,4 @@ public final class Machine {
falseRep = 0, trueRep = 1, maxintRep = 32767; falseRep = 0, trueRep = 1, maxintRep = 32767;
// ADDRESSES OF PRIMITIVE ROUTINES
public final static int idDisplacement = 1, notDisplacement = 2, andDisplacement = 3, orDisplacement = 4,
succDisplacement = 5, predDisplacement = 6, negDisplacement = 7, addDisplacement = 8, subDisplacement = 9,
multDisplacement = 10, divDisplacement = 11, modDisplacement = 12, ltDisplacement = 13, leDisplacement = 14,
geDisplacement = 15, gtDisplacement = 16, eqDisplacement = 17, neDisplacement = 18, eolDisplacement = 19,
eofDisplacement = 20, getDisplacement = 21, putDisplacement = 22, geteolDisplacement = 23,
puteolDisplacement = 24, getintDisplacement = 25, putintDisplacement = 26, newDisplacement = 27,
disposeDisplacement = 28;
} }

@ -0,0 +1,5 @@
package Triangle.AbstractMachine;
public enum OpCode {
LOAD, LOADA, LOADI, LOADL, STORE, STOREI, CALL, CALLI, RETURN, PUSH, POP, JUMP, JUMPI, JUMPIF, HALT
}

@ -0,0 +1,6 @@
package Triangle.AbstractMachine;
public enum Primitive {
ID, NOT, AND, OR, SUCC, PRED, NEG, ADD, SUB, MULT, DIV, MOD, LT, LE, GE, GT, EQ, NE, EOL, EOF, GET, PUT, GETEOL,
PUTEOL, GETINT, PUTINT, NEW, DISPOSE
}

@ -0,0 +1,5 @@
package Triangle.AbstractMachine;
public enum Register {
CB, CT, PB, PT, SB, ST, HB, HT, LB, L1, L2, L3, L4, L5, L6, CP
}

@ -14,12 +14,14 @@
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees;
import Triangle.CodeGenerator.RuntimeEntity; import Triangle.CodeGenerator.Entities.RuntimeEntity;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class AST { public abstract class AbstractSyntaxTree {
public AST(SourcePosition position) { private final SourcePosition position;
public AbstractSyntaxTree(SourcePosition position) {
this.position = position; this.position = position;
entity = null; entity = null;
} }
@ -28,13 +30,5 @@ public abstract class AST {
return position; return position;
} }
public abstract Object visit(Visitor v, Object o);
public final Object visit(Visitor v) {
return visit(v, null);
}
public final SourcePosition position;
public RuntimeEntity entity; public RuntimeEntity entity;
} }

@ -12,13 +12,21 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Actuals;
import Triangle.AbstractSyntaxTrees.AbstractSyntaxTree;
import Triangle.AbstractSyntaxTrees.Visitors.ActualParameterVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class ActualParameter extends AST { public abstract class ActualParameter extends AbstractSyntaxTree {
public ActualParameter(SourcePosition position) { public ActualParameter(SourcePosition position) {
super(position); super(position);
} }
public abstract <TArg, TResult> TResult visit(ActualParameterVisitor<TArg, TResult> visitor, TArg arg);
public <TArg, TResult> TResult visit(ActualParameterVisitor<TArg, TResult> visitor) {
return visit(visitor, null);
}
} }

@ -12,13 +12,21 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Actuals;
import Triangle.AbstractSyntaxTrees.AbstractSyntaxTree;
import Triangle.AbstractSyntaxTrees.Visitors.ActualParameterSequenceVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class ActualParameterSequence extends AST { public abstract class ActualParameterSequence extends AbstractSyntaxTree {
public ActualParameterSequence(SourcePosition position) { public ActualParameterSequence(SourcePosition position) {
super(position); super(position);
} }
public abstract <TArg, TResult> TResult visit(ActualParameterSequenceVisitor<TArg, TResult> v, TArg arg);
public <TResult> TResult visit(ActualParameterSequenceVisitor<Void, TResult> v) {
return visit(v, null);
}
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Actuals;
import Triangle.AbstractSyntaxTrees.Expressions.Expression;
import Triangle.AbstractSyntaxTrees.Visitors.ActualParameterVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class ConstActualParameter extends ActualParameter { public class ConstActualParameter extends ActualParameter {
@ -23,10 +25,9 @@ public class ConstActualParameter extends ActualParameter {
E = eAST; E = eAST;
} }
@Override public <TArg, TResult> TResult visit(ActualParameterVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitConstActualParameter(this, arg);
return v.visitConstActualParameter(this, o);
} }
public Expression E; public final Expression E;
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Actuals;
import Triangle.AbstractSyntaxTrees.Visitors.ActualParameterSequenceVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class EmptyActualParameterSequence extends ActualParameterSequence { public class EmptyActualParameterSequence extends ActualParameterSequence {
@ -22,8 +23,7 @@ public class EmptyActualParameterSequence extends ActualParameterSequence {
super(position); super(position);
} }
@Override public <TArg, TResult> TResult visit(ActualParameterSequenceVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitEmptyActualParameterSequence(this, arg);
return v.visitEmptyActualParameterSequence(this, o);
} }
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Actuals;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Visitors.ActualParameterVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class FuncActualParameter extends ActualParameter { public class FuncActualParameter extends ActualParameter {
@ -23,10 +25,9 @@ public class FuncActualParameter extends ActualParameter {
I = iAST; I = iAST;
} }
@Override public <TArg, TResult> TResult visit(ActualParameterVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitFuncActualParameter(this, arg);
return v.visitFuncActualParameter(this, o);
} }
public Identifier I; public final Identifier I;
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Actuals;
import Triangle.AbstractSyntaxTrees.Visitors.ActualParameterSequenceVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class MultipleActualParameterSequence extends ActualParameterSequence { public class MultipleActualParameterSequence extends ActualParameterSequence {
@ -25,11 +26,10 @@ public class MultipleActualParameterSequence extends ActualParameterSequence {
APS = apsAST; APS = apsAST;
} }
@Override public <TArg, TResult> TResult visit(ActualParameterSequenceVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitMultipleActualParameterSequence(this, arg);
return v.visitMultipleActualParameterSequence(this, o);
} }
public ActualParameter AP; public final ActualParameter AP;
public ActualParameterSequence APS; public final ActualParameterSequence APS;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Actuals;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Visitors.ActualParameterVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class ProcActualParameter extends ActualParameter { public class ProcActualParameter extends ActualParameter {
@ -23,10 +25,9 @@ public class ProcActualParameter extends ActualParameter {
I = iAST; I = iAST;
} }
@Override public <TArg, TResult> TResult visit(ActualParameterVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitProcActualParameter(this, arg);
return v.visitProcActualParameter(this, o);
} }
public Identifier I; public final Identifier I;
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Actuals;
import Triangle.AbstractSyntaxTrees.Visitors.ActualParameterSequenceVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleActualParameterSequence extends ActualParameterSequence { public class SingleActualParameterSequence extends ActualParameterSequence {
@ -23,10 +24,9 @@ public class SingleActualParameterSequence extends ActualParameterSequence {
AP = apAST; AP = apAST;
} }
@Override public <TArg, TResult> TResult visit(ActualParameterSequenceVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitSingleActualParameterSequence(this, arg);
return v.visitSingleActualParameterSequence(this, o);
} }
public ActualParameter AP; public final ActualParameter AP;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Actuals;
import Triangle.AbstractSyntaxTrees.Visitors.ActualParameterVisitor;
import Triangle.AbstractSyntaxTrees.Vnames.Vname;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class VarActualParameter extends ActualParameter { public class VarActualParameter extends ActualParameter {
@ -23,10 +25,9 @@ public class VarActualParameter extends ActualParameter {
V = vAST; V = vAST;
} }
@Override public <TArg, TResult> TResult visit(ActualParameterVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitVarActualParameter(this, arg);
return v.visitVarActualParameter(this, o);
} }
public Vname V; public final Vname V;
} }

@ -12,11 +12,13 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Aggregates;
import Triangle.AbstractSyntaxTrees.AbstractSyntaxTree;
import Triangle.AbstractSyntaxTrees.Visitors.ArrayAggregateVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class ArrayAggregate extends AST { public abstract class ArrayAggregate extends AbstractSyntaxTree {
public ArrayAggregate(SourcePosition position) { public ArrayAggregate(SourcePosition position) {
super(position); super(position);
@ -24,4 +26,10 @@ public abstract class ArrayAggregate extends AST {
} }
public int elemCount; public int elemCount;
public abstract <TArg, TResult> TResult visit(ArrayAggregateVisitor<TArg, TResult> visitor, TArg arg);
public <TArg, TResult> TResult visit(ArrayAggregateVisitor<TArg, TResult> visitor) {
return visit(visitor, null);
}
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Aggregates;
import Triangle.AbstractSyntaxTrees.Expressions.Expression;
import Triangle.AbstractSyntaxTrees.Visitors.ArrayAggregateVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class MultipleArrayAggregate extends ArrayAggregate { public class MultipleArrayAggregate extends ArrayAggregate {
@ -24,11 +26,10 @@ public class MultipleArrayAggregate extends ArrayAggregate {
AA = aaAST; AA = aaAST;
} }
@Override public <TArg, TResult> TResult visit(ArrayAggregateVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitMultipleArrayAggregate(this, arg);
return v.visitMultipleArrayAggregate(this, o);
} }
public Expression E; public final Expression E;
public ArrayAggregate AA; public final ArrayAggregate AA;
} }

@ -12,26 +12,27 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Aggregates;
import Triangle.AbstractSyntaxTrees.Expressions.Expression;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Visitors.RecordAggregateVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class MultipleRecordAggregate extends RecordAggregate { public class MultipleRecordAggregate extends RecordAggregate {
public MultipleRecordAggregate(Identifier iAST, Expression eAST, RecordAggregate raAST, public MultipleRecordAggregate(Identifier iAST, Expression eAST, RecordAggregate raAST, SourcePosition position) {
SourcePosition position) {
super(position); super(position);
I = iAST; I = iAST;
E = eAST; E = eAST;
RA = raAST; RA = raAST;
} }
@Override public <TArg, TResult> TResult visit(RecordAggregateVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitMultipleRecordAggregate(this, arg);
return v.visitMultipleRecordAggregate(this, o);
} }
public Identifier I; public final Identifier I;
public Expression E; public final Expression E;
public RecordAggregate RA; public final RecordAggregate RA;
} }

@ -12,11 +12,14 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Aggregates;
import Triangle.AbstractSyntaxTrees.AbstractSyntaxTree;
import Triangle.AbstractSyntaxTrees.Types.FieldTypeDenoter;
import Triangle.AbstractSyntaxTrees.Visitors.RecordAggregateVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class RecordAggregate extends AST { public abstract class RecordAggregate extends AbstractSyntaxTree {
public RecordAggregate(SourcePosition position) { public RecordAggregate(SourcePosition position) {
super(position); super(position);
@ -24,4 +27,10 @@ public abstract class RecordAggregate extends AST {
} }
public FieldTypeDenoter type; public FieldTypeDenoter type;
public abstract <TArg, TResult> TResult visit(RecordAggregateVisitor<TArg, TResult> visitor, TArg arg);
public <TArg, TResult> TResult visit(RecordAggregateVisitor<TArg, TResult> visitor) {
return visit(visitor, null);
}
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Aggregates;
import Triangle.AbstractSyntaxTrees.Expressions.Expression;
import Triangle.AbstractSyntaxTrees.Visitors.ArrayAggregateVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleArrayAggregate extends ArrayAggregate { public class SingleArrayAggregate extends ArrayAggregate {
@ -23,10 +25,9 @@ public class SingleArrayAggregate extends ArrayAggregate {
E = eAST; E = eAST;
} }
@Override public <TArg, TResult> TResult visit(ArrayAggregateVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitSingleArrayAggregate(this, arg);
return v.visitSingleArrayAggregate(this, o);
} }
public Expression E; public final Expression E;
} }

@ -12,8 +12,11 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Aggregates;
import Triangle.AbstractSyntaxTrees.Expressions.Expression;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Visitors.RecordAggregateVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleRecordAggregate extends RecordAggregate { public class SingleRecordAggregate extends RecordAggregate {
@ -24,11 +27,10 @@ public class SingleRecordAggregate extends RecordAggregate {
E = eAST; E = eAST;
} }
@Override public <TArg, TResult> TResult visit(RecordAggregateVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitSingleRecordAggregate(this, arg);
return v.visitSingleRecordAggregate(this, o);
} }
public Identifier I; public final Identifier I;
public Expression E; public final Expression E;
} }

@ -12,8 +12,11 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Commands;
import Triangle.AbstractSyntaxTrees.Expressions.Expression;
import Triangle.AbstractSyntaxTrees.Visitors.CommandVisitor;
import Triangle.AbstractSyntaxTrees.Vnames.Vname;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class AssignCommand extends Command { public class AssignCommand extends Command {
@ -24,11 +27,10 @@ public class AssignCommand extends Command {
E = eAST; E = eAST;
} }
@Override public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitAssignCommand(this, arg);
return v.visitAssignCommand(this, o);
} }
public Vname V; public final Vname V;
public Expression E; public final Expression E;
} }

@ -12,8 +12,11 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Commands;
import Triangle.AbstractSyntaxTrees.Actuals.ActualParameterSequence;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Visitors.CommandVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class CallCommand extends Command { public class CallCommand extends Command {
@ -24,11 +27,10 @@ public class CallCommand extends Command {
APS = apsAST; APS = apsAST;
} }
@Override public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitCallCommand(this, arg);
return v.visitCallCommand(this, o);
} }
public Identifier I; public final Identifier I;
public ActualParameterSequence APS; public final ActualParameterSequence APS;
} }

@ -12,13 +12,21 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Commands;
import Triangle.AbstractSyntaxTrees.AbstractSyntaxTree;
import Triangle.AbstractSyntaxTrees.Visitors.CommandVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class Command extends AST { public abstract class Command extends AbstractSyntaxTree {
public Command(SourcePosition position) { public Command(SourcePosition position) {
super(position); super(position);
} }
public abstract <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> visitor, TArg arg);
public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> visitor) {
return visit(visitor, null);
}
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Commands;
import Triangle.AbstractSyntaxTrees.Visitors.CommandVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class EmptyCommand extends Command { public class EmptyCommand extends Command {
@ -22,8 +23,7 @@ public class EmptyCommand extends Command {
super(position); super(position);
} }
@Override public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitEmptyCommand(this, arg);
return v.visitEmptyCommand(this, o);
} }
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Commands;
import Triangle.AbstractSyntaxTrees.Expressions.Expression;
import Triangle.AbstractSyntaxTrees.Visitors.CommandVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class IfCommand extends Command { public class IfCommand extends Command {
@ -25,11 +27,10 @@ public class IfCommand extends Command {
C2 = c2AST; C2 = c2AST;
} }
@Override public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitIfCommand(this, arg);
return v.visitIfCommand(this, o);
} }
public Expression E; public final Expression E;
public Command C1, C2; public final Command C1, C2;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Commands;
import Triangle.AbstractSyntaxTrees.Declarations.Declaration;
import Triangle.AbstractSyntaxTrees.Visitors.CommandVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class LetCommand extends Command { public class LetCommand extends Command {
@ -24,11 +26,10 @@ public class LetCommand extends Command {
C = cAST; C = cAST;
} }
@Override public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitLetCommand(this, arg);
return v.visitLetCommand(this, o);
} }
public Declaration D; public final Declaration D;
public Command C; public final Command C;
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Commands;
import Triangle.AbstractSyntaxTrees.Visitors.CommandVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class SequentialCommand extends Command { public class SequentialCommand extends Command {
@ -24,10 +25,9 @@ public class SequentialCommand extends Command {
C2 = c2AST; C2 = c2AST;
} }
@Override public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitSequentialCommand(this, arg);
return v.visitSequentialCommand(this, o);
} }
public Command C1, C2; public final Command C1, C2;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Commands;
import Triangle.AbstractSyntaxTrees.Expressions.Expression;
import Triangle.AbstractSyntaxTrees.Visitors.CommandVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class WhileCommand extends Command { public class WhileCommand extends Command {
@ -24,11 +26,10 @@ public class WhileCommand extends Command {
C = cAST; C = cAST;
} }
@Override public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitWhileCommand(this, arg);
return v.visitWhileCommand(this, o);
} }
public Expression E; public final Expression E;
public Command C; public final Command C;
} }

@ -12,8 +12,11 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Declarations;
import Triangle.AbstractSyntaxTrees.Terminals.Operator;
import Triangle.AbstractSyntaxTrees.Types.TypeDenoter;
import Triangle.AbstractSyntaxTrees.Visitors.DeclarationVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class BinaryOperatorDeclaration extends Declaration { public class BinaryOperatorDeclaration extends Declaration {
@ -27,11 +30,10 @@ public class BinaryOperatorDeclaration extends Declaration {
RES = resultAST; RES = resultAST;
} }
@Override public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitBinaryOperatorDeclaration(this, arg);
return v.visitBinaryOperatorDeclaration(this, o);
} }
public Operator O; public final Operator O;
public TypeDenoter ARG1, ARG2, RES; public final TypeDenoter ARG1, ARG2, RES;
} }

@ -12,8 +12,11 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Declarations;
import Triangle.AbstractSyntaxTrees.Expressions.Expression;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Visitors.DeclarationVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class ConstDeclaration extends Declaration { public class ConstDeclaration extends Declaration {
@ -24,11 +27,10 @@ public class ConstDeclaration extends Declaration {
E = eAST; E = eAST;
} }
@Override public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitConstDeclaration(this, arg);
return v.visitConstDeclaration(this, o);
} }
public Identifier I; public final Identifier I;
public Expression E; public final Expression E;
} }

@ -12,11 +12,13 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Declarations;
import Triangle.AbstractSyntaxTrees.AbstractSyntaxTree;
import Triangle.AbstractSyntaxTrees.Visitors.DeclarationVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class Declaration extends AST { public abstract class Declaration extends AbstractSyntaxTree {
public Declaration(SourcePosition position) { public Declaration(SourcePosition position) {
super(position); super(position);
@ -24,4 +26,10 @@ public abstract class Declaration extends AST {
} }
public boolean duplicated; public boolean duplicated;
public abstract <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> visitor, TArg arg);
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> visitor) {
return visit(visitor, null);
}
} }

@ -12,8 +12,13 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Declarations;
import Triangle.AbstractSyntaxTrees.Expressions.Expression;
import Triangle.AbstractSyntaxTrees.Formals.FormalParameterSequence;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Types.TypeDenoter;
import Triangle.AbstractSyntaxTrees.Visitors.DeclarationVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class FuncDeclaration extends Declaration { public class FuncDeclaration extends Declaration {
@ -27,13 +32,12 @@ public class FuncDeclaration extends Declaration {
E = eAST; E = eAST;
} }
@Override public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitFuncDeclaration(this, arg);
return v.visitFuncDeclaration(this, o);
} }
public Identifier I; public final Identifier I;
public FormalParameterSequence FPS; public final FormalParameterSequence FPS;
public TypeDenoter T; public TypeDenoter T;
public Expression E; public final Expression E;
} }

@ -12,8 +12,12 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Declarations;
import Triangle.AbstractSyntaxTrees.Commands.Command;
import Triangle.AbstractSyntaxTrees.Formals.FormalParameterSequence;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Visitors.DeclarationVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class ProcDeclaration extends Declaration { public class ProcDeclaration extends Declaration {
@ -25,12 +29,11 @@ public class ProcDeclaration extends Declaration {
C = cAST; C = cAST;
} }
@Override public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitProcDeclaration(this, arg);
return v.visitProcDeclaration(this, o);
} }
public Identifier I; public final Identifier I;
public FormalParameterSequence FPS; public final FormalParameterSequence FPS;
public Command C; public final Command C;
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Declarations;
import Triangle.AbstractSyntaxTrees.Visitors.DeclarationVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class SequentialDeclaration extends Declaration { public class SequentialDeclaration extends Declaration {
@ -24,10 +25,9 @@ public class SequentialDeclaration extends Declaration {
D2 = d2AST; D2 = d2AST;
} }
@Override public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitSequentialDeclaration(this, arg);
return v.visitSequentialDeclaration(this, o);
} }
public Declaration D1, D2; public final Declaration D1, D2;
} }

@ -12,25 +12,26 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Declarations;
import Triangle.AbstractSyntaxTrees.Terminals.Operator;
import Triangle.AbstractSyntaxTrees.Types.TypeDenoter;
import Triangle.AbstractSyntaxTrees.Visitors.DeclarationVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class UnaryOperatorDeclaration extends Declaration { public class UnaryOperatorDeclaration extends Declaration {
public UnaryOperatorDeclaration(Operator oAST, TypeDenoter argAST, TypeDenoter resultAST, public UnaryOperatorDeclaration(Operator oAST, TypeDenoter argAST, TypeDenoter resultAST, SourcePosition position) {
SourcePosition position) {
super(position); super(position);
O = oAST; O = oAST;
ARG = argAST; ARG = argAST;
RES = resultAST; RES = resultAST;
} }
@Override public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitUnaryOperatorDeclaration(this, arg);
return v.visitUnaryOperatorDeclaration(this, o);
} }
public Operator O; public final Operator O;
public TypeDenoter ARG, RES; public final TypeDenoter ARG, RES;
} }

@ -12,8 +12,11 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Declarations;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Types.TypeDenoter;
import Triangle.AbstractSyntaxTrees.Visitors.DeclarationVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class VarDeclaration extends Declaration { public class VarDeclaration extends Declaration {
@ -24,11 +27,10 @@ public class VarDeclaration extends Declaration {
T = tAST; T = tAST;
} }
@Override public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitVarDeclaration(this, arg);
return v.visitVarDeclaration(this, o);
} }
public Identifier I; public final Identifier I;
public TypeDenoter T; public TypeDenoter T;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Expressions;
import Triangle.AbstractSyntaxTrees.Aggregates.ArrayAggregate;
import Triangle.AbstractSyntaxTrees.Visitors.ExpressionVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class ArrayExpression extends Expression { public class ArrayExpression extends Expression {
@ -23,10 +25,9 @@ public class ArrayExpression extends Expression {
AA = aaAST; AA = aaAST;
} }
@Override public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitArrayExpression(this, arg);
return v.visitArrayExpression(this, o);
} }
public ArrayAggregate AA; public final ArrayAggregate AA;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Expressions;
import Triangle.AbstractSyntaxTrees.Terminals.Operator;
import Triangle.AbstractSyntaxTrees.Visitors.ExpressionVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class BinaryExpression extends Expression { public class BinaryExpression extends Expression {
@ -25,11 +27,10 @@ public class BinaryExpression extends Expression {
E2 = e2AST; E2 = e2AST;
} }
@Override public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitBinaryExpression(this, arg);
return v.visitBinaryExpression(this, o);
} }
public Expression E1, E2; public final Expression E1, E2;
public Operator O; public final Operator O;
} }

@ -12,8 +12,11 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Expressions;
import Triangle.AbstractSyntaxTrees.Actuals.ActualParameterSequence;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Visitors.ExpressionVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class CallExpression extends Expression { public class CallExpression extends Expression {
@ -24,11 +27,10 @@ public class CallExpression extends Expression {
APS = apsAST; APS = apsAST;
} }
@Override public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitCallExpression(this, arg);
return v.visitCallExpression(this, o);
} }
public Identifier I; public final Identifier I;
public ActualParameterSequence APS; public final ActualParameterSequence APS;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Expressions;
import Triangle.AbstractSyntaxTrees.Terminals.CharacterLiteral;
import Triangle.AbstractSyntaxTrees.Visitors.ExpressionVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class CharacterExpression extends Expression { public class CharacterExpression extends Expression {
@ -23,10 +25,9 @@ public class CharacterExpression extends Expression {
CL = clAST; CL = clAST;
} }
@Override public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitCharacterExpression(this, arg);
return v.visitCharacterExpression(this, o);
} }
public CharacterLiteral CL; public final CharacterLiteral CL;
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Expressions;
import Triangle.AbstractSyntaxTrees.Visitors.ExpressionVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class EmptyExpression extends Expression { public class EmptyExpression extends Expression {
@ -22,8 +23,7 @@ public class EmptyExpression extends Expression {
super(position); super(position);
} }
@Override public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitEmptyExpression(this, arg);
return v.visitEmptyExpression(this, o);
} }
} }

@ -12,11 +12,14 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Expressions;
import Triangle.AbstractSyntaxTrees.AbstractSyntaxTree;
import Triangle.AbstractSyntaxTrees.Types.TypeDenoter;
import Triangle.AbstractSyntaxTrees.Visitors.ExpressionVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class Expression extends AST { public abstract class Expression extends AbstractSyntaxTree {
public Expression(SourcePosition position) { public Expression(SourcePosition position) {
super(position); super(position);
@ -24,4 +27,10 @@ public abstract class Expression extends AST {
} }
public TypeDenoter type; public TypeDenoter type;
public abstract <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> visitor, TArg arg);
public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> visitor) {
return visit(visitor, null);
}
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Expressions;
import Triangle.AbstractSyntaxTrees.Visitors.ExpressionVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class IfExpression extends Expression { public class IfExpression extends Expression {
@ -25,10 +26,9 @@ public class IfExpression extends Expression {
E3 = e3AST; E3 = e3AST;
} }
@Override public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitIfExpression(this, arg);
return v.visitIfExpression(this, o);
} }
public Expression E1, E2, E3; public final Expression E1, E2, E3;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Expressions;
import Triangle.AbstractSyntaxTrees.Terminals.IntegerLiteral;
import Triangle.AbstractSyntaxTrees.Visitors.ExpressionVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class IntegerExpression extends Expression { public class IntegerExpression extends Expression {
@ -23,10 +25,9 @@ public class IntegerExpression extends Expression {
IL = ilAST; IL = ilAST;
} }
@Override public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitIntegerExpression(this, arg);
return v.visitIntegerExpression(this, o);
} }
public IntegerLiteral IL; public final IntegerLiteral IL;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Expressions;
import Triangle.AbstractSyntaxTrees.Declarations.Declaration;
import Triangle.AbstractSyntaxTrees.Visitors.ExpressionVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class LetExpression extends Expression { public class LetExpression extends Expression {
@ -24,11 +26,10 @@ public class LetExpression extends Expression {
E = eAST; E = eAST;
} }
@Override public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitLetExpression(this, arg);
return v.visitLetExpression(this, o);
} }
public Declaration D; public final Declaration D;
public Expression E; public final Expression E;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Expressions;
import Triangle.AbstractSyntaxTrees.Aggregates.RecordAggregate;
import Triangle.AbstractSyntaxTrees.Visitors.ExpressionVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class RecordExpression extends Expression { public class RecordExpression extends Expression {
@ -23,10 +25,9 @@ public class RecordExpression extends Expression {
RA = raAST; RA = raAST;
} }
@Override public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitRecordExpression(this, arg);
return v.visitRecordExpression(this, o);
} }
public RecordAggregate RA; public final RecordAggregate RA;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Expressions;
import Triangle.AbstractSyntaxTrees.Terminals.Operator;
import Triangle.AbstractSyntaxTrees.Visitors.ExpressionVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class UnaryExpression extends Expression { public class UnaryExpression extends Expression {
@ -24,11 +26,10 @@ public class UnaryExpression extends Expression {
E = eAST; E = eAST;
} }
@Override public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitUnaryExpression(this, arg);
return v.visitUnaryExpression(this, o);
} }
public Expression E; public final Expression E;
public Operator O; public final Operator O;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Expressions;
import Triangle.AbstractSyntaxTrees.Visitors.ExpressionVisitor;
import Triangle.AbstractSyntaxTrees.Vnames.Vname;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class VnameExpression extends Expression { public class VnameExpression extends Expression {
@ -23,10 +25,9 @@ public class VnameExpression extends Expression {
V = vAST; V = vAST;
} }
@Override public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitVnameExpression(this, arg);
return v.visitVnameExpression(this, o);
} }
public Vname V; public final Vname V;
} }

@ -12,8 +12,11 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Formals;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Types.TypeDenoter;
import Triangle.AbstractSyntaxTrees.Visitors.DeclarationVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class ConstFormalParameter extends FormalParameter { public class ConstFormalParameter extends FormalParameter {
@ -24,20 +27,20 @@ public class ConstFormalParameter extends FormalParameter {
T = tAST; T = tAST;
} }
@Override public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitConstFormalParameter(this, arg);
return v.visitConstFormalParameter(this, o);
} }
public Identifier I;
public TypeDenoter T;
@Override @Override
public boolean equals(Object fpAST) { public boolean equals(Object fpAST) {
if (fpAST instanceof ConstFormalParameter) { if (fpAST instanceof ConstFormalParameter) {
ConstFormalParameter cfpAST = (ConstFormalParameter) fpAST; var cfpAST = (ConstFormalParameter) fpAST;
return T.equals(cfpAST.T); return T.equals(cfpAST.T);
} else } else {
return false; return false;
} }
}
public final Identifier I;
public TypeDenoter T;
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Formals;
import Triangle.AbstractSyntaxTrees.Visitors.FormalParameterSequenceVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class EmptyFormalParameterSequence extends FormalParameterSequence { public class EmptyFormalParameterSequence extends FormalParameterSequence {
@ -22,9 +23,8 @@ public class EmptyFormalParameterSequence extends FormalParameterSequence {
super(position); super(position);
} }
@Override public <TArg, TResult> TResult visit(FormalParameterSequenceVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitEmptyFormalParameterSequence(this, arg);
return v.visitEmptyFormalParameterSequence(this, o);
} }
@Override @Override

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Formals;
import Triangle.AbstractSyntaxTrees.Declarations.Declaration;
import Triangle.AbstractSyntaxTrees.Visitors.DeclarationVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class FormalParameter extends Declaration { public abstract class FormalParameter extends Declaration {
@ -25,4 +27,9 @@ public abstract class FormalParameter extends Declaration {
@Override @Override
public abstract boolean equals(Object fpAST); public abstract boolean equals(Object fpAST);
public abstract <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> visitor, TArg arg);
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> visitor) {
return visit(visitor, null);
}
} }

@ -12,11 +12,13 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Formals;
import Triangle.AbstractSyntaxTrees.AbstractSyntaxTree;
import Triangle.AbstractSyntaxTrees.Visitors.FormalParameterSequenceVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class FormalParameterSequence extends AST { public abstract class FormalParameterSequence extends AbstractSyntaxTree {
public FormalParameterSequence(SourcePosition position) { public FormalParameterSequence(SourcePosition position) {
super(position); super(position);
@ -24,4 +26,10 @@ public abstract class FormalParameterSequence extends AST {
@Override @Override
public abstract boolean equals(Object fpsAST); public abstract boolean equals(Object fpsAST);
public abstract <TArg, TResult> TResult visit(FormalParameterSequenceVisitor<TArg, TResult> visitor, TArg arg);
public <TArg, TResult> TResult visit(FormalParameterSequenceVisitor<TArg, TResult> visitor) {
return visit(visitor, null);
}
} }

@ -12,8 +12,11 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Formals;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Types.TypeDenoter;
import Triangle.AbstractSyntaxTrees.Visitors.DeclarationVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class FuncFormalParameter extends FormalParameter { public class FuncFormalParameter extends FormalParameter {
@ -26,9 +29,8 @@ public class FuncFormalParameter extends FormalParameter {
T = tAST; T = tAST;
} }
@Override public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitFuncFormalParameter(this, arg);
return v.visitFuncFormalParameter(this, o);
} }
@Override @Override
@ -40,7 +42,7 @@ public class FuncFormalParameter extends FormalParameter {
return false; return false;
} }
public Identifier I; public final Identifier I;
public FormalParameterSequence FPS; public final FormalParameterSequence FPS;
public TypeDenoter T; public TypeDenoter T;
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Formals;
import Triangle.AbstractSyntaxTrees.Visitors.FormalParameterSequenceVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class MultipleFormalParameterSequence extends FormalParameterSequence { public class MultipleFormalParameterSequence extends FormalParameterSequence {
@ -25,9 +26,8 @@ public class MultipleFormalParameterSequence extends FormalParameterSequence {
FPS = fpsAST; FPS = fpsAST;
} }
@Override public <TArg, TResult> TResult visit(FormalParameterSequenceVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitMultipleFormalParameterSequence(this, arg);
return v.visitMultipleFormalParameterSequence(this, o);
} }
@Override @Override
@ -35,10 +35,11 @@ public class MultipleFormalParameterSequence extends FormalParameterSequence {
if (fpsAST instanceof MultipleFormalParameterSequence) { if (fpsAST instanceof MultipleFormalParameterSequence) {
MultipleFormalParameterSequence mfpsAST = (MultipleFormalParameterSequence) fpsAST; MultipleFormalParameterSequence mfpsAST = (MultipleFormalParameterSequence) fpsAST;
return FP.equals(mfpsAST.FP) && FPS.equals(mfpsAST.FPS); return FP.equals(mfpsAST.FP) && FPS.equals(mfpsAST.FPS);
} else } else {
return false; return false;
} }
}
public FormalParameter FP; public final FormalParameter FP;
public FormalParameterSequence FPS; public final FormalParameterSequence FPS;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Formals;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Visitors.DeclarationVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class ProcFormalParameter extends FormalParameter { public class ProcFormalParameter extends FormalParameter {
@ -24,20 +26,20 @@ public class ProcFormalParameter extends FormalParameter {
FPS = fpsAST; FPS = fpsAST;
} }
@Override public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitProcFormalParameter(this, arg);
return v.visitProcFormalParameter(this, o);
} }
public Identifier I;
public FormalParameterSequence FPS;
@Override @Override
public boolean equals(Object fpAST) { public boolean equals(Object fpAST) {
if (fpAST instanceof ProcFormalParameter) { if (fpAST instanceof ProcFormalParameter) {
ProcFormalParameter pfpAST = (ProcFormalParameter) fpAST; ProcFormalParameter pfpAST = (ProcFormalParameter) fpAST;
return FPS.equals(pfpAST.FPS); return FPS.equals(pfpAST.FPS);
} else } else {
return false; return false;
} }
}
public final Identifier I;
public final FormalParameterSequence FPS;
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Formals;
import Triangle.AbstractSyntaxTrees.Visitors.FormalParameterSequenceVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleFormalParameterSequence extends FormalParameterSequence { public class SingleFormalParameterSequence extends FormalParameterSequence {
@ -23,9 +24,8 @@ public class SingleFormalParameterSequence extends FormalParameterSequence {
FP = fpAST; FP = fpAST;
} }
@Override public <TArg, TResult> TResult visit(FormalParameterSequenceVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitSingleFormalParameterSequence(this, arg);
return v.visitSingleFormalParameterSequence(this, o);
} }
@Override @Override
@ -33,9 +33,10 @@ public class SingleFormalParameterSequence extends FormalParameterSequence {
if (fpsAST instanceof SingleFormalParameterSequence) { if (fpsAST instanceof SingleFormalParameterSequence) {
SingleFormalParameterSequence sfpsAST = (SingleFormalParameterSequence) fpsAST; SingleFormalParameterSequence sfpsAST = (SingleFormalParameterSequence) fpsAST;
return FP.equals(sfpsAST.FP); return FP.equals(sfpsAST.FP);
} else } else {
return false; return false;
} }
}
public FormalParameter FP; public final FormalParameter FP;
} }

@ -12,8 +12,11 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Formals;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Types.TypeDenoter;
import Triangle.AbstractSyntaxTrees.Visitors.DeclarationVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class VarFormalParameter extends FormalParameter { public class VarFormalParameter extends FormalParameter {
@ -24,20 +27,20 @@ public class VarFormalParameter extends FormalParameter {
T = tAST; T = tAST;
} }
@Override public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitVarFormalParameter(this, arg);
return v.visitVarFormalParameter(this, o);
} }
public Identifier I;
public TypeDenoter T;
@Override @Override
public boolean equals(Object fpAST) { public boolean equals(Object fpAST) {
if (fpAST instanceof VarFormalParameter) { if (fpAST instanceof VarFormalParameter) {
VarFormalParameter vfpAST = (VarFormalParameter) fpAST; VarFormalParameter vfpAST = (VarFormalParameter) fpAST;
return T.equals(vfpAST.T); return T.equals(vfpAST.T);
} else } else {
return false; return false;
} }
}
public final Identifier I;
public TypeDenoter T;
} }

@ -14,19 +14,24 @@
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees;
import Triangle.AbstractSyntaxTrees.Commands.Command;
import Triangle.AbstractSyntaxTrees.Visitors.ProgramVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class Program extends AST { public class Program extends AbstractSyntaxTree {
public Program(Command cAST, SourcePosition position) { public Program(Command cAST, SourcePosition position) {
super(position); super(position);
C = cAST; C = cAST;
} }
@Override public Command C;
public Object visit(Visitor v, Object o) {
return v.visitProgram(this, o); public <TArg, TResult> TResult visit(ProgramVisitor<TArg, TResult> visitor, TArg arg) {
return visitor.visitProgram(this, arg);
} }
public Command C; public <TResult> TResult visit(ProgramVisitor<Void, TResult> visitor) {
return visit(visitor, null);
}
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Terminals;
import Triangle.AbstractSyntaxTrees.Visitors.LiteralVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class CharacterLiteral extends Terminal { public class CharacterLiteral extends Terminal {
@ -22,9 +23,15 @@ public class CharacterLiteral extends Terminal {
super(spelling, position); super(spelling, position);
} }
@Override public <TArg, TResult> TResult visit(LiteralVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitCharacterLiteral(this, arg);
return v.visitCharacterLiteral(this, o);
} }
public <TArg, TResult> TResult visit(LiteralVisitor<TArg, TResult> visitor) {
return visit(visitor, null);
}
public int getValue() {
return spelling.charAt(1);
}
} }

@ -12,8 +12,11 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Terminals;
import Triangle.AbstractSyntaxTrees.AbstractSyntaxTree;
import Triangle.AbstractSyntaxTrees.Types.TypeDenoter;
import Triangle.AbstractSyntaxTrees.Visitors.IdentifierVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class Identifier extends Terminal { public class Identifier extends Terminal {
@ -24,11 +27,14 @@ public class Identifier extends Terminal {
decl = null; decl = null;
} }
@Override public TypeDenoter type;
public Object visit(Visitor v, Object o) { public AbstractSyntaxTree decl; // Either a Declaration or a FieldTypeDenoter
return v.visitIdentifier(this, o);
public <TArg, TResult> TResult visit(IdentifierVisitor<TArg, TResult> visitor, TArg arg) {
return visitor.visitIdentifier(this, arg);
} }
public TypeDenoter type; public <TArg, TResult> TResult visit(IdentifierVisitor<TArg, TResult> visitor) {
public AST decl; // Either a Declaration or a FieldTypeDenoter return visit(visitor, null);
}
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Terminals;
import Triangle.AbstractSyntaxTrees.Visitors.LiteralVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class IntegerLiteral extends Terminal { public class IntegerLiteral extends Terminal {
@ -22,9 +23,15 @@ public class IntegerLiteral extends Terminal {
super(spelling, position); super(spelling, position);
} }
@Override public <TArg, TResult> TResult visit(LiteralVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitIntegerLiteral(this, arg);
return v.visitIntegerLiteral(this, o);
} }
public <TArg, TResult> TResult visit(LiteralVisitor<TArg, TResult> visitor) {
return visit(visitor, null);
}
public int getValue() {
return Integer.parseInt(spelling);
}
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Terminals;
import Triangle.AbstractSyntaxTrees.Declarations.Declaration;
import Triangle.AbstractSyntaxTrees.Visitors.OperatorVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class Operator extends Terminal { public class Operator extends Terminal {
@ -23,10 +25,13 @@ public class Operator extends Terminal {
decl = null; decl = null;
} }
@Override public Declaration decl;
public Object visit(Visitor v, Object o) {
return v.visitOperator(this, o); public <TArg, TResult> TResult visit(OperatorVisitor<TArg, TResult> v, TArg arg) {
return v.visitOperator(this, arg);
} }
public Declaration decl; public <TArg, TResult> TResult visit(OperatorVisitor<TArg, TResult> visitor) {
return visit(visitor, null);
}
} }

@ -12,11 +12,12 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Terminals;
import Triangle.AbstractSyntaxTrees.AbstractSyntaxTree;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
abstract public class Terminal extends AST { public abstract class Terminal extends AbstractSyntaxTree {
public Terminal(String spelling, SourcePosition position) { public Terminal(String spelling, SourcePosition position) {
super(position); super(position);

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Types;
import Triangle.AbstractSyntaxTrees.Visitors.TypeDenoterVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class AnyTypeDenoter extends TypeDenoter { public class AnyTypeDenoter extends TypeDenoter {
@ -22,9 +23,8 @@ public class AnyTypeDenoter extends TypeDenoter {
super(position); super(position);
} }
@Override public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitAnyTypeDenoter(this, arg);
return v.visitAnyTypeDenoter(this, o);
} }
@Override @Override

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Types;
import Triangle.AbstractSyntaxTrees.Terminals.IntegerLiteral;
import Triangle.AbstractSyntaxTrees.Visitors.TypeDenoterVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class ArrayTypeDenoter extends TypeDenoter { public class ArrayTypeDenoter extends TypeDenoter {
@ -24,22 +26,22 @@ public class ArrayTypeDenoter extends TypeDenoter {
T = tAST; T = tAST;
} }
@Override public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitArrayTypeDenoter(this, arg);
return v.visitArrayTypeDenoter(this, o);
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj != null && obj instanceof ErrorTypeDenoter) if (obj != null && obj instanceof ErrorTypeDenoter) {
return true; return true;
else if (obj != null && obj instanceof ArrayTypeDenoter) } else if (obj != null && obj instanceof ArrayTypeDenoter) {
return this.IL.spelling.compareTo(((ArrayTypeDenoter) obj).IL.spelling) == 0 return this.IL.spelling.compareTo(((ArrayTypeDenoter) obj).IL.spelling) == 0
&& this.T.equals(((ArrayTypeDenoter) obj).T); && this.T.equals(((ArrayTypeDenoter) obj).T);
else } else {
return false; return false;
} }
}
public IntegerLiteral IL; public final IntegerLiteral IL;
public TypeDenoter T; public TypeDenoter T;
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Types;
import Triangle.AbstractSyntaxTrees.Visitors.TypeDenoterVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class BoolTypeDenoter extends TypeDenoter { public class BoolTypeDenoter extends TypeDenoter {
@ -22,16 +23,16 @@ public class BoolTypeDenoter extends TypeDenoter {
super(position); super(position);
} }
@Override public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitBoolTypeDenoter(this, arg);
return v.visitBoolTypeDenoter(this, o);
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof ErrorTypeDenoter)) if ((obj != null) && (obj instanceof ErrorTypeDenoter)) {
return true; return true;
else } else {
return ((obj != null) && (obj instanceof BoolTypeDenoter)); return ((obj != null) && (obj instanceof BoolTypeDenoter));
} }
}
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Types;
import Triangle.AbstractSyntaxTrees.Visitors.TypeDenoterVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class CharTypeDenoter extends TypeDenoter { public class CharTypeDenoter extends TypeDenoter {
@ -22,16 +23,16 @@ public class CharTypeDenoter extends TypeDenoter {
super(position); super(position);
} }
@Override public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitCharTypeDenoter(this, arg);
return v.visitCharTypeDenoter(this, o);
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj != null && obj instanceof ErrorTypeDenoter) if (obj != null && obj instanceof ErrorTypeDenoter) {
return true; return true;
else } else {
return (obj != null && obj instanceof CharTypeDenoter); return (obj != null && obj instanceof CharTypeDenoter);
} }
}
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Types;
import Triangle.AbstractSyntaxTrees.Visitors.TypeDenoterVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class ErrorTypeDenoter extends TypeDenoter { public class ErrorTypeDenoter extends TypeDenoter {
@ -22,9 +23,8 @@ public class ErrorTypeDenoter extends TypeDenoter {
super(position); super(position);
} }
@Override public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitErrorTypeDenoter(this, arg);
return v.visitErrorTypeDenoter(this, o);
} }
@Override @Override

@ -12,7 +12,7 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Types;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
@ -21,7 +21,4 @@ public abstract class FieldTypeDenoter extends TypeDenoter {
public FieldTypeDenoter(SourcePosition position) { public FieldTypeDenoter(SourcePosition position) {
super(position); super(position);
} }
@Override
public abstract boolean equals(Object obj);
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Types;
import Triangle.AbstractSyntaxTrees.Visitors.TypeDenoterVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class IntTypeDenoter extends TypeDenoter { public class IntTypeDenoter extends TypeDenoter {
@ -22,16 +23,16 @@ public class IntTypeDenoter extends TypeDenoter {
super(position); super(position);
} }
@Override public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitIntTypeDenoter(this, arg);
return v.visitIntTypeDenoter(this, o);
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj != null && obj instanceof ErrorTypeDenoter) if (obj != null && obj instanceof ErrorTypeDenoter) {
return true; return true;
else } else {
return (obj != null && obj instanceof IntTypeDenoter); return (obj != null && obj instanceof IntTypeDenoter);
} }
}
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Types;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Visitors.TypeDenoterVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class MultipleFieldTypeDenoter extends FieldTypeDenoter { public class MultipleFieldTypeDenoter extends FieldTypeDenoter {
@ -26,9 +28,8 @@ public class MultipleFieldTypeDenoter extends FieldTypeDenoter {
FT = ftAST; FT = ftAST;
} }
@Override public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitMultipleFieldTypeDenoter(this, arg);
return v.visitMultipleFieldTypeDenoter(this, o);
} }
@Override @Override
@ -36,11 +37,12 @@ public class MultipleFieldTypeDenoter extends FieldTypeDenoter {
if (obj != null && obj instanceof MultipleFieldTypeDenoter) { if (obj != null && obj instanceof MultipleFieldTypeDenoter) {
MultipleFieldTypeDenoter ft = (MultipleFieldTypeDenoter) obj; MultipleFieldTypeDenoter ft = (MultipleFieldTypeDenoter) obj;
return (this.I.spelling.compareTo(ft.I.spelling) == 0) && this.T.equals(ft.T) && this.FT.equals(ft.FT); return (this.I.spelling.compareTo(ft.I.spelling) == 0) && this.T.equals(ft.T) && this.FT.equals(ft.FT);
} else } else {
return false; return false;
} }
}
public Identifier I; public final Identifier I;
public TypeDenoter T; public TypeDenoter T;
public FieldTypeDenoter FT; public FieldTypeDenoter FT;
} }

@ -12,8 +12,9 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Types;
import Triangle.AbstractSyntaxTrees.Visitors.TypeDenoterVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class RecordTypeDenoter extends TypeDenoter { public class RecordTypeDenoter extends TypeDenoter {
@ -23,20 +24,20 @@ public class RecordTypeDenoter extends TypeDenoter {
FT = ftAST; FT = ftAST;
} }
@Override public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitRecordTypeDenoter(this, arg);
return v.visitRecordTypeDenoter(this, o);
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj != null && obj instanceof ErrorTypeDenoter) if (obj != null && obj instanceof ErrorTypeDenoter) {
return true; return true;
else if (obj != null && obj instanceof RecordTypeDenoter) } else if (obj != null && obj instanceof RecordTypeDenoter) {
return this.FT.equals(((RecordTypeDenoter) obj).FT); return this.FT.equals(((RecordTypeDenoter) obj).FT);
else } else {
return false; return false;
} }
}
public FieldTypeDenoter FT; public FieldTypeDenoter FT;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Types;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Visitors.TypeDenoterVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class SimpleTypeDenoter extends TypeDenoter { public class SimpleTypeDenoter extends TypeDenoter {
@ -23,9 +25,8 @@ public class SimpleTypeDenoter extends TypeDenoter {
I = iAST; I = iAST;
} }
@Override public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitSimpleTypeDenoter(this, arg);
return v.visitSimpleTypeDenoter(this, o);
} }
@Override @Override
@ -33,5 +34,5 @@ public class SimpleTypeDenoter extends TypeDenoter {
return false; // should not happen return false; // should not happen
} }
public Identifier I; public final Identifier I;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Types;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Visitors.TypeDenoterVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleFieldTypeDenoter extends FieldTypeDenoter { public class SingleFieldTypeDenoter extends FieldTypeDenoter {
@ -24,9 +26,8 @@ public class SingleFieldTypeDenoter extends FieldTypeDenoter {
T = tAST; T = tAST;
} }
@Override public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitSingleFieldTypeDenoter(this, arg);
return v.visitSingleFieldTypeDenoter(this, o);
} }
@Override @Override
@ -34,10 +35,11 @@ public class SingleFieldTypeDenoter extends FieldTypeDenoter {
if (obj != null && obj instanceof SingleFieldTypeDenoter) { if (obj != null && obj instanceof SingleFieldTypeDenoter) {
SingleFieldTypeDenoter ft = (SingleFieldTypeDenoter) obj; SingleFieldTypeDenoter ft = (SingleFieldTypeDenoter) obj;
return (this.I.spelling.compareTo(ft.I.spelling) == 0) && this.T.equals(ft.T); return (this.I.spelling.compareTo(ft.I.spelling) == 0) && this.T.equals(ft.T);
} else } else {
return false; return false;
} }
}
public Identifier I; public final Identifier I;
public TypeDenoter T; public TypeDenoter T;
} }

@ -12,8 +12,11 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Types;
import Triangle.AbstractSyntaxTrees.Declarations.Declaration;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Visitors.DeclarationVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class TypeDeclaration extends Declaration { public class TypeDeclaration extends Declaration {
@ -24,11 +27,10 @@ public class TypeDeclaration extends Declaration {
T = tAST; T = tAST;
} }
@Override public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitTypeDeclaration(this, arg);
return v.visitTypeDeclaration(this, o);
} }
public Identifier I; public final Identifier I;
public TypeDenoter T; public TypeDenoter T;
} }

@ -12,11 +12,13 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Types;
import Triangle.AbstractSyntaxTrees.AbstractSyntaxTree;
import Triangle.AbstractSyntaxTrees.Visitors.TypeDenoterVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class TypeDenoter extends AST { public abstract class TypeDenoter extends AbstractSyntaxTree {
public TypeDenoter(SourcePosition position) { public TypeDenoter(SourcePosition position) {
super(position); super(position);
@ -25,4 +27,9 @@ public abstract class TypeDenoter extends AST {
@Override @Override
public abstract boolean equals(Object obj); public abstract boolean equals(Object obj);
public abstract <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> visitor, TArg arg);
public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> visitor) {
return visit(visitor, null);
}
} }

@ -1,154 +0,0 @@
/*
* @(#)Visitor.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
public interface Visitor {
// Commands
Object visitAssignCommand(AssignCommand ast, Object o);
Object visitCallCommand(CallCommand ast, Object o);
Object visitEmptyCommand(EmptyCommand ast, Object o);
Object visitIfCommand(IfCommand ast, Object o);
Object visitLetCommand(LetCommand ast, Object o);
Object visitSequentialCommand(SequentialCommand ast, Object o);
Object visitWhileCommand(WhileCommand ast, Object o);
// Expressions
Object visitArrayExpression(ArrayExpression ast, Object o);
Object visitBinaryExpression(BinaryExpression ast, Object o);
Object visitCallExpression(CallExpression ast, Object o);
Object visitCharacterExpression(CharacterExpression ast, Object o);
Object visitEmptyExpression(EmptyExpression ast, Object o);
Object visitIfExpression(IfExpression ast, Object o);
Object visitIntegerExpression(IntegerExpression ast, Object o);
Object visitLetExpression(LetExpression ast, Object o);
Object visitRecordExpression(RecordExpression ast, Object o);
Object visitUnaryExpression(UnaryExpression ast, Object o);
Object visitVnameExpression(VnameExpression ast, Object o);
// Declarations
Object visitBinaryOperatorDeclaration(BinaryOperatorDeclaration ast, Object o);
Object visitConstDeclaration(ConstDeclaration ast, Object o);
Object visitFuncDeclaration(FuncDeclaration ast, Object o);
Object visitProcDeclaration(ProcDeclaration ast, Object o);
Object visitSequentialDeclaration(SequentialDeclaration ast, Object o);
Object visitTypeDeclaration(TypeDeclaration ast, Object o);
Object visitUnaryOperatorDeclaration(UnaryOperatorDeclaration ast, Object o);
Object visitVarDeclaration(VarDeclaration ast, Object o);
// Array Aggregates
Object visitMultipleArrayAggregate(MultipleArrayAggregate ast, Object o);
Object visitSingleArrayAggregate(SingleArrayAggregate ast, Object o);
// Record Aggregates
Object visitMultipleRecordAggregate(MultipleRecordAggregate ast, Object o);
Object visitSingleRecordAggregate(SingleRecordAggregate ast, Object o);
// Formal Parameters
Object visitConstFormalParameter(ConstFormalParameter ast, Object o);
Object visitFuncFormalParameter(FuncFormalParameter ast, Object o);
Object visitProcFormalParameter(ProcFormalParameter ast, Object o);
Object visitVarFormalParameter(VarFormalParameter ast, Object o);
Object visitEmptyFormalParameterSequence(EmptyFormalParameterSequence ast, Object o);
Object visitMultipleFormalParameterSequence(MultipleFormalParameterSequence ast, Object o);
Object visitSingleFormalParameterSequence(SingleFormalParameterSequence ast, Object o);
// Actual Parameters
Object visitConstActualParameter(ConstActualParameter ast, Object o);
Object visitFuncActualParameter(FuncActualParameter ast, Object o);
Object visitProcActualParameter(ProcActualParameter ast, Object o);
Object visitVarActualParameter(VarActualParameter ast, Object o);
Object visitEmptyActualParameterSequence(EmptyActualParameterSequence ast, Object o);
Object visitMultipleActualParameterSequence(MultipleActualParameterSequence ast, Object o);
Object visitSingleActualParameterSequence(SingleActualParameterSequence ast, Object o);
// Type Denoters
Object visitAnyTypeDenoter(AnyTypeDenoter ast, Object o);
Object visitArrayTypeDenoter(ArrayTypeDenoter ast, Object o);
Object visitBoolTypeDenoter(BoolTypeDenoter ast, Object o);
Object visitCharTypeDenoter(CharTypeDenoter ast, Object o);
Object visitErrorTypeDenoter(ErrorTypeDenoter ast, Object o);
Object visitSimpleTypeDenoter(SimpleTypeDenoter ast, Object o);
Object visitIntTypeDenoter(IntTypeDenoter ast, Object o);
Object visitRecordTypeDenoter(RecordTypeDenoter ast, Object o);
Object visitMultipleFieldTypeDenoter(MultipleFieldTypeDenoter ast, Object o);
Object visitSingleFieldTypeDenoter(SingleFieldTypeDenoter ast, Object o);
// Literals, Identifiers and Operators
Object visitCharacterLiteral(CharacterLiteral ast, Object o);
Object visitIdentifier(Identifier ast, Object o);
Object visitIntegerLiteral(IntegerLiteral ast, Object o);
Object visitOperator(Operator ast, Object o);
// Value-or-variable names
Object visitDotVname(DotVname ast, Object o);
Object visitSimpleVname(SimpleVname ast, Object o);
Object visitSubscriptVname(SubscriptVname ast, Object o);
// Programs
Object visitProgram(Program ast, Object o);
}

@ -0,0 +1,15 @@
package Triangle.AbstractSyntaxTrees.Visitors;
import Triangle.AbstractSyntaxTrees.Actuals.EmptyActualParameterSequence;
import Triangle.AbstractSyntaxTrees.Actuals.MultipleActualParameterSequence;
import Triangle.AbstractSyntaxTrees.Actuals.SingleActualParameterSequence;
public interface ActualParameterSequenceVisitor<TArg, TResult> {
TResult visitEmptyActualParameterSequence(EmptyActualParameterSequence ast, TArg arg);
TResult visitMultipleActualParameterSequence(MultipleActualParameterSequence ast, TArg arg);
TResult visitSingleActualParameterSequence(SingleActualParameterSequence ast, TArg arg);
}

@ -0,0 +1,18 @@
package Triangle.AbstractSyntaxTrees.Visitors;
import Triangle.AbstractSyntaxTrees.Actuals.ConstActualParameter;
import Triangle.AbstractSyntaxTrees.Actuals.FuncActualParameter;
import Triangle.AbstractSyntaxTrees.Actuals.ProcActualParameter;
import Triangle.AbstractSyntaxTrees.Actuals.VarActualParameter;
public interface ActualParameterVisitor<TArg, TResult> {
TResult visitConstActualParameter(ConstActualParameter ast, TArg arg);
TResult visitFuncActualParameter(FuncActualParameter ast, TArg arg);
TResult visitProcActualParameter(ProcActualParameter ast, TArg arg);
TResult visitVarActualParameter(VarActualParameter ast, TArg arg);
}

@ -0,0 +1,12 @@
package Triangle.AbstractSyntaxTrees.Visitors;
import Triangle.AbstractSyntaxTrees.Aggregates.MultipleArrayAggregate;
import Triangle.AbstractSyntaxTrees.Aggregates.SingleArrayAggregate;
public interface ArrayAggregateVisitor<TArg, TResult> {
TResult visitMultipleArrayAggregate(MultipleArrayAggregate ast, TArg arg);
TResult visitSingleArrayAggregate(SingleArrayAggregate ast, TArg arg);
}

@ -0,0 +1,27 @@
package Triangle.AbstractSyntaxTrees.Visitors;
import Triangle.AbstractSyntaxTrees.Commands.AssignCommand;
import Triangle.AbstractSyntaxTrees.Commands.CallCommand;
import Triangle.AbstractSyntaxTrees.Commands.EmptyCommand;
import Triangle.AbstractSyntaxTrees.Commands.IfCommand;
import Triangle.AbstractSyntaxTrees.Commands.LetCommand;
import Triangle.AbstractSyntaxTrees.Commands.SequentialCommand;
import Triangle.AbstractSyntaxTrees.Commands.WhileCommand;
public interface CommandVisitor<TArg, TResult> {
TResult visitAssignCommand(AssignCommand ast, TArg arg);
TResult visitCallCommand(CallCommand ast, TArg arg);
TResult visitEmptyCommand(EmptyCommand ast, TArg arg);
TResult visitIfCommand(IfCommand ast, TArg arg);
TResult visitLetCommand(LetCommand ast, TArg arg);
TResult visitSequentialCommand(SequentialCommand ast, TArg arg);
TResult visitWhileCommand(WhileCommand ast, TArg arg);
}

@ -0,0 +1,30 @@
package Triangle.AbstractSyntaxTrees.Visitors;
import Triangle.AbstractSyntaxTrees.Declarations.BinaryOperatorDeclaration;
import Triangle.AbstractSyntaxTrees.Declarations.ConstDeclaration;
import Triangle.AbstractSyntaxTrees.Declarations.FuncDeclaration;
import Triangle.AbstractSyntaxTrees.Declarations.ProcDeclaration;
import Triangle.AbstractSyntaxTrees.Declarations.SequentialDeclaration;
import Triangle.AbstractSyntaxTrees.Declarations.UnaryOperatorDeclaration;
import Triangle.AbstractSyntaxTrees.Declarations.VarDeclaration;
import Triangle.AbstractSyntaxTrees.Types.TypeDeclaration;
public interface DeclarationVisitor<TArg, TResult> extends FormalParameterVisitor<TArg, TResult> {
TResult visitBinaryOperatorDeclaration(BinaryOperatorDeclaration ast, TArg arg);
TResult visitConstDeclaration(ConstDeclaration ast, TArg arg);
TResult visitFuncDeclaration(FuncDeclaration ast, TArg arg);
TResult visitProcDeclaration(ProcDeclaration ast, TArg arg);
TResult visitSequentialDeclaration(SequentialDeclaration ast, TArg arg);
TResult visitTypeDeclaration(TypeDeclaration ast, TArg arg);
TResult visitUnaryOperatorDeclaration(UnaryOperatorDeclaration ast, TArg arg);
TResult visitVarDeclaration(VarDeclaration ast, TArg arg);
}

@ -0,0 +1,39 @@
package Triangle.AbstractSyntaxTrees.Visitors;
import Triangle.AbstractSyntaxTrees.Expressions.ArrayExpression;
import Triangle.AbstractSyntaxTrees.Expressions.BinaryExpression;
import Triangle.AbstractSyntaxTrees.Expressions.CallExpression;
import Triangle.AbstractSyntaxTrees.Expressions.CharacterExpression;
import Triangle.AbstractSyntaxTrees.Expressions.EmptyExpression;
import Triangle.AbstractSyntaxTrees.Expressions.IfExpression;
import Triangle.AbstractSyntaxTrees.Expressions.IntegerExpression;
import Triangle.AbstractSyntaxTrees.Expressions.LetExpression;
import Triangle.AbstractSyntaxTrees.Expressions.RecordExpression;
import Triangle.AbstractSyntaxTrees.Expressions.UnaryExpression;
import Triangle.AbstractSyntaxTrees.Expressions.VnameExpression;
public interface ExpressionVisitor<TArg, TResult> {
TResult visitArrayExpression(ArrayExpression ast, TArg arg);
TResult visitBinaryExpression(BinaryExpression ast, TArg arg);
TResult visitCallExpression(CallExpression ast, TArg arg);
TResult visitCharacterExpression(CharacterExpression ast, TArg arg);
TResult visitEmptyExpression(EmptyExpression ast, TArg arg);
TResult visitIfExpression(IfExpression ast, TArg arg);
TResult visitIntegerExpression(IntegerExpression ast, TArg arg);
TResult visitLetExpression(LetExpression ast, TArg arg);
TResult visitRecordExpression(RecordExpression ast, TArg arg);
TResult visitUnaryExpression(UnaryExpression ast, TArg arg);
TResult visitVnameExpression(VnameExpression ast, TArg arg);
}

@ -0,0 +1,12 @@
package Triangle.AbstractSyntaxTrees.Visitors;
import Triangle.AbstractSyntaxTrees.Types.MultipleFieldTypeDenoter;
import Triangle.AbstractSyntaxTrees.Types.SingleFieldTypeDenoter;
public interface FieldTypeDenoterVisitor<TArg, TResult> {
TResult visitMultipleFieldTypeDenoter(MultipleFieldTypeDenoter ast, TArg arg);
TResult visitSingleFieldTypeDenoter(SingleFieldTypeDenoter ast, TArg arg);
}

@ -0,0 +1,15 @@
package Triangle.AbstractSyntaxTrees.Visitors;
import Triangle.AbstractSyntaxTrees.Formals.EmptyFormalParameterSequence;
import Triangle.AbstractSyntaxTrees.Formals.MultipleFormalParameterSequence;
import Triangle.AbstractSyntaxTrees.Formals.SingleFormalParameterSequence;
public interface FormalParameterSequenceVisitor<TArg, TResult> {
TResult visitEmptyFormalParameterSequence(EmptyFormalParameterSequence ast, TArg arg);
TResult visitMultipleFormalParameterSequence(MultipleFormalParameterSequence ast, TArg arg);
TResult visitSingleFormalParameterSequence(SingleFormalParameterSequence ast, TArg arg);
}

@ -0,0 +1,18 @@
package Triangle.AbstractSyntaxTrees.Visitors;
import Triangle.AbstractSyntaxTrees.Formals.ConstFormalParameter;
import Triangle.AbstractSyntaxTrees.Formals.FuncFormalParameter;
import Triangle.AbstractSyntaxTrees.Formals.ProcFormalParameter;
import Triangle.AbstractSyntaxTrees.Formals.VarFormalParameter;
public interface FormalParameterVisitor<TArg, TResult> {
TResult visitConstFormalParameter(ConstFormalParameter ast, TArg arg);
TResult visitFuncFormalParameter(FuncFormalParameter ast, TArg arg);
TResult visitProcFormalParameter(ProcFormalParameter ast, TArg arg);
TResult visitVarFormalParameter(VarFormalParameter ast, TArg arg);
}

@ -0,0 +1,9 @@
package Triangle.AbstractSyntaxTrees.Visitors;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
public interface IdentifierVisitor<TArg, TResult> {
TResult visitIdentifier(Identifier ast, TArg arg);
}

@ -0,0 +1,12 @@
package Triangle.AbstractSyntaxTrees.Visitors;
import Triangle.AbstractSyntaxTrees.Terminals.CharacterLiteral;
import Triangle.AbstractSyntaxTrees.Terminals.IntegerLiteral;
public interface LiteralVisitor<TArg, TResult> {
TResult visitCharacterLiteral(CharacterLiteral ast, TArg arg);
TResult visitIntegerLiteral(IntegerLiteral ast, TArg arg);
}

@ -0,0 +1,9 @@
package Triangle.AbstractSyntaxTrees.Visitors;
import Triangle.AbstractSyntaxTrees.Terminals.Operator;
public interface OperatorVisitor<TArg, TResult> {
TResult visitOperator(Operator ast, TArg arg);
}

@ -0,0 +1,9 @@
package Triangle.AbstractSyntaxTrees.Visitors;
import Triangle.AbstractSyntaxTrees.Program;
public interface ProgramVisitor<TArg, TResult> {
TResult visitProgram(Program ast, TArg arg);
}

@ -0,0 +1,12 @@
package Triangle.AbstractSyntaxTrees.Visitors;
import Triangle.AbstractSyntaxTrees.Aggregates.MultipleRecordAggregate;
import Triangle.AbstractSyntaxTrees.Aggregates.SingleRecordAggregate;
public interface RecordAggregateVisitor<TArg, TResult> {
TResult visitMultipleRecordAggregate(MultipleRecordAggregate ast, TArg arg);
TResult visitSingleRecordAggregate(SingleRecordAggregate ast, TArg arg);
}

@ -0,0 +1,30 @@
package Triangle.AbstractSyntaxTrees.Visitors;
import Triangle.AbstractSyntaxTrees.Types.AnyTypeDenoter;
import Triangle.AbstractSyntaxTrees.Types.ArrayTypeDenoter;
import Triangle.AbstractSyntaxTrees.Types.BoolTypeDenoter;
import Triangle.AbstractSyntaxTrees.Types.CharTypeDenoter;
import Triangle.AbstractSyntaxTrees.Types.ErrorTypeDenoter;
import Triangle.AbstractSyntaxTrees.Types.IntTypeDenoter;
import Triangle.AbstractSyntaxTrees.Types.RecordTypeDenoter;
import Triangle.AbstractSyntaxTrees.Types.SimpleTypeDenoter;
public interface TypeDenoterVisitor<TArg, TResult> extends FieldTypeDenoterVisitor<TArg, TResult> {
TResult visitAnyTypeDenoter(AnyTypeDenoter ast, TArg arg);
TResult visitArrayTypeDenoter(ArrayTypeDenoter ast, TArg arg);
TResult visitBoolTypeDenoter(BoolTypeDenoter ast, TArg arg);
TResult visitCharTypeDenoter(CharTypeDenoter ast, TArg arg);
TResult visitErrorTypeDenoter(ErrorTypeDenoter ast, TArg arg);
TResult visitSimpleTypeDenoter(SimpleTypeDenoter ast, TArg arg);
TResult visitIntTypeDenoter(IntTypeDenoter ast, TArg arg);
TResult visitRecordTypeDenoter(RecordTypeDenoter ast, TArg arg);
}

@ -0,0 +1,15 @@
package Triangle.AbstractSyntaxTrees.Visitors;
import Triangle.AbstractSyntaxTrees.Vnames.DotVname;
import Triangle.AbstractSyntaxTrees.Vnames.SimpleVname;
import Triangle.AbstractSyntaxTrees.Vnames.SubscriptVname;
public interface VnameVisitor<TArg, TResult> {
TResult visitDotVname(DotVname ast, TArg arg);
TResult visitSimpleVname(SimpleVname ast, TArg arg);
TResult visitSubscriptVname(SubscriptVname ast, TArg arg);
}

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Vnames;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Visitors.VnameVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class DotVname extends Vname { public class DotVname extends Vname {
@ -24,11 +26,10 @@ public class DotVname extends Vname {
I = iAST; I = iAST;
} }
@Override public <TArg, TResult> TResult visit(VnameVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitDotVname(this, arg);
return v.visitDotVname(this, o);
} }
public Identifier I; public final Identifier I;
public Vname V; public final Vname V;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Vnames;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Visitors.VnameVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class SimpleVname extends Vname { public class SimpleVname extends Vname {
@ -23,10 +25,9 @@ public class SimpleVname extends Vname {
I = iAST; I = iAST;
} }
@Override public <TArg, TResult> TResult visit(VnameVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitSimpleVname(this, arg);
return v.visitSimpleVname(this, o);
} }
public Identifier I; public final Identifier I;
} }

@ -12,8 +12,10 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Vnames;
import Triangle.AbstractSyntaxTrees.Expressions.Expression;
import Triangle.AbstractSyntaxTrees.Visitors.VnameVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public class SubscriptVname extends Vname { public class SubscriptVname extends Vname {
@ -24,11 +26,10 @@ public class SubscriptVname extends Vname {
E = eAST; E = eAST;
} }
@Override public <TArg, TResult> TResult visit(VnameVisitor<TArg, TResult> v, TArg arg) {
public Object visit(Visitor v, Object o) { return v.visitSubscriptVname(this, arg);
return v.visitSubscriptVname(this, o);
} }
public Expression E; public final Expression E;
public Vname V; public final Vname V;
} }

@ -12,11 +12,14 @@
* of the authors. * of the authors.
*/ */
package Triangle.AbstractSyntaxTrees; package Triangle.AbstractSyntaxTrees.Vnames;
import Triangle.AbstractSyntaxTrees.AbstractSyntaxTree;
import Triangle.AbstractSyntaxTrees.Types.TypeDenoter;
import Triangle.AbstractSyntaxTrees.Visitors.VnameVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition; import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class Vname extends AST { public abstract class Vname extends AbstractSyntaxTree {
public Vname(SourcePosition position) { public Vname(SourcePosition position) {
super(position); super(position);
@ -27,4 +30,10 @@ public abstract class Vname extends AST {
public boolean variable, indexed; public boolean variable, indexed;
public int offset; public int offset;
public TypeDenoter type; public TypeDenoter type;
public abstract <TArg, TResult> TResult visit(VnameVisitor<TArg, TResult> visitor, TArg arg);
public <TArg, TResult> TResult visit(VnameVisitor<TArg, TResult> visitor) {
return visit(visitor, null);
}
} }

Some files were not shown because too many files have changed in this diff Show More