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 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);
switch (r) {
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(r.toString());
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.
*/
@ -142,89 +98,90 @@ public class Disassembler {
* @param d the displacment of the primitive routine.
*/
private static void writePrimitive(int d) {
switch (d) {
case Machine.idDisplacement:
var primitive = Primitive.values()[d];
switch (primitive) {
case ID:
System.out.print("id ");
break;
case Machine.notDisplacement:
case NOT:
System.out.print("not ");
break;
case Machine.andDisplacement:
case AND:
System.out.print("and ");
break;
case Machine.orDisplacement:
case OR:
System.out.print("or ");
break;
case Machine.succDisplacement:
case SUCC:
System.out.print("succ ");
break;
case Machine.predDisplacement:
case PRED:
System.out.print("pred ");
break;
case Machine.negDisplacement:
case NEG:
System.out.print("neg ");
break;
case Machine.addDisplacement:
case ADD:
System.out.print("add ");
break;
case Machine.subDisplacement:
case SUB:
System.out.print("sub ");
break;
case Machine.multDisplacement:
case MULT:
System.out.print("mult ");
break;
case Machine.divDisplacement:
case DIV:
System.out.print("div ");
break;
case Machine.modDisplacement:
case MOD:
System.out.print("mod ");
break;
case Machine.ltDisplacement:
case LT:
System.out.print("lt ");
break;
case Machine.leDisplacement:
case LE:
System.out.print("le ");
break;
case Machine.geDisplacement:
case GE:
System.out.print("ge ");
break;
case Machine.gtDisplacement:
case GT:
System.out.print("gt ");
break;
case Machine.eqDisplacement:
case EQ:
System.out.print("eq ");
break;
case Machine.neDisplacement:
case NE:
System.out.print("ne ");
break;
case Machine.eolDisplacement:
case EOL:
System.out.print("eol ");
break;
case Machine.eofDisplacement:
case EOF:
System.out.print("eof ");
break;
case Machine.getDisplacement:
case GET:
System.out.print("get ");
break;
case Machine.putDisplacement:
case PUT:
System.out.print("put ");
break;
case Machine.geteolDisplacement:
case GETEOL:
System.out.print("geteol ");
break;
case Machine.puteolDisplacement:
case PUTEOL:
System.out.print("puteol ");
break;
case Machine.getintDisplacement:
case GETINT:
System.out.print("getint ");
break;
case Machine.putintDisplacement:
case PUTINT:
System.out.print("putint ");
break;
case Machine.newDisplacement:
case NEW:
System.out.print("new ");
break;
case Machine.disposeDisplacement:
case DISPOSE:
System.out.print("dispose ");
break;
}
@ -237,98 +194,98 @@ public class Disassembler {
*/
private static void writeInstruction(Instruction instr) {
switch (instr.op) {
case Machine.LOADop:
switch (instr.opCode) {
case LOAD:
System.out.print("LOAD ");
writeN(instr.n);
writeD(instr.d);
writeR('[', instr.r, ']');
writeN(instr.length);
writeD(instr.operand);
writeR('[', instr.register, ']');
break;
case Machine.LOADAop:
case LOADA:
System.out.print("LOADA ");
blankN();
writeD(instr.d);
writeR('[', instr.r, ']');
writeD(instr.operand);
writeR('[', instr.register, ']');
break;
case Machine.LOADIop:
case LOADI:
System.out.print("LOADI ");
writeN(instr.n);
writeN(instr.length);
break;
case Machine.LOADLop:
case LOADL:
System.out.print("LOADL ");
blankN();
writeD(instr.d);
writeD(instr.operand);
break;
case Machine.STOREop:
case STORE:
System.out.print("STORE ");
writeN(instr.n);
writeD(instr.d);
writeR('[', instr.r, ']');
writeN(instr.length);
writeD(instr.operand);
writeR('[', instr.register, ']');
break;
case Machine.STOREIop:
case STOREI:
System.out.print("STOREI");
writeN(instr.n);
writeN(instr.length);
break;
case Machine.CALLop:
case CALL:
System.out.print("CALL ");
if (instr.r == Machine.PBr) {
if (instr.register == Register.PB) {
blankN();
writePrimitive(instr.d);
writePrimitive(instr.operand);
} else {
writeR('(', instr.n, ')');
writeR('(', instr.length, ')');
System.out.print(" ");
writeD(instr.d);
writeR('[', instr.r, ']');
writeD(instr.operand);
writeR('[', instr.register, ']');
}
break;
case Machine.CALLIop:
case CALLI:
System.out.print("CALLI ");
break;
case Machine.RETURNop:
case RETURN:
System.out.print("RETURN");
writeN(instr.n);
writeD(instr.d);
writeN(instr.length);
writeD(instr.operand);
break;
case Machine.PUSHop:
case PUSH:
System.out.print("PUSH ");
blankN();
writeD(instr.d);
writeD(instr.operand);
break;
case Machine.POPop:
case POP:
System.out.print("POP ");
writeN(instr.n);
writeD(instr.d);
writeN(instr.length);
writeD(instr.operand);
break;
case Machine.JUMPop:
case JUMP:
System.out.print("JUMP ");
blankN();
writeD(instr.d);
writeR('[', instr.r, ']');
writeD(instr.operand);
writeR('[', instr.register, ']');
break;
case Machine.JUMPIop:
case JUMPI:
System.out.print("JUMPI ");
break;
case Machine.JUMPIFop:
case JUMPIF:
System.out.print("JUMPIF");
writeN(instr.n);
writeD(instr.d);
writeR('[', instr.r, ']');
writeN(instr.length);
writeD(instr.operand);
writeR('[', instr.register, ']');
break;
case Machine.HALTop:
case HALT:
System.out.print("HALT ");
}
}

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

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

@ -31,10 +31,6 @@ public final class Machine {
// 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
public static Instruction[] code = new Instruction[1024];
@ -46,9 +42,6 @@ public final class Machine {
// 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
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;
// 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;
import Triangle.CodeGenerator.RuntimeEntity;
import Triangle.CodeGenerator.Entities.RuntimeEntity;
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;
entity = null;
}
@ -28,13 +30,5 @@ public abstract class AST {
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;
}

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

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

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

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

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

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

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

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

@ -12,26 +12,27 @@
* 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;
public class MultipleRecordAggregate extends RecordAggregate {
public MultipleRecordAggregate(Identifier iAST, Expression eAST, RecordAggregate raAST,
SourcePosition position) {
public MultipleRecordAggregate(Identifier iAST, Expression eAST, RecordAggregate raAST, SourcePosition position) {
super(position);
I = iAST;
E = eAST;
RA = raAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitMultipleRecordAggregate(this, o);
public <TArg, TResult> TResult visit(RecordAggregateVisitor<TArg, TResult> v, TArg arg) {
return v.visitMultipleRecordAggregate(this, arg);
}
public Identifier I;
public Expression E;
public RecordAggregate RA;
public final Identifier I;
public final Expression E;
public final RecordAggregate RA;
}

@ -12,11 +12,14 @@
* 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;
public abstract class RecordAggregate extends AST {
public abstract class RecordAggregate extends AbstractSyntaxTree {
public RecordAggregate(SourcePosition position) {
super(position);
@ -24,4 +27,10 @@ public abstract class RecordAggregate extends AST {
}
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.
*/
package Triangle.AbstractSyntaxTrees;
package Triangle.AbstractSyntaxTrees.Aggregates;
import Triangle.AbstractSyntaxTrees.Expressions.Expression;
import Triangle.AbstractSyntaxTrees.Visitors.ArrayAggregateVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleArrayAggregate extends ArrayAggregate {
@ -23,10 +25,9 @@ public class SingleArrayAggregate extends ArrayAggregate {
E = eAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSingleArrayAggregate(this, o);
public <TArg, TResult> TResult visit(ArrayAggregateVisitor<TArg, TResult> v, TArg arg) {
return v.visitSingleArrayAggregate(this, arg);
}
public Expression E;
public final Expression E;
}

@ -12,8 +12,11 @@
* 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;
public class SingleRecordAggregate extends RecordAggregate {
@ -24,11 +27,10 @@ public class SingleRecordAggregate extends RecordAggregate {
E = eAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSingleRecordAggregate(this, o);
public <TArg, TResult> TResult visit(RecordAggregateVisitor<TArg, TResult> v, TArg arg) {
return v.visitSingleRecordAggregate(this, arg);
}
public Identifier I;
public Expression E;
public final Identifier I;
public final Expression E;
}

@ -12,8 +12,11 @@
* 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;
public class AssignCommand extends Command {
@ -24,11 +27,10 @@ public class AssignCommand extends Command {
E = eAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitAssignCommand(this, o);
public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) {
return v.visitAssignCommand(this, arg);
}
public Vname V;
public Expression E;
public final Vname V;
public final Expression E;
}

@ -12,8 +12,11 @@
* 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;
public class CallCommand extends Command {
@ -24,11 +27,10 @@ public class CallCommand extends Command {
APS = apsAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitCallCommand(this, o);
public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) {
return v.visitCallCommand(this, arg);
}
public Identifier I;
public ActualParameterSequence APS;
public final Identifier I;
public final ActualParameterSequence APS;
}

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

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

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

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

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

@ -12,8 +12,11 @@
* 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;
public class BinaryOperatorDeclaration extends Declaration {
@ -27,11 +30,10 @@ public class BinaryOperatorDeclaration extends Declaration {
RES = resultAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitBinaryOperatorDeclaration(this, o);
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
return v.visitBinaryOperatorDeclaration(this, arg);
}
public Operator O;
public TypeDenoter ARG1, ARG2, RES;
public final Operator O;
public final TypeDenoter ARG1, ARG2, RES;
}

@ -12,8 +12,11 @@
* 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;
public class ConstDeclaration extends Declaration {
@ -24,11 +27,10 @@ public class ConstDeclaration extends Declaration {
E = eAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitConstDeclaration(this, o);
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
return v.visitConstDeclaration(this, arg);
}
public Identifier I;
public Expression E;
public final Identifier I;
public final Expression E;
}

@ -12,11 +12,13 @@
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
package Triangle.AbstractSyntaxTrees.Declarations;
import Triangle.AbstractSyntaxTrees.AbstractSyntaxTree;
import Triangle.AbstractSyntaxTrees.Visitors.DeclarationVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class Declaration extends AST {
public abstract class Declaration extends AbstractSyntaxTree {
public Declaration(SourcePosition position) {
super(position);
@ -24,4 +26,10 @@ public abstract class Declaration extends AST {
}
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.
*/
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;
public class FuncDeclaration extends Declaration {
@ -27,13 +32,12 @@ public class FuncDeclaration extends Declaration {
E = eAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitFuncDeclaration(this, o);
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
return v.visitFuncDeclaration(this, arg);
}
public Identifier I;
public FormalParameterSequence FPS;
public final Identifier I;
public final FormalParameterSequence FPS;
public TypeDenoter T;
public Expression E;
public final Expression E;
}

@ -12,8 +12,12 @@
* 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;
public class ProcDeclaration extends Declaration {
@ -25,12 +29,11 @@ public class ProcDeclaration extends Declaration {
C = cAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitProcDeclaration(this, o);
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
return v.visitProcDeclaration(this, arg);
}
public Identifier I;
public FormalParameterSequence FPS;
public Command C;
public final Identifier I;
public final FormalParameterSequence FPS;
public final Command C;
}

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

@ -12,25 +12,26 @@
* 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;
public class UnaryOperatorDeclaration extends Declaration {
public UnaryOperatorDeclaration(Operator oAST, TypeDenoter argAST, TypeDenoter resultAST,
SourcePosition position) {
public UnaryOperatorDeclaration(Operator oAST, TypeDenoter argAST, TypeDenoter resultAST, SourcePosition position) {
super(position);
O = oAST;
ARG = argAST;
RES = resultAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitUnaryOperatorDeclaration(this, o);
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
return v.visitUnaryOperatorDeclaration(this, arg);
}
public Operator O;
public TypeDenoter ARG, RES;
public final Operator O;
public final TypeDenoter ARG, RES;
}

@ -12,8 +12,11 @@
* 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;
public class VarDeclaration extends Declaration {
@ -24,11 +27,10 @@ public class VarDeclaration extends Declaration {
T = tAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitVarDeclaration(this, o);
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
return v.visitVarDeclaration(this, arg);
}
public Identifier I;
public final Identifier I;
public TypeDenoter T;
}

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

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

@ -12,8 +12,11 @@
* 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;
public class CallExpression extends Expression {
@ -24,11 +27,10 @@ public class CallExpression extends Expression {
APS = apsAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitCallExpression(this, o);
public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) {
return v.visitCallExpression(this, arg);
}
public Identifier I;
public ActualParameterSequence APS;
public final Identifier I;
public final ActualParameterSequence APS;
}

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

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

@ -12,11 +12,14 @@
* 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;
public abstract class Expression extends AST {
public abstract class Expression extends AbstractSyntaxTree {
public Expression(SourcePosition position) {
super(position);
@ -24,4 +27,10 @@ public abstract class Expression extends AST {
}
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.
*/
package Triangle.AbstractSyntaxTrees;
package Triangle.AbstractSyntaxTrees.Expressions;
import Triangle.AbstractSyntaxTrees.Visitors.ExpressionVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class IfExpression extends Expression {
@ -25,10 +26,9 @@ public class IfExpression extends Expression {
E3 = e3AST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitIfExpression(this, o);
public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) {
return v.visitIfExpression(this, arg);
}
public Expression E1, E2, E3;
public final Expression E1, E2, E3;
}

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

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

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

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

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

@ -12,8 +12,11 @@
* 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;
public class ConstFormalParameter extends FormalParameter {
@ -24,20 +27,20 @@ public class ConstFormalParameter extends FormalParameter {
T = tAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitConstFormalParameter(this, o);
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
return v.visitConstFormalParameter(this, arg);
}
public Identifier I;
public TypeDenoter T;
@Override
public boolean equals(Object fpAST) {
if (fpAST instanceof ConstFormalParameter) {
ConstFormalParameter cfpAST = (ConstFormalParameter) fpAST;
var cfpAST = (ConstFormalParameter) fpAST;
return T.equals(cfpAST.T);
} else
} else {
return false;
}
}
public final Identifier I;
public TypeDenoter T;
}

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

@ -12,8 +12,10 @@
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
package Triangle.AbstractSyntaxTrees.Formals;
import Triangle.AbstractSyntaxTrees.Declarations.Declaration;
import Triangle.AbstractSyntaxTrees.Visitors.DeclarationVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class FormalParameter extends Declaration {
@ -25,4 +27,9 @@ public abstract class FormalParameter extends Declaration {
@Override
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.
*/
package Triangle.AbstractSyntaxTrees;
package Triangle.AbstractSyntaxTrees.Formals;
import Triangle.AbstractSyntaxTrees.AbstractSyntaxTree;
import Triangle.AbstractSyntaxTrees.Visitors.FormalParameterSequenceVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class FormalParameterSequence extends AST {
public abstract class FormalParameterSequence extends AbstractSyntaxTree {
public FormalParameterSequence(SourcePosition position) {
super(position);
@ -24,4 +26,10 @@ public abstract class FormalParameterSequence extends AST {
@Override
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.
*/
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;
public class FuncFormalParameter extends FormalParameter {
@ -26,9 +29,8 @@ public class FuncFormalParameter extends FormalParameter {
T = tAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitFuncFormalParameter(this, o);
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
return v.visitFuncFormalParameter(this, arg);
}
@Override
@ -40,7 +42,7 @@ public class FuncFormalParameter extends FormalParameter {
return false;
}
public Identifier I;
public FormalParameterSequence FPS;
public final Identifier I;
public final FormalParameterSequence FPS;
public TypeDenoter T;
}

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

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

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

@ -12,8 +12,11 @@
* 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;
public class VarFormalParameter extends FormalParameter {
@ -24,20 +27,20 @@ public class VarFormalParameter extends FormalParameter {
T = tAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitVarFormalParameter(this, o);
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
return v.visitVarFormalParameter(this, arg);
}
public Identifier I;
public TypeDenoter T;
@Override
public boolean equals(Object fpAST) {
if (fpAST instanceof VarFormalParameter) {
VarFormalParameter vfpAST = (VarFormalParameter) fpAST;
return T.equals(vfpAST.T);
} else
} else {
return false;
}
}
public final Identifier I;
public TypeDenoter T;
}

@ -14,19 +14,24 @@
package Triangle.AbstractSyntaxTrees;
import Triangle.AbstractSyntaxTrees.Commands.Command;
import Triangle.AbstractSyntaxTrees.Visitors.ProgramVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class Program extends AST {
public class Program extends AbstractSyntaxTree {
public Program(Command cAST, SourcePosition position) {
super(position);
C = cAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitProgram(this, o);
public Command C;
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.
*/
package Triangle.AbstractSyntaxTrees;
package Triangle.AbstractSyntaxTrees.Terminals;
import Triangle.AbstractSyntaxTrees.Visitors.LiteralVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class CharacterLiteral extends Terminal {
@ -22,9 +23,15 @@ public class CharacterLiteral extends Terminal {
super(spelling, position);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitCharacterLiteral(this, o);
public <TArg, TResult> TResult visit(LiteralVisitor<TArg, TResult> v, TArg arg) {
return v.visitCharacterLiteral(this, arg);
}
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.
*/
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;
public class Identifier extends Terminal {
@ -24,11 +27,14 @@ public class Identifier extends Terminal {
decl = null;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitIdentifier(this, o);
public TypeDenoter type;
public AbstractSyntaxTree decl; // Either a Declaration or a FieldTypeDenoter
public <TArg, TResult> TResult visit(IdentifierVisitor<TArg, TResult> visitor, TArg arg) {
return visitor.visitIdentifier(this, arg);
}
public TypeDenoter type;
public AST decl; // Either a Declaration or a FieldTypeDenoter
public <TArg, TResult> TResult visit(IdentifierVisitor<TArg, TResult> visitor) {
return visit(visitor, null);
}
}

@ -12,8 +12,9 @@
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
package Triangle.AbstractSyntaxTrees.Terminals;
import Triangle.AbstractSyntaxTrees.Visitors.LiteralVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class IntegerLiteral extends Terminal {
@ -22,9 +23,15 @@ public class IntegerLiteral extends Terminal {
super(spelling, position);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitIntegerLiteral(this, o);
public <TArg, TResult> TResult visit(LiteralVisitor<TArg, TResult> v, TArg arg) {
return v.visitIntegerLiteral(this, arg);
}
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.
*/
package Triangle.AbstractSyntaxTrees;
package Triangle.AbstractSyntaxTrees.Terminals;
import Triangle.AbstractSyntaxTrees.Declarations.Declaration;
import Triangle.AbstractSyntaxTrees.Visitors.OperatorVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class Operator extends Terminal {
@ -23,10 +25,13 @@ public class Operator extends Terminal {
decl = null;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitOperator(this, o);
public Declaration decl;
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.
*/
package Triangle.AbstractSyntaxTrees;
package Triangle.AbstractSyntaxTrees.Terminals;
import Triangle.AbstractSyntaxTrees.AbstractSyntaxTree;
import Triangle.SyntacticAnalyzer.SourcePosition;
abstract public class Terminal extends AST {
public abstract class Terminal extends AbstractSyntaxTree {
public Terminal(String spelling, SourcePosition position) {
super(position);

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

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

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

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

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

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

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

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

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

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

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

@ -12,8 +12,11 @@
* 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;
public class TypeDeclaration extends Declaration {
@ -24,11 +27,10 @@ public class TypeDeclaration extends Declaration {
T = tAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitTypeDeclaration(this, o);
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
return v.visitTypeDeclaration(this, arg);
}
public Identifier I;
public final Identifier I;
public TypeDenoter T;
}

@ -12,11 +12,13 @@
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
package Triangle.AbstractSyntaxTrees.Types;
import Triangle.AbstractSyntaxTrees.AbstractSyntaxTree;
import Triangle.AbstractSyntaxTrees.Visitors.TypeDenoterVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class TypeDenoter extends AST {
public abstract class TypeDenoter extends AbstractSyntaxTree {
public TypeDenoter(SourcePosition position) {
super(position);
@ -25,4 +27,9 @@ public abstract class TypeDenoter extends AST {
@Override
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.
*/
package Triangle.AbstractSyntaxTrees;
package Triangle.AbstractSyntaxTrees.Vnames;
import Triangle.AbstractSyntaxTrees.Terminals.Identifier;
import Triangle.AbstractSyntaxTrees.Visitors.VnameVisitor;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class DotVname extends Vname {
@ -24,11 +26,10 @@ public class DotVname extends Vname {
I = iAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitDotVname(this, o);
public <TArg, TResult> TResult visit(VnameVisitor<TArg, TResult> v, TArg arg) {
return v.visitDotVname(this, arg);
}
public Identifier I;
public Vname V;
public final Identifier I;
public final Vname V;
}

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

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

@ -12,11 +12,14 @@
* 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;
public abstract class Vname extends AST {
public abstract class Vname extends AbstractSyntaxTree {
public Vname(SourcePosition position) {
super(position);
@ -27,4 +30,10 @@ public abstract class Vname extends AST {
public boolean variable, indexed;
public int offset;
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