Format code and fix warnings.

main
Deryck Brown 3 years ago
parent 2c426b5b2e
commit a02acc009b
  1. 718
      Triangle.AbstractMachine.Disassembler/src/main/java/Triangle/AbstractMachine/Disassembler.java
  2. 1188
      Triangle.AbstractMachine.Interpreter/src/main/java/Triangle/AbstractMachine/Interpreter.java
  3. 72
      Triangle.AbstractMachine/src/main/java/Triangle/AbstractMachine/Instruction.java
  4. 156
      Triangle.AbstractMachine/src/main/java/Triangle/AbstractMachine/Machine.java
  5. 20
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/AST.java
  6. 6
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ActualParameter.java
  7. 6
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ActualParameterSequence.java
  8. 22
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/AnyTypeDenoter.java
  9. 10
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ArrayAggregate.java
  10. 19
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ArrayExpression.java
  11. 43
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ArrayTypeDenoter.java
  12. 22
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/AssignCommand.java
  13. 25
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/BinaryExpression.java
  14. 29
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/BinaryOperatorDeclaration.java
  15. 28
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/BoolTypeDenoter.java
  16. 23
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/CallCommand.java
  17. 23
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/CallExpression.java
  18. 28
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/CharTypeDenoter.java
  19. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/CharacterExpression.java
  20. 14
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/CharacterLiteral.java
  21. 6
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Command.java
  22. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ConstActualParameter.java
  23. 23
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ConstDeclaration.java
  24. 39
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ConstFormalParameter.java
  25. 10
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Declaration.java
  26. 22
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/DotVname.java
  27. 14
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/EmptyActualParameterSequence.java
  28. 14
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/EmptyCommand.java
  29. 14
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/EmptyExpression.java
  30. 22
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/EmptyFormalParameterSequence.java
  31. 22
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ErrorTypeDenoter.java
  32. 10
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Expression.java
  33. 10
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/FieldTypeDenoter.java
  34. 10
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/FormalParameter.java
  35. 10
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/FormalParameterSequence.java
  36. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/FuncActualParameter.java
  37. 33
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/FuncDeclaration.java
  38. 44
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/FuncFormalParameter.java
  39. 22
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Identifier.java
  40. 25
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/IfCommand.java
  41. 23
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/IfExpression.java
  42. 28
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/IntTypeDenoter.java
  43. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/IntegerExpression.java
  44. 14
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/IntegerLiteral.java
  45. 22
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/LetCommand.java
  46. 22
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/LetExpression.java
  47. 24
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/MultipleActualParameterSequence.java
  48. 23
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/MultipleArrayAggregate.java
  49. 46
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/MultipleFieldTypeDenoter.java
  50. 40
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/MultipleFormalParameterSequence.java
  51. 28
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/MultipleRecordAggregate.java
  52. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Operator.java
  53. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ProcActualParameter.java
  54. 27
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ProcDeclaration.java
  55. 39
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ProcFormalParameter.java
  56. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Program.java
  57. 10
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/RecordAggregate.java
  58. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/RecordExpression.java
  59. 36
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/RecordTypeDenoter.java
  60. 20
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/SequentialCommand.java
  61. 21
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/SequentialDeclaration.java
  62. 26
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/SimpleTypeDenoter.java
  63. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/SimpleVname.java
  64. 19
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/SingleActualParameterSequence.java
  65. 19
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/SingleArrayAggregate.java
  66. 40
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/SingleFieldTypeDenoter.java
  67. 35
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/SingleFormalParameterSequence.java
  68. 23
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/SingleRecordAggregate.java
  69. 22
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/SubscriptVname.java
  70. 10
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Terminal.java
  71. 23
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/TypeDeclaration.java
  72. 10
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/TypeDenoter.java
  73. 23
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/UnaryExpression.java
  74. 26
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/UnaryOperatorDeclaration.java
  75. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/VarActualParameter.java
  76. 23
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/VarDeclaration.java
  77. 39
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/VarFormalParameter.java
  78. 146
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Visitor.java
  79. 16
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/Vname.java
  80. 18
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/VnameExpression.java
  81. 22
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/WhileCommand.java
  82. 1867
      Triangle.Compiler/src/main/java/Triangle/CodeGenerator/Encoder.java
  83. 16
      Triangle.Compiler/src/main/java/Triangle/CodeGenerator/EqualityRoutine.java
  84. 18
      Triangle.Compiler/src/main/java/Triangle/CodeGenerator/Field.java
  85. 54
      Triangle.Compiler/src/main/java/Triangle/CodeGenerator/Frame.java
  86. 18
      Triangle.Compiler/src/main/java/Triangle/CodeGenerator/KnownAddress.java
  87. 18
      Triangle.Compiler/src/main/java/Triangle/CodeGenerator/KnownRoutine.java
  88. 18
      Triangle.Compiler/src/main/java/Triangle/CodeGenerator/KnownValue.java
  89. 10
      Triangle.Compiler/src/main/java/Triangle/CodeGenerator/ObjectAddress.java
  90. 18
      Triangle.Compiler/src/main/java/Triangle/CodeGenerator/PrimitiveRoutine.java
  91. 16
      Triangle.Compiler/src/main/java/Triangle/CodeGenerator/RuntimeEntity.java
  92. 6
      Triangle.Compiler/src/main/java/Triangle/CodeGenerator/TypeRepresentation.java
  93. 18
      Triangle.Compiler/src/main/java/Triangle/CodeGenerator/UnknownAddress.java
  94. 18
      Triangle.Compiler/src/main/java/Triangle/CodeGenerator/UnknownRoutine.java
  95. 18
      Triangle.Compiler/src/main/java/Triangle/CodeGenerator/UnknownValue.java
  96. 184
      Triangle.Compiler/src/main/java/Triangle/Compiler.java
  97. 1803
      Triangle.Compiler/src/main/java/Triangle/ContextualAnalyzer/Checker.java
  98. 20
      Triangle.Compiler/src/main/java/Triangle/ContextualAnalyzer/IdEntry.java
  99. 172
      Triangle.Compiler/src/main/java/Triangle/ContextualAnalyzer/IdentificationTable.java
  100. 42
      Triangle.Compiler/src/main/java/Triangle/ErrorReporter.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -20,8 +20,8 @@ import java.io.FileNotFoundException;
