Initial commit of version 2.1.

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

@ -0,0 +1,18 @@
{
"cSpell.words": [
"actuals",
"Analyser",
"Denoter",
"DENOTERS",
"Deryck",
"geteol",
"getint",
"maxint",
"notgreater",
"notless",
"puteol",
"putint",
"Vname"
],
"java.configuration.updateBuildConfiguration": "automatic"
}

@ -0,0 +1,20 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>triangle.tools</groupId>
<artifactId>triangle-disassembler</artifactId>
<version>2.1</version>
<parent>
<groupId>triangle.tools</groupId>
<artifactId>triangle-tools</artifactId>
<version>2.1</version>
<relativePath>../</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>triangle.tools</groupId>
<artifactId>triangle-abstractmachine</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
</project>

@ -0,0 +1,398 @@
/*
* @(#)Disassembler.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractMachine;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
* Disassembles the TAM code in the given file, and displays the
* instructions on standard output.
*
* For example:
*
* <pre>
* java TAM.Disassembler obj.tam
* </pre>
*
* <p>
* Copyright 1991 David A. Watt, University of Glasgow<br>
* Copyright 1998 Deryck F. Brown, The Robert Gordon University<br>
* </p>
*
*/
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();
}
}

@ -0,0 +1,20 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>triangle.tools</groupId>
<artifactId>triangle-interpreter</artifactId>
<version>2.1</version>
<parent>
<groupId>triangle.tools</groupId>
<artifactId>triangle-tools</artifactId>
<version>2.1</version>
<relativePath>../</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>triangle.tools</groupId>
<artifactId>triangle-abstractmachine</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
</project>