import java.io.IOException;
/**
* Disassembles the TAM code in the given file, and displays the
* instructions on standard output.
* Disassembles the TAM code in the given file, and displays the instructions on
* standard output.
*
* For example:
*
@ -38,361 +38,361 @@ import java.io.IOException;
public class Disassembler {
static String objectName;
static int CT;
/**
* Writes the r-field of an instruction in the form "l<I>reg</I>r", where
* l and r are the bracket characters to use.
*
* @param leftbracket the character to print before the register.
* @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) {
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(rightbracket);
}
/**
* Writes a void n-field of an instruction.
*/
private static void blankN() {
System.out.print(" ");
}
// Writes the n-field of an instruction.
/**
* Writes the n-field of an instruction in the form "(n)".
*
* @param n the integer to write.
*/
private static void writeN(int n) {
System.out.print("(" + n + ") ");
if (n < 10)
System.out.print(" ");
else if (n < 100)
System.out.print(" ");
}
/**
* Writes the d-field of an instruction.
*
* @param d the integer to write.
*/
private static void writeD(int d) {
System.out.print(d);
}
/**
* Writes the name of primitive routine with relative address d.
*
* @param d the displacment of the primitive routine.
*/
private static void writePrimitive(int d) {
switch (d) {
case Machine.idDisplacement:
System.out.print("id ");
break;
case Machine.notDisplacement:
System.out.print("not ");
break;
case Machine.andDisplacement:
System.out.print("and ");
break;
case Machine.orDisplacement:
System.out.print("or ");
break;
case Machine.succDisplacement:
System.out.print("succ ");
break;
case Machine.predDisplacement:
System.out.print("pred ");
break;
case Machine.negDisplacement:
System.out.print("neg ");
break;
case Machine.addDisplacement:
System.out.print("add ");
break;
case Machine.subDisplacement:
System.out.print("sub ");
break;
case Machine.multDisplacement:
System.out.print("mult ");
break;
case Machine.divDisplacement:
System.out.print("div ");
break;
case Machine.modDisplacement:
System.out.print("mod ");
break;
case Machine.ltDisplacement:
System.out.print("lt ");
break;
case Machine.leDisplacement:
System.out.print("le ");
break;
case Machine.geDisplacement:
System.out.print("ge ");
break;
case Machine.gtDisplacement:
System.out.print("gt ");
break;
case Machine.eqDisplacement:
System.out.print("eq ");
break;
case Machine.neDisplacement:
System.out.print("ne ");
break;
case Machine.eolDisplacement:
System.out.print("eol ");
break;
case Machine.eofDisplacement:
System.out.print("eof ");
break;
case Machine.getDisplacement:
System.out.print("get ");
break;
case Machine.putDisplacement:
System.out.print("put ");
break;
case Machine.geteolDisplacement:
System.out.print("geteol ");
break;
case Machine.puteolDisplacement:
System.out.print("puteol ");
break;
case Machine.getintDisplacement:
System.out.print("getint ");
break;
case Machine.putintDisplacement:
System.out.print("putint ");
break;
case Machine.newDisplacement:
System.out.print("new ");
break;
case Machine.disposeDisplacement:
System.out.print("dispose ");
break;
}
}
/**
* Writes the given instruction in assembly-code format.
*
* @param instr the instruction to display.
*/
private static void writeInstruction(Instruction instr) {
switch (instr.op) {
case Machine.LOADop:
System.out.print("LOAD ");
writeN(instr.n);
writeD(instr.d);
writeR('[', instr.r, ']');
break;
case Machine.LOADAop:
System.out.print("LOADA ");
blankN();
writeD(instr.d);
writeR('[', instr.r, ']');
break;
case Machine.LOADIop:
System.out.print("LOADI ");
writeN(instr.n);
break;
case Machine.LOADLop:
System.out.print("LOADL ");
blankN();
writeD(instr.d);
break;
case Machine.STOREop:
System.out.print("STORE ");
writeN(instr.n);
writeD(instr.d);
writeR('[', instr.r, ']');
break;
case Machine.STOREIop:
System.out.print("STOREI");
writeN(instr.n);
break;
case Machine.CALLop:
System.out.print("CALL ");
if (instr.r == Machine.PBr) {
blankN();
writePrimitive(instr.d);
} else {
writeR('(', instr.n, ')');
System.out.print(" ");
writeD(instr.d);
writeR('[', instr.r, ']');
}
break;
case Machine.CALLIop:
System.out.print("CALLI ");
break;
case Machine.RETURNop:
System.out.print("RETURN");
writeN(instr.n);
writeD(instr.d);
break;
case Machine.PUSHop:
System.out.print("PUSH ");
blankN();
writeD(instr.d);
break;
case Machine.POPop:
System.out.print("POP ");
writeN(instr.n);
writeD(instr.d);
break;
case Machine.JUMPop:
System.out.print("JUMP ");
blankN();
writeD(instr.d);
writeR('[', instr.r, ']');
break;
case Machine.JUMPIop:
System.out.print("JUMPI ");
break;
case Machine.JUMPIFop:
System.out.print("JUMPIF");
writeN(instr.n);
writeD(instr.d);
writeR('[', instr.r, ']');
break;
case Machine.HALTop:
System.out.print("HALT ");
}
}
/**
* Writes all instructions of the program in code store.
*/
private static void disassembleProgram() {
for (int addr = Machine.CB; addr < CT; addr++) {
System.out.print(addr + ": ");
writeInstruction(Machine.code[addr]);
System.out.println();
}
}
// LOADING
/**
* Loads the TAM object program into code store from the named file.
*
* @param objectName the name of the file containing the program.
*/
static void loadObjectProgram(String objectName) {
FileInputStream objectFile = null;
DataInputStream objectStream = null;
int addr;
boolean finished = false;
try {
objectFile = new FileInputStream(objectName);
objectStream = new DataInputStream(objectFile);
addr = Machine.CB;
while (!finished) {
Machine.code[addr] = Instruction.read(objectStream);
if (Machine.code[addr] == null)
finished = true;
else
addr = addr + 1;
}
CT = addr;
objectFile.close();
} catch (FileNotFoundException s) {
CT = Machine.CB;
System.err.println("Error opening object file: " + s);
} catch (IOException s) {
CT = Machine.CB;
System.err.println("Error reading object file: " + s);
}
}
// DISASSEMBLE
public static void main(String[] args) {
System.out.println("********** TAM Disassembler (Sun Version 2.1) **********");
if (args.length == 1)
objectName = args[0];
else
objectName = "obj.tam";
loadObjectProgram(objectName);
disassembleProgram();
}
static String objectName;
static int CT;
/**
* Writes the r-field of an instruction in the form "l<I>reg</I>r", where l and
* r are the bracket characters to use.
*
* @param leftbracket the character to print before the register.
* @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) {
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(rightbracket);
}
/**
* Writes a void n-field of an instruction.
*/
private static void blankN() {
System.out.print(" ");
}
// Writes the n-field of an instruction.
/**
* Writes the n-field of an instruction in the form "(n)".
*
* @param n the integer to write.
*/
private static void writeN(int n) {
System.out.print("(" + n + ") ");
if (n < 10)
System.out.print(" ");
else if (n < 100)
System.out.print(" ");
}
/**
* Writes the d-field of an instruction.
*
* @param d the integer to write.
*/
private static void writeD(int d) {
System.out.print(d);
}
/**
* Writes the name of primitive routine with relative address d.
*
* @param d the displacment of the primitive routine.
*/
private static void writePrimitive(int d) {
switch (d) {
case Machine.idDisplacement:
System.out.print("id ");
break;
case Machine.notDisplacement:
System.out.print("not ");
break;
case Machine.andDisplacement:
System.out.print("and ");
break;
case Machine.orDisplacement:
System.out.print("or ");
break;
case Machine.succDisplacement:
System.out.print("succ ");
break;
case Machine.predDisplacement:
System.out.print("pred ");
break;
case Machine.negDisplacement:
System.out.print("neg ");
break;
case Machine.addDisplacement:
System.out.print("add ");
break;
case Machine.subDisplacement:
System.out.print("sub ");
break;
case Machine.multDisplacement:
System.out.print("mult ");
break;
case Machine.divDisplacement:
System.out.print("div ");
break;
case Machine.modDisplacement:
System.out.print("mod ");
break;
case Machine.ltDisplacement:
System.out.print("lt ");
break;
case Machine.leDisplacement:
System.out.print("le ");
break;
case Machine.geDisplacement:
System.out.print("ge ");
break;
case Machine.gtDisplacement:
System.out.print("gt ");
break;
case Machine.eqDisplacement:
System.out.print("eq ");
break;
case Machine.neDisplacement:
System.out.print("ne ");
break;
case Machine.eolDisplacement:
System.out.print("eol ");
break;
case Machine.eofDisplacement:
System.out.print("eof ");
break;
case Machine.getDisplacement:
System.out.print("get ");
break;
case Machine.putDisplacement:
System.out.print("put ");
break;
case Machine.geteolDisplacement:
System.out.print("geteol ");
break;
case Machine.puteolDisplacement:
System.out.print("puteol ");
break;
case Machine.getintDisplacement:
System.out.print("getint ");
break;
case Machine.putintDisplacement:
System.out.print("putint ");
break;
case Machine.newDisplacement:
System.out.print("new ");
break;
case Machine.disposeDisplacement:
System.out.print("dispose ");
break;
}
}
/**
* Writes the given instruction in assembly-code format.
*
* @param instr the instruction to display.
*/
private static void writeInstruction(Instruction instr) {
switch (instr.op) {
case Machine.LOADop:
System.out.print("LOAD ");
writeN(instr.n);
writeD(instr.d);
writeR('[', instr.r, ']');
break;
case Machine.LOADAop:
System.out.print("LOADA ");
blankN();
writeD(instr.d);
writeR('[', instr.r, ']');
break;
case Machine.LOADIop:
System.out.print("LOADI ");
writeN(instr.n);
break;
case Machine.LOADLop:
System.out.print("LOADL ");
blankN();
writeD(instr.d);
break;
case Machine.STOREop:
System.out.print("STORE ");
writeN(instr.n);
writeD(instr.d);
writeR('[', instr.r, ']');
break;
case Machine.STOREIop:
System.out.print("STOREI");
writeN(instr.n);
break;
case Machine.CALLop:
System.out.print("CALL ");
if (instr.r == Machine.PBr) {
blankN();
writePrimitive(instr.d);
} else {
writeR('(', instr.n, ')');
System.out.print(" ");
writeD(instr.d);
writeR('[', instr.r, ']');
}
break;
case Machine.CALLIop:
System.out.print("CALLI ");
break;
case Machine.RETURNop:
System.out.print("RETURN");
writeN(instr.n);
writeD(instr.d);
break;
case Machine.PUSHop:
System.out.print("PUSH ");
blankN();
writeD(instr.d);
break;
case Machine.POPop:
System.out.print("POP ");
writeN(instr.n);
writeD(instr.d);
break;
case Machine.JUMPop:
System.out.print("JUMP ");
blankN();
writeD(instr.d);
writeR('[', instr.r, ']');
break;
case Machine.JUMPIop:
System.out.print("JUMPI ");
break;
case Machine.JUMPIFop:
System.out.print("JUMPIF");
writeN(instr.n);
writeD(instr.d);
writeR('[', instr.r, ']');
break;
case Machine.HALTop:
System.out.print("HALT ");
}
}
/**
* Writes all instructions of the program in code store.
*/
private static void disassembleProgram() {
for (int addr = Machine.CB; addr < CT; addr++) {
System.out.print(addr + ": ");
writeInstruction(Machine.code[addr]);
System.out.println();
}
}
// LOADING
/**
* Loads the TAM object program into code store from the named file.
*
* @param objectName the name of the file containing the program.
*/
static void loadObjectProgram(String objectName) {
FileInputStream objectFile = null;
DataInputStream objectStream = null;
int addr;
boolean finished = false;
try {
objectFile = new FileInputStream(objectName);
objectStream = new DataInputStream(objectFile);
addr = Machine.CB;
while (!finished) {
Machine.code[addr] = Instruction.read(objectStream);
if (Machine.code[addr] == null)
finished = true;
else
addr = addr + 1;
}
CT = addr;
objectFile.close();
} catch (FileNotFoundException s) {
CT = Machine.CB;
System.err.println("Error opening object file: " + s);
} catch (IOException s) {
CT = Machine.CB;
System.err.println("Error reading object file: " + s);
}
}
// DISASSEMBLE
public static void main(String[] args) {
System.out.println("********** TAM Disassembler (Sun Version 2.1) **********");
if (args.length == 1)
objectName = args[0];
else
objectName = "obj.tam";
loadObjectProgram(objectName);
disassembleProgram();
}
}

@ -21,44 +21,44 @@ import java.io.IOException;
public class Instruction {
public Instruction() {
op = 0;
r = 0;
n = 0;
d = 0;
}
public Instruction() {
op = 0;
r = 0;
n = 0;
d = 0;
}
// Java has no type synonyms, so the following representations are
// assumed:
//
// type
// OpCode = 0..15; {4 bits unsigned}
// Length = 0..255; {8 bits unsigned}
// Operand = -32767..+32767; {16 bits signed}
// Java has no type synonyms, so the following representations are
// assumed:
//
// type
// OpCode = 0..15; {4 bits unsigned}
// Length = 0..255; {8 bits unsigned}
// 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
// Represents TAM instructions.
public int op; // OpCode
public int r; // RegisterNumber
public int n; // Length
public int d; // Operand
public void write(DataOutputStream output) throws IOException {
output.writeInt(op);
output.writeInt(r);
output.writeInt(n);
output.writeInt(d);
}
public void write(DataOutputStream output) throws IOException {
output.writeInt(op);
output.writeInt(r);
output.writeInt(n);
output.writeInt(d);
}
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;
} catch (EOFException s) {
return null;
}
}
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;
} catch (EOFException s) {
return null;
}
}
}

@ -16,110 +16,56 @@ package Triangle.AbstractMachine;
public final class Machine {
public final static int maxRoutineLevel = 7;
// WORDS AND ADDRESSES
// Java has no type synonyms, so the following representations are
// assumed:
//
// type
// Word = -32767..+32767; {16 bits signed}
// DoubleWord = -2147483648..+2147483647; {32 bits signed}
// CodeAddress = 0..+32767; {15 bits unsigned}
// DataAddress = 0..+32767; {15 bits unsigned}
// 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];
// CODE STORE REGISTERS
public final static int CB = 0,
PB = 1024, // = upper bound of code array + 1
PT = 1052; // = PB + 28
// 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,
closureSize = 2 * addressSize,
linkDataSize = 3 * addressSize,
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;
public final static int maxRoutineLevel = 7;
// WORDS AND ADDRESSES
// Java has no type synonyms, so the following representations are
// assumed:
//
// type
// Word = -32767..+32767; {16 bits signed}
// DoubleWord = -2147483648..+2147483647; {32 bits signed}
// CodeAddress = 0..+32767; {15 bits unsigned}
// DataAddress = 0..+32767; {15 bits unsigned}
// 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];
// CODE STORE REGISTERS
public final static int CB = 0, PB = 1024, // = upper bound of code array + 1
PT = 1052; // = PB + 28
// 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,
closureSize = 2 * addressSize,
linkDataSize = 3 * addressSize,
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;
}