@ -0,0 +1,620 @@
/*
* @(#)Interpreter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractMachine;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Interpreter {
static String objectName;
// DATA STORE
static int[] data = new int[1024];
// DATA STORE REGISTERS AND OTHER REGISTERS
final static int CB = 0,
SB = 0,
HB = 1024; // = upper bound of data array + 1
static int CT, CP, ST, HT, LB, status;
// status values
final static int running = 0, halted = 1, failedDataStoreFull = 2, failedInvalidCodeAddress = 3,
failedInvalidInstruction = 4, failedOverflow = 5, failedZeroDivide = 6,
failedIOError = 7;
static long accumulator;
static int content(int r) {
// Returns the current content of register r,
// even if r is one of the pseudo-registers L1..L6.
switch (r) {
case Machine.CBr:
return CB;
case Machine.CTr:
return CT;
case Machine.PBr:
return Machine.PB;
case Machine.PTr:
return Machine.PT;
case Machine.SBr:
return SB;
case Machine.STr:
return ST;
case Machine.HBr:
return HB;
case Machine.HTr:
return HT;
case Machine.LBr:
return LB;
case Machine.L1r:
return data[LB];
case Machine.L2r:
return data[data[LB]];
case Machine.L3r:
return data[data[data[LB]]];
case Machine.L4r:
return data[data[data[data[LB]]]];
case Machine.L5r:
return data[data[data[data[data[LB]]]]];
case Machine.L6r:
return data[data[data[data[data[data[LB]]]]]];
case Machine.CPr:
return CP;
default:
return 0;
}
}
// PROGRAM STATUS
static void dump() {
// Writes a summary of the machine state.
int addr, staticLink, dynamicLink,
localRegNum;
System.out.println("");
System.out.println("State of data store and registers:");
System.out.println("");
if (HT == HB)
System.out.println(" |--------| (heap is empty)");
else {
System.out.println(" HB-->");
System.out.println(" |--------|");
for (addr = HB - 1; addr >= HT; addr--) {
System.out.print(addr + ":");
if (addr == HT)
System.out.print(" HT-->");
else
System.out.print(" ");
System.out.println("|" + data[addr] + "|");
}
System.out.println(" |--------|");
}
System.out.println(" |////////|");
System.out.println(" |////////|");
if (ST == SB)
System.out.println(" |--------| (stack is empty)");
else {
dynamicLink = LB;
staticLink = LB;
localRegNum = Machine.LBr;
System.out.println(" ST--> |////////|");
System.out.println(" |--------|");
for (addr = ST - 1; addr >= SB; addr--) {
System.out.print(addr + ":");
if (addr == SB)
System.out.print(" SB-->");
else if (addr == staticLink) {
switch (localRegNum) {
case Machine.LBr:
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;
}
staticLink = data[addr];
localRegNum = localRegNum + 1;
} else
System.out.print(" ");
if ((addr == dynamicLink) && (dynamicLink != SB))
System.out.print("|SL=" + data[addr] + "|");
else if ((addr == dynamicLink + 1) && (dynamicLink != SB))
System.out.print("|DL=" + data[addr] + "|");
else if ((addr == dynamicLink + 2) && (dynamicLink != SB))
System.out.print("|RA=" + data[addr] + "|");
else
System.out.print("|" + data[addr] + "|");
System.out.println("");
if (addr == dynamicLink) {
System.out.println(" |--------|");
dynamicLink = data[addr + 1];
}
}
}
System.out.println("");
}
static void showStatus() {
// Writes an indication of whether and why the program has terminated.
System.out.println("");
switch (status) {
case running:
System.out.println("Program is running.");
break;
case halted:
System.out.println("Program has halted normally.");
break;
case failedDataStoreFull:
System.out.println("Program has failed due to exhaustion of Data Store.");
break;
case failedInvalidCodeAddress:
System.out.println("Program has failed due to an invalid code address.");
break;
case failedInvalidInstruction:
System.out.println("Program has failed due to an invalid instruction.");
break;
case failedOverflow:
System.out.println("Program has failed due to overflow.");
break;
case failedZeroDivide:
System.out.println("Program has failed due to division by zero.");
break;
case failedIOError:
System.out.println("Program has failed due to an IO error.");
break;
}
if (status != halted)
dump();
}
// INTERPRETATION
static void checkSpace(int spaceNeeded) {
// Signals failure if there is not enough space to expand the stack or
// heap by spaceNeeded.
if (HT - ST < spaceNeeded)
status = failedDataStoreFull;
}
static boolean isTrue(int datum) {
// Tests whether the given datum represents true.
return (datum == Machine.trueRep);
}
static boolean equal(int size, int addr1, int addr2) {
// Tests whether two multi-word objects are equal, given their common
// size and their base addresses.
boolean eq;
int index;
eq = true;
index = 0;
while (eq && (index < size))
if (data[addr1 + index] == data[addr2 + index])
index = index + 1;
else
eq = false;
return eq;
}
static int overflowChecked(long datum) {
// Signals failure if the datum is too large to fit into a single word,
// otherwise returns the datum as a single word.
if ((-Machine.maxintRep <= datum) && (datum <= Machine.maxintRep))
return (int) datum;
else {
status = failedOverflow;
return 0;
}
}
static int toInt(boolean b) {
return b ? Machine.trueRep : Machine.falseRep;
}
static int currentChar;
static int readInt() throws java.io.IOException {
int temp = 0;
int sign = 1;
do {
currentChar = System.in.read();
} while (Character.isWhitespace((char) currentChar));
if ((currentChar == '-') || (currentChar == '+'))
do {
sign = (currentChar == '-') ? -1 : 1;
currentChar = System.in.read();
} while ((currentChar == '-') || currentChar == '+');
if (Character.isDigit((char) currentChar))
do {
temp = temp * 10 + (currentChar - '0');
currentChar = System.in.read();
} while (Character.isDigit((char) currentChar));
return sign * temp;
}
static void callPrimitive(int primitiveDisplacement) {
// Invokes the given primitive routine.
int addr, size;
char ch;
switch (primitiveDisplacement) {
case Machine.idDisplacement:
break; // nothing to be done
case Machine.notDisplacement:
data[ST - 1] = toInt(!isTrue(data[ST - 1]));
break;
case Machine.andDisplacement:
ST = ST - 1;
data[ST - 1] = toInt(isTrue(data[ST - 1]) & isTrue(data[ST]));
break;
case Machine.orDisplacement:
ST = ST - 1;
data[ST - 1] = toInt(isTrue(data[ST - 1]) | isTrue(data[ST]));
break;
case Machine.succDisplacement:
data[ST - 1] = overflowChecked(data[ST - 1] + 1);
break;
case Machine.predDisplacement:
data[ST - 1] = overflowChecked(data[ST - 1] - 1);
break;
case Machine.negDisplacement:
data[ST - 1] = -data[ST - 1];
break;
case Machine.addDisplacement:
ST = ST - 1;
accumulator = data[ST - 1];
data[ST - 1] = overflowChecked(accumulator + data[ST]);
break;
case Machine.subDisplacement:
ST = ST - 1;
accumulator = data[ST - 1];
data[ST - 1] = overflowChecked(accumulator - data[ST]);
break;
case Machine.multDisplacement:
ST = ST - 1;
accumulator = data[ST - 1];
data[ST - 1] = overflowChecked(accumulator * data[ST]);
break;
case Machine.divDisplacement:
ST = ST - 1;
accumulator = data[ST - 1];
if (data[ST] != 0)
data[ST - 1] = (int) (accumulator / data[ST]);
else
status = failedZeroDivide;
break;
case Machine.modDisplacement:
ST = ST - 1;
accumulator = data[ST - 1];
if (data[ST] != 0)
data[ST - 1] = (int) (accumulator % data[ST]);
else
status = failedZeroDivide;
break;
case Machine.ltDisplacement:
ST = ST - 1;
data[ST - 1] = toInt(data[ST - 1] < data[ST]);
break;
case Machine.leDisplacement:
ST = ST - 1;
data[ST - 1] = toInt(data[ST - 1] <= data[ST]);
break;
case Machine.geDisplacement:
ST = ST - 1;
data[ST - 1] = toInt(data[ST - 1] >= data[ST]);
break;
case Machine.gtDisplacement:
ST = ST - 1;
data[ST - 1] = toInt(data[ST - 1] > data[ST]);
break;
case Machine.eqDisplacement:
size = data[ST - 1]; // size of each comparand
ST = ST - 2 * size;
data[ST - 1] = toInt(equal(size, ST - 1, ST - 1 + size));
break;
case Machine.neDisplacement:
size = data[ST - 1]; // size of each comparand
ST = ST - 2 * size;
data[ST - 1] = toInt(!equal(size, ST - 1, ST - 1 + size));
break;
case Machine.eolDisplacement:
data[ST] = toInt(currentChar == '\n');
ST = ST + 1;
break;
case Machine.eofDisplacement:
data[ST] = toInt(currentChar == -1);
ST = ST + 1;
break;
case Machine.getDisplacement:
ST = ST - 1;
addr = data[ST];
try {
currentChar = System.in.read();
} catch (java.io.IOException s) {
status = failedIOError;
}
data[addr] = (int) currentChar;
break;
case Machine.putDisplacement:
ST = ST - 1;
ch = (char) data[ST];
System.out.print(ch);
break;
case Machine.geteolDisplacement:
try {
while ((currentChar = System.in.read()) != '\n')
;
} catch (java.io.IOException s) {
status = failedIOError;
}
break;
case Machine.puteolDisplacement:
System.out.println("");
break;
case Machine.getintDisplacement:
ST = ST - 1;
addr = data[ST];
try {
accumulator = readInt();
} catch (java.io.IOException s) {
status = failedIOError;
}
data[addr] = (int) accumulator;
break;
case Machine.putintDisplacement:
ST = ST - 1;
accumulator = data[ST];
System.out.print(accumulator);
break;
case Machine.newDisplacement:
size = data[ST - 1];
checkSpace(size);
HT = HT - size;
data[ST - 1] = HT;
break;
case Machine.disposeDisplacement:
ST = ST - 1; // no action taken at present
break;
}
}
static void interpretProgram() {
// Runs the program in code store.
Instruction currentInstr;
int op, r, n, d, addr, index;
// Initialize registers ...
ST = SB;
HT = HB;
LB = SB;
CP = CB;
status = running;
do {
// Fetch instruction ...
currentInstr = Machine.code[CP];
// Decode instruction ...
op = currentInstr.op;
r = currentInstr.r;
n = currentInstr.n;
d = currentInstr.d;
// Execute instruction ...
switch (op) {
case Machine.LOADop:
addr = d + content(r);
checkSpace(n);
for (index = 0; index < n; index++)
data[ST + index] = data[addr + index];
ST = ST + n;
CP = CP + 1;
break;
case Machine.LOADAop:
addr = d + content(r);
checkSpace(1);
data[ST] = addr;
ST = ST + 1;
CP = CP + 1;
break;
case Machine.LOADIop:
ST = ST - 1;
addr = data[ST];
checkSpace(n);
for (index = 0; index < n; index++)
data[ST + index] = data[addr + index];
ST = ST + n;
CP = CP + 1;
break;
case Machine.LOADLop:
checkSpace(1);
data[ST] = d;
ST = ST + 1;
CP = CP + 1;
break;
case Machine.STOREop:
addr = d + content(r);
ST = ST - n;
for (index = 0; index < n; index++)
data[addr + index] = data[ST + index];
CP = CP + 1;
break;
case Machine.STOREIop:
ST = ST - 1;
addr = data[ST];
ST = ST - n;
for (index = 0; index < n; index++)
data[addr + index] = data[ST + index];
CP = CP + 1;
break;
case Machine.CALLop:
addr = d + content(r);
if (addr >= Machine.PB) {
callPrimitive(addr - Machine.PB);
CP = CP + 1;
} else {
checkSpace(3);
if ((0 <= n) && (n <= 15))
data[ST] = content(n); // static link
else
status = failedInvalidInstruction;
data[ST + 1] = LB; // dynamic link
data[ST + 2] = CP + 1; // return address
LB = ST;
ST = ST + 3;
CP = addr;
}
break;
case Machine.CALLIop:
ST = ST - 2;
addr = data[ST + 1];
if (addr >= Machine.PB) {
callPrimitive(addr - Machine.PB);
CP = CP + 1;
} else {
// data[ST] = static link already
data[ST + 1] = LB; // dynamic link
data[ST + 2] = CP + 1; // return address
LB = ST;
ST = ST + 3;
CP = addr;
}
break;
case Machine.RETURNop:
addr = LB - d;
CP = data[LB + 2];
LB = data[LB + 1];
ST = ST - n;
for (index = 0; index < n; index++)
data[addr + index] = data[ST + index];
ST = addr + n;
break;
case Machine.PUSHop:
checkSpace(d);
ST = ST + d;
CP = CP + 1;
break;
case Machine.POPop:
addr = ST - n - d;
ST = ST - n;
for (index = 0; index < n; index++)
data[addr + index] = data[ST + index];
ST = addr + n;
CP = CP + 1;
break;
case Machine.JUMPop:
CP = d + content(r);
break;
case Machine.JUMPIop:
ST = ST - 1;
CP = data[ST];
break;
case Machine.JUMPIFop:
ST = ST - 1;
if (data[ST] == n)
CP = d + content(r);
else
CP = CP + 1;
break;
case Machine.HALTop:
status = halted;
break;
}
if ((CP < CB) || (CP >= CT))
status = failedInvalidCodeAddress;
} while (status == running);
}
// LOADING
static void loadObjectProgram(String objectName) {
// Loads the TAM object program into code store from the named file.
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 = CB;
System.err.println("Error opening object file: " + s);
} catch (IOException s) {
CT = CB;
System.err.println("Error reading object file: " + s);
}
}
// RUNNING
public static void main(String[] args) {
System.out.println("********** TAM Interpreter (Java Version 2.1) **********");
if (args.length == 1)
objectName = args[0];
else
objectName = "obj.tam";
loadObjectProgram(objectName);
if (CT != CB) {
interpretProgram();
showStatus();
}
}
}

@ -0,0 +1,14 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>triangle.tools</groupId>
<artifactId>triangle-abstractmachine</artifactId>
<version>2.1</version>
<packaging>jar</packaging>
<parent>
<groupId>triangle.tools</groupId>
<artifactId>triangle-tools</artifactId>
<version>2.1</version>
<relativePath>../</relativePath>
</parent>
</project>

@ -0,0 +1,64 @@
/*
* @(#)Instruction.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractMachine;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
public class Instruction {
public Instruction() {
op = 0;
r = 0;
n = 0;
d = 0;
}
// Java has no type synonyms, so the following representations are
// assumed:
//
// 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
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;
}
}
}

@ -0,0 +1,125 @@
/*
* @(#)Machine.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.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;
}

@ -0,0 +1,2 @@
c:\Java\Repos\Triangle-Tools\Triangle.AbstractMachine\src\main\java\Triangle\AbstractMachine\Machine.java
c:\Java\Repos\Triangle-Tools\Triangle.AbstractMachine\src\main\java\Triangle\AbstractMachine\Instruction.java

@ -0,0 +1,17 @@
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 80
[*.sh]
end_of_line = lf
[*.java]
indent_size = 4
max_line_length = 120

@ -0,0 +1,20 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>triangle.tools</groupId>
<artifactId>triangle-compiler</artifactId>
<version>2.1</version>
<parent>
<groupId>triangle.tools</groupId>
<artifactId>triangle-tools</artifactId>
<version>2.1</version>
<relativePath>../</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>triangle.tools</groupId>
<artifactId>triangle-abstractmachine</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
</project>

@ -0,0 +1,35 @@
/*
* @(#)AST.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.CodeGenerator.RuntimeEntity;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class AST {
public AST(SourcePosition thePosition) {
position = thePosition;
entity = null;
}
public SourcePosition getPosition() {
return position;
}
public abstract Object visit(Visitor v, Object o);
public SourcePosition position;
public RuntimeEntity entity;
}

@ -0,0 +1,24 @@
/*
* @(#)ActualParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class ActualParameter extends AST {
public ActualParameter(SourcePosition thePosition) {
super(thePosition);
}
}

@ -0,0 +1,24 @@
/*
* @(#)ActualParameterSequence.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class ActualParameterSequence extends AST {
public ActualParameterSequence(SourcePosition thePosition) {
super(thePosition);
}
}

@ -0,0 +1,32 @@
/*
* @(#)AnyTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class AnyTypeDenoter extends TypeDenoter {
public AnyTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
public Object visit(Visitor v, Object o) {
return v.visitAnyTypeDenoter(this, o);
}
public boolean equals(Object obj) {
return false;
}
}

@ -0,0 +1,27 @@
/*
* @(#)ArrayAggregate.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class ArrayAggregate extends AST {
public ArrayAggregate(SourcePosition thePosition) {
super(thePosition);
elemCount = 0;
}
public int elemCount;
}

@ -0,0 +1,32 @@
/*
* @(#)ArrayExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class ArrayExpression extends Expression {
public ArrayExpression(ArrayAggregate aaAST,
SourcePosition thePosition) {
super(thePosition);
AA = aaAST;
}
public Object visit(Visitor v, Object o) {
return v.visitArrayExpression(this, o);
}
public ArrayAggregate AA;
}

@ -0,0 +1,44 @@
/*
* @(#)ArrayTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class ArrayTypeDenoter extends TypeDenoter {
public ArrayTypeDenoter(IntegerLiteral ilAST, TypeDenoter tAST,
SourcePosition thePosition) {
super(thePosition);
IL = ilAST;
T = tAST;
}
public Object visit(Visitor v, Object o) {
return v.visitArrayTypeDenoter(this, o);
}
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;
}

@ -0,0 +1,33 @@
/*
* @(#)AssignCommand.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class AssignCommand extends Command {
public AssignCommand(Vname vAST, Expression eAST, SourcePosition thePosition) {
super(thePosition);
V = vAST;
E = eAST;
}
public Object visit(Visitor v, Object o) {
return v.visitAssignCommand(this, o);
}
public Vname V;
public Expression E;
}

@ -0,0 +1,35 @@
/*
* @(#)BinaryExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
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 Object visit(Visitor v, Object o) {
return v.visitBinaryExpression(this, o);
}
public Expression E1, E2;
public Operator O;
}

@ -0,0 +1,37 @@
/*
* @(#)BinaryOperatorDeclaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
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 Object visit(Visitor v, Object o) {
return v.visitBinaryOperatorDeclaration(this, o);
}
public Operator O;
public TypeDenoter ARG1, ARG2, RES;
}

@ -0,0 +1,35 @@
/*
* @(#)BoolTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class BoolTypeDenoter extends TypeDenoter {
public BoolTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
public Object visit(Visitor v, Object o) {
return v.visitBoolTypeDenoter(this, o);
}
public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof ErrorTypeDenoter))
return true;
else
return ((obj != null) && (obj instanceof BoolTypeDenoter));
}
}

@ -0,0 +1,34 @@
/*
* @(#)CallCommand.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class CallCommand extends Command {
public CallCommand(Identifier iAST, ActualParameterSequence apsAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
APS = apsAST;
}
public Object visit(Visitor v, Object o) {
return v.visitCallCommand(this, o);
}
public Identifier I;
public ActualParameterSequence APS;
}

@ -0,0 +1,34 @@
/*
* @(#)CallExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class CallExpression extends Expression {
public CallExpression(Identifier iAST, ActualParameterSequence apsAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
APS = apsAST;
}
public Object visit(Visitor v, Object o) {
return v.visitCallExpression(this, o);
}
public Identifier I;
public ActualParameterSequence APS;
}

@ -0,0 +1,35 @@
/*
* @(#)CharTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class CharTypeDenoter extends TypeDenoter {
public CharTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
public Object visit(Visitor v, Object o) {
return v.visitCharTypeDenoter(this, o);
}
public boolean equals(Object obj) {
if (obj != null && obj instanceof ErrorTypeDenoter)
return true;
else
return (obj != null && obj instanceof CharTypeDenoter);
}
}

@ -0,0 +1,31 @@
/*
* @(#)CharacterExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class CharacterExpression extends Expression {
public CharacterExpression(CharacterLiteral clAST, SourcePosition thePosition) {
super(thePosition);
CL = clAST;
}
public Object visit(Visitor v, Object o) {
return v.visitCharacterExpression(this, o);
}
public CharacterLiteral CL;
}

@ -0,0 +1,29 @@
/*
* @(#)CharacterLiteral.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class CharacterLiteral extends Terminal {
public CharacterLiteral(String theSpelling, SourcePosition thePosition) {
super(theSpelling, thePosition);
}
public Object visit(Visitor v, Object o) {
return v.visitCharacterLiteral(this, o);
}
}

@ -0,0 +1,24 @@
/*
* @(#)Command.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class Command extends AST {
public Command(SourcePosition thePosition) {
super(thePosition);
}
}

@ -0,0 +1,31 @@
/*
* @(#)ConstActualParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class ConstActualParameter extends ActualParameter {
public ConstActualParameter(Expression eAST, SourcePosition thePosition) {
super(thePosition);
E = eAST;
}
public Object visit(Visitor v, Object o) {
return v.visitConstActualParameter(this, o);
}
public Expression E;
}

@ -0,0 +1,34 @@
/*
* @(#)ConstDeclaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class ConstDeclaration extends Declaration {
public ConstDeclaration(Identifier iAST, Expression eAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
E = eAST;
}
public Object visit(Visitor v, Object o) {
return v.visitConstDeclaration(this, o);
}
public Identifier I;
public Expression E;
}

@ -0,0 +1,42 @@
/*
* @(#)ConstFormalParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class ConstFormalParameter extends FormalParameter {
public ConstFormalParameter(Identifier iAST, TypeDenoter tAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
}
public Object visit(Visitor v, Object o) {
return v.visitConstFormalParameter(this, o);
}
public Identifier I;
public TypeDenoter T;
public boolean equals(Object fpAST) {
if (fpAST instanceof ConstFormalParameter) {
ConstFormalParameter cfpAST = (ConstFormalParameter) fpAST;
return T.equals(cfpAST.T);
} else
return false;
}
}

@ -0,0 +1,27 @@
/*
* @(#)Declaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class Declaration extends AST {
public Declaration(SourcePosition thePosition) {
super(thePosition);
duplicated = false;
}
public boolean duplicated;
}

@ -0,0 +1,33 @@
/*
* @(#)DotVname.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class DotVname extends Vname {
public DotVname(Vname vAST, Identifier iAST, SourcePosition thePosition) {
super(thePosition);
V = vAST;
I = iAST;
}
public Object visit(Visitor v, Object o) {
return v.visitDotVname(this, o);
}
public Identifier I;
public Vname V;
}

@ -0,0 +1,28 @@
/*
* @(#)EmptyActualParameterSequence.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class EmptyActualParameterSequence extends ActualParameterSequence {
public EmptyActualParameterSequence(SourcePosition thePosition) {
super(thePosition);
}
public Object visit(Visitor v, Object o) {
return v.visitEmptyActualParameterSequence(this, o);
}
}

@ -0,0 +1,28 @@
/*
* @(#)EmptyCommand.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class EmptyCommand extends Command {
public EmptyCommand(SourcePosition thePosition) {
super(thePosition);
}
public Object visit(Visitor v, Object o) {
return v.visitEmptyCommand(this, o);
}
}

@ -0,0 +1,28 @@
/*
* @(#)EmptyExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class EmptyExpression extends Expression {
public EmptyExpression(SourcePosition thePosition) {
super(thePosition);
}
public Object visit(Visitor v, Object o) {
return v.visitEmptyExpression(this, o);
}
}

@ -0,0 +1,32 @@
/*
* @(#)EmptyFormalParameterSequence.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class EmptyFormalParameterSequence extends FormalParameterSequence {
public EmptyFormalParameterSequence(SourcePosition thePosition) {
super(thePosition);
}
public Object visit(Visitor v, Object o) {
return v.visitEmptyFormalParameterSequence(this, o);
}
public boolean equals(Object fpsAST) {
return (fpsAST instanceof EmptyFormalParameterSequence);
}
}

@ -0,0 +1,32 @@
/*
* @(#)ErrorTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class ErrorTypeDenoter extends TypeDenoter {
public ErrorTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
public Object visit(Visitor v, Object o) {
return v.visitErrorTypeDenoter(this, o);
}
public boolean equals(Object obj) {
return true;
}
}

@ -0,0 +1,27 @@
/*
* @(#)Expression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class Expression extends AST {
public Expression(SourcePosition thePosition) {
super(thePosition);
type = null;
}
public TypeDenoter type;
}

@ -0,0 +1,26 @@
/*
* @(#)FieldTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class FieldTypeDenoter extends TypeDenoter {
public FieldTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
public abstract boolean equals(Object obj);
}

@ -0,0 +1,27 @@
/*
* @(#)FormalParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class FormalParameter extends Declaration {
public FormalParameter(SourcePosition thePosition) {
super(thePosition);
}
public abstract boolean equals(Object fpAST);
}

@ -0,0 +1,26 @@
/*
* @(#)FormalParameterSequence.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class FormalParameterSequence extends AST {
public FormalParameterSequence(SourcePosition thePosition) {
super(thePosition);
}
public abstract boolean equals(Object fpsAST);
}

@ -0,0 +1,31 @@
/*
* @(#)FuncActualParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class FuncActualParameter extends ActualParameter {
public FuncActualParameter(Identifier iAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
}
public Object visit(Visitor v, Object o) {
return v.visitFuncActualParameter(this, o);
}
public Identifier I;
}

@ -0,0 +1,39 @@
/*
* @(#)FuncDeclaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
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 Object visit(Visitor v, Object o) {
return v.visitFuncDeclaration(this, o);
}
public Identifier I;
public FormalParameterSequence FPS;
public TypeDenoter T;
public Expression E;
}

@ -0,0 +1,44 @@
/*
* @(#)FuncFormalParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
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 Object visit(Visitor v, Object o) {
return v.visitFuncFormalParameter(this, o);
}
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;
}

@ -0,0 +1,33 @@
/*
* @(#)Identifier.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class Identifier extends Terminal {
public Identifier(String theSpelling, SourcePosition thePosition) {
super(theSpelling, thePosition);
type = null;
decl = null;
}
public Object visit(Visitor v, Object o) {
return v.visitIdentifier(this, o);
}
public TypeDenoter type;
public AST decl; // Either a Declaration or a FieldTypeDenoter
}

@ -0,0 +1,35 @@
/*
* @(#)IfCommand.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
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 Object visit(Visitor v, Object o) {
return v.visitIfCommand(this, o);
}
public Expression E;
public Command C1, C2;
}

@ -0,0 +1,34 @@
/*
* @(#)IfExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
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 Object visit(Visitor v, Object o) {
return v.visitIfExpression(this, o);
}
public Expression E1, E2, E3;
}

@ -0,0 +1,35 @@
/*
* @(#)IntTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class IntTypeDenoter extends TypeDenoter {
public IntTypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
public Object visit(Visitor v, Object o) {
return v.visitIntTypeDenoter(this, o);
}
public boolean equals(Object obj) {
if (obj != null && obj instanceof ErrorTypeDenoter)
return true;
else
return (obj != null && obj instanceof IntTypeDenoter);
}
}

@ -0,0 +1,31 @@
/*
* @(#)IntegerExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class IntegerExpression extends Expression {
public IntegerExpression(IntegerLiteral ilAST, SourcePosition thePosition) {
super(thePosition);
IL = ilAST;
}
public Object visit(Visitor v, Object o) {
return v.visitIntegerExpression(this, o);
}
public IntegerLiteral IL;
}

@ -0,0 +1,29 @@
/*
* @(#)IntegerLiteral.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class IntegerLiteral extends Terminal {
public IntegerLiteral(String theSpelling, SourcePosition thePosition) {
super(theSpelling, thePosition);
}
public Object visit(Visitor v, Object o) {
return v.visitIntegerLiteral(this, o);
}
}

@ -0,0 +1,33 @@
/*
* @(#)LetCommand.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class LetCommand extends Command {
public LetCommand(Declaration dAST, Command cAST, SourcePosition thePosition) {
super(thePosition);
D = dAST;
C = cAST;
}
public Object visit(Visitor v, Object o) {
return v.visitLetCommand(this, o);
}
public Declaration D;
public Command C;
}

@ -0,0 +1,33 @@
/*
* @(#)LetExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class LetExpression extends Expression {
public LetExpression(Declaration dAST, Expression eAST, SourcePosition thePosition) {
super(thePosition);
D = dAST;
E = eAST;
}
public Object visit(Visitor v, Object o) {
return v.visitLetExpression(this, o);
}
public Declaration D;
public Expression E;
}

@ -0,0 +1,34 @@
/*
* @(#)MultipleActualParameterSequence.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class MultipleActualParameterSequence extends ActualParameterSequence {
public MultipleActualParameterSequence(ActualParameter apAST, ActualParameterSequence apsAST,
SourcePosition thePosition) {
super(thePosition);
AP = apAST;
APS = apsAST;
}
public Object visit(Visitor v, Object o) {
return v.visitMultipleActualParameterSequence(this, o);
}
public ActualParameter AP;
public ActualParameterSequence APS;
}

@ -0,0 +1,34 @@
/*
* @(#)MultipleArrayAggregate.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class MultipleArrayAggregate extends ArrayAggregate {
public MultipleArrayAggregate(Expression eAST, ArrayAggregate aaAST,
SourcePosition thePosition) {
super(thePosition);
E = eAST;
AA = aaAST;
}
public Object visit(Visitor v, Object o) {
return v.visitMultipleArrayAggregate(this, o);
}
public Expression E;
public ArrayAggregate AA;
}

@ -0,0 +1,46 @@
/*
* @(#)MultipleFieldTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
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 Object visit(Visitor v, Object o) {
return v.visitMultipleFieldTypeDenoter(this, o);
}
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;
}

@ -0,0 +1,42 @@
/*
* @(#)MultipleFormalParameterSequence.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class MultipleFormalParameterSequence extends FormalParameterSequence {
public MultipleFormalParameterSequence(FormalParameter fpAST, FormalParameterSequence fpsAST,
SourcePosition thePosition) {
super(thePosition);
FP = fpAST;
FPS = fpsAST;
}
public Object visit(Visitor v, Object o) {
return v.visitMultipleFormalParameterSequence(this, o);
}
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;
}

@ -0,0 +1,36 @@
/*
* @(#)MultipleRecordAggregate.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
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 Object visit(Visitor v, Object o) {
return v.visitMultipleRecordAggregate(this, o);
}
public Identifier I;
public Expression E;
public RecordAggregate RA;
}

@ -0,0 +1,31 @@
/*
* @(#)Operator.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class Operator extends Terminal {
public Operator(String theSpelling, SourcePosition thePosition) {
super(theSpelling, thePosition);
decl = null;
}
public Object visit(Visitor v, Object o) {
return v.visitOperator(this, o);
}
public Declaration decl;
}

@ -0,0 +1,31 @@
/*
* @(#)ProcActualParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class ProcActualParameter extends ActualParameter {
public ProcActualParameter(Identifier iAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
}
public Object visit(Visitor v, Object o) {
return v.visitProcActualParameter(this, o);
}
public Identifier I;
}

@ -0,0 +1,36 @@
/*
* @(#)ProcDeclaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
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 Object visit(Visitor v, Object o) {
return v.visitProcDeclaration(this, o);
}
public Identifier I;
public FormalParameterSequence FPS;
public Command C;
}

@ -0,0 +1,42 @@
/*
* @(#)ProcFormalParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class ProcFormalParameter extends FormalParameter {
public ProcFormalParameter(Identifier iAST, FormalParameterSequence fpsAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
FPS = fpsAST;
}
public Object visit(Visitor v, Object o) {
return v.visitProcFormalParameter(this, o);
}
public Identifier I;
public FormalParameterSequence FPS;
public boolean equals(Object fpAST) {
if (fpAST instanceof ProcFormalParameter) {
ProcFormalParameter pfpAST = (ProcFormalParameter) fpAST;
return FPS.equals(pfpAST.FPS);
} else
return false;
}
}

@ -0,0 +1,31 @@
/*
* @(#)Program.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class Program extends AST {
public Program(Command cAST, SourcePosition thePosition) {
super(thePosition);
C = cAST;
}
public Object visit(Visitor v, Object o) {
return v.visitProgram(this, o);
}
public Command C;
}

@ -0,0 +1,27 @@
/*
* @(#)RecordAggregate.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class RecordAggregate extends AST {
public RecordAggregate(SourcePosition thePosition) {
super(thePosition);
type = null;
}
public FieldTypeDenoter type;
}

@ -0,0 +1,31 @@
/*
* @(#)RecordExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class RecordExpression extends Expression {
public RecordExpression(RecordAggregate raAST, SourcePosition thePosition) {
super(thePosition);
RA = raAST;
}
public Object visit(Visitor v, Object o) {
return v.visitRecordExpression(this, o);
}
public RecordAggregate RA;
}

@ -0,0 +1,40 @@
/*
* @(#)RecordTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class RecordTypeDenoter extends TypeDenoter {
public RecordTypeDenoter(FieldTypeDenoter ftAST, SourcePosition thePosition) {
super(thePosition);
FT = ftAST;
}
public Object visit(Visitor v, Object o) {
return v.visitRecordTypeDenoter(this, o);
}
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;
}

@ -0,0 +1,32 @@
/*
* @(#)SequentialCommand.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class SequentialCommand extends Command {
public SequentialCommand(Command c1AST, Command c2AST, SourcePosition thePosition) {
super(thePosition);
C1 = c1AST;
C2 = c2AST;
}
public Object visit(Visitor v, Object o) {
return v.visitSequentialCommand(this, o);
}
public Command C1, C2;
}

@ -0,0 +1,33 @@
/*
* @(#)SequentialDeclaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class SequentialDeclaration extends Declaration {
public SequentialDeclaration(Declaration d1AST, Declaration d2AST,
SourcePosition thePosition) {
super(thePosition);
D1 = d1AST;
D2 = d2AST;
}
public Object visit(Visitor v, Object o) {
return v.visitSequentialDeclaration(this, o);
}
public Declaration D1, D2;
}

@ -0,0 +1,35 @@
/*
* @(#)SimpleTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class SimpleTypeDenoter extends TypeDenoter {
public SimpleTypeDenoter(Identifier iAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
}
public Object visit(Visitor v, Object o) {
return v.visitSimpleTypeDenoter(this, o);
}
public boolean equals(Object obj) {
return false; // should not happen
}
public Identifier I;
}

@ -0,0 +1,31 @@
/*
* @(#)SimpleVname.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class SimpleVname extends Vname {
public SimpleVname(Identifier iAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
}
public Object visit(Visitor v, Object o) {
return v.visitSimpleVname(this, o);
}
public Identifier I;
}

@ -0,0 +1,32 @@
/*
* @(#)SingleActualParameterSequence.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleActualParameterSequence extends ActualParameterSequence {
public SingleActualParameterSequence(ActualParameter apAST,
SourcePosition thePosition) {
super(thePosition);
AP = apAST;
}
public Object visit(Visitor v, Object o) {
return v.visitSingleActualParameterSequence(this, o);
}
public ActualParameter AP;
}

@ -0,0 +1,32 @@
/*
* @(#)SingleArrayAggregate.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleArrayAggregate extends ArrayAggregate {
public SingleArrayAggregate(Expression eAST,
SourcePosition thePosition) {
super(thePosition);
E = eAST;
}
public Object visit(Visitor v, Object o) {
return v.visitSingleArrayAggregate(this, o);
}
public Expression E;
}

@ -0,0 +1,43 @@
/*
* @(#)SingleFieldTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleFieldTypeDenoter extends FieldTypeDenoter {
public SingleFieldTypeDenoter(Identifier iAST, TypeDenoter tAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
}
public Object visit(Visitor v, Object o) {
return v.visitSingleFieldTypeDenoter(this, o);
}
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;
}

@ -0,0 +1,40 @@
/*
* @(#)SingleFormalParameterSequence.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleFormalParameterSequence extends FormalParameterSequence {
public SingleFormalParameterSequence(FormalParameter fpAST,
SourcePosition thePosition) {
super(thePosition);
FP = fpAST;
}
public Object visit(Visitor v, Object o) {
return v.visitSingleFormalParameterSequence(this, o);
}
public boolean equals(Object fpsAST) {
if (fpsAST instanceof SingleFormalParameterSequence) {
SingleFormalParameterSequence sfpsAST = (SingleFormalParameterSequence) fpsAST;
return FP.equals(sfpsAST.FP);
} else
return false;
}
public FormalParameter FP;
}

@ -0,0 +1,34 @@
/*
* @(#)SingleRecordAggregate.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleRecordAggregate extends RecordAggregate {
public SingleRecordAggregate(Identifier iAST, Expression eAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
E = eAST;
}
public Object visit(Visitor v, Object o) {
return v.visitSingleRecordAggregate(this, o);
}
public Identifier I;
public Expression E;
}

@ -0,0 +1,33 @@
/*
* @(#)SubscriptVname.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class SubscriptVname extends Vname {
public SubscriptVname(Vname vAST, Expression eAST, SourcePosition thePosition) {
super(thePosition);
V = vAST;
E = eAST;
}
public Object visit(Visitor v, Object o) {
return v.visitSubscriptVname(this, o);
}
public Expression E;
public Vname V;
}

@ -0,0 +1,27 @@
/*
* @(#)Terminal.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
abstract public class Terminal extends AST {
public Terminal(String theSpelling, SourcePosition thePosition) {
super(thePosition);
spelling = theSpelling;
}
public String spelling;
}

@ -0,0 +1,34 @@
/*
* @(#)TypeDeclaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class TypeDeclaration extends Declaration {
public TypeDeclaration(Identifier iAST, TypeDenoter tAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
}
public Object visit(Visitor v, Object o) {
return v.visitTypeDeclaration(this, o);
}
public Identifier I;
public TypeDenoter T;
}

@ -0,0 +1,27 @@
/*
* @(#)TypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class TypeDenoter extends AST {
public TypeDenoter(SourcePosition thePosition) {
super(thePosition);
}
public abstract boolean equals(Object obj);
}

@ -0,0 +1,34 @@
/*
* @(#)UnaryExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class UnaryExpression extends Expression {
public UnaryExpression(Operator oAST, Expression eAST,
SourcePosition thePosition) {
super(thePosition);
O = oAST;
E = eAST;
}
public Object visit(Visitor v, Object o) {
return v.visitUnaryExpression(this, o);
}
public Expression E;
public Operator O;
}

@ -0,0 +1,35 @@
/*
* @(#)UnaryOperatorDeclaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
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 Object visit(Visitor v, Object o) {
return v.visitUnaryOperatorDeclaration(this, o);
}
public Operator O;
public TypeDenoter ARG, RES;
}

@ -0,0 +1,31 @@
/*
* @(#)VarActualParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class VarActualParameter extends ActualParameter {
public VarActualParameter(Vname vAST, SourcePosition thePosition) {
super(thePosition);
V = vAST;
}
public Object visit(Visitor v, Object o) {
return v.visitVarActualParameter(this, o);
}
public Vname V;
}

@ -0,0 +1,34 @@
/*
* @(#)VarDeclaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class VarDeclaration extends Declaration {
public VarDeclaration(Identifier iAST, TypeDenoter tAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
}
public Object visit(Visitor v, Object o) {
return v.visitVarDeclaration(this, o);
}
public Identifier I;
public TypeDenoter T;
}

@ -0,0 +1,42 @@
/*
* @(#)ValFormalParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class VarFormalParameter extends FormalParameter {
public VarFormalParameter(Identifier iAST, TypeDenoter tAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
}
public Object visit(Visitor v, Object o) {
return v.visitVarFormalParameter(this, o);
}
public Identifier I;
public TypeDenoter T;
public boolean equals(Object fpAST) {
if (fpAST instanceof VarFormalParameter) {
VarFormalParameter vfpAST = (VarFormalParameter) fpAST;
return T.equals(vfpAST.T);
} else
return false;
}
}

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

@ -0,0 +1,30 @@
/*
* @(#)Vname.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public abstract class Vname extends AST {
public Vname(SourcePosition thePosition) {
super(thePosition);
variable = false;
type = null;
}
public boolean variable, indexed;
public int offset;
public TypeDenoter type;
}

@ -0,0 +1,31 @@
/*
* @(#)VnameExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class VnameExpression extends Expression {
public VnameExpression(Vname vAST, SourcePosition thePosition) {
super(thePosition);
V = vAST;
}
public Object visit(Visitor v, Object o) {
return v.visitVnameExpression(this, o);
}
public Vname V;
}

@ -0,0 +1,33 @@
/*
* @(#)WhileCommand.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.AbstractSyntaxTrees;
import Triangle.SyntacticAnalyzer.SourcePosition;
public class WhileCommand extends Command {
public WhileCommand(Expression eAST, Command cAST, SourcePosition thePosition) {
super(thePosition);
E = eAST;
C = cAST;
}
public Object visit(Visitor v, Object o) {
return v.visitWhileCommand(this, o);
}
public Expression E;
public Command C;
}

@ -0,0 +1,983 @@
/*
* @(#)Encoder.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.CodeGenerator;
import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import Triangle.ErrorReporter;
import Triangle.StdEnvironment;
import Triangle.AbstractMachine.Instruction;
import Triangle.AbstractMachine.Machine;
import Triangle.AbstractSyntaxTrees.AST;
import Triangle.AbstractSyntaxTrees.AnyTypeDenoter;
import Triangle.AbstractSyntaxTrees.ArrayExpression;
import Triangle.AbstractSyntaxTrees.ArrayTypeDenoter;
import Triangle.AbstractSyntaxTrees.AssignCommand;
import Triangle.AbstractSyntaxTrees.BinaryExpression;
import Triangle.AbstractSyntaxTrees.BinaryOperatorDeclaration;
import Triangle.AbstractSyntaxTrees.BoolTypeDenoter;
import Triangle.AbstractSyntaxTrees.CallCommand;
import Triangle.AbstractSyntaxTrees.CallExpression;
import Triangle.AbstractSyntaxTrees.CharTypeDenoter;
import Triangle.AbstractSyntaxTrees.CharacterExpression;
import Triangle.AbstractSyntaxTrees.CharacterLiteral;
import Triangle.AbstractSyntaxTrees.ConstActualParameter;
import Triangle.AbstractSyntaxTrees.ConstDeclaration;
import Triangle.AbstractSyntaxTrees.ConstFormalParameter;
import Triangle.AbstractSyntaxTrees.Declaration;
import Triangle.AbstractSyntaxTrees.DotVname;
import Triangle.AbstractSyntaxTrees.EmptyActualParameterSequence;
import Triangle.AbstractSyntaxTrees.EmptyCommand;
import Triangle.AbstractSyntaxTrees.EmptyExpression;
import Triangle.AbstractSyntaxTrees.EmptyFormalParameterSequence;
import Triangle.AbstractSyntaxTrees.ErrorTypeDenoter;
import Triangle.AbstractSyntaxTrees.FuncActualParameter;
import Triangle.AbstractSyntaxTrees.FuncDeclaration;
import Triangle.AbstractSyntaxTrees.FuncFormalParameter;
import Triangle.AbstractSyntaxTrees.Identifier;
import Triangle.AbstractSyntaxTrees.IfCommand;
import Triangle.AbstractSyntaxTrees.IfExpression;
import Triangle.AbstractSyntaxTrees.IntTypeDenoter;
import Triangle.AbstractSyntaxTrees.IntegerExpression;
import Triangle.AbstractSyntaxTrees.IntegerLiteral;
import Triangle.AbstractSyntaxTrees.LetCommand;
import Triangle.AbstractSyntaxTrees.LetExpression;
import Triangle.AbstractSyntaxTrees.MultipleActualParameterSequence;
import Triangle.AbstractSyntaxTrees.MultipleArrayAggregate;
import Triangle.AbstractSyntaxTrees.MultipleFieldTypeDenoter;
import Triangle.AbstractSyntaxTrees.MultipleFormalParameterSequence;
import Triangle.AbstractSyntaxTrees.MultipleRecordAggregate;
import Triangle.AbstractSyntaxTrees.Operator;
import Triangle.AbstractSyntaxTrees.ProcActualParameter;
import Triangle.AbstractSyntaxTrees.ProcDeclaration;
import Triangle.AbstractSyntaxTrees.ProcFormalParameter;
import Triangle.AbstractSyntaxTrees.Program;
import Triangle.AbstractSyntaxTrees.RecordExpression;
import Triangle.AbstractSyntaxTrees.RecordTypeDenoter;
import Triangle.AbstractSyntaxTrees.SequentialCommand;
import Triangle.AbstractSyntaxTrees.SequentialDeclaration;
import Triangle.AbstractSyntaxTrees.SimpleTypeDenoter;
import Triangle.AbstractSyntaxTrees.SimpleVname;
import Triangle.AbstractSyntaxTrees.SingleActualParameterSequence;
import Triangle.AbstractSyntaxTrees.SingleArrayAggregate;
import Triangle.AbstractSyntaxTrees.SingleFieldTypeDenoter;
import Triangle.AbstractSyntaxTrees.SingleFormalParameterSequence;
import Triangle.AbstractSyntaxTrees.SingleRecordAggregate;
import Triangle.AbstractSyntaxTrees.SubscriptVname;
import Triangle.AbstractSyntaxTrees.TypeDeclaration;
import Triangle.AbstractSyntaxTrees.UnaryExpression;
import Triangle.AbstractSyntaxTrees.UnaryOperatorDeclaration;
import Triangle.AbstractSyntaxTrees.VarActualParameter;
import Triangle.AbstractSyntaxTrees.VarDeclaration;
import Triangle.AbstractSyntaxTrees.VarFormalParameter;
import Triangle.AbstractSyntaxTrees.Visitor;
import Triangle.AbstractSyntaxTrees.Vname;
import Triangle.AbstractSyntaxTrees.VnameExpression;
import Triangle.AbstractSyntaxTrees.WhileCommand;
public final class Encoder implements Visitor {
// Commands
public Object visitAssignCommand(AssignCommand ast, Object o) {
Frame frame = (Frame) o;
Integer valSize = (Integer) ast.E.visit(this, frame);
encodeStore(ast.V, new Frame(frame, valSize.intValue()),
valSize.intValue());
return null;
}
public Object visitCallCommand(CallCommand ast, Object o) {
Frame frame = (Frame) o;
Integer argsSize = (Integer) ast.APS.visit(this, frame);
ast.I.visit(this, new Frame(frame.level, argsSize));
return null;
}
public Object visitEmptyCommand(EmptyCommand ast, Object o) {
return null;
}
public Object visitIfCommand(IfCommand ast, Object o) {
Frame frame = (Frame) o;
int jumpifAddr, jumpAddr;
Integer valSize = (Integer) ast.E.visit(this, frame);
jumpifAddr = nextInstrAddr;
emit(Machine.JUMPIFop, Machine.falseRep, Machine.CBr, 0);
ast.C1.visit(this, frame);
jumpAddr = nextInstrAddr;
emit(Machine.JUMPop, 0, Machine.CBr, 0);
patch(jumpifAddr, nextInstrAddr);
ast.C2.visit(this, frame);
patch(jumpAddr, nextInstrAddr);
return null;
}
public Object visitLetCommand(LetCommand ast, Object o) {
Frame frame = (Frame) o;
int extraSize = ((Integer) ast.D.visit(this, frame)).intValue();
ast.C.visit(this, new Frame(frame, extraSize));
if (extraSize > 0)
emit(Machine.POPop, 0, 0, extraSize);
return null;
}
public Object visitSequentialCommand(SequentialCommand ast, Object o) {
ast.C1.visit(this, o);
ast.C2.visit(this, o);
return null;
}
public Object visitWhileCommand(WhileCommand ast, Object o) {
Frame frame = (Frame) o;
int jumpAddr, loopAddr;
jumpAddr = nextInstrAddr;
emit(Machine.JUMPop, 0, Machine.CBr, 0);
loopAddr = nextInstrAddr;
ast.C.visit(this, frame);
patch(jumpAddr, nextInstrAddr);
ast.E.visit(this, frame);
emit(Machine.JUMPIFop, Machine.trueRep, Machine.CBr, loopAddr);
return null;
}
// Expressions
public Object visitArrayExpression(ArrayExpression ast, Object o) {
ast.type.visit(this, null);
return ast.AA.visit(this, o);
}
public Object visitBinaryExpression(BinaryExpression ast, Object o) {
Frame frame = (Frame) o;
Integer valSize = (Integer) ast.type.visit(this, null);
int valSize1 = ((Integer) ast.E1.visit(this, frame)).intValue();
Frame frame1 = new Frame(frame, valSize1);
int valSize2 = ((Integer) ast.E2.visit(this, frame1)).intValue();
Frame frame2 = new Frame(frame.level, valSize1 + valSize2);
ast.O.visit(this, frame2);
return valSize;
}
public Object visitCallExpression(CallExpression ast, Object o) {
Frame frame = (Frame) o;
Integer valSize = (Integer) ast.type.visit(this, null);
Integer argsSize = (Integer) ast.APS.visit(this, frame);
ast.I.visit(this, new Frame(frame.level, argsSize));
return valSize;
}
public Object visitCharacterExpression(CharacterExpression ast,
Object o) {
Frame frame = (Frame) o;
Integer valSize = (Integer) ast.type.visit(this, null);
emit(Machine.LOADLop, 0, 0, ast.CL.spelling.charAt(1));
return valSize;
}
public Object visitEmptyExpression(EmptyExpression ast, Object o) {
return new Integer(0);
}
public Object visitIfExpression(IfExpression ast, Object o) {
Frame frame = (Frame) o;
Integer valSize;
int jumpifAddr, jumpAddr;
ast.type.visit(this, null);
ast.E1.visit(this, frame);
jumpifAddr = nextInstrAddr;
emit(Machine.JUMPIFop, Machine.falseRep, Machine.CBr, 0);
valSize = (Integer) ast.E2.visit(this, frame);
jumpAddr = nextInstrAddr;
emit(Machine.JUMPop, 0, Machine.CBr, 0);
patch(jumpifAddr, nextInstrAddr);
valSize = (Integer) ast.E3.visit(this, frame);
patch(jumpAddr, nextInstrAddr);
return valSize;
}
public Object visitIntegerExpression(IntegerExpression ast, Object o) {
Frame frame = (Frame) o;
Integer valSize = (Integer) ast.type.visit(this, null);
emit(Machine.LOADLop, 0, 0, Integer.parseInt(ast.IL.spelling));
return valSize;
}
public Object visitLetExpression(LetExpression ast, Object o) {
Frame frame = (Frame) o;
ast.type.visit(this, null);
int extraSize = ((Integer) ast.D.visit(this, frame)).intValue();
Frame frame1 = new Frame(frame, extraSize);
Integer valSize = (Integer) ast.E.visit(this, frame1);
if (extraSize > 0)
emit(Machine.POPop, valSize.intValue(), 0, extraSize);
return valSize;
}
public Object visitRecordExpression(RecordExpression ast, Object o) {
ast.type.visit(this, null);
return ast.RA.visit(this, o);
}
public Object visitUnaryExpression(UnaryExpression ast, Object o) {
Frame frame = (Frame) o;
Integer valSize = (Integer) ast.type.visit(this, null);
ast.E.visit(this, frame);
ast.O.visit(this, new Frame(frame.level, valSize.intValue()));
return valSize;
}
public Object visitVnameExpression(VnameExpression ast, Object o) {
Frame frame = (Frame) o;
Integer valSize = (Integer) ast.type.visit(this, null);
encodeFetch(ast.V, frame, valSize.intValue());
return valSize;
}
// Declarations
public Object visitBinaryOperatorDeclaration(BinaryOperatorDeclaration ast,
Object o) {
return new Integer(0);
}
public Object visitConstDeclaration(ConstDeclaration ast, Object o) {
Frame frame = (Frame) o;
int extraSize = 0;
if (ast.E instanceof CharacterExpression) {
CharacterLiteral CL = ((CharacterExpression) ast.E).CL;
ast.entity = new KnownValue(Machine.characterSize,
characterValuation(CL.spelling));
} else if (ast.E instanceof IntegerExpression) {
IntegerLiteral IL = ((IntegerExpression) ast.E).IL;
ast.entity = new KnownValue(Machine.integerSize,
Integer.parseInt(IL.spelling));
} else {
int valSize = ((Integer) ast.E.visit(this, frame)).intValue();
ast.entity = new UnknownValue(valSize, frame.level, frame.size);
extraSize = valSize;
}
writeTableDetails(ast);
return new Integer(extraSize);
}
public Object visitFuncDeclaration(FuncDeclaration ast, Object o) {
Frame frame = (Frame) o;
int jumpAddr = nextInstrAddr;
int argsSize = 0, valSize = 0;
emit(Machine.JUMPop, 0, Machine.CBr, 0);
ast.entity = new KnownRoutine(Machine.closureSize, frame.level, nextInstrAddr);
writeTableDetails(ast);
if (frame.level == Machine.maxRoutineLevel)
reporter.reportRestriction("can't nest routines more than 7 deep");
else {
Frame frame1 = new Frame(frame.level + 1, 0);
argsSize = ((Integer) ast.FPS.visit(this, frame1)).intValue();
Frame frame2 = new Frame(frame.level + 1, Machine.linkDataSize);
valSize = ((Integer) ast.E.visit(this, frame2)).intValue();
}
emit(Machine.RETURNop, valSize, 0, argsSize);
patch(jumpAddr, nextInstrAddr);
return new Integer(0);
}
public Object visitProcDeclaration(ProcDeclaration ast, Object o) {
Frame frame = (Frame) o;
int jumpAddr = nextInstrAddr;
int argsSize = 0;
emit(Machine.JUMPop, 0, Machine.CBr, 0);
ast.entity = new KnownRoutine(Machine.closureSize, frame.level,
nextInstrAddr);
writeTableDetails(ast);
if (frame.level == Machine.maxRoutineLevel)
reporter.reportRestriction("can't nest routines so deeply");
else {
Frame frame1 = new Frame(frame.level + 1, 0);
argsSize = ((Integer) ast.FPS.visit(this, frame1)).intValue();
Frame frame2 = new Frame(frame.level + 1, Machine.linkDataSize);
ast.C.visit(this, frame2);
}
emit(Machine.RETURNop, 0, 0, argsSize);
patch(jumpAddr, nextInstrAddr);
return new Integer(0);
}
public Object visitSequentialDeclaration(SequentialDeclaration ast, Object o) {
Frame frame = (Frame) o;
int extraSize1, extraSize2;
extraSize1 = ((Integer) ast.D1.visit(this, frame)).intValue();
Frame frame1 = new Frame(frame, extraSize1);
extraSize2 = ((Integer) ast.D2.visit(this, frame1)).intValue();
return new Integer(extraSize1 + extraSize2);
}
public Object visitTypeDeclaration(TypeDeclaration ast, Object o) {
// just to ensure the type's representation is decided
ast.T.visit(this, null);
return new Integer(0);
}
public Object visitUnaryOperatorDeclaration(UnaryOperatorDeclaration ast,
Object o) {
return new Integer(0);
}
public Object visitVarDeclaration(VarDeclaration ast, Object o) {
Frame frame = (Frame) o;
int extraSize;
extraSize = ((Integer) ast.T.visit(this, null)).intValue();
emit(Machine.PUSHop, 0, 0, extraSize);
ast.entity = new KnownAddress(Machine.addressSize, frame.level, frame.size);
writeTableDetails(ast);
return new Integer(extraSize);
}
// Array Aggregates
public Object visitMultipleArrayAggregate(MultipleArrayAggregate ast,
Object o) {
Frame frame = (Frame) o;
int elemSize = ((Integer) ast.E.visit(this, frame)).intValue();
Frame frame1 = new Frame(frame, elemSize);
int arraySize = ((Integer) ast.AA.visit(this, frame1)).intValue();
return new Integer(elemSize + arraySize);
}
public Object visitSingleArrayAggregate(SingleArrayAggregate ast, Object o) {
return ast.E.visit(this, o);
}
// Record Aggregates
public Object visitMultipleRecordAggregate(MultipleRecordAggregate ast,
Object o) {
Frame frame = (Frame) o;
int fieldSize = ((Integer) ast.E.visit(this, frame)).intValue();
Frame frame1 = new Frame(frame, fieldSize);
int recordSize = ((Integer) ast.RA.visit(this, frame1)).intValue();
return new Integer(fieldSize + recordSize);
}
public Object visitSingleRecordAggregate(SingleRecordAggregate ast,
Object o) {
return ast.E.visit(this, o);
}
// Formal Parameters
public Object visitConstFormalParameter(ConstFormalParameter ast, Object o) {
Frame frame = (Frame) o;
int valSize = ((Integer) ast.T.visit(this, null)).intValue();
ast.entity = new UnknownValue(valSize, frame.level, -frame.size - valSize);
writeTableDetails(ast);
return new Integer(valSize);
}
public Object visitFuncFormalParameter(FuncFormalParameter ast, Object o) {
Frame frame = (Frame) o;
int argsSize = Machine.closureSize;
ast.entity = new UnknownRoutine(Machine.closureSize, frame.level,
-frame.size - argsSize);
writeTableDetails(ast);
return new Integer(argsSize);
}
public Object visitProcFormalParameter(ProcFormalParameter ast, Object o) {
Frame frame = (Frame) o;
int argsSize = Machine.closureSize;
ast.entity = new UnknownRoutine(Machine.closureSize, frame.level,
-frame.size - argsSize);
writeTableDetails(ast);
return new Integer(argsSize);
}
public Object visitVarFormalParameter(VarFormalParameter ast, Object o) {
Frame frame = (Frame) o;
ast.T.visit(this, null);
ast.entity = new UnknownAddress(Machine.addressSize, frame.level,
-frame.size - Machine.addressSize);
writeTableDetails(ast);
return new Integer(Machine.addressSize);
}
public Object visitEmptyFormalParameterSequence(
EmptyFormalParameterSequence ast, Object o) {
return new Integer(0);
}
public Object visitMultipleFormalParameterSequence(
MultipleFormalParameterSequence ast, Object o) {
Frame frame = (Frame) o;
int argsSize1 = ((Integer) ast.FPS.visit(this, frame)).intValue();
Frame frame1 = new Frame(frame, argsSize1);
int argsSize2 = ((Integer) ast.FP.visit(this, frame1)).intValue();
return new Integer(argsSize1 + argsSize2);
}
public Object visitSingleFormalParameterSequence(
SingleFormalParameterSequence ast, Object o) {
return ast.FP.visit(this, o);
}
// Actual Parameters
public Object visitConstActualParameter(ConstActualParameter ast, Object o) {
return ast.E.visit(this, o);
}
public Object visitFuncActualParameter(FuncActualParameter ast, Object o) {
Frame frame = (Frame) o;
if (ast.I.decl.entity instanceof KnownRoutine) {
ObjectAddress address = ((KnownRoutine) ast.I.decl.entity).address;
// static link, code address
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level), 0);
emit(Machine.LOADAop, 0, Machine.CBr, address.displacement);
} else if (ast.I.decl.entity instanceof UnknownRoutine) {
ObjectAddress address = ((UnknownRoutine) ast.I.decl.entity).address;
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level,
address.level), address.displacement);
} else if (ast.I.decl.entity instanceof PrimitiveRoutine) {
int displacement = ((PrimitiveRoutine) ast.I.decl.entity).displacement;
// static link, code address
emit(Machine.LOADAop, 0, Machine.SBr, 0);
emit(Machine.LOADAop, 0, Machine.PBr, displacement);
}
return new Integer(Machine.closureSize);
}
public Object visitProcActualParameter(ProcActualParameter ast, Object o) {
Frame frame = (Frame) o;
if (ast.I.decl.entity instanceof KnownRoutine) {
ObjectAddress address = ((KnownRoutine) ast.I.decl.entity).address;
// static link, code address
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level), 0);
emit(Machine.LOADAop, 0, Machine.CBr, address.displacement);
} else if (ast.I.decl.entity instanceof UnknownRoutine) {
ObjectAddress address = ((UnknownRoutine) ast.I.decl.entity).address;
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level,
address.level), address.displacement);
} else if (ast.I.decl.entity instanceof PrimitiveRoutine) {
int displacement = ((PrimitiveRoutine) ast.I.decl.entity).displacement;
// static link, code address
emit(Machine.LOADAop, 0, Machine.SBr, 0);
emit(Machine.LOADAop, 0, Machine.PBr, displacement);
}
return new Integer(Machine.closureSize);
}
public Object visitVarActualParameter(VarActualParameter ast, Object o) {
encodeFetchAddress(ast.V, (Frame) o);
return new Integer(Machine.addressSize);
}
public Object visitEmptyActualParameterSequence(
EmptyActualParameterSequence ast, Object o) {
return new Integer(0);
}
public Object visitMultipleActualParameterSequence(
MultipleActualParameterSequence ast, Object o) {
Frame frame = (Frame) o;
int argsSize1 = ((Integer) ast.AP.visit(this, frame)).intValue();
Frame frame1 = new Frame(frame, argsSize1);
int argsSize2 = ((Integer) ast.APS.visit(this, frame1)).intValue();
return new Integer(argsSize1 + argsSize2);
}
public Object visitSingleActualParameterSequence(
SingleActualParameterSequence ast, Object o) {
return ast.AP.visit(this, o);
}
// Type Denoters
public Object visitAnyTypeDenoter(AnyTypeDenoter ast, Object o) {
return new Integer(0);
}
public Object visitArrayTypeDenoter(ArrayTypeDenoter ast, Object o) {
int typeSize;
if (ast.entity == null) {
int elemSize = ((Integer) ast.T.visit(this, null)).intValue();
typeSize = Integer.parseInt(ast.IL.spelling) * elemSize;
ast.entity = new TypeRepresentation(typeSize);
writeTableDetails(ast);
} else
typeSize = ast.entity.size;
return new Integer(typeSize);
}
public Object visitBoolTypeDenoter(BoolTypeDenoter ast, Object o) {
if (ast.entity == null) {
ast.entity = new TypeRepresentation(Machine.booleanSize);
writeTableDetails(ast);
}
return new Integer(Machine.booleanSize);
}
public Object visitCharTypeDenoter(CharTypeDenoter ast, Object o) {
if (ast.entity == null) {
ast.entity = new TypeRepresentation(Machine.characterSize);
writeTableDetails(ast);
}
return new Integer(Machine.characterSize);
}
public Object visitErrorTypeDenoter(ErrorTypeDenoter ast, Object o) {
return new Integer(0);
}
public Object visitSimpleTypeDenoter(SimpleTypeDenoter ast,
Object o) {
return new Integer(0);
}
public Object visitIntTypeDenoter(IntTypeDenoter ast, Object o) {
if (ast.entity == null) {
ast.entity = new TypeRepresentation(Machine.integerSize);
writeTableDetails(ast);
}
return new Integer(Machine.integerSize);
}
public Object visitRecordTypeDenoter(RecordTypeDenoter ast, Object o) {
int typeSize;
if (ast.entity == null) {
typeSize = ((Integer) ast.FT.visit(this, new Integer(0))).intValue();
ast.entity = new TypeRepresentation(typeSize);
writeTableDetails(ast);
} else
typeSize = ast.entity.size;
return new Integer(typeSize);
}
public Object visitMultipleFieldTypeDenoter(MultipleFieldTypeDenoter ast,
Object o) {
int offset = ((Integer) o).intValue();
int fieldSize;
if (ast.entity == null) {
fieldSize = ((Integer) ast.T.visit(this, null)).intValue();
ast.entity = new Field(fieldSize, offset);
writeTableDetails(ast);
} else
fieldSize = ast.entity.size;
Integer offset1 = new Integer(offset + fieldSize);
int recSize = ((Integer) ast.FT.visit(this, offset1)).intValue();
return new Integer(fieldSize + recSize);
}
public Object visitSingleFieldTypeDenoter(SingleFieldTypeDenoter ast,
Object o) {
int offset = ((Integer) o).intValue();
int fieldSize;
if (ast.entity == null) {
fieldSize = ((Integer) ast.T.visit(this, null)).intValue();
ast.entity = new Field(fieldSize, offset);
writeTableDetails(ast);
} else
fieldSize = ast.entity.size;
return new Integer(fieldSize);
}
// Literals, Identifiers and Operators
public Object visitCharacterLiteral(CharacterLiteral ast, Object o) {
return null;
}
public Object visitIdentifier(Identifier ast, Object o) {
Frame frame = (Frame) o;
if (ast.decl.entity instanceof KnownRoutine) {
ObjectAddress address = ((KnownRoutine) ast.decl.entity).address;
emit(Machine.CALLop, displayRegister(frame.level, address.level),
Machine.CBr, address.displacement);
} else if (ast.decl.entity instanceof UnknownRoutine) {
ObjectAddress address = ((UnknownRoutine) ast.decl.entity).address;
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level,
address.level), address.displacement);
emit(Machine.CALLIop, 0, 0, 0);
} else if (ast.decl.entity instanceof PrimitiveRoutine) {
int displacement = ((PrimitiveRoutine) ast.decl.entity).displacement;
if (displacement != Machine.idDisplacement)
emit(Machine.CALLop, Machine.SBr, Machine.PBr, displacement);
} else if (ast.decl.entity instanceof EqualityRoutine) { // "=" or "\="
int displacement = ((EqualityRoutine) ast.decl.entity).displacement;
emit(Machine.LOADLop, 0, 0, frame.size / 2);
emit(Machine.CALLop, Machine.SBr, Machine.PBr, displacement);
}
return null;
}
public Object visitIntegerLiteral(IntegerLiteral ast, Object o) {
return null;
}
public Object visitOperator(Operator ast, Object o) {
Frame frame = (Frame) o;
if (ast.decl.entity instanceof KnownRoutine) {
ObjectAddress address = ((KnownRoutine) ast.decl.entity).address;
emit(Machine.CALLop, displayRegister(frame.level, address.level),
Machine.CBr, address.displacement);
} else if (ast.decl.entity instanceof UnknownRoutine) {
ObjectAddress address = ((UnknownRoutine) ast.decl.entity).address;
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level,
address.level), address.displacement);
emit(Machine.CALLIop, 0, 0, 0);
} else if (ast.decl.entity instanceof PrimitiveRoutine) {
int displacement = ((PrimitiveRoutine) ast.decl.entity).displacement;
if (displacement != Machine.idDisplacement)
emit(Machine.CALLop, Machine.SBr, Machine.PBr, displacement);
} else if (ast.decl.entity instanceof EqualityRoutine) { // "=" or "\="
int displacement = ((EqualityRoutine) ast.decl.entity).displacement;
emit(Machine.LOADLop, 0, 0, frame.size / 2);
emit(Machine.CALLop, Machine.SBr, Machine.PBr, displacement);
}
return null;
}
// Value-or-variable names
public Object visitDotVname(DotVname ast, Object o) {
Frame frame = (Frame) o;
RuntimeEntity baseObject = (RuntimeEntity) ast.V.visit(this, frame);
ast.offset = ast.V.offset + ((Field) ast.I.decl.entity).fieldOffset;
// I.decl points to the appropriate record field
ast.indexed = ast.V.indexed;
return baseObject;
}
public Object visitSimpleVname(SimpleVname ast, Object o) {
ast.offset = 0;
ast.indexed = false;
return ast.I.decl.entity;
}
public Object visitSubscriptVname(SubscriptVname ast, Object o) {
Frame frame = (Frame) o;
RuntimeEntity baseObject;
int elemSize, indexSize;
baseObject = (RuntimeEntity) ast.V.visit(this, frame);
ast.offset = ast.V.offset;
ast.indexed = ast.V.indexed;
elemSize = ((Integer) ast.type.visit(this, null)).intValue();
if (ast.E instanceof IntegerExpression) {
IntegerLiteral IL = ((IntegerExpression) ast.E).IL;
ast.offset = ast.offset + Integer.parseInt(IL.spelling) * elemSize;
} else {
// v-name is indexed by a proper expression, not a literal
if (ast.indexed)
frame.size = frame.size + Machine.integerSize;
indexSize = ((Integer) ast.E.visit(this, frame)).intValue();
if (elemSize != 1) {
emit(Machine.LOADLop, 0, 0, elemSize);
emit(Machine.CALLop, Machine.SBr, Machine.PBr,
Machine.multDisplacement);
}
if (ast.indexed)
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
else
ast.indexed = true;
}
return baseObject;
}
// Programs
public Object visitProgram(Program ast, Object o) {
return ast.C.visit(this, o);
}
public Encoder(ErrorReporter reporter) {
this.reporter = reporter;
nextInstrAddr = Machine.CB;
elaborateStdEnvironment();
}
private ErrorReporter reporter;
// Generates code to run a program.
// showingTable is true iff entity description details
// are to be displayed.
public final void encodeRun(Program theAST, boolean showingTable) {
tableDetailsReqd = showingTable;
// startCodeGeneration();
theAST.visit(this, new Frame(0, 0));
emit(Machine.HALTop, 0, 0, 0);
}
// Decides run-time representation of a standard constant.
private final void elaborateStdConst(Declaration constDeclaration,
int value) {
if (constDeclaration instanceof ConstDeclaration) {
ConstDeclaration decl = (ConstDeclaration) constDeclaration;
int typeSize = ((Integer) decl.E.type.visit(this, null)).intValue();
decl.entity = new KnownValue(typeSize, value);
writeTableDetails(constDeclaration);
}
}
// Decides run-time representation of a standard routine.
private final void elaborateStdPrimRoutine(Declaration routineDeclaration,
int routineOffset) {
routineDeclaration.entity = new PrimitiveRoutine(Machine.closureSize, routineOffset);
writeTableDetails(routineDeclaration);
}
private final void elaborateStdEqRoutine(Declaration routineDeclaration,
int routineOffset) {
routineDeclaration.entity = new EqualityRoutine(Machine.closureSize, routineOffset);
writeTableDetails(routineDeclaration);
}
private final void elaborateStdRoutine(Declaration routineDeclaration,
int routineOffset) {
routineDeclaration.entity = new KnownRoutine(Machine.closureSize, 0, routineOffset);
writeTableDetails(routineDeclaration);
}
private final void elaborateStdEnvironment() {
tableDetailsReqd = false;
elaborateStdConst(StdEnvironment.falseDecl, Machine.falseRep);
elaborateStdConst(StdEnvironment.trueDecl, Machine.trueRep);
elaborateStdPrimRoutine(StdEnvironment.notDecl, Machine.notDisplacement);
elaborateStdPrimRoutine(StdEnvironment.andDecl, Machine.andDisplacement);
elaborateStdPrimRoutine(StdEnvironment.orDecl, Machine.orDisplacement);
elaborateStdConst(StdEnvironment.maxintDecl, Machine.maxintRep);
elaborateStdPrimRoutine(StdEnvironment.addDecl, Machine.addDisplacement);
elaborateStdPrimRoutine(StdEnvironment.subtractDecl, Machine.subDisplacement);
elaborateStdPrimRoutine(StdEnvironment.multiplyDecl, Machine.multDisplacement);
elaborateStdPrimRoutine(StdEnvironment.divideDecl, Machine.divDisplacement);
elaborateStdPrimRoutine(StdEnvironment.moduloDecl, Machine.modDisplacement);
elaborateStdPrimRoutine(StdEnvironment.lessDecl, Machine.ltDisplacement);
elaborateStdPrimRoutine(StdEnvironment.notgreaterDecl, Machine.leDisplacement);
elaborateStdPrimRoutine(StdEnvironment.greaterDecl, Machine.gtDisplacement);
elaborateStdPrimRoutine(StdEnvironment.notlessDecl, Machine.geDisplacement);
elaborateStdPrimRoutine(StdEnvironment.chrDecl, Machine.idDisplacement);
elaborateStdPrimRoutine(StdEnvironment.ordDecl, Machine.idDisplacement);
elaborateStdPrimRoutine(StdEnvironment.eolDecl, Machine.eolDisplacement);
elaborateStdPrimRoutine(StdEnvironment.eofDecl, Machine.eofDisplacement);
elaborateStdPrimRoutine(StdEnvironment.getDecl, Machine.getDisplacement);
elaborateStdPrimRoutine(StdEnvironment.putDecl, Machine.putDisplacement);
elaborateStdPrimRoutine(StdEnvironment.getintDecl, Machine.getintDisplacement);
elaborateStdPrimRoutine(StdEnvironment.putintDecl, Machine.putintDisplacement);
elaborateStdPrimRoutine(StdEnvironment.geteolDecl, Machine.geteolDisplacement);
elaborateStdPrimRoutine(StdEnvironment.puteolDecl, Machine.puteolDisplacement);
elaborateStdEqRoutine(StdEnvironment.equalDecl, Machine.eqDisplacement);
elaborateStdEqRoutine(StdEnvironment.unequalDecl, Machine.neDisplacement);
}
// Saves the object program in the named file.
public void saveObjectProgram(String objectName) {
FileOutputStream objectFile = null;
DataOutputStream objectStream = null;
int addr;
try {
objectFile = new FileOutputStream(objectName);
objectStream = new DataOutputStream(objectFile);
addr = Machine.CB;
for (addr = Machine.CB; addr < nextInstrAddr; addr++)
Machine.code[addr].write(objectStream);
objectFile.close();
} catch (FileNotFoundException s) {
System.err.println("Error opening object file: " + s);
} catch (IOException s) {
System.err.println("Error writing object file: " + s);
}
}
boolean tableDetailsReqd;
public static void writeTableDetails(AST ast) {
}
// OBJECT CODE
// Implementation notes:
// Object code is generated directly into the TAM Code Store, starting at CB.
// The address of the next instruction is held in nextInstrAddr.
private int nextInstrAddr;
// Appends an instruction, with the given fields, to the object code.
private void emit(int op, int n, int r, int d) {
Instruction nextInstr = new Instruction();
if (n > 255) {
reporter.reportRestriction("length of operand can't exceed 255 words");
n = 255; // to allow code generation to continue
}
nextInstr.op = op;
nextInstr.n = n;
nextInstr.r = r;
nextInstr.d = d;
if (nextInstrAddr == Machine.PB)
reporter.reportRestriction("too many instructions for code segment");
else {
Machine.code[nextInstrAddr] = nextInstr;
nextInstrAddr = nextInstrAddr + 1;
}
}
// Patches the d-field of the instruction at address addr.
private void patch(int addr, int d) {
Machine.code[addr].d = d;
}
// DATA REPRESENTATION
public int characterValuation(String spelling) {
// Returns the machine representation of the given character literal.
return spelling.charAt(1);
// since the character literal is of the form 'x'}
}
// REGISTERS
// Returns the register number appropriate for object code at currentLevel
// to address a data object at objectLevel.
private int displayRegister(int currentLevel, int objectLevel) {
if (objectLevel == 0)
return Machine.SBr;
else if (currentLevel - objectLevel <= 6)
return Machine.LBr + currentLevel - objectLevel; // LBr|L1r|...|L6r
else {
reporter.reportRestriction("can't access data more than 6 levels out");
return Machine.L6r; // to allow code generation to continue
}
}
// Generates code to fetch the value of a named constant or variable
// and push it on to the stack.
// currentLevel is the routine level where the vname occurs.
// frameSize is the anticipated size of the local stack frame when
// the constant or variable is fetched at run-time.
// valSize is the size of the constant or variable's value.
private void encodeStore(Vname V, Frame frame, int valSize) {
RuntimeEntity baseObject = (RuntimeEntity) V.visit(this, frame);
// If indexed = true, code will have been generated to load an index value.
if (valSize > 255) {
reporter.reportRestriction("can't store values larger than 255 words");
valSize = 255; // to allow code generation to continue
}
if (baseObject instanceof KnownAddress) {
ObjectAddress address = ((KnownAddress) baseObject).address;
if (V.indexed) {
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level),
address.displacement + V.offset);
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
emit(Machine.STOREIop, valSize, 0, 0);
} else {
emit(Machine.STOREop, valSize, displayRegister(frame.level,
address.level), address.displacement + V.offset);
}
} else if (baseObject instanceof UnknownAddress) {
ObjectAddress address = ((UnknownAddress) baseObject).address;
emit(Machine.LOADop, Machine.addressSize, displayRegister(frame.level,
address.level), address.displacement);
if (V.indexed)
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
if (V.offset != 0) {
emit(Machine.LOADLop, 0, 0, V.offset);
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
}
emit(Machine.STOREIop, valSize, 0, 0);
}
}
// Generates code to fetch the value of a named constant or variable
// and push it on to the stack.
// currentLevel is the routine level where the vname occurs.
// frameSize is the anticipated size of the local stack frame when
// the constant or variable is fetched at run-time.
// valSize is the size of the constant or variable's value.
private void encodeFetch(Vname V, Frame frame, int valSize) {
RuntimeEntity baseObject = (RuntimeEntity) V.visit(this, frame);
// If indexed = true, code will have been generated to load an index value.
if (valSize > 255) {
reporter.reportRestriction("can't load values larger than 255 words");
valSize = 255; // to allow code generation to continue
}
if (baseObject instanceof KnownValue) {
// presumably offset = 0 and indexed = false
int value = ((KnownValue) baseObject).value;
emit(Machine.LOADLop, 0, 0, value);
} else if ((baseObject instanceof UnknownValue) ||
(baseObject instanceof KnownAddress)) {
ObjectAddress address = (baseObject instanceof UnknownValue) ? ((UnknownValue) baseObject).address
: ((KnownAddress) baseObject).address;
if (V.indexed) {
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level),
address.displacement + V.offset);
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
emit(Machine.LOADIop, valSize, 0, 0);
} else
emit(Machine.LOADop, valSize, displayRegister(frame.level,
address.level), address.displacement + V.offset);
} else if (baseObject instanceof UnknownAddress) {
ObjectAddress address = ((UnknownAddress) baseObject).address;
emit(Machine.LOADop, Machine.addressSize, displayRegister(frame.level,
address.level), address.displacement);
if (V.indexed)
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
if (V.offset != 0) {
emit(Machine.LOADLop, 0, 0, V.offset);
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
}
emit(Machine.LOADIop, valSize, 0, 0);
}
}
// Generates code to compute and push the address of a named variable.
// vname is the program phrase that names this variable.
// currentLevel is the routine level where the vname occurs.
// frameSize is the anticipated size of the local stack frame when
// the variable is addressed at run-time.
private void encodeFetchAddress(Vname V, Frame frame) {
RuntimeEntity baseObject = (RuntimeEntity) V.visit(this, frame);
// If indexed = true, code will have been generated to load an index value.
if (baseObject instanceof KnownAddress) {
ObjectAddress address = ((KnownAddress) baseObject).address;
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level),
address.displacement + V.offset);
if (V.indexed)
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
} else if (baseObject instanceof UnknownAddress) {
ObjectAddress address = ((UnknownAddress) baseObject).address;
emit(Machine.LOADop, Machine.addressSize, displayRegister(frame.level,
address.level), address.displacement);
if (V.indexed)
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
if (V.offset != 0) {
emit(Machine.LOADLop, 0, 0, V.offset);
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
}
}
}
}

@ -0,0 +1,30 @@
/*
* @(#)EqualityRoutine.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.CodeGenerator;
public class EqualityRoutine extends RuntimeEntity {
public EqualityRoutine() {
super();
}
public EqualityRoutine(int size, int displacement) {
super(size);
this.displacement = displacement;
}
public int displacement;
}

@ -0,0 +1,31 @@
/*
* @(#)Field.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.CodeGenerator;
public class Field extends RuntimeEntity {
public Field() {
super();
fieldOffset = 0;
}
public Field(int size, int fieldOffset) {
super(size);
this.fieldOffset = fieldOffset;
}
public int fieldOffset;
}

@ -0,0 +1,46 @@
/*
* @(#)Frame.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.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;
}

@ -0,0 +1,31 @@
/*
* @(#)KnownAddress.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.CodeGenerator;
public class KnownAddress extends RuntimeEntity {
public KnownAddress() {
super();
address = null;
}
public KnownAddress(int size, int level, int displacement) {
super(size);
address = new ObjectAddress(level, displacement);
}
public ObjectAddress address;
}

@ -0,0 +1,31 @@
/*
* @(#)KnownRoutine.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.CodeGenerator;
public class KnownRoutine extends RuntimeEntity {
public KnownRoutine() {
super();
address = null;
}
public KnownRoutine(int size, int level, int displacement) {
super(size);
address = new ObjectAddress(level, displacement);
}
public ObjectAddress address;
}

@ -0,0 +1,31 @@
/*
* @(#)KnownValue.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.CodeGenerator;
public class KnownValue extends RuntimeEntity {
public KnownValue() {
super();
value = 0;
}
public KnownValue(int size, int value) {
super(size);
this.value = value;
}
public int value;
}

@ -0,0 +1,26 @@
/*
* @(#)ObjectAddress.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.CodeGenerator;
public final class ObjectAddress {
public ObjectAddress(int level, int displacement) {
this.level = level;
this.displacement = displacement;
}
public int level, displacement;
}

@ -0,0 +1,31 @@
/*
* @(#)PrimitiveRoutine.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.CodeGenerator;
public class PrimitiveRoutine extends RuntimeEntity {
public PrimitiveRoutine() {
super();
displacement = 0;
}
public PrimitiveRoutine(int size, int displacement) {
super(size);
this.displacement = displacement;
}
public int displacement;
}

@ -0,0 +1,33 @@
/*
* @(#)RuntimeEntity.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.CodeGenerator;
// Run-time object
public abstract class RuntimeEntity {
public final static int maxRoutineLevel = 7;
public RuntimeEntity() {
size = 0;
}
public RuntimeEntity(int size) {
this.size = size;
}
public int size;
}

@ -0,0 +1,23 @@
/*
* @(#)TypeRepresentation.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.CodeGenerator;
public class TypeRepresentation extends RuntimeEntity {
public TypeRepresentation(int size) {
super(size);
}
}

@ -0,0 +1,31 @@
/*
* @(#)UnknownAddress.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package Triangle.CodeGenerator;
public class UnknownAddress extends RuntimeEntity {
public UnknownAddress() {
super();
address = null;
}
public UnknownAddress(int size, int level, int displacement) {
super(size);
address = new ObjectAddress(level, displacement);
}
public ObjectAddress address;
}

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