@ -19,17 +19,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class AST {
public AST(SourcePosition thePosition) {
position = thePosition;
entity = null;
}
public AST(SourcePosition thePosition) {
position = thePosition;
entity = null;
}
public SourcePosition getPosition() {
return position;
}
public SourcePosition getPosition() {
return position;
}
public abstract Object visit(Visitor v, Object o);
public abstract Object visit(Visitor v, Object o);
public SourcePosition position;
public RuntimeEntity entity;
public SourcePosition position;
public RuntimeEntity entity;
}

@ -18,7 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class ActualParameter extends AST {
public ActualParameter(SourcePosition thePosition) {
super(thePosition);
}
public ActualParameter(SourcePosition thePosition) {
super(thePosition);
}
}

@ -18,7 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class ActualParameterSequence extends AST {
public ActualParameterSequence(SourcePosition thePosition) {
super(thePosition);
}
public ActualParameterSequence(SourcePosition thePosition) {
super(thePosition);
}
}

@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class AnyTypeDenoter extends TypeDenoter {
public AnyTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
public AnyTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitAnyTypeDenoter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitAnyTypeDenoter(this, o);
}
@Override
public boolean equals(Object obj) {
return false;
}
@Override
public boolean equals(Object obj) {
return false;
}
}

@ -18,10 +18,10 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class ArrayAggregate extends AST {
public ArrayAggregate(SourcePosition thePosition) {
super(thePosition);
elemCount = 0;
}
public ArrayAggregate(SourcePosition thePosition) {
super(thePosition);
elemCount = 0;
}
public int elemCount;
public int elemCount;
}

@ -18,16 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class ArrayExpression extends Expression {
public ArrayExpression(ArrayAggregate aaAST,
SourcePosition thePosition) {
super(thePosition);
AA = aaAST;
}
public ArrayExpression(ArrayAggregate aaAST, SourcePosition thePosition) {
super(thePosition);
AA = aaAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitArrayExpression(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitArrayExpression(this, o);
}
public ArrayAggregate AA;
public ArrayAggregate AA;
}

@ -18,29 +18,28 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class ArrayTypeDenoter extends TypeDenoter {
public ArrayTypeDenoter(IntegerLiteral ilAST, TypeDenoter tAST,
SourcePosition thePosition) {
super(thePosition);
IL = ilAST;
T = tAST;
}
public ArrayTypeDenoter(IntegerLiteral ilAST, TypeDenoter tAST, SourcePosition thePosition) {
super(thePosition);
IL = ilAST;
T = tAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitArrayTypeDenoter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitArrayTypeDenoter(this, o);
}
@Override
public boolean equals(Object obj) {
if (obj != null && obj instanceof ErrorTypeDenoter)
return true;
else if (obj != null && obj instanceof ArrayTypeDenoter)
return this.IL.spelling.compareTo(((ArrayTypeDenoter) obj).IL.spelling) == 0 &&
this.T.equals(((ArrayTypeDenoter) obj).T);
else
return false;
}
@Override
public boolean equals(Object obj) {
if (obj != null && obj instanceof ErrorTypeDenoter)
return true;
else if (obj != null && obj instanceof ArrayTypeDenoter)
return this.IL.spelling.compareTo(((ArrayTypeDenoter) obj).IL.spelling) == 0
&& this.T.equals(((ArrayTypeDenoter) obj).T);
else
return false;
}
public IntegerLiteral IL;
public TypeDenoter T;
public IntegerLiteral IL;
public TypeDenoter T;
}

@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class AssignCommand extends Command {
public AssignCommand(Vname vAST, Expression eAST, SourcePosition thePosition) {
super(thePosition);
V = vAST;
E = eAST;
}
public AssignCommand(Vname vAST, Expression eAST, SourcePosition thePosition) {
super(thePosition);
V = vAST;
E = eAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitAssignCommand(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitAssignCommand(this, o);
}
public Vname V;
public Expression E;
public Vname V;
public Expression E;
}

@ -18,19 +18,18 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class BinaryExpression extends Expression {
public BinaryExpression(Expression e1AST, Operator oAST, Expression e2AST,
SourcePosition thePosition) {
super(thePosition);
O = oAST;
E1 = e1AST;
E2 = e2AST;
}
public BinaryExpression(Expression e1AST, Operator oAST, Expression e2AST, SourcePosition thePosition) {
super(thePosition);
O = oAST;
E1 = e1AST;
E2 = e2AST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitBinaryExpression(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitBinaryExpression(this, o);
}
public Expression E1, E2;
public Operator O;
public Expression E1, E2;
public Operator O;
}

@ -18,21 +18,20 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class BinaryOperatorDeclaration extends Declaration {
public BinaryOperatorDeclaration(Operator oAST, TypeDenoter arg1AST,
TypeDenoter arg2AST, TypeDenoter resultAST,
SourcePosition thePosition) {
super(thePosition);
O = oAST;
ARG1 = arg1AST;
ARG2 = arg2AST;
RES = resultAST;
}
public BinaryOperatorDeclaration(Operator oAST, TypeDenoter arg1AST, TypeDenoter arg2AST, TypeDenoter resultAST,
SourcePosition thePosition) {
super(thePosition);
O = oAST;
ARG1 = arg1AST;
ARG2 = arg2AST;
RES = resultAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitBinaryOperatorDeclaration(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitBinaryOperatorDeclaration(this, o);
}
public Operator O;
public TypeDenoter ARG1, ARG2, RES;
public Operator O;
public TypeDenoter ARG1, ARG2, RES;
}

@ -18,20 +18,20 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class BoolTypeDenoter extends TypeDenoter {
public BoolTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
public BoolTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitBoolTypeDenoter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitBoolTypeDenoter(this, o);
}
@Override
public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof ErrorTypeDenoter))
return true;
else
return ((obj != null) && (obj instanceof BoolTypeDenoter));
}
@Override
public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof ErrorTypeDenoter))
return true;
else
return ((obj != null) && (obj instanceof BoolTypeDenoter));
}
}

@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class CallCommand extends Command {
public CallCommand(Identifier iAST, ActualParameterSequence apsAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
APS = apsAST;
}
public CallCommand(Identifier iAST, ActualParameterSequence apsAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
APS = apsAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitCallCommand(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitCallCommand(this, o);
}
public Identifier I;
public ActualParameterSequence APS;
public Identifier I;
public ActualParameterSequence APS;
}

@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class CallExpression extends Expression {
public CallExpression(Identifier iAST, ActualParameterSequence apsAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
APS = apsAST;
}
public CallExpression(Identifier iAST, ActualParameterSequence apsAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
APS = apsAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitCallExpression(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitCallExpression(this, o);
}
public Identifier I;
public ActualParameterSequence APS;
public Identifier I;
public ActualParameterSequence APS;
}

@ -18,20 +18,20 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class CharTypeDenoter extends TypeDenoter {
public CharTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
public CharTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitCharTypeDenoter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitCharTypeDenoter(this, o);
}
@Override
public boolean equals(Object obj) {
if (obj != null && obj instanceof ErrorTypeDenoter)
return true;
else
return (obj != null && obj instanceof CharTypeDenoter);
}
@Override
public boolean equals(Object obj) {
if (obj != null && obj instanceof ErrorTypeDenoter)
return true;
else
return (obj != null && obj instanceof CharTypeDenoter);
}
}

@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class CharacterExpression extends Expression {
public CharacterExpression(CharacterLiteral clAST, SourcePosition thePosition) {
super(thePosition);
CL = clAST;
}
public CharacterExpression(CharacterLiteral clAST, SourcePosition thePosition) {
super(thePosition);
CL = clAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitCharacterExpression(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitCharacterExpression(this, o);
}
public CharacterLiteral CL;
public CharacterLiteral CL;
}

@ -18,13 +18,13 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class CharacterLiteral extends Terminal {
public CharacterLiteral(String theSpelling, SourcePosition thePosition) {
super(theSpelling, thePosition);
}
public CharacterLiteral(String theSpelling, SourcePosition thePosition) {
super(theSpelling, thePosition);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitCharacterLiteral(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitCharacterLiteral(this, o);
}
}

@ -18,7 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class Command extends AST {
public Command(SourcePosition thePosition) {
super(thePosition);
}
public Command(SourcePosition thePosition) {
super(thePosition);
}
}

@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class ConstActualParameter extends ActualParameter {
public ConstActualParameter(Expression eAST, SourcePosition thePosition) {
super(thePosition);
E = eAST;
}
public ConstActualParameter(Expression eAST, SourcePosition thePosition) {
super(thePosition);
E = eAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitConstActualParameter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitConstActualParameter(this, o);
}
public Expression E;
public Expression E;
}

@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class ConstDeclaration extends Declaration {
public ConstDeclaration(Identifier iAST, Expression eAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
E = eAST;
}
public ConstDeclaration(Identifier iAST, Expression eAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
E = eAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitConstDeclaration(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitConstDeclaration(this, o);
}
public Identifier I;
public Expression E;
public Identifier I;
public Expression E;
}

@ -18,27 +18,26 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class ConstFormalParameter extends FormalParameter {
public ConstFormalParameter(Identifier iAST, TypeDenoter tAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
}
public ConstFormalParameter(Identifier iAST, TypeDenoter tAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitConstFormalParameter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitConstFormalParameter(this, o);
}
public Identifier I;
public TypeDenoter T;
public Identifier I;
public TypeDenoter T;
@Override
public boolean equals(Object fpAST) {
if (fpAST instanceof ConstFormalParameter) {
ConstFormalParameter cfpAST = (ConstFormalParameter) fpAST;
return T.equals(cfpAST.T);
} else
return false;
}
@Override
public boolean equals(Object fpAST) {
if (fpAST instanceof ConstFormalParameter) {
ConstFormalParameter cfpAST = (ConstFormalParameter) fpAST;
return T.equals(cfpAST.T);
} else
return false;
}
}

@ -18,10 +18,10 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class Declaration extends AST {
public Declaration(SourcePosition thePosition) {
super(thePosition);
duplicated = false;
}
public Declaration(SourcePosition thePosition) {
super(thePosition);
duplicated = false;
}
public boolean duplicated;
public boolean duplicated;
}

@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class DotVname extends Vname {
public DotVname(Vname vAST, Identifier iAST, SourcePosition thePosition) {
super(thePosition);
V = vAST;
I = iAST;
}
public DotVname(Vname vAST, Identifier iAST, SourcePosition thePosition) {
super(thePosition);
V = vAST;
I = iAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitDotVname(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitDotVname(this, o);
}
public Identifier I;
public Vname V;
public Identifier I;
public Vname V;
}

@ -18,12 +18,12 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class EmptyActualParameterSequence extends ActualParameterSequence {
public EmptyActualParameterSequence(SourcePosition thePosition) {
super(thePosition);
}
public EmptyActualParameterSequence(SourcePosition thePosition) {
super(thePosition);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitEmptyActualParameterSequence(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitEmptyActualParameterSequence(this, o);
}
}

@ -18,12 +18,12 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class EmptyCommand extends Command {
public EmptyCommand(SourcePosition thePosition) {
super(thePosition);
}
public EmptyCommand(SourcePosition thePosition) {
super(thePosition);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitEmptyCommand(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitEmptyCommand(this, o);
}
}

@ -18,12 +18,12 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class EmptyExpression extends Expression {
public EmptyExpression(SourcePosition thePosition) {
super(thePosition);
}
public EmptyExpression(SourcePosition thePosition) {
super(thePosition);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitEmptyExpression(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitEmptyExpression(this, o);
}
}

@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class EmptyFormalParameterSequence extends FormalParameterSequence {
public EmptyFormalParameterSequence(SourcePosition thePosition) {
super(thePosition);
}
public EmptyFormalParameterSequence(SourcePosition thePosition) {
super(thePosition);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitEmptyFormalParameterSequence(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitEmptyFormalParameterSequence(this, o);
}
@Override
public boolean equals(Object fpsAST) {
return (fpsAST instanceof EmptyFormalParameterSequence);
}
@Override
public boolean equals(Object fpsAST) {
return (fpsAST instanceof EmptyFormalParameterSequence);
}
}

@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class ErrorTypeDenoter extends TypeDenoter {
public ErrorTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
public ErrorTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitErrorTypeDenoter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitErrorTypeDenoter(this, o);
}
@Override
public boolean equals(Object obj) {
return true;
}
@Override
public boolean equals(Object obj) {
return true;
}
}

@ -18,10 +18,10 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class Expression extends AST {
public Expression(SourcePosition thePosition) {
super(thePosition);
type = null;
}
public Expression(SourcePosition thePosition) {
super(thePosition);
type = null;
}
public TypeDenoter type;
public TypeDenoter type;
}

@ -18,10 +18,10 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class FieldTypeDenoter extends TypeDenoter {
public FieldTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
public FieldTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
@Override
public abstract boolean equals(Object obj);
@Override
public abstract boolean equals(Object obj);
}

@ -18,11 +18,11 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class FormalParameter extends Declaration {
public FormalParameter(SourcePosition thePosition) {
super(thePosition);
}
public FormalParameter(SourcePosition thePosition) {
super(thePosition);
}
@Override
public abstract boolean equals(Object fpAST);
@Override
public abstract boolean equals(Object fpAST);
}

@ -18,10 +18,10 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class FormalParameterSequence extends AST {
public FormalParameterSequence(SourcePosition thePosition) {
super(thePosition);
}
public FormalParameterSequence(SourcePosition thePosition) {
super(thePosition);
}
@Override
public abstract boolean equals(Object fpsAST);
@Override
public abstract boolean equals(Object fpsAST);
}

@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class FuncActualParameter extends ActualParameter {
public FuncActualParameter(Identifier iAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
}
public FuncActualParameter(Identifier iAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitFuncActualParameter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitFuncActualParameter(this, o);
}
public Identifier I;
public Identifier I;
}

@ -18,23 +18,22 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class FuncDeclaration extends Declaration {
public FuncDeclaration(Identifier iAST, FormalParameterSequence fpsAST,
TypeDenoter tAST, Expression eAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
FPS = fpsAST;
T = tAST;
E = eAST;
}
public FuncDeclaration(Identifier iAST, FormalParameterSequence fpsAST, TypeDenoter tAST, Expression eAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
FPS = fpsAST;
T = tAST;
E = eAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitFuncDeclaration(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitFuncDeclaration(this, o);
}
public Identifier I;
public FormalParameterSequence FPS;
public TypeDenoter T;
public Expression E;
public Identifier I;
public FormalParameterSequence FPS;
public TypeDenoter T;
public Expression E;
}

@ -18,29 +18,29 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class FuncFormalParameter extends FormalParameter {
public FuncFormalParameter(Identifier iAST, FormalParameterSequence fpsAST,
TypeDenoter tAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
FPS = fpsAST;
T = tAST;
}
public FuncFormalParameter(Identifier iAST, FormalParameterSequence fpsAST, TypeDenoter tAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
FPS = fpsAST;
T = tAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitFuncFormalParameter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitFuncFormalParameter(this, o);
}
@Override
public boolean equals(Object fpAST) {
if (fpAST instanceof FuncFormalParameter) {
FuncFormalParameter ffpAST = (FuncFormalParameter) fpAST;
return FPS.equals(ffpAST.FPS) && T.equals(ffpAST.T);
} else
return false;
}
@Override
public boolean equals(Object fpAST) {
if (fpAST instanceof FuncFormalParameter) {
FuncFormalParameter ffpAST = (FuncFormalParameter) fpAST;
return FPS.equals(ffpAST.FPS) && T.equals(ffpAST.T);
} else
return false;
}
public Identifier I;
public FormalParameterSequence FPS;
public TypeDenoter T;
public Identifier I;
public FormalParameterSequence FPS;
public TypeDenoter T;
}

@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class Identifier extends Terminal {
public Identifier(String theSpelling, SourcePosition thePosition) {
super(theSpelling, thePosition);
type = null;
decl = null;
}
public Identifier(String theSpelling, SourcePosition thePosition) {
super(theSpelling, thePosition);
type = null;
decl = null;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitIdentifier(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitIdentifier(this, o);
}
public TypeDenoter type;
public AST decl; // Either a Declaration or a FieldTypeDenoter
public TypeDenoter type;
public AST decl; // Either a Declaration or a FieldTypeDenoter
}

@ -18,19 +18,18 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class IfCommand extends Command {
public IfCommand(Expression eAST, Command c1AST, Command c2AST,
SourcePosition thePosition) {
super(thePosition);
E = eAST;
C1 = c1AST;
C2 = c2AST;
}
public IfCommand(Expression eAST, Command c1AST, Command c2AST, SourcePosition thePosition) {
super(thePosition);
E = eAST;
C1 = c1AST;
C2 = c2AST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitIfCommand(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitIfCommand(this, o);
}
public Expression E;
public Command C1, C2;
public Expression E;
public Command C1, C2;
}

@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class IfExpression extends Expression {
public IfExpression(Expression e1AST, Expression e2AST, Expression e3AST,
SourcePosition thePosition) {
super(thePosition);
E1 = e1AST;
E2 = e2AST;
E3 = e3AST;
}
public IfExpression(Expression e1AST, Expression e2AST, Expression e3AST, SourcePosition thePosition) {
super(thePosition);
E1 = e1AST;
E2 = e2AST;
E3 = e3AST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitIfExpression(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitIfExpression(this, o);
}
public Expression E1, E2, E3;
public Expression E1, E2, E3;
}

@ -18,20 +18,20 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class IntTypeDenoter extends TypeDenoter {
public IntTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
public IntTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitIntTypeDenoter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitIntTypeDenoter(this, o);
}
@Override
public boolean equals(Object obj) {
if (obj != null && obj instanceof ErrorTypeDenoter)
return true;
else
return (obj != null && obj instanceof IntTypeDenoter);
}
@Override
public boolean equals(Object obj) {
if (obj != null && obj instanceof ErrorTypeDenoter)
return true;
else
return (obj != null && obj instanceof IntTypeDenoter);
}
}

@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class IntegerExpression extends Expression {
public IntegerExpression(IntegerLiteral ilAST, SourcePosition thePosition) {
super(thePosition);
IL = ilAST;
}
public IntegerExpression(IntegerLiteral ilAST, SourcePosition thePosition) {
super(thePosition);
IL = ilAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitIntegerExpression(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitIntegerExpression(this, o);
}
public IntegerLiteral IL;
public IntegerLiteral IL;
}

@ -18,13 +18,13 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class IntegerLiteral extends Terminal {
public IntegerLiteral(String theSpelling, SourcePosition thePosition) {
super(theSpelling, thePosition);
}
public IntegerLiteral(String theSpelling, SourcePosition thePosition) {
super(theSpelling, thePosition);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitIntegerLiteral(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitIntegerLiteral(this, o);
}
}

@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class LetCommand extends Command {
public LetCommand(Declaration dAST, Command cAST, SourcePosition thePosition) {
super(thePosition);
D = dAST;
C = cAST;
}
public LetCommand(Declaration dAST, Command cAST, SourcePosition thePosition) {
super(thePosition);
D = dAST;
C = cAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitLetCommand(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitLetCommand(this, o);
}
public Declaration D;
public Command C;
public Declaration D;
public Command C;
}

@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class LetExpression extends Expression {
public LetExpression(Declaration dAST, Expression eAST, SourcePosition thePosition) {
super(thePosition);
D = dAST;
E = eAST;
}
public LetExpression(Declaration dAST, Expression eAST, SourcePosition thePosition) {
super(thePosition);
D = dAST;
E = eAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitLetExpression(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitLetExpression(this, o);
}
public Declaration D;
public Expression E;
public Declaration D;
public Expression E;
}

@ -18,18 +18,18 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class MultipleActualParameterSequence extends ActualParameterSequence {
public MultipleActualParameterSequence(ActualParameter apAST, ActualParameterSequence apsAST,
SourcePosition thePosition) {
super(thePosition);
AP = apAST;
APS = apsAST;
}
public MultipleActualParameterSequence(ActualParameter apAST, ActualParameterSequence apsAST,
SourcePosition thePosition) {
super(thePosition);
AP = apAST;
APS = apsAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitMultipleActualParameterSequence(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitMultipleActualParameterSequence(this, o);
}
public ActualParameter AP;
public ActualParameterSequence APS;
public ActualParameter AP;
public ActualParameterSequence APS;
}

@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class MultipleArrayAggregate extends ArrayAggregate {
public MultipleArrayAggregate(Expression eAST, ArrayAggregate aaAST,
SourcePosition thePosition) {
super(thePosition);
E = eAST;
AA = aaAST;
}
public MultipleArrayAggregate(Expression eAST, ArrayAggregate aaAST, SourcePosition thePosition) {
super(thePosition);
E = eAST;
AA = aaAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitMultipleArrayAggregate(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitMultipleArrayAggregate(this, o);
}
public Expression E;
public ArrayAggregate AA;
public Expression E;
public ArrayAggregate AA;
}

@ -18,31 +18,29 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class MultipleFieldTypeDenoter extends FieldTypeDenoter {
public MultipleFieldTypeDenoter(Identifier iAST, TypeDenoter tAST, FieldTypeDenoter ftAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
FT = ftAST;
}
public MultipleFieldTypeDenoter(Identifier iAST, TypeDenoter tAST, FieldTypeDenoter ftAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
FT = ftAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitMultipleFieldTypeDenoter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitMultipleFieldTypeDenoter(this, o);
}
@Override
public boolean equals(Object obj) {
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
return false;
}
@Override
public boolean equals(Object obj) {
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
return false;
}
public Identifier I;
public TypeDenoter T;
public FieldTypeDenoter FT;
public Identifier I;
public TypeDenoter T;
public FieldTypeDenoter FT;
}

@ -18,27 +18,27 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class MultipleFormalParameterSequence extends FormalParameterSequence {
public MultipleFormalParameterSequence(FormalParameter fpAST, FormalParameterSequence fpsAST,
SourcePosition thePosition) {
super(thePosition);
FP = fpAST;
FPS = fpsAST;
}
public MultipleFormalParameterSequence(FormalParameter fpAST, FormalParameterSequence fpsAST,
SourcePosition thePosition) {
super(thePosition);
FP = fpAST;
FPS = fpsAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitMultipleFormalParameterSequence(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitMultipleFormalParameterSequence(this, o);
}
@Override
public boolean equals(Object fpsAST) {
if (fpsAST instanceof MultipleFormalParameterSequence) {
MultipleFormalParameterSequence mfpsAST = (MultipleFormalParameterSequence) fpsAST;
return FP.equals(mfpsAST.FP) && FPS.equals(mfpsAST.FPS);
} else
return false;
}
@Override
public boolean equals(Object fpsAST) {
if (fpsAST instanceof MultipleFormalParameterSequence) {
MultipleFormalParameterSequence mfpsAST = (MultipleFormalParameterSequence) fpsAST;
return FP.equals(mfpsAST.FP) && FPS.equals(mfpsAST.FPS);
} else
return false;
}
public FormalParameter FP;
public FormalParameterSequence FPS;
public FormalParameter FP;
public FormalParameterSequence FPS;
}

@ -18,20 +18,20 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class MultipleRecordAggregate extends RecordAggregate {
public MultipleRecordAggregate(Identifier iAST, Expression eAST, RecordAggregate raAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
E = eAST;
RA = raAST;
}
public MultipleRecordAggregate(Identifier iAST, Expression eAST, RecordAggregate raAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
E = eAST;
RA = raAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitMultipleRecordAggregate(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitMultipleRecordAggregate(this, o);
}
public Identifier I;
public Expression E;
public RecordAggregate RA;
public Identifier I;
public Expression E;
public RecordAggregate RA;
}

@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class Operator extends Terminal {
public Operator(String theSpelling, SourcePosition thePosition) {
super(theSpelling, thePosition);
decl = null;
}
public Operator(String theSpelling, SourcePosition thePosition) {
super(theSpelling, thePosition);
decl = null;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitOperator(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitOperator(this, o);
}
public Declaration decl;
public Declaration decl;
}

@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class ProcActualParameter extends ActualParameter {
public ProcActualParameter(Identifier iAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
}
public ProcActualParameter(Identifier iAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitProcActualParameter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitProcActualParameter(this, o);
}
public Identifier I;
public Identifier I;
}

@ -18,20 +18,19 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class ProcDeclaration extends Declaration {
public ProcDeclaration(Identifier iAST, FormalParameterSequence fpsAST,
Command cAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
FPS = fpsAST;
C = cAST;
}
public ProcDeclaration(Identifier iAST, FormalParameterSequence fpsAST, Command cAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
FPS = fpsAST;
C = cAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitProcDeclaration(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitProcDeclaration(this, o);
}
public Identifier I;
public FormalParameterSequence FPS;
public Command C;
public Identifier I;
public FormalParameterSequence FPS;
public Command C;
}

@ -18,27 +18,26 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class ProcFormalParameter extends FormalParameter {
public ProcFormalParameter(Identifier iAST, FormalParameterSequence fpsAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
FPS = fpsAST;
}
public ProcFormalParameter(Identifier iAST, FormalParameterSequence fpsAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
FPS = fpsAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitProcFormalParameter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitProcFormalParameter(this, o);
}
public Identifier I;
public FormalParameterSequence FPS;
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
return false;
}
@Override
public boolean equals(Object fpAST) {
if (fpAST instanceof ProcFormalParameter) {
ProcFormalParameter pfpAST = (ProcFormalParameter) fpAST;
return FPS.equals(pfpAST.FPS);
} else
return false;
}
}

@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class Program extends AST {
public Program(Command cAST, SourcePosition thePosition) {
super(thePosition);
C = cAST;
}
public Program(Command cAST, SourcePosition thePosition) {
super(thePosition);
C = cAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitProgram(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitProgram(this, o);
}
public Command C;
public Command C;
}

@ -18,10 +18,10 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class RecordAggregate extends AST {
public RecordAggregate(SourcePosition thePosition) {
super(thePosition);
type = null;
}
public RecordAggregate(SourcePosition thePosition) {
super(thePosition);
type = null;
}
public FieldTypeDenoter type;
public FieldTypeDenoter type;
}

@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class RecordExpression extends Expression {
public RecordExpression(RecordAggregate raAST, SourcePosition thePosition) {
super(thePosition);
RA = raAST;
}
public RecordExpression(RecordAggregate raAST, SourcePosition thePosition) {
super(thePosition);
RA = raAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitRecordExpression(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitRecordExpression(this, o);
}
public RecordAggregate RA;
public RecordAggregate RA;
}

@ -18,25 +18,25 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class RecordTypeDenoter extends TypeDenoter {
public RecordTypeDenoter(FieldTypeDenoter ftAST, SourcePosition thePosition) {
super(thePosition);
FT = ftAST;
}
public RecordTypeDenoter(FieldTypeDenoter ftAST, SourcePosition thePosition) {
super(thePosition);
FT = ftAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitRecordTypeDenoter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitRecordTypeDenoter(this, o);
}
@Override
public boolean equals(Object obj) {
if (obj != null && obj instanceof ErrorTypeDenoter)
return true;
else if (obj != null && obj instanceof RecordTypeDenoter)
return this.FT.equals(((RecordTypeDenoter) obj).FT);
else
return false;
}
@Override
public boolean equals(Object obj) {
if (obj != null && obj instanceof ErrorTypeDenoter)
return true;
else if (obj != null && obj instanceof RecordTypeDenoter)
return this.FT.equals(((RecordTypeDenoter) obj).FT);
else
return false;
}
public FieldTypeDenoter FT;
public FieldTypeDenoter FT;
}

@ -18,16 +18,16 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class SequentialCommand extends Command {
public SequentialCommand(Command c1AST, Command c2AST, SourcePosition thePosition) {
super(thePosition);
C1 = c1AST;
C2 = c2AST;
}
public SequentialCommand(Command c1AST, Command c2AST, SourcePosition thePosition) {
super(thePosition);
C1 = c1AST;
C2 = c2AST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSequentialCommand(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSequentialCommand(this, o);
}
public Command C1, C2;
public Command C1, C2;
}

@ -18,17 +18,16 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class SequentialDeclaration extends Declaration {
public SequentialDeclaration(Declaration d1AST, Declaration d2AST,
SourcePosition thePosition) {
super(thePosition);
D1 = d1AST;
D2 = d2AST;
}
public SequentialDeclaration(Declaration d1AST, Declaration d2AST, SourcePosition thePosition) {
super(thePosition);
D1 = d1AST;
D2 = d2AST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSequentialDeclaration(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSequentialDeclaration(this, o);
}
public Declaration D1, D2;
public Declaration D1, D2;
}

@ -18,20 +18,20 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class SimpleTypeDenoter extends TypeDenoter {
public SimpleTypeDenoter(Identifier iAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
}
public SimpleTypeDenoter(Identifier iAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSimpleTypeDenoter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSimpleTypeDenoter(this, o);
}
@Override
public boolean equals(Object obj) {
return false; // should not happen
}
@Override
public boolean equals(Object obj) {
return false; // should not happen
}
public Identifier I;
public Identifier I;
}

@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class SimpleVname extends Vname {
public SimpleVname(Identifier iAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
}
public SimpleVname(Identifier iAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSimpleVname(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSimpleVname(this, o);
}
public Identifier I;
public Identifier I;
}

@ -18,16 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleActualParameterSequence extends ActualParameterSequence {
public SingleActualParameterSequence(ActualParameter apAST,
SourcePosition thePosition) {
super(thePosition);
AP = apAST;
}
public SingleActualParameterSequence(ActualParameter apAST, SourcePosition thePosition) {
super(thePosition);
AP = apAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSingleActualParameterSequence(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSingleActualParameterSequence(this, o);
}
public ActualParameter AP;
public ActualParameter AP;
}

@ -18,16 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleArrayAggregate extends ArrayAggregate {
public SingleArrayAggregate(Expression eAST,
SourcePosition thePosition) {
super(thePosition);
E = eAST;
}
public SingleArrayAggregate(Expression eAST, SourcePosition thePosition) {
super(thePosition);
E = eAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSingleArrayAggregate(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSingleArrayAggregate(this, o);
}
public Expression E;
public Expression E;
}

@ -18,28 +18,26 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleFieldTypeDenoter extends FieldTypeDenoter {
public SingleFieldTypeDenoter(Identifier iAST, TypeDenoter tAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
}
public SingleFieldTypeDenoter(Identifier iAST, TypeDenoter tAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSingleFieldTypeDenoter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSingleFieldTypeDenoter(this, o);
}
@Override
public boolean equals(Object obj) {
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
return false;
}
@Override
public boolean equals(Object obj) {
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
return false;
}
public Identifier I;
public TypeDenoter T;
public Identifier I;
public TypeDenoter T;
}

@ -18,25 +18,24 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleFormalParameterSequence extends FormalParameterSequence {
public SingleFormalParameterSequence(FormalParameter fpAST,
SourcePosition thePosition) {
super(thePosition);
FP = fpAST;
}
public SingleFormalParameterSequence(FormalParameter fpAST, SourcePosition thePosition) {
super(thePosition);
FP = fpAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSingleFormalParameterSequence(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSingleFormalParameterSequence(this, o);
}
@Override
public boolean equals(Object fpsAST) {
if (fpsAST instanceof SingleFormalParameterSequence) {
SingleFormalParameterSequence sfpsAST = (SingleFormalParameterSequence) fpsAST;
return FP.equals(sfpsAST.FP);
} else
return false;
}
@Override
public boolean equals(Object fpsAST) {
if (fpsAST instanceof SingleFormalParameterSequence) {
SingleFormalParameterSequence sfpsAST = (SingleFormalParameterSequence) fpsAST;
return FP.equals(sfpsAST.FP);
} else
return false;
}
public FormalParameter FP;
public FormalParameter FP;
}

@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleRecordAggregate extends RecordAggregate {
public SingleRecordAggregate(Identifier iAST, Expression eAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
E = eAST;
}
public SingleRecordAggregate(Identifier iAST, Expression eAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
E = eAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSingleRecordAggregate(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSingleRecordAggregate(this, o);
}
public Identifier I;
public Expression E;
public Identifier I;
public Expression E;
}

@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class SubscriptVname extends Vname {
public SubscriptVname(Vname vAST, Expression eAST, SourcePosition thePosition) {
super(thePosition);
V = vAST;
E = eAST;
}
public SubscriptVname(Vname vAST, Expression eAST, SourcePosition thePosition) {
super(thePosition);
V = vAST;
E = eAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSubscriptVname(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitSubscriptVname(this, o);
}
public Expression E;
public Vname V;
public Expression E;
public Vname V;
}

@ -18,10 +18,10 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
abstract public class Terminal extends AST {
public Terminal(String theSpelling, SourcePosition thePosition) {
super(thePosition);
spelling = theSpelling;
}
public Terminal(String theSpelling, SourcePosition thePosition) {
super(thePosition);
spelling = theSpelling;
}
public String spelling;
public String spelling;
}

@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class TypeDeclaration extends Declaration {
public TypeDeclaration(Identifier iAST, TypeDenoter tAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
}
public TypeDeclaration(Identifier iAST, TypeDenoter tAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitTypeDeclaration(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitTypeDeclaration(this, o);
}
public Identifier I;
public TypeDenoter T;
public Identifier I;
public TypeDenoter T;
}

@ -18,11 +18,11 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class TypeDenoter extends AST {
public TypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
public TypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
@Override
public abstract boolean equals(Object obj);
@Override
public abstract boolean equals(Object obj);
}

@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class UnaryExpression extends Expression {
public UnaryExpression(Operator oAST, Expression eAST,
SourcePosition thePosition) {
super(thePosition);
O = oAST;
E = eAST;
}
public UnaryExpression(Operator oAST, Expression eAST, SourcePosition thePosition) {
super(thePosition);
O = oAST;
E = eAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitUnaryExpression(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitUnaryExpression(this, o);
}
public Expression E;
public Operator O;
public Expression E;
public Operator O;
}

@ -18,19 +18,19 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class UnaryOperatorDeclaration extends Declaration {
public UnaryOperatorDeclaration(Operator oAST, TypeDenoter argAST,
TypeDenoter resultAST, SourcePosition thePosition) {
super(thePosition);
O = oAST;
ARG = argAST;
RES = resultAST;
}
public UnaryOperatorDeclaration(Operator oAST, TypeDenoter argAST, TypeDenoter resultAST,
SourcePosition thePosition) {
super(thePosition);
O = oAST;
ARG = argAST;
RES = resultAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitUnaryOperatorDeclaration(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitUnaryOperatorDeclaration(this, o);
}
public Operator O;
public TypeDenoter ARG, RES;
public Operator O;
public TypeDenoter ARG, RES;
}

@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class VarActualParameter extends ActualParameter {
public VarActualParameter(Vname vAST, SourcePosition thePosition) {
super(thePosition);
V = vAST;
}
public VarActualParameter(Vname vAST, SourcePosition thePosition) {
super(thePosition);
V = vAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitVarActualParameter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitVarActualParameter(this, o);
}
public Vname V;
public Vname V;
}

@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class VarDeclaration extends Declaration {
public VarDeclaration(Identifier iAST, TypeDenoter tAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
}
public VarDeclaration(Identifier iAST, TypeDenoter tAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitVarDeclaration(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitVarDeclaration(this, o);
}
public Identifier I;
public TypeDenoter T;
public Identifier I;
public TypeDenoter T;
}

@ -18,27 +18,26 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class VarFormalParameter extends FormalParameter {
public VarFormalParameter(Identifier iAST, TypeDenoter tAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
}
public VarFormalParameter(Identifier iAST, TypeDenoter tAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitVarFormalParameter(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitVarFormalParameter(this, o);
}
public Identifier I;
public TypeDenoter T;
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
return false;
}
@Override
public boolean equals(Object fpAST) {
if (fpAST instanceof VarFormalParameter) {
VarFormalParameter vfpAST = (VarFormalParameter) fpAST;
return T.equals(vfpAST.T);
} else
return false;
}
}

@ -16,139 +16,139 @@ package Triangle.AbstractSyntaxTrees;
public interface Visitor {
// Commands
public abstract Object visitAssignCommand(AssignCommand ast, Object o);
// Commands
public abstract Object visitAssignCommand(AssignCommand ast, Object o);
public abstract Object visitCallCommand(CallCommand ast, Object o);
public abstract Object visitCallCommand(CallCommand ast, Object o);
public abstract Object visitEmptyCommand(EmptyCommand ast, Object o);
public abstract Object visitEmptyCommand(EmptyCommand ast, Object o);
public abstract Object visitIfCommand(IfCommand ast, Object o);
public abstract Object visitIfCommand(IfCommand ast, Object o);
public abstract Object visitLetCommand(LetCommand ast, Object o);
public abstract Object visitLetCommand(LetCommand ast, Object o);
public abstract Object visitSequentialCommand(SequentialCommand ast, Object o);
public abstract Object visitSequentialCommand(SequentialCommand ast, Object o);
public abstract Object visitWhileCommand(WhileCommand ast, Object o);
public abstract Object visitWhileCommand(WhileCommand ast, Object o);
// Expressions
public abstract Object visitArrayExpression(ArrayExpression ast, Object o);
// Expressions
public abstract Object visitArrayExpression(ArrayExpression ast, Object o);
public abstract Object visitBinaryExpression(BinaryExpression ast, Object o);
public abstract Object visitBinaryExpression(BinaryExpression ast, Object o);
public abstract Object visitCallExpression(CallExpression ast, Object o);
public abstract Object visitCallExpression(CallExpression ast, Object o);
public abstract Object visitCharacterExpression(CharacterExpression ast, Object o);
public abstract Object visitCharacterExpression(CharacterExpression ast, Object o);
public abstract Object visitEmptyExpression(EmptyExpression ast, Object o);
public abstract Object visitEmptyExpression(EmptyExpression ast, Object o);
public abstract Object visitIfExpression(IfExpression ast, Object o);
public abstract Object visitIfExpression(IfExpression ast, Object o);
public abstract Object visitIntegerExpression(IntegerExpression ast, Object o);
public abstract Object visitIntegerExpression(IntegerExpression ast, Object o);
public abstract Object visitLetExpression(LetExpression ast, Object o);
public abstract Object visitLetExpression(LetExpression ast, Object o);
public abstract Object visitRecordExpression(RecordExpression ast, Object o);
public abstract Object visitRecordExpression(RecordExpression ast, Object o);
public abstract Object visitUnaryExpression(UnaryExpression ast, Object o);
public abstract Object visitUnaryExpression(UnaryExpression ast, Object o);
public abstract Object visitVnameExpression(VnameExpression ast, Object o);
public abstract Object visitVnameExpression(VnameExpression ast, Object o);
// Declarations
public abstract Object visitBinaryOperatorDeclaration(BinaryOperatorDeclaration ast, Object o);
// Declarations
public abstract Object visitBinaryOperatorDeclaration(BinaryOperatorDeclaration ast, Object o);
public abstract Object visitConstDeclaration(ConstDeclaration ast, Object o);
public abstract Object visitConstDeclaration(ConstDeclaration ast, Object o);
public abstract Object visitFuncDeclaration(FuncDeclaration ast, Object o);
public abstract Object visitFuncDeclaration(FuncDeclaration ast, Object o);
public abstract Object visitProcDeclaration(ProcDeclaration ast, Object o);
public abstract Object visitProcDeclaration(ProcDeclaration ast, Object o);
public abstract Object visitSequentialDeclaration(SequentialDeclaration ast, Object o);
public abstract Object visitSequentialDeclaration(SequentialDeclaration ast, Object o);
public abstract Object visitTypeDeclaration(TypeDeclaration ast, Object o);
public abstract Object visitTypeDeclaration(TypeDeclaration ast, Object o);
public abstract Object visitUnaryOperatorDeclaration(UnaryOperatorDeclaration ast, Object o);
public abstract Object visitUnaryOperatorDeclaration(UnaryOperatorDeclaration ast, Object o);
public abstract Object visitVarDeclaration(VarDeclaration ast, Object o);
public abstract Object visitVarDeclaration(VarDeclaration ast, Object o);
// Array Aggregates
public abstract Object visitMultipleArrayAggregate(MultipleArrayAggregate ast, Object o);
// Array Aggregates
public abstract Object visitMultipleArrayAggregate(MultipleArrayAggregate ast, Object o);
public abstract Object visitSingleArrayAggregate(SingleArrayAggregate ast, Object o);
public abstract Object visitSingleArrayAggregate(SingleArrayAggregate ast, Object o);
// Record Aggregates
public abstract Object visitMultipleRecordAggregate(MultipleRecordAggregate ast, Object o);
// Record Aggregates
public abstract Object visitMultipleRecordAggregate(MultipleRecordAggregate ast, Object o);
public abstract Object visitSingleRecordAggregate(SingleRecordAggregate ast, Object o);
public abstract Object visitSingleRecordAggregate(SingleRecordAggregate ast, Object o);
// Formal Parameters
public abstract Object visitConstFormalParameter(ConstFormalParameter ast, Object o);
// Formal Parameters
public abstract Object visitConstFormalParameter(ConstFormalParameter ast, Object o);
public abstract Object visitFuncFormalParameter(FuncFormalParameter ast, Object o);
public abstract Object visitFuncFormalParameter(FuncFormalParameter ast, Object o);
public abstract Object visitProcFormalParameter(ProcFormalParameter ast, Object o);
public abstract Object visitProcFormalParameter(ProcFormalParameter ast, Object o);
public abstract Object visitVarFormalParameter(VarFormalParameter ast, Object o);
public abstract Object visitVarFormalParameter(VarFormalParameter ast, Object o);
public abstract Object visitEmptyFormalParameterSequence(EmptyFormalParameterSequence ast, Object o);
public abstract Object visitEmptyFormalParameterSequence(EmptyFormalParameterSequence ast, Object o);
public abstract Object visitMultipleFormalParameterSequence(MultipleFormalParameterSequence ast, Object o);
public abstract Object visitMultipleFormalParameterSequence(MultipleFormalParameterSequence ast, Object o);
public abstract Object visitSingleFormalParameterSequence(SingleFormalParameterSequence ast, Object o);
public abstract Object visitSingleFormalParameterSequence(SingleFormalParameterSequence ast, Object o);
// Actual Parameters
public abstract Object visitConstActualParameter(ConstActualParameter ast, Object o);
// Actual Parameters
public abstract Object visitConstActualParameter(ConstActualParameter ast, Object o);
public abstract Object visitFuncActualParameter(FuncActualParameter ast, Object o);
public abstract Object visitFuncActualParameter(FuncActualParameter ast, Object o);
public abstract Object visitProcActualParameter(ProcActualParameter ast, Object o);
public abstract Object visitProcActualParameter(ProcActualParameter ast, Object o);
public abstract Object visitVarActualParameter(VarActualParameter ast, Object o);
public abstract Object visitVarActualParameter(VarActualParameter ast, Object o);
public abstract Object visitEmptyActualParameterSequence(EmptyActualParameterSequence ast, Object o);
public abstract Object visitEmptyActualParameterSequence(EmptyActualParameterSequence ast, Object o);
public abstract Object visitMultipleActualParameterSequence(MultipleActualParameterSequence ast, Object o);
public abstract Object visitMultipleActualParameterSequence(MultipleActualParameterSequence ast, Object o);
public abstract Object visitSingleActualParameterSequence(SingleActualParameterSequence ast, Object o);
public abstract Object visitSingleActualParameterSequence(SingleActualParameterSequence ast, Object o);
// Type Denoters
public abstract Object visitAnyTypeDenoter(AnyTypeDenoter ast, Object o);
// Type Denoters
public abstract Object visitAnyTypeDenoter(AnyTypeDenoter ast, Object o);
public abstract Object visitArrayTypeDenoter(ArrayTypeDenoter ast, Object o);
public abstract Object visitArrayTypeDenoter(ArrayTypeDenoter ast, Object o);
public abstract Object visitBoolTypeDenoter(BoolTypeDenoter ast, Object o);
public abstract Object visitBoolTypeDenoter(BoolTypeDenoter ast, Object o);
public abstract Object visitCharTypeDenoter(CharTypeDenoter ast, Object o);
public abstract Object visitCharTypeDenoter(CharTypeDenoter ast, Object o);
public abstract Object visitErrorTypeDenoter(ErrorTypeDenoter ast, Object o);
public abstract Object visitErrorTypeDenoter(ErrorTypeDenoter ast, Object o);
public abstract Object visitSimpleTypeDenoter(SimpleTypeDenoter ast, Object o);
public abstract Object visitSimpleTypeDenoter(SimpleTypeDenoter ast, Object o);
public abstract Object visitIntTypeDenoter(IntTypeDenoter ast, Object o);
public abstract Object visitIntTypeDenoter(IntTypeDenoter ast, Object o);
public abstract Object visitRecordTypeDenoter(RecordTypeDenoter ast, Object o);
public abstract Object visitRecordTypeDenoter(RecordTypeDenoter ast, Object o);
public abstract Object visitMultipleFieldTypeDenoter(MultipleFieldTypeDenoter ast, Object o);
public abstract Object visitMultipleFieldTypeDenoter(MultipleFieldTypeDenoter ast, Object o);
public abstract Object visitSingleFieldTypeDenoter(SingleFieldTypeDenoter ast, Object o);
public abstract Object visitSingleFieldTypeDenoter(SingleFieldTypeDenoter ast, Object o);
// Literals, Identifiers and Operators
public abstract Object visitCharacterLiteral(CharacterLiteral ast, Object o);
// Literals, Identifiers and Operators
public abstract Object visitCharacterLiteral(CharacterLiteral ast, Object o);
public abstract Object visitIdentifier(Identifier ast, Object o);
public abstract Object visitIdentifier(Identifier ast, Object o);
public abstract Object visitIntegerLiteral(IntegerLiteral ast, Object o);
public abstract Object visitIntegerLiteral(IntegerLiteral ast, Object o);
public abstract Object visitOperator(Operator ast, Object o);
public abstract Object visitOperator(Operator ast, Object o);
// Value-or-variable names
public abstract Object visitDotVname(DotVname ast, Object o);
// Value-or-variable names
public abstract Object visitDotVname(DotVname ast, Object o);
public abstract Object visitSimpleVname(SimpleVname ast, Object o);
public abstract Object visitSimpleVname(SimpleVname ast, Object o);
public abstract Object visitSubscriptVname(SubscriptVname ast, Object o);
public abstract Object visitSubscriptVname(SubscriptVname ast, Object o);
// Programs
public abstract Object visitProgram(Program ast, Object o);
// Programs
public abstract Object visitProgram(Program ast, Object o);
}

@ -18,13 +18,13 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class Vname extends AST {
public Vname(SourcePosition thePosition) {
super(thePosition);
variable = false;
type = null;
}
public Vname(SourcePosition thePosition) {
super(thePosition);
variable = false;
type = null;
}
public boolean variable, indexed;
public int offset;
public TypeDenoter type;
public boolean variable, indexed;
public int offset;
public TypeDenoter type;
}

@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class VnameExpression extends Expression {
public VnameExpression(Vname vAST, SourcePosition thePosition) {
super(thePosition);
V = vAST;
}
public VnameExpression(Vname vAST, SourcePosition thePosition) {
super(thePosition);
V = vAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitVnameExpression(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitVnameExpression(this, o);
}
public Vname V;
public Vname V;
}

@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class WhileCommand extends Command {
public WhileCommand(Expression eAST, Command cAST, SourcePosition thePosition) {
super(thePosition);
E = eAST;
C = cAST;
}
public WhileCommand(Expression eAST, Command cAST, SourcePosition thePosition) {
super(thePosition);
E = eAST;
C = cAST;
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitWhileCommand(this, o);
}
@Override
public Object visit(Visitor v, Object o) {
return v.visitWhileCommand(this, o);
}
public Expression E;
public Command C;
public Expression E;
public Command C;
}

@ -16,15 +16,15 @@ package Triangle.CodeGenerator;
public class EqualityRoutine extends RuntimeEntity {
public EqualityRoutine() {
super();
}
public EqualityRoutine() {
super();
}
public EqualityRoutine(int size, int displacement) {
super(size);
this.displacement = displacement;
}
public EqualityRoutine(int size, int displacement) {
super(size);
this.displacement = displacement;
}
public int displacement;
public int displacement;
}

@ -16,16 +16,16 @@ package Triangle.CodeGenerator;
public class Field extends RuntimeEntity {
public Field() {
super();
fieldOffset = 0;
}
public Field() {
super();
fieldOffset = 0;
}
public Field(int size, int fieldOffset) {
super(size);
this.fieldOffset = fieldOffset;
}
public Field(int size, int fieldOffset) {
super(size);
this.fieldOffset = fieldOffset;
}
public int fieldOffset;
public int fieldOffset;
}

@ -16,31 +16,31 @@ package Triangle.CodeGenerator;
public class Frame {
public Frame() {
this.level = 0;
this.size = 0;
}
public Frame(int level, Integer size) {
this.level = level;
this.size = size.intValue();
}
public Frame(int level, int size) {
this.level = level;
this.size = size;
}
public Frame(Frame frame, int sizeIncrement) {
this.level = frame.level;
this.size = frame.size + sizeIncrement;
}
public Frame(Frame frame, Integer sizeIncrement) {
this.level = frame.level;
this.size = frame.size + sizeIncrement.intValue();
}
protected int level;
protected int size;
public Frame() {
this.level = 0;
this.size = 0;
}
public Frame(int level, Integer size) {
this.level = level;
this.size = size.intValue();
}
public Frame(int level, int size) {
this.level = level;
this.size = size;
}
public Frame(Frame frame, int sizeIncrement) {
this.level = frame.level;
this.size = frame.size + sizeIncrement;
}
public Frame(Frame frame, Integer sizeIncrement) {
this.level = frame.level;
this.size = frame.size + sizeIncrement.intValue();
}
protected int level;
protected int size;
}

@ -16,16 +16,16 @@ package Triangle.CodeGenerator;
public class KnownAddress extends RuntimeEntity {
public KnownAddress() {
super();
address = null;
}
public KnownAddress() {
super();
address = null;
}
public KnownAddress(int size, int level, int displacement) {
super(size);
address = new ObjectAddress(level, displacement);
}
public KnownAddress(int size, int level, int displacement) {
super(size);
address = new ObjectAddress(level, displacement);
}
public ObjectAddress address;
public ObjectAddress address;
}

@ -16,16 +16,16 @@ package Triangle.CodeGenerator;
public class KnownRoutine extends RuntimeEntity {
public KnownRoutine() {
super();
address = null;
}
public KnownRoutine() {
super();
address = null;
}
public KnownRoutine(int size, int level, int displacement) {
super(size);
address = new ObjectAddress(level, displacement);
}
public KnownRoutine(int size, int level, int displacement) {
super(size);
address = new ObjectAddress(level, displacement);
}
public ObjectAddress address;
public ObjectAddress address;
}

@ -16,16 +16,16 @@ package Triangle.CodeGenerator;
public class KnownValue extends RuntimeEntity {
public KnownValue() {
super();
value = 0;
}
public KnownValue() {
super();
value = 0;
}
public KnownValue(int size, int value) {
super(size);
this.value = value;
}
public KnownValue(int size, int value) {
super(size);
this.value = value;
}
public int value;
public int value;
}

@ -16,11 +16,11 @@ package Triangle.CodeGenerator;
public final class ObjectAddress {
public ObjectAddress(int level, int displacement) {
this.level = level;
this.displacement = displacement;
}
public ObjectAddress(int level, int displacement) {
this.level = level;
this.displacement = displacement;
}
public int level, displacement;
public int level, displacement;
}

@ -16,16 +16,16 @@ package Triangle.CodeGenerator;
public class PrimitiveRoutine extends RuntimeEntity {
public PrimitiveRoutine() {
super();
displacement = 0;
}
public PrimitiveRoutine() {
super();
displacement = 0;
}
public PrimitiveRoutine(int size, int displacement) {
super(size);
this.displacement = displacement;
}
public PrimitiveRoutine(int size, int displacement) {
super(size);
this.displacement = displacement;
}
public int displacement;
public int displacement;
}

@ -18,16 +18,16 @@ package Triangle.CodeGenerator;
public abstract class RuntimeEntity {
public final static int maxRoutineLevel = 7;
public final static int maxRoutineLevel = 7;
public RuntimeEntity() {
size = 0;
}
public RuntimeEntity() {
size = 0;
}
public RuntimeEntity(int size) {
this.size = size;
}
public RuntimeEntity(int size) {
this.size = size;
}
public int size;
public int size;
}

@ -16,8 +16,8 @@ package Triangle.CodeGenerator;
public class TypeRepresentation extends RuntimeEntity {
public TypeRepresentation(int size) {
super(size);
}
public TypeRepresentation(int size) {
super(size);
}
}

@ -16,16 +16,16 @@ package Triangle.CodeGenerator;
public class UnknownAddress extends RuntimeEntity {
public UnknownAddress() {
super();
address = null;
}
public UnknownAddress() {
super();
address = null;
}
public UnknownAddress(int size, int level, int displacement) {
super(size);
address = new ObjectAddress(level, displacement);
}
public UnknownAddress(int size, int level, int displacement) {
super(size);
address = new ObjectAddress(level, displacement);
}
public ObjectAddress address;
public ObjectAddress address;
}

@ -16,16 +16,16 @@ package Triangle.CodeGenerator;
public class UnknownRoutine extends RuntimeEntity {
public UnknownRoutine() {
super();
address = null;
}
public UnknownRoutine() {
super();
address = null;
}
public UnknownRoutine(int size, int level, int displacement) {
super(size);
address = new ObjectAddress(level, displacement);
}
public UnknownRoutine(int size, int level, int displacement) {
super(size);
address = new ObjectAddress(level, displacement);
}
public ObjectAddress address;
public ObjectAddress address;
}

@ -16,16 +16,16 @@ package Triangle.CodeGenerator;
public class UnknownValue extends RuntimeEntity {
public UnknownValue() {
super();
address = null;
}
public UnknownValue() {
super();
address = null;
}
public UnknownValue(int size, int level, int displacement) {
super(size);
address = new ObjectAddress(level, displacement);
}
public UnknownValue(int size, int level, int displacement) {
super(size);
address = new ObjectAddress(level, displacement);
}
public ObjectAddress address;
public ObjectAddress address;
}

@ -30,98 +30,94 @@ import Triangle.TreeDrawer.Drawer;
*/
public class Compiler {
/** The filename for the object program, normally obj.tam. */
static String objectName = "obj.tam";
private static Scanner scanner;
private static Parser parser;
private static Checker checker;
private static Encoder encoder;
private static ErrorReporter reporter;
private static Drawer drawer;
/** The AST representing the source program. */
private static Program theAST;
/**
* Compile the source program to TAM machine code.
*
* @param sourceName the name of the file containing the
* source program.
* @param objectName the name of the file containing the
* object program.
* @param showingAST true iff the AST is to be displayed after
* contextual analysis (not currently implemented).
* @param showingTable true iff the object description details are to
* be displayed during code generation (not
* currently implemented).
* @return true iff the source program is free of compile-time errors,
* otherwise false.
*/
static boolean compileProgram(String sourceName, String objectName,
boolean showingAST, boolean showingTable) {
System.out.println("********** " +
"Triangle Compiler (Java Version 2.1)" +
" **********");
System.out.println("Syntactic Analysis ...");
SourceFile source = new SourceFile(sourceName);
if (source == null) {
System.out.println("Can't access source file " + sourceName);
System.exit(1);
}
scanner = new Scanner(source);
reporter = new ErrorReporter();
parser = new Parser(scanner, reporter);
checker = new Checker(reporter);
encoder = new Encoder(reporter);
drawer = new Drawer();
// scanner.enableDebugging();
theAST = parser.parseProgram(); // 1st pass
if (reporter.numErrors == 0) {
// if (showingAST) {
// drawer.draw(theAST);
// }
System.out.println("Contextual Analysis ...");
checker.check(theAST); // 2nd pass
if (showingAST) {
drawer.draw(theAST);
}
if (reporter.numErrors == 0) {
System.out.println("Code Generation ...");
encoder.encodeRun(theAST, showingTable); // 3rd pass
}
}
boolean successful = (reporter.numErrors == 0);
if (successful) {
encoder.saveObjectProgram(objectName);
System.out.println("Compilation was successful.");
} else {
System.out.println("Compilation was unsuccessful.");
}
return successful;
}
/**
* Triangle compiler main program.
*
* @param args the only command-line argument to the program specifies
* the source filename.
*/
public static void main(String[] args) {
boolean compiledOK;
if (args.length != 1) {
System.out.println("Usage: tc filename");
System.exit(1);
}
String sourceName = args[0];
compiledOK = compileProgram(sourceName, objectName, false, false);
}
/** The filename for the object program, normally obj.tam. */
static String objectName = "obj.tam";
private static Scanner scanner;
private static Parser parser;
private static Checker checker;
private static Encoder encoder;
private static ErrorReporter reporter;
private static Drawer drawer;
/** The AST representing the source program. */
private static Program theAST;
/**
* Compile the source program to TAM machine code.
*
* @param sourceName the name of the file containing the source program.
* @param objectName the name of the file containing the object program.
* @param showingAST true iff the AST is to be displayed after contextual
* analysis (not currently implemented).
* @param showingTable true iff the object description details are to be
* displayed during code generation (not currently
* implemented).
* @return true iff the source program is free of compile-time errors, otherwise
* false.
*/
static boolean compileProgram(String sourceName, String objectName, boolean showingAST, boolean showingTable) {
System.out.println("********** " + "Triangle Compiler (Java Version 2.1)" + " **********");
System.out.println("Syntactic Analysis ...");
SourceFile source = SourceFile.ofPath(sourceName);
if (source == null) {
System.out.println("Can't access source file " + sourceName);
System.exit(1);
}
scanner = new Scanner(source);
reporter = new ErrorReporter();
parser = new Parser(scanner, reporter);
checker = new Checker(reporter);
encoder = new Encoder(reporter);
drawer = new Drawer();
// scanner.enableDebugging();
theAST = parser.parseProgram(); // 1st pass
if (reporter.numErrors == 0) {
// if (showingAST) {
// drawer.draw(theAST);
// }
System.out.println("Contextual Analysis ...");
checker.check(theAST); // 2nd pass
if (showingAST) {
drawer.draw(theAST);
}
if (reporter.numErrors == 0) {
System.out.println("Code Generation ...");
encoder.encodeRun(theAST, showingTable); // 3rd pass
}
}
boolean successful = (reporter.numErrors == 0);
if (successful) {
encoder.saveObjectProgram(objectName);
System.out.println("Compilation was successful.");
} else {
System.out.println("Compilation was unsuccessful.");
}
return successful;
}
/**
* Triangle compiler main program.
*
* @param args the only command-line argument to the program specifies the
* source filename.
*/
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage: tc filename");
System.exit(1);
}
String sourceName = args[0];
var compiledOK = compileProgram(sourceName, objectName, false, false);
System.exit(compiledOK ? 0 : 1);
}
}

@ -18,16 +18,16 @@ import Triangle.AbstractSyntaxTrees.Declaration;
public class IdEntry {
protected String id;
protected Declaration attr;
protected int level;
protected IdEntry previous;
protected String id;
protected Declaration attr;
protected int level;
protected IdEntry previous;
IdEntry(String id, Declaration attr, int level, IdEntry previous) {
this.id = id;
this.attr = attr;
this.level = level;
this.previous = previous;
}
IdEntry(String id, Declaration attr, int level, IdEntry previous) {
this.id = id;
this.attr = attr;
this.level = level;
this.previous = previous;
}
}

@ -18,91 +18,91 @@ import Triangle.AbstractSyntaxTrees.Declaration;
public final class IdentificationTable {
private int level;
private IdEntry latest;
public IdentificationTable() {
level = 0;
latest = null;
}
// Opens a new level in the identification table, 1 higher than the
// current topmost level.
public void openScope() {
level++;
}
// Closes the topmost level in the identification table, discarding
// all entries belonging to that level.
public void closeScope() {
IdEntry entry, local;
// Presumably, idTable.level > 0.
entry = this.latest;
while (entry.level == this.level) {
local = entry;
entry = local.previous;
}
this.level--;
this.latest = entry;
}
// Makes a new entry in the identification table for the given identifier
// and attribute. The new entry belongs to the current level.
// duplicated is set to to true iff there is already an entry for the
// same identifier at the current level.
public void enter(String id, Declaration attr) {
IdEntry entry = this.latest;
boolean present = false, searching = true;
// Check for duplicate entry ...
while (searching) {
if (entry == null || entry.level < this.level)
searching = false;
else if (entry.id.equals(id)) {
present = true;
searching = false;
} else
entry = entry.previous;
}
attr.duplicated = present;
// Add new entry ...
entry = new IdEntry(id, attr, this.level, this.latest);
this.latest = entry;
}
// Finds an entry for the given identifier in the identification table,
// if any. If there are several entries for that identifier, finds the
// entry at the highest level, in accordance with the scope rules.
// Returns null iff no entry is found.
// otherwise returns the attribute field of the entry found.
public Declaration retrieve(String id) {
IdEntry entry;
Declaration attr = null;
boolean present = false, searching = true;
entry = this.latest;
while (searching) {
if (entry == null)
searching = false;
else if (entry.id.equals(id)) {
present = true;
searching = false;
attr = entry.attr;
} else
entry = entry.previous;
}
return attr;
}
private int level;
private IdEntry latest;
public IdentificationTable() {
level = 0;
latest = null;
}
// Opens a new level in the identification table, 1 higher than the
// current topmost level.
public void openScope() {
level++;
}
// Closes the topmost level in the identification table, discarding
// all entries belonging to that level.
public void closeScope() {
IdEntry entry, local;
// Presumably, idTable.level > 0.
entry = this.latest;
while (entry.level == this.level) {
local = entry;
entry = local.previous;
}
this.level--;
this.latest = entry;
}
// Makes a new entry in the identification table for the given identifier
// and attribute. The new entry belongs to the current level.
// duplicated is set to to true iff there is already an entry for the
// same identifier at the current level.
public void enter(String id, Declaration attr) {
IdEntry entry = this.latest;
boolean present = false, searching = true;
// Check for duplicate entry ...
while (searching) {
if (entry == null || entry.level < this.level)
searching = false;
else if (entry.id.equals(id)) {
present = true;
searching = false;
} else
entry = entry.previous;
}
attr.duplicated = present;
// Add new entry ...
entry = new IdEntry(id, attr, this.level, this.latest);
this.latest = entry;
}
// Finds an entry for the given identifier in the identification table,
// if any. If there are several entries for that identifier, finds the
// entry at the highest level, in accordance with the scope rules.
// Returns null iff no entry is found.
// otherwise returns the attribute field of the entry found.
public Declaration retrieve(String id) {
IdEntry entry;
Declaration attr = null;
boolean present = false, searching = true;
entry = this.latest;
while (searching) {
if (entry == null)
searching = false;
else if (entry.id.equals(id)) {
present = true;
searching = false;
attr = entry.attr;
} else
entry = entry.previous;
}
return attr;
}
}

@ -18,25 +18,25 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class ErrorReporter {
int numErrors;
ErrorReporter() {
numErrors = 0;
}
public void reportError(String message, String tokenName, SourcePosition pos) {
System.out.print("ERROR: ");
for (int p = 0; p < message.length(); p++)
if (message.charAt(p) == '%')
System.out.print(tokenName);
else
System.out.print(message.charAt(p));
System.out.println(" " + pos.start + ".." + pos.finish);
numErrors++;
}
public void reportRestriction(String message) {
System.out.println("RESTRICTION: " + message);
}
int numErrors;
ErrorReporter() {
numErrors = 0;
}
public void reportError(String message, String tokenName, SourcePosition pos) {
System.out.print("ERROR: ");
for (int p = 0; p < message.length(); p++)
if (message.charAt(p) == '%')
System.out.print(tokenName);
else
System.out.print(message.charAt(p));
System.out.println(" " + pos.start + ".." + pos.finish);
numErrors++;
}
public void reportRestriction(String message) {
System.out.println("RESTRICTION: " + message);
}
}

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