Format code and fix warnings.
This commit is contained in:
parent
2c426b5b2e
commit
a02acc009b
@ -20,8 +20,8 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disassembles the TAM code in the given file, and displays the
|
* Disassembles the TAM code in the given file, and displays the instructions on
|
||||||
* instructions on standard output.
|
* standard output.
|
||||||
*
|
*
|
||||||
* For example:
|
* For example:
|
||||||
*
|
*
|
||||||
@ -38,361 +38,361 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class Disassembler {
|
public class Disassembler {
|
||||||
|
|
||||||
static String objectName;
|
static String objectName;
|
||||||
|
|
||||||
static int CT;
|
static int CT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the r-field of an instruction in the form "l<I>reg</I>r", where
|
* Writes the r-field of an instruction in the form "l<I>reg</I>r", where l and
|
||||||
* l and r are the bracket characters to use.
|
* r are the bracket characters to use.
|
||||||
*
|
*
|
||||||
* @param leftbracket the character to print before the register.
|
* @param leftbracket the character to print before the register.
|
||||||
* @param r the number of the register.
|
* @param r the number of the register.
|
||||||
* @param rightbracket the character to print after the register.
|
* @param rightbracket the character to print after the register.
|
||||||
*/
|
*/
|
||||||
private static void writeR(char leftbracket, int r, char rightbracket) {
|
private static void writeR(char leftbracket, int r, char rightbracket) {
|
||||||
|
|
||||||
System.out.print(leftbracket);
|
System.out.print(leftbracket);
|
||||||
switch (r) {
|
switch (r) {
|
||||||
case Machine.CBr:
|
case Machine.CBr:
|
||||||
System.out.print("CB");
|
System.out.print("CB");
|
||||||
break;
|
break;
|
||||||
case Machine.CTr:
|
case Machine.CTr:
|
||||||
System.out.print("CT");
|
System.out.print("CT");
|
||||||
break;
|
break;
|
||||||
case Machine.PBr:
|
case Machine.PBr:
|
||||||
System.out.print("PB");
|
System.out.print("PB");
|
||||||
break;
|
break;
|
||||||
case Machine.PTr:
|
case Machine.PTr:
|
||||||
System.out.print("PT");
|
System.out.print("PT");
|
||||||
break;
|
break;
|
||||||
case Machine.SBr:
|
case Machine.SBr:
|
||||||
System.out.print("SB");
|
System.out.print("SB");
|
||||||
break;
|
break;
|
||||||
case Machine.STr:
|
case Machine.STr:
|
||||||
System.out.print("ST");
|
System.out.print("ST");
|
||||||
break;
|
break;
|
||||||
case Machine.HBr:
|
case Machine.HBr:
|
||||||
System.out.print("HB");
|
System.out.print("HB");
|
||||||
break;
|
break;
|
||||||
case Machine.HTr:
|
case Machine.HTr:
|
||||||
System.out.print("HT");
|
System.out.print("HT");
|
||||||
break;
|
break;
|
||||||
case Machine.LBr:
|
case Machine.LBr:
|
||||||
System.out.print("LB");
|
System.out.print("LB");
|
||||||
break;
|
break;
|
||||||
case Machine.L1r:
|
case Machine.L1r:
|
||||||
System.out.print("L1");
|
System.out.print("L1");
|
||||||
break;
|
break;
|
||||||
case Machine.L2r:
|
case Machine.L2r:
|
||||||
System.out.print("L2");
|
System.out.print("L2");
|
||||||
break;
|
break;
|
||||||
case Machine.L3r:
|
case Machine.L3r:
|
||||||
System.out.print("L3");
|
System.out.print("L3");
|
||||||
break;
|
break;
|
||||||
case Machine.L4r:
|
case Machine.L4r:
|
||||||
System.out.print("L4");
|
System.out.print("L4");
|
||||||
break;
|
break;
|
||||||
case Machine.L5r:
|
case Machine.L5r:
|
||||||
System.out.print("L5");
|
System.out.print("L5");
|
||||||
break;
|
break;
|
||||||
case Machine.L6r:
|
case Machine.L6r:
|
||||||
System.out.print("L6");
|
System.out.print("L6");
|
||||||
break;
|
break;
|
||||||
case Machine.CPr:
|
case Machine.CPr:
|
||||||
System.out.print("CP");
|
System.out.print("CP");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
System.out.print(rightbracket);
|
System.out.print(rightbracket);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a void n-field of an instruction.
|
* Writes a void n-field of an instruction.
|
||||||
*/
|
*/
|
||||||
private static void blankN() {
|
private static void blankN() {
|
||||||
System.out.print(" ");
|
System.out.print(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writes the n-field of an instruction.
|
// Writes the n-field of an instruction.
|
||||||
/**
|
/**
|
||||||
* Writes the n-field of an instruction in the form "(n)".
|
* Writes the n-field of an instruction in the form "(n)".
|
||||||
*
|
*
|
||||||
* @param n the integer to write.
|
* @param n the integer to write.
|
||||||
*/
|
*/
|
||||||
private static void writeN(int n) {
|
private static void writeN(int n) {
|
||||||
System.out.print("(" + n + ") ");
|
System.out.print("(" + n + ") ");
|
||||||
if (n < 10)
|
if (n < 10)
|
||||||
System.out.print(" ");
|
System.out.print(" ");
|
||||||
else if (n < 100)
|
else if (n < 100)
|
||||||
System.out.print(" ");
|
System.out.print(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the d-field of an instruction.
|
* Writes the d-field of an instruction.
|
||||||
*
|
*
|
||||||
* @param d the integer to write.
|
* @param d the integer to write.
|
||||||
*/
|
*/
|
||||||
private static void writeD(int d) {
|
private static void writeD(int d) {
|
||||||
System.out.print(d);
|
System.out.print(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the name of primitive routine with relative address d.
|
* Writes the name of primitive routine with relative address d.
|
||||||
*
|
*
|
||||||
* @param d the displacment of the primitive routine.
|
* @param d the displacment of the primitive routine.
|
||||||
*/
|
*/
|
||||||
private static void writePrimitive(int d) {
|
private static void writePrimitive(int d) {
|
||||||
switch (d) {
|
switch (d) {
|
||||||
case Machine.idDisplacement:
|
case Machine.idDisplacement:
|
||||||
System.out.print("id ");
|
System.out.print("id ");
|
||||||
break;
|
break;
|
||||||
case Machine.notDisplacement:
|
case Machine.notDisplacement:
|
||||||
System.out.print("not ");
|
System.out.print("not ");
|
||||||
break;
|
break;
|
||||||
case Machine.andDisplacement:
|
case Machine.andDisplacement:
|
||||||
System.out.print("and ");
|
System.out.print("and ");
|
||||||
break;
|
break;
|
||||||
case Machine.orDisplacement:
|
case Machine.orDisplacement:
|
||||||
System.out.print("or ");
|
System.out.print("or ");
|
||||||
break;
|
break;
|
||||||
case Machine.succDisplacement:
|
case Machine.succDisplacement:
|
||||||
System.out.print("succ ");
|
System.out.print("succ ");
|
||||||
break;
|
break;
|
||||||
case Machine.predDisplacement:
|
case Machine.predDisplacement:
|
||||||
System.out.print("pred ");
|
System.out.print("pred ");
|
||||||
break;
|
break;
|
||||||
case Machine.negDisplacement:
|
case Machine.negDisplacement:
|
||||||
System.out.print("neg ");
|
System.out.print("neg ");
|
||||||
break;
|
break;
|
||||||
case Machine.addDisplacement:
|
case Machine.addDisplacement:
|
||||||
System.out.print("add ");
|
System.out.print("add ");
|
||||||
break;
|
break;
|
||||||
case Machine.subDisplacement:
|
case Machine.subDisplacement:
|
||||||
System.out.print("sub ");
|
System.out.print("sub ");
|
||||||
break;
|
break;
|
||||||
case Machine.multDisplacement:
|
case Machine.multDisplacement:
|
||||||
System.out.print("mult ");
|
System.out.print("mult ");
|
||||||
break;
|
break;
|
||||||
case Machine.divDisplacement:
|
case Machine.divDisplacement:
|
||||||
System.out.print("div ");
|
System.out.print("div ");
|
||||||
break;
|
break;
|
||||||
case Machine.modDisplacement:
|
case Machine.modDisplacement:
|
||||||
System.out.print("mod ");
|
System.out.print("mod ");
|
||||||
break;
|
break;
|
||||||
case Machine.ltDisplacement:
|
case Machine.ltDisplacement:
|
||||||
System.out.print("lt ");
|
System.out.print("lt ");
|
||||||
break;
|
break;
|
||||||
case Machine.leDisplacement:
|
case Machine.leDisplacement:
|
||||||
System.out.print("le ");
|
System.out.print("le ");
|
||||||
break;
|
break;
|
||||||
case Machine.geDisplacement:
|
case Machine.geDisplacement:
|
||||||
System.out.print("ge ");
|
System.out.print("ge ");
|
||||||
break;
|
break;
|
||||||
case Machine.gtDisplacement:
|
case Machine.gtDisplacement:
|
||||||
System.out.print("gt ");
|
System.out.print("gt ");
|
||||||
break;
|
break;
|
||||||
case Machine.eqDisplacement:
|
case Machine.eqDisplacement:
|
||||||
System.out.print("eq ");
|
System.out.print("eq ");
|
||||||
break;
|
break;
|
||||||
case Machine.neDisplacement:
|
case Machine.neDisplacement:
|
||||||
System.out.print("ne ");
|
System.out.print("ne ");
|
||||||
break;
|
break;
|
||||||
case Machine.eolDisplacement:
|
case Machine.eolDisplacement:
|
||||||
System.out.print("eol ");
|
System.out.print("eol ");
|
||||||
break;
|
break;
|
||||||
case Machine.eofDisplacement:
|
case Machine.eofDisplacement:
|
||||||
System.out.print("eof ");
|
System.out.print("eof ");
|
||||||
break;
|
break;
|
||||||
case Machine.getDisplacement:
|
case Machine.getDisplacement:
|
||||||
System.out.print("get ");
|
System.out.print("get ");
|
||||||
break;
|
break;
|
||||||
case Machine.putDisplacement:
|
case Machine.putDisplacement:
|
||||||
System.out.print("put ");
|
System.out.print("put ");
|
||||||
break;
|
break;
|
||||||
case Machine.geteolDisplacement:
|
case Machine.geteolDisplacement:
|
||||||
System.out.print("geteol ");
|
System.out.print("geteol ");
|
||||||
break;
|
break;
|
||||||
case Machine.puteolDisplacement:
|
case Machine.puteolDisplacement:
|
||||||
System.out.print("puteol ");
|
System.out.print("puteol ");
|
||||||
break;
|
break;
|
||||||
case Machine.getintDisplacement:
|
case Machine.getintDisplacement:
|
||||||
System.out.print("getint ");
|
System.out.print("getint ");
|
||||||
break;
|
break;
|
||||||
case Machine.putintDisplacement:
|
case Machine.putintDisplacement:
|
||||||
System.out.print("putint ");
|
System.out.print("putint ");
|
||||||
break;
|
break;
|
||||||
case Machine.newDisplacement:
|
case Machine.newDisplacement:
|
||||||
System.out.print("new ");
|
System.out.print("new ");
|
||||||
break;
|
break;
|
||||||
case Machine.disposeDisplacement:
|
case Machine.disposeDisplacement:
|
||||||
System.out.print("dispose ");
|
System.out.print("dispose ");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the given instruction in assembly-code format.
|
* Writes the given instruction in assembly-code format.
|
||||||
*
|
*
|
||||||
* @param instr the instruction to display.
|
* @param instr the instruction to display.
|
||||||
*/
|
*/
|
||||||
private static void writeInstruction(Instruction instr) {
|
private static void writeInstruction(Instruction instr) {
|
||||||
|
|
||||||
switch (instr.op) {
|
switch (instr.op) {
|
||||||
case Machine.LOADop:
|
case Machine.LOADop:
|
||||||
System.out.print("LOAD ");
|
System.out.print("LOAD ");
|
||||||
writeN(instr.n);
|
writeN(instr.n);
|
||||||
writeD(instr.d);
|
writeD(instr.d);
|
||||||
writeR('[', instr.r, ']');
|
writeR('[', instr.r, ']');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Machine.LOADAop:
|
case Machine.LOADAop:
|
||||||
System.out.print("LOADA ");
|
System.out.print("LOADA ");
|
||||||
blankN();
|
blankN();
|
||||||
writeD(instr.d);
|
writeD(instr.d);
|
||||||
writeR('[', instr.r, ']');
|
writeR('[', instr.r, ']');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Machine.LOADIop:
|
case Machine.LOADIop:
|
||||||
System.out.print("LOADI ");
|
System.out.print("LOADI ");
|
||||||
writeN(instr.n);
|
writeN(instr.n);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Machine.LOADLop:
|
case Machine.LOADLop:
|
||||||
System.out.print("LOADL ");
|
System.out.print("LOADL ");
|
||||||
blankN();
|
blankN();
|
||||||
writeD(instr.d);
|
writeD(instr.d);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Machine.STOREop:
|
case Machine.STOREop:
|
||||||
System.out.print("STORE ");
|
System.out.print("STORE ");
|
||||||
writeN(instr.n);
|
writeN(instr.n);
|
||||||
writeD(instr.d);
|
writeD(instr.d);
|
||||||
writeR('[', instr.r, ']');
|
writeR('[', instr.r, ']');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Machine.STOREIop:
|
case Machine.STOREIop:
|
||||||
System.out.print("STOREI");
|
System.out.print("STOREI");
|
||||||
writeN(instr.n);
|
writeN(instr.n);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Machine.CALLop:
|
case Machine.CALLop:
|
||||||
System.out.print("CALL ");
|
System.out.print("CALL ");
|
||||||
if (instr.r == Machine.PBr) {
|
if (instr.r == Machine.PBr) {
|
||||||
blankN();
|
blankN();
|
||||||
writePrimitive(instr.d);
|
writePrimitive(instr.d);
|
||||||
} else {
|
} else {
|
||||||
writeR('(', instr.n, ')');
|
writeR('(', instr.n, ')');
|
||||||
System.out.print(" ");
|
System.out.print(" ");
|
||||||
writeD(instr.d);
|
writeD(instr.d);
|
||||||
writeR('[', instr.r, ']');
|
writeR('[', instr.r, ']');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Machine.CALLIop:
|
case Machine.CALLIop:
|
||||||
System.out.print("CALLI ");
|
System.out.print("CALLI ");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Machine.RETURNop:
|
case Machine.RETURNop:
|
||||||
System.out.print("RETURN");
|
System.out.print("RETURN");
|
||||||
writeN(instr.n);
|
writeN(instr.n);
|
||||||
writeD(instr.d);
|
writeD(instr.d);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Machine.PUSHop:
|
case Machine.PUSHop:
|
||||||
System.out.print("PUSH ");
|
System.out.print("PUSH ");
|
||||||
blankN();
|
blankN();
|
||||||
writeD(instr.d);
|
writeD(instr.d);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Machine.POPop:
|
case Machine.POPop:
|
||||||
System.out.print("POP ");
|
System.out.print("POP ");
|
||||||
writeN(instr.n);
|
writeN(instr.n);
|
||||||
writeD(instr.d);
|
writeD(instr.d);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Machine.JUMPop:
|
case Machine.JUMPop:
|
||||||
System.out.print("JUMP ");
|
System.out.print("JUMP ");
|
||||||
blankN();
|
blankN();
|
||||||
writeD(instr.d);
|
writeD(instr.d);
|
||||||
writeR('[', instr.r, ']');
|
writeR('[', instr.r, ']');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Machine.JUMPIop:
|
case Machine.JUMPIop:
|
||||||
System.out.print("JUMPI ");
|
System.out.print("JUMPI ");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Machine.JUMPIFop:
|
case Machine.JUMPIFop:
|
||||||
System.out.print("JUMPIF");
|
System.out.print("JUMPIF");
|
||||||
writeN(instr.n);
|
writeN(instr.n);
|
||||||
writeD(instr.d);
|
writeD(instr.d);
|
||||||
writeR('[', instr.r, ']');
|
writeR('[', instr.r, ']');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Machine.HALTop:
|
case Machine.HALTop:
|
||||||
System.out.print("HALT ");
|
System.out.print("HALT ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes all instructions of the program in code store.
|
* Writes all instructions of the program in code store.
|
||||||
*/
|
*/
|
||||||
private static void disassembleProgram() {
|
private static void disassembleProgram() {
|
||||||
for (int addr = Machine.CB; addr < CT; addr++) {
|
for (int addr = Machine.CB; addr < CT; addr++) {
|
||||||
System.out.print(addr + ": ");
|
System.out.print(addr + ": ");
|
||||||
writeInstruction(Machine.code[addr]);
|
writeInstruction(Machine.code[addr]);
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOADING
|
// LOADING
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the TAM object program into code store from the named file.
|
* Loads the TAM object program into code store from the named file.
|
||||||
*
|
*
|
||||||
* @param objectName the name of the file containing the program.
|
* @param objectName the name of the file containing the program.
|
||||||
*/
|
*/
|
||||||
static void loadObjectProgram(String objectName) {
|
static void loadObjectProgram(String objectName) {
|
||||||
|
|
||||||
FileInputStream objectFile = null;
|
FileInputStream objectFile = null;
|
||||||
DataInputStream objectStream = null;
|
DataInputStream objectStream = null;
|
||||||
|
|
||||||
int addr;
|
int addr;
|
||||||
boolean finished = false;
|
boolean finished = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
objectFile = new FileInputStream(objectName);
|
objectFile = new FileInputStream(objectName);
|
||||||
objectStream = new DataInputStream(objectFile);
|
objectStream = new DataInputStream(objectFile);
|
||||||
|
|
||||||
addr = Machine.CB;
|
addr = Machine.CB;
|
||||||
while (!finished) {
|
while (!finished) {
|
||||||
Machine.code[addr] = Instruction.read(objectStream);
|
Machine.code[addr] = Instruction.read(objectStream);
|
||||||
if (Machine.code[addr] == null)
|
if (Machine.code[addr] == null)
|
||||||
finished = true;
|
finished = true;
|
||||||
else
|
else
|
||||||
addr = addr + 1;
|
addr = addr + 1;
|
||||||
}
|
}
|
||||||
CT = addr;
|
CT = addr;
|
||||||
objectFile.close();
|
objectFile.close();
|
||||||
} catch (FileNotFoundException s) {
|
} catch (FileNotFoundException s) {
|
||||||
CT = Machine.CB;
|
CT = Machine.CB;
|
||||||
System.err.println("Error opening object file: " + s);
|
System.err.println("Error opening object file: " + s);
|
||||||
} catch (IOException s) {
|
} catch (IOException s) {
|
||||||
CT = Machine.CB;
|
CT = Machine.CB;
|
||||||
System.err.println("Error reading object file: " + s);
|
System.err.println("Error reading object file: " + s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DISASSEMBLE
|
// DISASSEMBLE
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("********** TAM Disassembler (Sun Version 2.1) **********");
|
System.out.println("********** TAM Disassembler (Sun Version 2.1) **********");
|
||||||
|
|
||||||
if (args.length == 1)
|
if (args.length == 1)
|
||||||
objectName = args[0];
|
objectName = args[0];
|
||||||
else
|
else
|
||||||
objectName = "obj.tam";
|
objectName = "obj.tam";
|
||||||
|
|
||||||
loadObjectProgram(objectName);
|
loadObjectProgram(objectName);
|
||||||
disassembleProgram();
|
disassembleProgram();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -21,44 +21,44 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class Instruction {
|
public class Instruction {
|
||||||
|
|
||||||
public Instruction() {
|
public Instruction() {
|
||||||
op = 0;
|
op = 0;
|
||||||
r = 0;
|
r = 0;
|
||||||
n = 0;
|
n = 0;
|
||||||
d = 0;
|
d = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Java has no type synonyms, so the following representations are
|
// Java has no type synonyms, so the following representations are
|
||||||
// assumed:
|
// assumed:
|
||||||
//
|
//
|
||||||
// type
|
// type
|
||||||
// OpCode = 0..15; {4 bits unsigned}
|
// OpCode = 0..15; {4 bits unsigned}
|
||||||
// Length = 0..255; {8 bits unsigned}
|
// Length = 0..255; {8 bits unsigned}
|
||||||
// Operand = -32767..+32767; {16 bits signed}
|
// Operand = -32767..+32767; {16 bits signed}
|
||||||
|
|
||||||
// Represents TAM instructions.
|
// Represents TAM instructions.
|
||||||
public int op; // OpCode
|
public int op; // OpCode
|
||||||
public int r; // RegisterNumber
|
public int r; // RegisterNumber
|
||||||
public int n; // Length
|
public int n; // Length
|
||||||
public int d; // Operand
|
public int d; // Operand
|
||||||
|
|
||||||
public void write(DataOutputStream output) throws IOException {
|
public void write(DataOutputStream output) throws IOException {
|
||||||
output.writeInt(op);
|
output.writeInt(op);
|
||||||
output.writeInt(r);
|
output.writeInt(r);
|
||||||
output.writeInt(n);
|
output.writeInt(n);
|
||||||
output.writeInt(d);
|
output.writeInt(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Instruction read(DataInputStream input) throws IOException {
|
public static Instruction read(DataInputStream input) throws IOException {
|
||||||
Instruction inst = new Instruction();
|
Instruction inst = new Instruction();
|
||||||
try {
|
try {
|
||||||
inst.op = input.readInt();
|
inst.op = input.readInt();
|
||||||
inst.r = input.readInt();
|
inst.r = input.readInt();
|
||||||
inst.n = input.readInt();
|
inst.n = input.readInt();
|
||||||
inst.d = input.readInt();
|
inst.d = input.readInt();
|
||||||
return inst;
|
return inst;
|
||||||
} catch (EOFException s) {
|
} catch (EOFException s) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,110 +16,56 @@ package Triangle.AbstractMachine;
|
|||||||
|
|
||||||
public final class Machine {
|
public final class Machine {
|
||||||
|
|
||||||
public final static int maxRoutineLevel = 7;
|
public final static int maxRoutineLevel = 7;
|
||||||
|
|
||||||
// WORDS AND ADDRESSES
|
// WORDS AND ADDRESSES
|
||||||
|
|
||||||
// Java has no type synonyms, so the following representations are
|
// Java has no type synonyms, so the following representations are
|
||||||
// assumed:
|
// assumed:
|
||||||
//
|
//
|
||||||
// type
|
// type
|
||||||
// Word = -32767..+32767; {16 bits signed}
|
// Word = -32767..+32767; {16 bits signed}
|
||||||
// DoubleWord = -2147483648..+2147483647; {32 bits signed}
|
// DoubleWord = -2147483648..+2147483647; {32 bits signed}
|
||||||
// CodeAddress = 0..+32767; {15 bits unsigned}
|
// CodeAddress = 0..+32767; {15 bits unsigned}
|
||||||
// DataAddress = 0..+32767; {15 bits unsigned}
|
// DataAddress = 0..+32767; {15 bits unsigned}
|
||||||
|
|
||||||
// INSTRUCTIONS
|
// INSTRUCTIONS
|
||||||
|
|
||||||
// Operation codes
|
// Operation codes
|
||||||
public final static int LOADop = 0,
|
public final static int LOADop = 0, LOADAop = 1, LOADIop = 2, LOADLop = 3, STOREop = 4, STOREIop = 5, CALLop = 6,
|
||||||
LOADAop = 1,
|
CALLIop = 7, RETURNop = 8, PUSHop = 10, POPop = 11, JUMPop = 12, JUMPIop = 13, JUMPIFop = 14, HALTop = 15;
|
||||||
LOADIop = 2,
|
|
||||||
LOADLop = 3,
|
|
||||||
STOREop = 4,
|
|
||||||
STOREIop = 5,
|
|
||||||
CALLop = 6,
|
|
||||||
CALLIop = 7,
|
|
||||||
RETURNop = 8,
|
|
||||||
PUSHop = 10,
|
|
||||||
POPop = 11,
|
|
||||||
JUMPop = 12,
|
|
||||||
JUMPIop = 13,
|
|
||||||
JUMPIFop = 14,
|
|
||||||
HALTop = 15;
|
|
||||||
|
|
||||||
// CODE STORE
|
// CODE STORE
|
||||||
|
|
||||||
public static Instruction[] code = new Instruction[1024];
|
public static Instruction[] code = new Instruction[1024];
|
||||||
|
|
||||||
// CODE STORE REGISTERS
|
// CODE STORE REGISTERS
|
||||||
|
|
||||||
public final static int CB = 0,
|
public final static int CB = 0, PB = 1024, // = upper bound of code array + 1
|
||||||
PB = 1024, // = upper bound of code array + 1
|
PT = 1052; // = PB + 28
|
||||||
PT = 1052; // = PB + 28
|
|
||||||
|
|
||||||
// REGISTER NUMBERS
|
// REGISTER NUMBERS
|
||||||
|
|
||||||
public final static int CBr = 0,
|
public final static int CBr = 0, CTr = 1, PBr = 2, PTr = 3, SBr = 4, STr = 5, HBr = 6, HTr = 7, LBr = 8,
|
||||||
CTr = 1,
|
L1r = LBr + 1, L2r = LBr + 2, L3r = LBr + 3, L4r = LBr + 4, L5r = LBr + 5, L6r = LBr + 6, CPr = 15;
|
||||||
PBr = 2,
|
|
||||||
PTr = 3,
|
|
||||||
SBr = 4,
|
|
||||||
STr = 5,
|
|
||||||
HBr = 6,
|
|
||||||
HTr = 7,
|
|
||||||
LBr = 8,
|
|
||||||
L1r = LBr + 1,
|
|
||||||
L2r = LBr + 2,
|
|
||||||
L3r = LBr + 3,
|
|
||||||
L4r = LBr + 4,
|
|
||||||
L5r = LBr + 5,
|
|
||||||
L6r = LBr + 6,
|
|
||||||
CPr = 15;
|
|
||||||
|
|
||||||
// DATA REPRESENTATION
|
// DATA REPRESENTATION
|
||||||
|
|
||||||
public final static int booleanSize = 1,
|
public final static int booleanSize = 1, characterSize = 1, integerSize = 1, addressSize = 1,
|
||||||
characterSize = 1,
|
closureSize = 2 * addressSize,
|
||||||
integerSize = 1,
|
|
||||||
addressSize = 1,
|
|
||||||
closureSize = 2 * addressSize,
|
|
||||||
|
|
||||||
linkDataSize = 3 * addressSize,
|
linkDataSize = 3 * addressSize,
|
||||||
|
|
||||||
falseRep = 0,
|
falseRep = 0, trueRep = 1, maxintRep = 32767;
|
||||||
trueRep = 1,
|
|
||||||
maxintRep = 32767;
|
|
||||||
|
|
||||||
// ADDRESSES OF PRIMITIVE ROUTINES
|
// ADDRESSES OF PRIMITIVE ROUTINES
|
||||||
|
|
||||||
public final static int idDisplacement = 1,
|
public final static int idDisplacement = 1, notDisplacement = 2, andDisplacement = 3, orDisplacement = 4,
|
||||||
notDisplacement = 2,
|
succDisplacement = 5, predDisplacement = 6, negDisplacement = 7, addDisplacement = 8, subDisplacement = 9,
|
||||||
andDisplacement = 3,
|
multDisplacement = 10, divDisplacement = 11, modDisplacement = 12, ltDisplacement = 13, leDisplacement = 14,
|
||||||
orDisplacement = 4,
|
geDisplacement = 15, gtDisplacement = 16, eqDisplacement = 17, neDisplacement = 18, eolDisplacement = 19,
|
||||||
succDisplacement = 5,
|
eofDisplacement = 20, getDisplacement = 21, putDisplacement = 22, geteolDisplacement = 23,
|
||||||
predDisplacement = 6,
|
puteolDisplacement = 24, getintDisplacement = 25, putintDisplacement = 26, newDisplacement = 27,
|
||||||
negDisplacement = 7,
|
disposeDisplacement = 28;
|
||||||
addDisplacement = 8,
|
|
||||||
subDisplacement = 9,
|
|
||||||
multDisplacement = 10,
|
|
||||||
divDisplacement = 11,
|
|
||||||
modDisplacement = 12,
|
|
||||||
ltDisplacement = 13,
|
|
||||||
leDisplacement = 14,
|
|
||||||
geDisplacement = 15,
|
|
||||||
gtDisplacement = 16,
|
|
||||||
eqDisplacement = 17,
|
|
||||||
neDisplacement = 18,
|
|
||||||
eolDisplacement = 19,
|
|
||||||
eofDisplacement = 20,
|
|
||||||
getDisplacement = 21,
|
|
||||||
putDisplacement = 22,
|
|
||||||
geteolDisplacement = 23,
|
|
||||||
puteolDisplacement = 24,
|
|
||||||
getintDisplacement = 25,
|
|
||||||
putintDisplacement = 26,
|
|
||||||
newDisplacement = 27,
|
|
||||||
disposeDisplacement = 28;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public abstract class AST {
|
public abstract class AST {
|
||||||
|
|
||||||
public AST(SourcePosition thePosition) {
|
public AST(SourcePosition thePosition) {
|
||||||
position = thePosition;
|
position = thePosition;
|
||||||
entity = null;
|
entity = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SourcePosition getPosition() {
|
public SourcePosition getPosition() {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Object visit(Visitor v, Object o);
|
public abstract Object visit(Visitor v, Object o);
|
||||||
|
|
||||||
public SourcePosition position;
|
public SourcePosition position;
|
||||||
public RuntimeEntity entity;
|
public RuntimeEntity entity;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public abstract class ActualParameter extends AST {
|
public abstract class ActualParameter extends AST {
|
||||||
|
|
||||||
public ActualParameter(SourcePosition thePosition) {
|
public ActualParameter(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public abstract class ActualParameterSequence extends AST {
|
public abstract class ActualParameterSequence extends AST {
|
||||||
|
|
||||||
public ActualParameterSequence(SourcePosition thePosition) {
|
public ActualParameterSequence(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class AnyTypeDenoter extends TypeDenoter {
|
public class AnyTypeDenoter extends TypeDenoter {
|
||||||
|
|
||||||
public AnyTypeDenoter(SourcePosition thePosition) {
|
public AnyTypeDenoter(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitAnyTypeDenoter(this, o);
|
return v.visitAnyTypeDenoter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,10 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public abstract class ArrayAggregate extends AST {
|
public abstract class ArrayAggregate extends AST {
|
||||||
|
|
||||||
public ArrayAggregate(SourcePosition thePosition) {
|
public ArrayAggregate(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
elemCount = 0;
|
elemCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int elemCount;
|
public int elemCount;
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class ArrayExpression extends Expression {
|
public class ArrayExpression extends Expression {
|
||||||
|
|
||||||
public ArrayExpression(ArrayAggregate aaAST,
|
public ArrayExpression(ArrayAggregate aaAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
AA = aaAST;
|
||||||
AA = aaAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitArrayExpression(this, o);
|
return v.visitArrayExpression(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayAggregate AA;
|
public ArrayAggregate AA;
|
||||||
}
|
}
|
||||||
|
@ -18,29 +18,28 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class ArrayTypeDenoter extends TypeDenoter {
|
public class ArrayTypeDenoter extends TypeDenoter {
|
||||||
|
|
||||||
public ArrayTypeDenoter(IntegerLiteral ilAST, TypeDenoter tAST,
|
public ArrayTypeDenoter(IntegerLiteral ilAST, TypeDenoter tAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
IL = ilAST;
|
||||||
IL = ilAST;
|
T = tAST;
|
||||||
T = tAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitArrayTypeDenoter(this, o);
|
return v.visitArrayTypeDenoter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj != null && obj instanceof ErrorTypeDenoter)
|
if (obj != null && obj instanceof ErrorTypeDenoter)
|
||||||
return true;
|
return true;
|
||||||
else if (obj != null && obj instanceof ArrayTypeDenoter)
|
else if (obj != null && obj instanceof ArrayTypeDenoter)
|
||||||
return this.IL.spelling.compareTo(((ArrayTypeDenoter) obj).IL.spelling) == 0 &&
|
return this.IL.spelling.compareTo(((ArrayTypeDenoter) obj).IL.spelling) == 0
|
||||||
this.T.equals(((ArrayTypeDenoter) obj).T);
|
&& this.T.equals(((ArrayTypeDenoter) obj).T);
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntegerLiteral IL;
|
public IntegerLiteral IL;
|
||||||
public TypeDenoter T;
|
public TypeDenoter T;
|
||||||
}
|
}
|
||||||
|
@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class AssignCommand extends Command {
|
public class AssignCommand extends Command {
|
||||||
|
|
||||||
public AssignCommand(Vname vAST, Expression eAST, SourcePosition thePosition) {
|
public AssignCommand(Vname vAST, Expression eAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
V = vAST;
|
V = vAST;
|
||||||
E = eAST;
|
E = eAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitAssignCommand(this, o);
|
return v.visitAssignCommand(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vname V;
|
public Vname V;
|
||||||
public Expression E;
|
public Expression E;
|
||||||
}
|
}
|
||||||
|
@ -18,19 +18,18 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class BinaryExpression extends Expression {
|
public class BinaryExpression extends Expression {
|
||||||
|
|
||||||
public BinaryExpression(Expression e1AST, Operator oAST, Expression e2AST,
|
public BinaryExpression(Expression e1AST, Operator oAST, Expression e2AST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
O = oAST;
|
||||||
O = oAST;
|
E1 = e1AST;
|
||||||
E1 = e1AST;
|
E2 = e2AST;
|
||||||
E2 = e2AST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitBinaryExpression(this, o);
|
return v.visitBinaryExpression(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Expression E1, E2;
|
public Expression E1, E2;
|
||||||
public Operator O;
|
public Operator O;
|
||||||
}
|
}
|
||||||
|
@ -18,21 +18,20 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class BinaryOperatorDeclaration extends Declaration {
|
public class BinaryOperatorDeclaration extends Declaration {
|
||||||
|
|
||||||
public BinaryOperatorDeclaration(Operator oAST, TypeDenoter arg1AST,
|
public BinaryOperatorDeclaration(Operator oAST, TypeDenoter arg1AST, TypeDenoter arg2AST, TypeDenoter resultAST,
|
||||||
TypeDenoter arg2AST, TypeDenoter resultAST,
|
SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
O = oAST;
|
||||||
O = oAST;
|
ARG1 = arg1AST;
|
||||||
ARG1 = arg1AST;
|
ARG2 = arg2AST;
|
||||||
ARG2 = arg2AST;
|
RES = resultAST;
|
||||||
RES = resultAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitBinaryOperatorDeclaration(this, o);
|
return v.visitBinaryOperatorDeclaration(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Operator O;
|
public Operator O;
|
||||||
public TypeDenoter ARG1, ARG2, RES;
|
public TypeDenoter ARG1, ARG2, RES;
|
||||||
}
|
}
|
||||||
|
@ -18,20 +18,20 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class BoolTypeDenoter extends TypeDenoter {
|
public class BoolTypeDenoter extends TypeDenoter {
|
||||||
|
|
||||||
public BoolTypeDenoter(SourcePosition thePosition) {
|
public BoolTypeDenoter(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitBoolTypeDenoter(this, o);
|
return v.visitBoolTypeDenoter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if ((obj != null) && (obj instanceof ErrorTypeDenoter))
|
if ((obj != null) && (obj instanceof ErrorTypeDenoter))
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return ((obj != null) && (obj instanceof BoolTypeDenoter));
|
return ((obj != null) && (obj instanceof BoolTypeDenoter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class CallCommand extends Command {
|
public class CallCommand extends Command {
|
||||||
|
|
||||||
public CallCommand(Identifier iAST, ActualParameterSequence apsAST,
|
public CallCommand(Identifier iAST, ActualParameterSequence apsAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
I = iAST;
|
||||||
I = iAST;
|
APS = apsAST;
|
||||||
APS = apsAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitCallCommand(this, o);
|
return v.visitCallCommand(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
public ActualParameterSequence APS;
|
public ActualParameterSequence APS;
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class CallExpression extends Expression {
|
public class CallExpression extends Expression {
|
||||||
|
|
||||||
public CallExpression(Identifier iAST, ActualParameterSequence apsAST,
|
public CallExpression(Identifier iAST, ActualParameterSequence apsAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
I = iAST;
|
||||||
I = iAST;
|
APS = apsAST;
|
||||||
APS = apsAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitCallExpression(this, o);
|
return v.visitCallExpression(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
public ActualParameterSequence APS;
|
public ActualParameterSequence APS;
|
||||||
}
|
}
|
||||||
|
@ -18,20 +18,20 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class CharTypeDenoter extends TypeDenoter {
|
public class CharTypeDenoter extends TypeDenoter {
|
||||||
|
|
||||||
public CharTypeDenoter(SourcePosition thePosition) {
|
public CharTypeDenoter(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitCharTypeDenoter(this, o);
|
return v.visitCharTypeDenoter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj != null && obj instanceof ErrorTypeDenoter)
|
if (obj != null && obj instanceof ErrorTypeDenoter)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return (obj != null && obj instanceof CharTypeDenoter);
|
return (obj != null && obj instanceof CharTypeDenoter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class CharacterExpression extends Expression {
|
public class CharacterExpression extends Expression {
|
||||||
|
|
||||||
public CharacterExpression(CharacterLiteral clAST, SourcePosition thePosition) {
|
public CharacterExpression(CharacterLiteral clAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
CL = clAST;
|
CL = clAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitCharacterExpression(this, o);
|
return v.visitCharacterExpression(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CharacterLiteral CL;
|
public CharacterLiteral CL;
|
||||||
}
|
}
|
||||||
|
@ -18,13 +18,13 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class CharacterLiteral extends Terminal {
|
public class CharacterLiteral extends Terminal {
|
||||||
|
|
||||||
public CharacterLiteral(String theSpelling, SourcePosition thePosition) {
|
public CharacterLiteral(String theSpelling, SourcePosition thePosition) {
|
||||||
super(theSpelling, thePosition);
|
super(theSpelling, thePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitCharacterLiteral(this, o);
|
return v.visitCharacterLiteral(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public abstract class Command extends AST {
|
public abstract class Command extends AST {
|
||||||
|
|
||||||
public Command(SourcePosition thePosition) {
|
public Command(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class ConstActualParameter extends ActualParameter {
|
public class ConstActualParameter extends ActualParameter {
|
||||||
|
|
||||||
public ConstActualParameter(Expression eAST, SourcePosition thePosition) {
|
public ConstActualParameter(Expression eAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
E = eAST;
|
E = eAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitConstActualParameter(this, o);
|
return v.visitConstActualParameter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Expression E;
|
public Expression E;
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class ConstDeclaration extends Declaration {
|
public class ConstDeclaration extends Declaration {
|
||||||
|
|
||||||
public ConstDeclaration(Identifier iAST, Expression eAST,
|
public ConstDeclaration(Identifier iAST, Expression eAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
I = iAST;
|
||||||
I = iAST;
|
E = eAST;
|
||||||
E = eAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitConstDeclaration(this, o);
|
return v.visitConstDeclaration(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
public Expression E;
|
public Expression E;
|
||||||
}
|
}
|
||||||
|
@ -18,27 +18,26 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class ConstFormalParameter extends FormalParameter {
|
public class ConstFormalParameter extends FormalParameter {
|
||||||
|
|
||||||
public ConstFormalParameter(Identifier iAST, TypeDenoter tAST,
|
public ConstFormalParameter(Identifier iAST, TypeDenoter tAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
I = iAST;
|
||||||
I = iAST;
|
T = tAST;
|
||||||
T = tAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitConstFormalParameter(this, o);
|
return v.visitConstFormalParameter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
public TypeDenoter T;
|
public TypeDenoter T;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object fpAST) {
|
public boolean equals(Object fpAST) {
|
||||||
if (fpAST instanceof ConstFormalParameter) {
|
if (fpAST instanceof ConstFormalParameter) {
|
||||||
ConstFormalParameter cfpAST = (ConstFormalParameter) fpAST;
|
ConstFormalParameter cfpAST = (ConstFormalParameter) fpAST;
|
||||||
return T.equals(cfpAST.T);
|
return T.equals(cfpAST.T);
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,10 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public abstract class Declaration extends AST {
|
public abstract class Declaration extends AST {
|
||||||
|
|
||||||
public Declaration(SourcePosition thePosition) {
|
public Declaration(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
duplicated = false;
|
duplicated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean duplicated;
|
public boolean duplicated;
|
||||||
}
|
}
|
||||||
|
@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class DotVname extends Vname {
|
public class DotVname extends Vname {
|
||||||
|
|
||||||
public DotVname(Vname vAST, Identifier iAST, SourcePosition thePosition) {
|
public DotVname(Vname vAST, Identifier iAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
V = vAST;
|
V = vAST;
|
||||||
I = iAST;
|
I = iAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitDotVname(this, o);
|
return v.visitDotVname(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
public Vname V;
|
public Vname V;
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,12 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class EmptyActualParameterSequence extends ActualParameterSequence {
|
public class EmptyActualParameterSequence extends ActualParameterSequence {
|
||||||
|
|
||||||
public EmptyActualParameterSequence(SourcePosition thePosition) {
|
public EmptyActualParameterSequence(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitEmptyActualParameterSequence(this, o);
|
return v.visitEmptyActualParameterSequence(this, o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,12 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class EmptyCommand extends Command {
|
public class EmptyCommand extends Command {
|
||||||
|
|
||||||
public EmptyCommand(SourcePosition thePosition) {
|
public EmptyCommand(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitEmptyCommand(this, o);
|
return v.visitEmptyCommand(this, o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,12 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class EmptyExpression extends Expression {
|
public class EmptyExpression extends Expression {
|
||||||
|
|
||||||
public EmptyExpression(SourcePosition thePosition) {
|
public EmptyExpression(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitEmptyExpression(this, o);
|
return v.visitEmptyExpression(this, o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class EmptyFormalParameterSequence extends FormalParameterSequence {
|
public class EmptyFormalParameterSequence extends FormalParameterSequence {
|
||||||
|
|
||||||
public EmptyFormalParameterSequence(SourcePosition thePosition) {
|
public EmptyFormalParameterSequence(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitEmptyFormalParameterSequence(this, o);
|
return v.visitEmptyFormalParameterSequence(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object fpsAST) {
|
public boolean equals(Object fpsAST) {
|
||||||
return (fpsAST instanceof EmptyFormalParameterSequence);
|
return (fpsAST instanceof EmptyFormalParameterSequence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class ErrorTypeDenoter extends TypeDenoter {
|
public class ErrorTypeDenoter extends TypeDenoter {
|
||||||
|
|
||||||
public ErrorTypeDenoter(SourcePosition thePosition) {
|
public ErrorTypeDenoter(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitErrorTypeDenoter(this, o);
|
return v.visitErrorTypeDenoter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,10 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public abstract class Expression extends AST {
|
public abstract class Expression extends AST {
|
||||||
|
|
||||||
public Expression(SourcePosition thePosition) {
|
public Expression(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
type = null;
|
type = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeDenoter type;
|
public TypeDenoter type;
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,10 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public abstract class FieldTypeDenoter extends TypeDenoter {
|
public abstract class FieldTypeDenoter extends TypeDenoter {
|
||||||
|
|
||||||
public FieldTypeDenoter(SourcePosition thePosition) {
|
public FieldTypeDenoter(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean equals(Object obj);
|
public abstract boolean equals(Object obj);
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,11 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public abstract class FormalParameter extends Declaration {
|
public abstract class FormalParameter extends Declaration {
|
||||||
|
|
||||||
public FormalParameter(SourcePosition thePosition) {
|
public FormalParameter(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean equals(Object fpAST);
|
public abstract boolean equals(Object fpAST);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,10 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public abstract class FormalParameterSequence extends AST {
|
public abstract class FormalParameterSequence extends AST {
|
||||||
|
|
||||||
public FormalParameterSequence(SourcePosition thePosition) {
|
public FormalParameterSequence(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean equals(Object fpsAST);
|
public abstract boolean equals(Object fpsAST);
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class FuncActualParameter extends ActualParameter {
|
public class FuncActualParameter extends ActualParameter {
|
||||||
|
|
||||||
public FuncActualParameter(Identifier iAST, SourcePosition thePosition) {
|
public FuncActualParameter(Identifier iAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
I = iAST;
|
I = iAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitFuncActualParameter(this, o);
|
return v.visitFuncActualParameter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
}
|
}
|
||||||
|
@ -18,23 +18,22 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class FuncDeclaration extends Declaration {
|
public class FuncDeclaration extends Declaration {
|
||||||
|
|
||||||
public FuncDeclaration(Identifier iAST, FormalParameterSequence fpsAST,
|
public FuncDeclaration(Identifier iAST, FormalParameterSequence fpsAST, TypeDenoter tAST, Expression eAST,
|
||||||
TypeDenoter tAST, Expression eAST,
|
SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
I = iAST;
|
||||||
I = iAST;
|
FPS = fpsAST;
|
||||||
FPS = fpsAST;
|
T = tAST;
|
||||||
T = tAST;
|
E = eAST;
|
||||||
E = eAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitFuncDeclaration(this, o);
|
return v.visitFuncDeclaration(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
public FormalParameterSequence FPS;
|
public FormalParameterSequence FPS;
|
||||||
public TypeDenoter T;
|
public TypeDenoter T;
|
||||||
public Expression E;
|
public Expression E;
|
||||||
}
|
}
|
||||||
|
@ -18,29 +18,29 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class FuncFormalParameter extends FormalParameter {
|
public class FuncFormalParameter extends FormalParameter {
|
||||||
|
|
||||||
public FuncFormalParameter(Identifier iAST, FormalParameterSequence fpsAST,
|
public FuncFormalParameter(Identifier iAST, FormalParameterSequence fpsAST, TypeDenoter tAST,
|
||||||
TypeDenoter tAST, SourcePosition thePosition) {
|
SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
I = iAST;
|
I = iAST;
|
||||||
FPS = fpsAST;
|
FPS = fpsAST;
|
||||||
T = tAST;
|
T = tAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitFuncFormalParameter(this, o);
|
return v.visitFuncFormalParameter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object fpAST) {
|
public boolean equals(Object fpAST) {
|
||||||
if (fpAST instanceof FuncFormalParameter) {
|
if (fpAST instanceof FuncFormalParameter) {
|
||||||
FuncFormalParameter ffpAST = (FuncFormalParameter) fpAST;
|
FuncFormalParameter ffpAST = (FuncFormalParameter) fpAST;
|
||||||
return FPS.equals(ffpAST.FPS) && T.equals(ffpAST.T);
|
return FPS.equals(ffpAST.FPS) && T.equals(ffpAST.T);
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
public FormalParameterSequence FPS;
|
public FormalParameterSequence FPS;
|
||||||
public TypeDenoter T;
|
public TypeDenoter T;
|
||||||
}
|
}
|
||||||
|
@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class Identifier extends Terminal {
|
public class Identifier extends Terminal {
|
||||||
|
|
||||||
public Identifier(String theSpelling, SourcePosition thePosition) {
|
public Identifier(String theSpelling, SourcePosition thePosition) {
|
||||||
super(theSpelling, thePosition);
|
super(theSpelling, thePosition);
|
||||||
type = null;
|
type = null;
|
||||||
decl = null;
|
decl = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitIdentifier(this, o);
|
return v.visitIdentifier(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeDenoter type;
|
public TypeDenoter type;
|
||||||
public AST decl; // Either a Declaration or a FieldTypeDenoter
|
public AST decl; // Either a Declaration or a FieldTypeDenoter
|
||||||
}
|
}
|
||||||
|
@ -18,19 +18,18 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class IfCommand extends Command {
|
public class IfCommand extends Command {
|
||||||
|
|
||||||
public IfCommand(Expression eAST, Command c1AST, Command c2AST,
|
public IfCommand(Expression eAST, Command c1AST, Command c2AST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
E = eAST;
|
||||||
E = eAST;
|
C1 = c1AST;
|
||||||
C1 = c1AST;
|
C2 = c2AST;
|
||||||
C2 = c2AST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitIfCommand(this, o);
|
return v.visitIfCommand(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Expression E;
|
public Expression E;
|
||||||
public Command C1, C2;
|
public Command C1, C2;
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class IfExpression extends Expression {
|
public class IfExpression extends Expression {
|
||||||
|
|
||||||
public IfExpression(Expression e1AST, Expression e2AST, Expression e3AST,
|
public IfExpression(Expression e1AST, Expression e2AST, Expression e3AST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
E1 = e1AST;
|
||||||
E1 = e1AST;
|
E2 = e2AST;
|
||||||
E2 = e2AST;
|
E3 = e3AST;
|
||||||
E3 = e3AST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitIfExpression(this, o);
|
return v.visitIfExpression(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Expression E1, E2, E3;
|
public Expression E1, E2, E3;
|
||||||
}
|
}
|
||||||
|
@ -18,20 +18,20 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class IntTypeDenoter extends TypeDenoter {
|
public class IntTypeDenoter extends TypeDenoter {
|
||||||
|
|
||||||
public IntTypeDenoter(SourcePosition thePosition) {
|
public IntTypeDenoter(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitIntTypeDenoter(this, o);
|
return v.visitIntTypeDenoter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj != null && obj instanceof ErrorTypeDenoter)
|
if (obj != null && obj instanceof ErrorTypeDenoter)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return (obj != null && obj instanceof IntTypeDenoter);
|
return (obj != null && obj instanceof IntTypeDenoter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class IntegerExpression extends Expression {
|
public class IntegerExpression extends Expression {
|
||||||
|
|
||||||
public IntegerExpression(IntegerLiteral ilAST, SourcePosition thePosition) {
|
public IntegerExpression(IntegerLiteral ilAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
IL = ilAST;
|
IL = ilAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitIntegerExpression(this, o);
|
return v.visitIntegerExpression(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntegerLiteral IL;
|
public IntegerLiteral IL;
|
||||||
}
|
}
|
||||||
|
@ -18,13 +18,13 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class IntegerLiteral extends Terminal {
|
public class IntegerLiteral extends Terminal {
|
||||||
|
|
||||||
public IntegerLiteral(String theSpelling, SourcePosition thePosition) {
|
public IntegerLiteral(String theSpelling, SourcePosition thePosition) {
|
||||||
super(theSpelling, thePosition);
|
super(theSpelling, thePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitIntegerLiteral(this, o);
|
return v.visitIntegerLiteral(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class LetCommand extends Command {
|
public class LetCommand extends Command {
|
||||||
|
|
||||||
public LetCommand(Declaration dAST, Command cAST, SourcePosition thePosition) {
|
public LetCommand(Declaration dAST, Command cAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
D = dAST;
|
D = dAST;
|
||||||
C = cAST;
|
C = cAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitLetCommand(this, o);
|
return v.visitLetCommand(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Declaration D;
|
public Declaration D;
|
||||||
public Command C;
|
public Command C;
|
||||||
}
|
}
|
||||||
|
@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class LetExpression extends Expression {
|
public class LetExpression extends Expression {
|
||||||
|
|
||||||
public LetExpression(Declaration dAST, Expression eAST, SourcePosition thePosition) {
|
public LetExpression(Declaration dAST, Expression eAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
D = dAST;
|
D = dAST;
|
||||||
E = eAST;
|
E = eAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitLetExpression(this, o);
|
return v.visitLetExpression(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Declaration D;
|
public Declaration D;
|
||||||
public Expression E;
|
public Expression E;
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,18 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class MultipleActualParameterSequence extends ActualParameterSequence {
|
public class MultipleActualParameterSequence extends ActualParameterSequence {
|
||||||
|
|
||||||
public MultipleActualParameterSequence(ActualParameter apAST, ActualParameterSequence apsAST,
|
public MultipleActualParameterSequence(ActualParameter apAST, ActualParameterSequence apsAST,
|
||||||
SourcePosition thePosition) {
|
SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
AP = apAST;
|
AP = apAST;
|
||||||
APS = apsAST;
|
APS = apsAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitMultipleActualParameterSequence(this, o);
|
return v.visitMultipleActualParameterSequence(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActualParameter AP;
|
public ActualParameter AP;
|
||||||
public ActualParameterSequence APS;
|
public ActualParameterSequence APS;
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class MultipleArrayAggregate extends ArrayAggregate {
|
public class MultipleArrayAggregate extends ArrayAggregate {
|
||||||
|
|
||||||
public MultipleArrayAggregate(Expression eAST, ArrayAggregate aaAST,
|
public MultipleArrayAggregate(Expression eAST, ArrayAggregate aaAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
E = eAST;
|
||||||
E = eAST;
|
AA = aaAST;
|
||||||
AA = aaAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitMultipleArrayAggregate(this, o);
|
return v.visitMultipleArrayAggregate(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Expression E;
|
public Expression E;
|
||||||
public ArrayAggregate AA;
|
public ArrayAggregate AA;
|
||||||
}
|
}
|
||||||
|
@ -18,31 +18,29 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class MultipleFieldTypeDenoter extends FieldTypeDenoter {
|
public class MultipleFieldTypeDenoter extends FieldTypeDenoter {
|
||||||
|
|
||||||
public MultipleFieldTypeDenoter(Identifier iAST, TypeDenoter tAST, FieldTypeDenoter ftAST,
|
public MultipleFieldTypeDenoter(Identifier iAST, TypeDenoter tAST, FieldTypeDenoter ftAST,
|
||||||
SourcePosition thePosition) {
|
SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
I = iAST;
|
I = iAST;
|
||||||
T = tAST;
|
T = tAST;
|
||||||
FT = ftAST;
|
FT = ftAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitMultipleFieldTypeDenoter(this, o);
|
return v.visitMultipleFieldTypeDenoter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj != null && obj instanceof MultipleFieldTypeDenoter) {
|
if (obj != null && obj instanceof MultipleFieldTypeDenoter) {
|
||||||
MultipleFieldTypeDenoter ft = (MultipleFieldTypeDenoter) obj;
|
MultipleFieldTypeDenoter ft = (MultipleFieldTypeDenoter) obj;
|
||||||
return (this.I.spelling.compareTo(ft.I.spelling) == 0) &&
|
return (this.I.spelling.compareTo(ft.I.spelling) == 0) && this.T.equals(ft.T) && this.FT.equals(ft.FT);
|
||||||
this.T.equals(ft.T) &&
|
} else
|
||||||
this.FT.equals(ft.FT);
|
return false;
|
||||||
} else
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
public TypeDenoter T;
|
public TypeDenoter T;
|
||||||
public FieldTypeDenoter FT;
|
public FieldTypeDenoter FT;
|
||||||
}
|
}
|
||||||
|
@ -18,27 +18,27 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class MultipleFormalParameterSequence extends FormalParameterSequence {
|
public class MultipleFormalParameterSequence extends FormalParameterSequence {
|
||||||
|
|
||||||
public MultipleFormalParameterSequence(FormalParameter fpAST, FormalParameterSequence fpsAST,
|
public MultipleFormalParameterSequence(FormalParameter fpAST, FormalParameterSequence fpsAST,
|
||||||
SourcePosition thePosition) {
|
SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
FP = fpAST;
|
FP = fpAST;
|
||||||
FPS = fpsAST;
|
FPS = fpsAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitMultipleFormalParameterSequence(this, o);
|
return v.visitMultipleFormalParameterSequence(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object fpsAST) {
|
public boolean equals(Object fpsAST) {
|
||||||
if (fpsAST instanceof MultipleFormalParameterSequence) {
|
if (fpsAST instanceof MultipleFormalParameterSequence) {
|
||||||
MultipleFormalParameterSequence mfpsAST = (MultipleFormalParameterSequence) fpsAST;
|
MultipleFormalParameterSequence mfpsAST = (MultipleFormalParameterSequence) fpsAST;
|
||||||
return FP.equals(mfpsAST.FP) && FPS.equals(mfpsAST.FPS);
|
return FP.equals(mfpsAST.FP) && FPS.equals(mfpsAST.FPS);
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FormalParameter FP;
|
public FormalParameter FP;
|
||||||
public FormalParameterSequence FPS;
|
public FormalParameterSequence FPS;
|
||||||
}
|
}
|
||||||
|
@ -18,20 +18,20 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class MultipleRecordAggregate extends RecordAggregate {
|
public class MultipleRecordAggregate extends RecordAggregate {
|
||||||
|
|
||||||
public MultipleRecordAggregate(Identifier iAST, Expression eAST, RecordAggregate raAST,
|
public MultipleRecordAggregate(Identifier iAST, Expression eAST, RecordAggregate raAST,
|
||||||
SourcePosition thePosition) {
|
SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
I = iAST;
|
I = iAST;
|
||||||
E = eAST;
|
E = eAST;
|
||||||
RA = raAST;
|
RA = raAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitMultipleRecordAggregate(this, o);
|
return v.visitMultipleRecordAggregate(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
public Expression E;
|
public Expression E;
|
||||||
public RecordAggregate RA;
|
public RecordAggregate RA;
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class Operator extends Terminal {
|
public class Operator extends Terminal {
|
||||||
|
|
||||||
public Operator(String theSpelling, SourcePosition thePosition) {
|
public Operator(String theSpelling, SourcePosition thePosition) {
|
||||||
super(theSpelling, thePosition);
|
super(theSpelling, thePosition);
|
||||||
decl = null;
|
decl = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitOperator(this, o);
|
return v.visitOperator(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Declaration decl;
|
public Declaration decl;
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class ProcActualParameter extends ActualParameter {
|
public class ProcActualParameter extends ActualParameter {
|
||||||
|
|
||||||
public ProcActualParameter(Identifier iAST, SourcePosition thePosition) {
|
public ProcActualParameter(Identifier iAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
I = iAST;
|
I = iAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitProcActualParameter(this, o);
|
return v.visitProcActualParameter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
}
|
}
|
||||||
|
@ -18,20 +18,19 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class ProcDeclaration extends Declaration {
|
public class ProcDeclaration extends Declaration {
|
||||||
|
|
||||||
public ProcDeclaration(Identifier iAST, FormalParameterSequence fpsAST,
|
public ProcDeclaration(Identifier iAST, FormalParameterSequence fpsAST, Command cAST, SourcePosition thePosition) {
|
||||||
Command cAST, SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
I = iAST;
|
||||||
I = iAST;
|
FPS = fpsAST;
|
||||||
FPS = fpsAST;
|
C = cAST;
|
||||||
C = cAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitProcDeclaration(this, o);
|
return v.visitProcDeclaration(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
public FormalParameterSequence FPS;
|
public FormalParameterSequence FPS;
|
||||||
public Command C;
|
public Command C;
|
||||||
}
|
}
|
||||||
|
@ -18,27 +18,26 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class ProcFormalParameter extends FormalParameter {
|
public class ProcFormalParameter extends FormalParameter {
|
||||||
|
|
||||||
public ProcFormalParameter(Identifier iAST, FormalParameterSequence fpsAST,
|
public ProcFormalParameter(Identifier iAST, FormalParameterSequence fpsAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
I = iAST;
|
||||||
I = iAST;
|
FPS = fpsAST;
|
||||||
FPS = fpsAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitProcFormalParameter(this, o);
|
return v.visitProcFormalParameter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
public FormalParameterSequence FPS;
|
public FormalParameterSequence FPS;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object fpAST) {
|
public boolean equals(Object fpAST) {
|
||||||
if (fpAST instanceof ProcFormalParameter) {
|
if (fpAST instanceof ProcFormalParameter) {
|
||||||
ProcFormalParameter pfpAST = (ProcFormalParameter) fpAST;
|
ProcFormalParameter pfpAST = (ProcFormalParameter) fpAST;
|
||||||
return FPS.equals(pfpAST.FPS);
|
return FPS.equals(pfpAST.FPS);
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class Program extends AST {
|
public class Program extends AST {
|
||||||
|
|
||||||
public Program(Command cAST, SourcePosition thePosition) {
|
public Program(Command cAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
C = cAST;
|
C = cAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitProgram(this, o);
|
return v.visitProgram(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command C;
|
public Command C;
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,10 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public abstract class RecordAggregate extends AST {
|
public abstract class RecordAggregate extends AST {
|
||||||
|
|
||||||
public RecordAggregate(SourcePosition thePosition) {
|
public RecordAggregate(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
type = null;
|
type = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FieldTypeDenoter type;
|
public FieldTypeDenoter type;
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class RecordExpression extends Expression {
|
public class RecordExpression extends Expression {
|
||||||
|
|
||||||
public RecordExpression(RecordAggregate raAST, SourcePosition thePosition) {
|
public RecordExpression(RecordAggregate raAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
RA = raAST;
|
RA = raAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitRecordExpression(this, o);
|
return v.visitRecordExpression(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RecordAggregate RA;
|
public RecordAggregate RA;
|
||||||
}
|
}
|
||||||
|
@ -18,25 +18,25 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class RecordTypeDenoter extends TypeDenoter {
|
public class RecordTypeDenoter extends TypeDenoter {
|
||||||
|
|
||||||
public RecordTypeDenoter(FieldTypeDenoter ftAST, SourcePosition thePosition) {
|
public RecordTypeDenoter(FieldTypeDenoter ftAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
FT = ftAST;
|
FT = ftAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitRecordTypeDenoter(this, o);
|
return v.visitRecordTypeDenoter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj != null && obj instanceof ErrorTypeDenoter)
|
if (obj != null && obj instanceof ErrorTypeDenoter)
|
||||||
return true;
|
return true;
|
||||||
else if (obj != null && obj instanceof RecordTypeDenoter)
|
else if (obj != null && obj instanceof RecordTypeDenoter)
|
||||||
return this.FT.equals(((RecordTypeDenoter) obj).FT);
|
return this.FT.equals(((RecordTypeDenoter) obj).FT);
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FieldTypeDenoter FT;
|
public FieldTypeDenoter FT;
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,16 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class SequentialCommand extends Command {
|
public class SequentialCommand extends Command {
|
||||||
|
|
||||||
public SequentialCommand(Command c1AST, Command c2AST, SourcePosition thePosition) {
|
public SequentialCommand(Command c1AST, Command c2AST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
C1 = c1AST;
|
C1 = c1AST;
|
||||||
C2 = c2AST;
|
C2 = c2AST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitSequentialCommand(this, o);
|
return v.visitSequentialCommand(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command C1, C2;
|
public Command C1, C2;
|
||||||
}
|
}
|
||||||
|
@ -18,17 +18,16 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class SequentialDeclaration extends Declaration {
|
public class SequentialDeclaration extends Declaration {
|
||||||
|
|
||||||
public SequentialDeclaration(Declaration d1AST, Declaration d2AST,
|
public SequentialDeclaration(Declaration d1AST, Declaration d2AST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
D1 = d1AST;
|
||||||
D1 = d1AST;
|
D2 = d2AST;
|
||||||
D2 = d2AST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitSequentialDeclaration(this, o);
|
return v.visitSequentialDeclaration(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Declaration D1, D2;
|
public Declaration D1, D2;
|
||||||
}
|
}
|
||||||
|
@ -18,20 +18,20 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class SimpleTypeDenoter extends TypeDenoter {
|
public class SimpleTypeDenoter extends TypeDenoter {
|
||||||
|
|
||||||
public SimpleTypeDenoter(Identifier iAST, SourcePosition thePosition) {
|
public SimpleTypeDenoter(Identifier iAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
I = iAST;
|
I = iAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitSimpleTypeDenoter(this, o);
|
return v.visitSimpleTypeDenoter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return false; // should not happen
|
return false; // should not happen
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class SimpleVname extends Vname {
|
public class SimpleVname extends Vname {
|
||||||
|
|
||||||
public SimpleVname(Identifier iAST, SourcePosition thePosition) {
|
public SimpleVname(Identifier iAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
I = iAST;
|
I = iAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitSimpleVname(this, o);
|
return v.visitSimpleVname(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class SingleActualParameterSequence extends ActualParameterSequence {
|
public class SingleActualParameterSequence extends ActualParameterSequence {
|
||||||
|
|
||||||
public SingleActualParameterSequence(ActualParameter apAST,
|
public SingleActualParameterSequence(ActualParameter apAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
AP = apAST;
|
||||||
AP = apAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitSingleActualParameterSequence(this, o);
|
return v.visitSingleActualParameterSequence(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActualParameter AP;
|
public ActualParameter AP;
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class SingleArrayAggregate extends ArrayAggregate {
|
public class SingleArrayAggregate extends ArrayAggregate {
|
||||||
|
|
||||||
public SingleArrayAggregate(Expression eAST,
|
public SingleArrayAggregate(Expression eAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
E = eAST;
|
||||||
E = eAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitSingleArrayAggregate(this, o);
|
return v.visitSingleArrayAggregate(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Expression E;
|
public Expression E;
|
||||||
}
|
}
|
||||||
|
@ -18,28 +18,26 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class SingleFieldTypeDenoter extends FieldTypeDenoter {
|
public class SingleFieldTypeDenoter extends FieldTypeDenoter {
|
||||||
|
|
||||||
public SingleFieldTypeDenoter(Identifier iAST, TypeDenoter tAST,
|
public SingleFieldTypeDenoter(Identifier iAST, TypeDenoter tAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
I = iAST;
|
||||||
I = iAST;
|
T = tAST;
|
||||||
T = tAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitSingleFieldTypeDenoter(this, o);
|
return v.visitSingleFieldTypeDenoter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj != null && obj instanceof SingleFieldTypeDenoter) {
|
if (obj != null && obj instanceof SingleFieldTypeDenoter) {
|
||||||
SingleFieldTypeDenoter ft = (SingleFieldTypeDenoter) obj;
|
SingleFieldTypeDenoter ft = (SingleFieldTypeDenoter) obj;
|
||||||
return (this.I.spelling.compareTo(ft.I.spelling) == 0) &&
|
return (this.I.spelling.compareTo(ft.I.spelling) == 0) && this.T.equals(ft.T);
|
||||||
this.T.equals(ft.T);
|
} else
|
||||||
} else
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
public TypeDenoter T;
|
public TypeDenoter T;
|
||||||
}
|
}
|
||||||
|
@ -18,25 +18,24 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class SingleFormalParameterSequence extends FormalParameterSequence {
|
public class SingleFormalParameterSequence extends FormalParameterSequence {
|
||||||
|
|
||||||
public SingleFormalParameterSequence(FormalParameter fpAST,
|
public SingleFormalParameterSequence(FormalParameter fpAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
FP = fpAST;
|
||||||
FP = fpAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitSingleFormalParameterSequence(this, o);
|
return v.visitSingleFormalParameterSequence(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object fpsAST) {
|
public boolean equals(Object fpsAST) {
|
||||||
if (fpsAST instanceof SingleFormalParameterSequence) {
|
if (fpsAST instanceof SingleFormalParameterSequence) {
|
||||||
SingleFormalParameterSequence sfpsAST = (SingleFormalParameterSequence) fpsAST;
|
SingleFormalParameterSequence sfpsAST = (SingleFormalParameterSequence) fpsAST;
|
||||||
return FP.equals(sfpsAST.FP);
|
return FP.equals(sfpsAST.FP);
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FormalParameter FP;
|
public FormalParameter FP;
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class SingleRecordAggregate extends RecordAggregate {
|
public class SingleRecordAggregate extends RecordAggregate {
|
||||||
|
|
||||||
public SingleRecordAggregate(Identifier iAST, Expression eAST,
|
public SingleRecordAggregate(Identifier iAST, Expression eAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
I = iAST;
|
||||||
I = iAST;
|
E = eAST;
|
||||||
E = eAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitSingleRecordAggregate(this, o);
|
return v.visitSingleRecordAggregate(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
public Expression E;
|
public Expression E;
|
||||||
}
|
}
|
||||||
|
@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class SubscriptVname extends Vname {
|
public class SubscriptVname extends Vname {
|
||||||
|
|
||||||
public SubscriptVname(Vname vAST, Expression eAST, SourcePosition thePosition) {
|
public SubscriptVname(Vname vAST, Expression eAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
V = vAST;
|
V = vAST;
|
||||||
E = eAST;
|
E = eAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitSubscriptVname(this, o);
|
return v.visitSubscriptVname(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Expression E;
|
public Expression E;
|
||||||
public Vname V;
|
public Vname V;
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,10 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
abstract public class Terminal extends AST {
|
abstract public class Terminal extends AST {
|
||||||
|
|
||||||
public Terminal(String theSpelling, SourcePosition thePosition) {
|
public Terminal(String theSpelling, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
spelling = theSpelling;
|
spelling = theSpelling;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String spelling;
|
public String spelling;
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class TypeDeclaration extends Declaration {
|
public class TypeDeclaration extends Declaration {
|
||||||
|
|
||||||
public TypeDeclaration(Identifier iAST, TypeDenoter tAST,
|
public TypeDeclaration(Identifier iAST, TypeDenoter tAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
I = iAST;
|
||||||
I = iAST;
|
T = tAST;
|
||||||
T = tAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitTypeDeclaration(this, o);
|
return v.visitTypeDeclaration(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
public TypeDenoter T;
|
public TypeDenoter T;
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,11 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public abstract class TypeDenoter extends AST {
|
public abstract class TypeDenoter extends AST {
|
||||||
|
|
||||||
public TypeDenoter(SourcePosition thePosition) {
|
public TypeDenoter(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean equals(Object obj);
|
public abstract boolean equals(Object obj);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class UnaryExpression extends Expression {
|
public class UnaryExpression extends Expression {
|
||||||
|
|
||||||
public UnaryExpression(Operator oAST, Expression eAST,
|
public UnaryExpression(Operator oAST, Expression eAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
O = oAST;
|
||||||
O = oAST;
|
E = eAST;
|
||||||
E = eAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitUnaryExpression(this, o);
|
return v.visitUnaryExpression(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Expression E;
|
public Expression E;
|
||||||
public Operator O;
|
public Operator O;
|
||||||
}
|
}
|
||||||
|
@ -18,19 +18,19 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class UnaryOperatorDeclaration extends Declaration {
|
public class UnaryOperatorDeclaration extends Declaration {
|
||||||
|
|
||||||
public UnaryOperatorDeclaration(Operator oAST, TypeDenoter argAST,
|
public UnaryOperatorDeclaration(Operator oAST, TypeDenoter argAST, TypeDenoter resultAST,
|
||||||
TypeDenoter resultAST, SourcePosition thePosition) {
|
SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
O = oAST;
|
O = oAST;
|
||||||
ARG = argAST;
|
ARG = argAST;
|
||||||
RES = resultAST;
|
RES = resultAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitUnaryOperatorDeclaration(this, o);
|
return v.visitUnaryOperatorDeclaration(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Operator O;
|
public Operator O;
|
||||||
public TypeDenoter ARG, RES;
|
public TypeDenoter ARG, RES;
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class VarActualParameter extends ActualParameter {
|
public class VarActualParameter extends ActualParameter {
|
||||||
|
|
||||||
public VarActualParameter(Vname vAST, SourcePosition thePosition) {
|
public VarActualParameter(Vname vAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
V = vAST;
|
V = vAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitVarActualParameter(this, o);
|
return v.visitVarActualParameter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vname V;
|
public Vname V;
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class VarDeclaration extends Declaration {
|
public class VarDeclaration extends Declaration {
|
||||||
|
|
||||||
public VarDeclaration(Identifier iAST, TypeDenoter tAST,
|
public VarDeclaration(Identifier iAST, TypeDenoter tAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
I = iAST;
|
||||||
I = iAST;
|
T = tAST;
|
||||||
T = tAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitVarDeclaration(this, o);
|
return v.visitVarDeclaration(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
public TypeDenoter T;
|
public TypeDenoter T;
|
||||||
}
|
}
|
||||||
|
@ -18,27 +18,26 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class VarFormalParameter extends FormalParameter {
|
public class VarFormalParameter extends FormalParameter {
|
||||||
|
|
||||||
public VarFormalParameter(Identifier iAST, TypeDenoter tAST,
|
public VarFormalParameter(Identifier iAST, TypeDenoter tAST, SourcePosition thePosition) {
|
||||||
SourcePosition thePosition) {
|
super(thePosition);
|
||||||
super(thePosition);
|
I = iAST;
|
||||||
I = iAST;
|
T = tAST;
|
||||||
T = tAST;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitVarFormalParameter(this, o);
|
return v.visitVarFormalParameter(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier I;
|
public Identifier I;
|
||||||
public TypeDenoter T;
|
public TypeDenoter T;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object fpAST) {
|
public boolean equals(Object fpAST) {
|
||||||
if (fpAST instanceof VarFormalParameter) {
|
if (fpAST instanceof VarFormalParameter) {
|
||||||
VarFormalParameter vfpAST = (VarFormalParameter) fpAST;
|
VarFormalParameter vfpAST = (VarFormalParameter) fpAST;
|
||||||
return T.equals(vfpAST.T);
|
return T.equals(vfpAST.T);
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,139 +16,139 @@ package Triangle.AbstractSyntaxTrees;
|
|||||||
|
|
||||||
public interface Visitor {
|
public interface Visitor {
|
||||||
|
|
||||||
// Commands
|
// Commands
|
||||||
public abstract Object visitAssignCommand(AssignCommand ast, Object o);
|
public abstract Object visitAssignCommand(AssignCommand ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitCallCommand(CallCommand ast, Object o);
|
public abstract Object visitCallCommand(CallCommand ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitEmptyCommand(EmptyCommand ast, Object o);
|
public abstract Object visitEmptyCommand(EmptyCommand ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitIfCommand(IfCommand ast, Object o);
|
public abstract Object visitIfCommand(IfCommand ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitLetCommand(LetCommand ast, Object o);
|
public abstract Object visitLetCommand(LetCommand ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitSequentialCommand(SequentialCommand ast, Object o);
|
public abstract Object visitSequentialCommand(SequentialCommand ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitWhileCommand(WhileCommand ast, Object o);
|
public abstract Object visitWhileCommand(WhileCommand ast, Object o);
|
||||||
|
|
||||||
// Expressions
|
// Expressions
|
||||||
public abstract Object visitArrayExpression(ArrayExpression ast, Object o);
|
public abstract Object visitArrayExpression(ArrayExpression ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitBinaryExpression(BinaryExpression ast, Object o);
|
public abstract Object visitBinaryExpression(BinaryExpression ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitCallExpression(CallExpression ast, Object o);
|
public abstract Object visitCallExpression(CallExpression ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitCharacterExpression(CharacterExpression ast, Object o);
|
public abstract Object visitCharacterExpression(CharacterExpression ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitEmptyExpression(EmptyExpression ast, Object o);
|
public abstract Object visitEmptyExpression(EmptyExpression ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitIfExpression(IfExpression ast, Object o);
|
public abstract Object visitIfExpression(IfExpression ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitIntegerExpression(IntegerExpression ast, Object o);
|
public abstract Object visitIntegerExpression(IntegerExpression ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitLetExpression(LetExpression ast, Object o);
|
public abstract Object visitLetExpression(LetExpression ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitRecordExpression(RecordExpression ast, Object o);
|
public abstract Object visitRecordExpression(RecordExpression ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitUnaryExpression(UnaryExpression ast, Object o);
|
public abstract Object visitUnaryExpression(UnaryExpression ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitVnameExpression(VnameExpression ast, Object o);
|
public abstract Object visitVnameExpression(VnameExpression ast, Object o);
|
||||||
|
|
||||||
// Declarations
|
// Declarations
|
||||||
public abstract Object visitBinaryOperatorDeclaration(BinaryOperatorDeclaration ast, Object o);
|
public abstract Object visitBinaryOperatorDeclaration(BinaryOperatorDeclaration ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitConstDeclaration(ConstDeclaration ast, Object o);
|
public abstract Object visitConstDeclaration(ConstDeclaration ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitFuncDeclaration(FuncDeclaration ast, Object o);
|
public abstract Object visitFuncDeclaration(FuncDeclaration ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitProcDeclaration(ProcDeclaration ast, Object o);
|
public abstract Object visitProcDeclaration(ProcDeclaration ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitSequentialDeclaration(SequentialDeclaration ast, Object o);
|
public abstract Object visitSequentialDeclaration(SequentialDeclaration ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitTypeDeclaration(TypeDeclaration ast, Object o);
|
public abstract Object visitTypeDeclaration(TypeDeclaration ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitUnaryOperatorDeclaration(UnaryOperatorDeclaration ast, Object o);
|
public abstract Object visitUnaryOperatorDeclaration(UnaryOperatorDeclaration ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitVarDeclaration(VarDeclaration ast, Object o);
|
public abstract Object visitVarDeclaration(VarDeclaration ast, Object o);
|
||||||
|
|
||||||
// Array Aggregates
|
// Array Aggregates
|
||||||
public abstract Object visitMultipleArrayAggregate(MultipleArrayAggregate ast, Object o);
|
public abstract Object visitMultipleArrayAggregate(MultipleArrayAggregate ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitSingleArrayAggregate(SingleArrayAggregate ast, Object o);
|
public abstract Object visitSingleArrayAggregate(SingleArrayAggregate ast, Object o);
|
||||||
|
|
||||||
// Record Aggregates
|
// Record Aggregates
|
||||||
public abstract Object visitMultipleRecordAggregate(MultipleRecordAggregate ast, Object o);
|
public abstract Object visitMultipleRecordAggregate(MultipleRecordAggregate ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitSingleRecordAggregate(SingleRecordAggregate ast, Object o);
|
public abstract Object visitSingleRecordAggregate(SingleRecordAggregate ast, Object o);
|
||||||
|
|
||||||
// Formal Parameters
|
// Formal Parameters
|
||||||
public abstract Object visitConstFormalParameter(ConstFormalParameter ast, Object o);
|
public abstract Object visitConstFormalParameter(ConstFormalParameter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitFuncFormalParameter(FuncFormalParameter ast, Object o);
|
public abstract Object visitFuncFormalParameter(FuncFormalParameter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitProcFormalParameter(ProcFormalParameter ast, Object o);
|
public abstract Object visitProcFormalParameter(ProcFormalParameter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitVarFormalParameter(VarFormalParameter ast, Object o);
|
public abstract Object visitVarFormalParameter(VarFormalParameter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitEmptyFormalParameterSequence(EmptyFormalParameterSequence ast, Object o);
|
public abstract Object visitEmptyFormalParameterSequence(EmptyFormalParameterSequence ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitMultipleFormalParameterSequence(MultipleFormalParameterSequence ast, Object o);
|
public abstract Object visitMultipleFormalParameterSequence(MultipleFormalParameterSequence ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitSingleFormalParameterSequence(SingleFormalParameterSequence ast, Object o);
|
public abstract Object visitSingleFormalParameterSequence(SingleFormalParameterSequence ast, Object o);
|
||||||
|
|
||||||
// Actual Parameters
|
// Actual Parameters
|
||||||
public abstract Object visitConstActualParameter(ConstActualParameter ast, Object o);
|
public abstract Object visitConstActualParameter(ConstActualParameter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitFuncActualParameter(FuncActualParameter ast, Object o);
|
public abstract Object visitFuncActualParameter(FuncActualParameter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitProcActualParameter(ProcActualParameter ast, Object o);
|
public abstract Object visitProcActualParameter(ProcActualParameter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitVarActualParameter(VarActualParameter ast, Object o);
|
public abstract Object visitVarActualParameter(VarActualParameter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitEmptyActualParameterSequence(EmptyActualParameterSequence ast, Object o);
|
public abstract Object visitEmptyActualParameterSequence(EmptyActualParameterSequence ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitMultipleActualParameterSequence(MultipleActualParameterSequence ast, Object o);
|
public abstract Object visitMultipleActualParameterSequence(MultipleActualParameterSequence ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitSingleActualParameterSequence(SingleActualParameterSequence ast, Object o);
|
public abstract Object visitSingleActualParameterSequence(SingleActualParameterSequence ast, Object o);
|
||||||
|
|
||||||
// Type Denoters
|
// Type Denoters
|
||||||
public abstract Object visitAnyTypeDenoter(AnyTypeDenoter ast, Object o);
|
public abstract Object visitAnyTypeDenoter(AnyTypeDenoter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitArrayTypeDenoter(ArrayTypeDenoter ast, Object o);
|
public abstract Object visitArrayTypeDenoter(ArrayTypeDenoter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitBoolTypeDenoter(BoolTypeDenoter ast, Object o);
|
public abstract Object visitBoolTypeDenoter(BoolTypeDenoter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitCharTypeDenoter(CharTypeDenoter ast, Object o);
|
public abstract Object visitCharTypeDenoter(CharTypeDenoter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitErrorTypeDenoter(ErrorTypeDenoter ast, Object o);
|
public abstract Object visitErrorTypeDenoter(ErrorTypeDenoter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitSimpleTypeDenoter(SimpleTypeDenoter ast, Object o);
|
public abstract Object visitSimpleTypeDenoter(SimpleTypeDenoter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitIntTypeDenoter(IntTypeDenoter ast, Object o);
|
public abstract Object visitIntTypeDenoter(IntTypeDenoter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitRecordTypeDenoter(RecordTypeDenoter ast, Object o);
|
public abstract Object visitRecordTypeDenoter(RecordTypeDenoter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitMultipleFieldTypeDenoter(MultipleFieldTypeDenoter ast, Object o);
|
public abstract Object visitMultipleFieldTypeDenoter(MultipleFieldTypeDenoter ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitSingleFieldTypeDenoter(SingleFieldTypeDenoter ast, Object o);
|
public abstract Object visitSingleFieldTypeDenoter(SingleFieldTypeDenoter ast, Object o);
|
||||||
|
|
||||||
// Literals, Identifiers and Operators
|
// Literals, Identifiers and Operators
|
||||||
public abstract Object visitCharacterLiteral(CharacterLiteral ast, Object o);
|
public abstract Object visitCharacterLiteral(CharacterLiteral ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitIdentifier(Identifier ast, Object o);
|
public abstract Object visitIdentifier(Identifier ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitIntegerLiteral(IntegerLiteral ast, Object o);
|
public abstract Object visitIntegerLiteral(IntegerLiteral ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitOperator(Operator ast, Object o);
|
public abstract Object visitOperator(Operator ast, Object o);
|
||||||
|
|
||||||
// Value-or-variable names
|
// Value-or-variable names
|
||||||
public abstract Object visitDotVname(DotVname ast, Object o);
|
public abstract Object visitDotVname(DotVname ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitSimpleVname(SimpleVname ast, Object o);
|
public abstract Object visitSimpleVname(SimpleVname ast, Object o);
|
||||||
|
|
||||||
public abstract Object visitSubscriptVname(SubscriptVname ast, Object o);
|
public abstract Object visitSubscriptVname(SubscriptVname ast, Object o);
|
||||||
|
|
||||||
// Programs
|
// Programs
|
||||||
public abstract Object visitProgram(Program ast, Object o);
|
public abstract Object visitProgram(Program ast, Object o);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,13 +18,13 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public abstract class Vname extends AST {
|
public abstract class Vname extends AST {
|
||||||
|
|
||||||
public Vname(SourcePosition thePosition) {
|
public Vname(SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
variable = false;
|
variable = false;
|
||||||
type = null;
|
type = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean variable, indexed;
|
public boolean variable, indexed;
|
||||||
public int offset;
|
public int offset;
|
||||||
public TypeDenoter type;
|
public TypeDenoter type;
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,15 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class VnameExpression extends Expression {
|
public class VnameExpression extends Expression {
|
||||||
|
|
||||||
public VnameExpression(Vname vAST, SourcePosition thePosition) {
|
public VnameExpression(Vname vAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
V = vAST;
|
V = vAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitVnameExpression(this, o);
|
return v.visitVnameExpression(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vname V;
|
public Vname V;
|
||||||
}
|
}
|
||||||
|
@ -18,17 +18,17 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class WhileCommand extends Command {
|
public class WhileCommand extends Command {
|
||||||
|
|
||||||
public WhileCommand(Expression eAST, Command cAST, SourcePosition thePosition) {
|
public WhileCommand(Expression eAST, Command cAST, SourcePosition thePosition) {
|
||||||
super(thePosition);
|
super(thePosition);
|
||||||
E = eAST;
|
E = eAST;
|
||||||
C = cAST;
|
C = cAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(Visitor v, Object o) {
|
public Object visit(Visitor v, Object o) {
|
||||||
return v.visitWhileCommand(this, o);
|
return v.visitWhileCommand(this, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Expression E;
|
public Expression E;
|
||||||
public Command C;
|
public Command C;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -16,15 +16,15 @@ package Triangle.CodeGenerator;
|
|||||||
|
|
||||||
public class EqualityRoutine extends RuntimeEntity {
|
public class EqualityRoutine extends RuntimeEntity {
|
||||||
|
|
||||||
public EqualityRoutine() {
|
public EqualityRoutine() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EqualityRoutine(int size, int displacement) {
|
public EqualityRoutine(int size, int displacement) {
|
||||||
super(size);
|
super(size);
|
||||||
this.displacement = displacement;
|
this.displacement = displacement;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int displacement;
|
public int displacement;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,16 @@ package Triangle.CodeGenerator;
|
|||||||
|
|
||||||
public class Field extends RuntimeEntity {
|
public class Field extends RuntimeEntity {
|
||||||
|
|
||||||
public Field() {
|
public Field() {
|
||||||
super();
|
super();
|
||||||
fieldOffset = 0;
|
fieldOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Field(int size, int fieldOffset) {
|
public Field(int size, int fieldOffset) {
|
||||||
super(size);
|
super(size);
|
||||||
this.fieldOffset = fieldOffset;
|
this.fieldOffset = fieldOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int fieldOffset;
|
public int fieldOffset;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,31 +16,31 @@ package Triangle.CodeGenerator;
|
|||||||
|
|
||||||
public class Frame {
|
public class Frame {
|
||||||
|
|
||||||
public Frame() {
|
public Frame() {
|
||||||
this.level = 0;
|
this.level = 0;
|
||||||
this.size = 0;
|
this.size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Frame(int level, Integer size) {
|
public Frame(int level, Integer size) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.size = size.intValue();
|
this.size = size.intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Frame(int level, int size) {
|
public Frame(int level, int size) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Frame(Frame frame, int sizeIncrement) {
|
public Frame(Frame frame, int sizeIncrement) {
|
||||||
this.level = frame.level;
|
this.level = frame.level;
|
||||||
this.size = frame.size + sizeIncrement;
|
this.size = frame.size + sizeIncrement;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Frame(Frame frame, Integer sizeIncrement) {
|
public Frame(Frame frame, Integer sizeIncrement) {
|
||||||
this.level = frame.level;
|
this.level = frame.level;
|
||||||
this.size = frame.size + sizeIncrement.intValue();
|
this.size = frame.size + sizeIncrement.intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int level;
|
protected int level;
|
||||||
protected int size;
|
protected int size;
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,16 @@ package Triangle.CodeGenerator;
|
|||||||
|
|
||||||
public class KnownAddress extends RuntimeEntity {
|
public class KnownAddress extends RuntimeEntity {
|
||||||
|
|
||||||
public KnownAddress() {
|
public KnownAddress() {
|
||||||
super();
|
super();
|
||||||
address = null;
|
address = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public KnownAddress(int size, int level, int displacement) {
|
public KnownAddress(int size, int level, int displacement) {
|
||||||
super(size);
|
super(size);
|
||||||
address = new ObjectAddress(level, displacement);
|
address = new ObjectAddress(level, displacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectAddress address;
|
public ObjectAddress address;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,16 @@ package Triangle.CodeGenerator;
|
|||||||
|
|
||||||
public class KnownRoutine extends RuntimeEntity {
|
public class KnownRoutine extends RuntimeEntity {
|
||||||
|
|
||||||
public KnownRoutine() {
|
public KnownRoutine() {
|
||||||
super();
|
super();
|
||||||
address = null;
|
address = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public KnownRoutine(int size, int level, int displacement) {
|
public KnownRoutine(int size, int level, int displacement) {
|
||||||
super(size);
|
super(size);
|
||||||
address = new ObjectAddress(level, displacement);
|
address = new ObjectAddress(level, displacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectAddress address;
|
public ObjectAddress address;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,16 @@ package Triangle.CodeGenerator;
|
|||||||
|
|
||||||
public class KnownValue extends RuntimeEntity {
|
public class KnownValue extends RuntimeEntity {
|
||||||
|
|
||||||
public KnownValue() {
|
public KnownValue() {
|
||||||
super();
|
super();
|
||||||
value = 0;
|
value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public KnownValue(int size, int value) {
|
public KnownValue(int size, int value) {
|
||||||
super(size);
|
super(size);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int value;
|
public int value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,11 @@ package Triangle.CodeGenerator;
|
|||||||
|
|
||||||
public final class ObjectAddress {
|
public final class ObjectAddress {
|
||||||
|
|
||||||
public ObjectAddress(int level, int displacement) {
|
public ObjectAddress(int level, int displacement) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.displacement = displacement;
|
this.displacement = displacement;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int level, displacement;
|
public int level, displacement;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,16 @@ package Triangle.CodeGenerator;
|
|||||||
|
|
||||||
public class PrimitiveRoutine extends RuntimeEntity {
|
public class PrimitiveRoutine extends RuntimeEntity {
|
||||||
|
|
||||||
public PrimitiveRoutine() {
|
public PrimitiveRoutine() {
|
||||||
super();
|
super();
|
||||||
displacement = 0;
|
displacement = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PrimitiveRoutine(int size, int displacement) {
|
public PrimitiveRoutine(int size, int displacement) {
|
||||||
super(size);
|
super(size);
|
||||||
this.displacement = displacement;
|
this.displacement = displacement;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int displacement;
|
public int displacement;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,16 @@ package Triangle.CodeGenerator;
|
|||||||
|
|
||||||
public abstract class RuntimeEntity {
|
public abstract class RuntimeEntity {
|
||||||
|
|
||||||
public final static int maxRoutineLevel = 7;
|
public final static int maxRoutineLevel = 7;
|
||||||
|
|
||||||
public RuntimeEntity() {
|
public RuntimeEntity() {
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RuntimeEntity(int size) {
|
public RuntimeEntity(int size) {
|
||||||
this.size = size;
|
this.size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size;
|
public int size;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@ package Triangle.CodeGenerator;
|
|||||||
|
|
||||||
public class TypeRepresentation extends RuntimeEntity {
|
public class TypeRepresentation extends RuntimeEntity {
|
||||||
|
|
||||||
public TypeRepresentation(int size) {
|
public TypeRepresentation(int size) {
|
||||||
super(size);
|
super(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,16 @@ package Triangle.CodeGenerator;
|
|||||||
|
|
||||||
public class UnknownAddress extends RuntimeEntity {
|
public class UnknownAddress extends RuntimeEntity {
|
||||||
|
|
||||||
public UnknownAddress() {
|
public UnknownAddress() {
|
||||||
super();
|
super();
|
||||||
address = null;
|
address = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnknownAddress(int size, int level, int displacement) {
|
public UnknownAddress(int size, int level, int displacement) {
|
||||||
super(size);
|
super(size);
|
||||||
address = new ObjectAddress(level, displacement);
|
address = new ObjectAddress(level, displacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectAddress address;
|
public ObjectAddress address;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,16 @@ package Triangle.CodeGenerator;
|
|||||||
|
|
||||||
public class UnknownRoutine extends RuntimeEntity {
|
public class UnknownRoutine extends RuntimeEntity {
|
||||||
|
|
||||||
public UnknownRoutine() {
|
public UnknownRoutine() {
|
||||||
super();
|
super();
|
||||||
address = null;
|
address = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnknownRoutine(int size, int level, int displacement) {
|
public UnknownRoutine(int size, int level, int displacement) {
|
||||||
super(size);
|
super(size);
|
||||||
address = new ObjectAddress(level, displacement);
|
address = new ObjectAddress(level, displacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectAddress address;
|
public ObjectAddress address;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,16 @@ package Triangle.CodeGenerator;
|
|||||||
|
|
||||||
public class UnknownValue extends RuntimeEntity {
|
public class UnknownValue extends RuntimeEntity {
|
||||||
|
|
||||||
public UnknownValue() {
|
public UnknownValue() {
|
||||||
super();
|
super();
|
||||||
address = null;
|
address = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnknownValue(int size, int level, int displacement) {
|
public UnknownValue(int size, int level, int displacement) {
|
||||||
super(size);
|
super(size);
|
||||||
address = new ObjectAddress(level, displacement);
|
address = new ObjectAddress(level, displacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectAddress address;
|
public ObjectAddress address;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,98 +30,94 @@ import Triangle.TreeDrawer.Drawer;
|
|||||||
*/
|
*/
|
||||||
public class Compiler {
|
public class Compiler {
|
||||||
|
|
||||||
/** The filename for the object program, normally obj.tam. */
|
/** The filename for the object program, normally obj.tam. */
|
||||||
static String objectName = "obj.tam";
|
static String objectName = "obj.tam";
|
||||||
|
|
||||||
private static Scanner scanner;
|
private static Scanner scanner;
|
||||||
private static Parser parser;
|
private static Parser parser;
|
||||||
private static Checker checker;
|
private static Checker checker;
|
||||||
private static Encoder encoder;
|
private static Encoder encoder;
|
||||||
private static ErrorReporter reporter;
|
private static ErrorReporter reporter;
|
||||||
private static Drawer drawer;
|
private static Drawer drawer;
|
||||||
|
|
||||||
/** The AST representing the source program. */
|
/** The AST representing the source program. */
|
||||||
private static Program theAST;
|
private static Program theAST;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile the source program to TAM machine code.
|
* Compile the source program to TAM machine code.
|
||||||
*
|
*
|
||||||
* @param sourceName the name of the file containing the
|
* @param sourceName the name of the file containing the source program.
|
||||||
* source program.
|
* @param objectName the name of the file containing the object program.
|
||||||
* @param objectName the name of the file containing the
|
* @param showingAST true iff the AST is to be displayed after contextual
|
||||||
* object program.
|
* analysis (not currently implemented).
|
||||||
* @param showingAST true iff the AST is to be displayed after
|
* @param showingTable true iff the object description details are to be
|
||||||
* contextual analysis (not currently implemented).
|
* displayed during code generation (not currently
|
||||||
* @param showingTable true iff the object description details are to
|
* implemented).
|
||||||
* be displayed during code generation (not
|
* @return true iff the source program is free of compile-time errors, otherwise
|
||||||
* currently implemented).
|
* false.
|
||||||
* @return true iff the source program is free of compile-time errors,
|
*/
|
||||||
* otherwise false.
|
static boolean compileProgram(String sourceName, String objectName, boolean showingAST, boolean showingTable) {
|
||||||
*/
|
|
||||||
static boolean compileProgram(String sourceName, String objectName,
|
|
||||||
boolean showingAST, boolean showingTable) {
|
|
||||||
|
|
||||||
System.out.println("********** " +
|
System.out.println("********** " + "Triangle Compiler (Java Version 2.1)" + " **********");
|
||||||
"Triangle Compiler (Java Version 2.1)" +
|
|
||||||
" **********");
|
|
||||||
|
|
||||||
System.out.println("Syntactic Analysis ...");
|
System.out.println("Syntactic Analysis ...");
|
||||||
SourceFile source = new SourceFile(sourceName);
|
SourceFile source = SourceFile.ofPath(sourceName);
|
||||||
|
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
System.out.println("Can't access source file " + sourceName);
|
System.out.println("Can't access source file " + sourceName);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
scanner = new Scanner(source);
|
scanner = new Scanner(source);
|
||||||
reporter = new ErrorReporter();
|
reporter = new ErrorReporter();
|
||||||
parser = new Parser(scanner, reporter);
|
parser = new Parser(scanner, reporter);
|
||||||
checker = new Checker(reporter);
|
checker = new Checker(reporter);
|
||||||
encoder = new Encoder(reporter);
|
encoder = new Encoder(reporter);
|
||||||
drawer = new Drawer();
|
drawer = new Drawer();
|
||||||
|
|
||||||
// scanner.enableDebugging();
|
// scanner.enableDebugging();
|
||||||
theAST = parser.parseProgram(); // 1st pass
|
theAST = parser.parseProgram(); // 1st pass
|
||||||
if (reporter.numErrors == 0) {
|
if (reporter.numErrors == 0) {
|
||||||
// if (showingAST) {
|
// if (showingAST) {
|
||||||
// drawer.draw(theAST);
|
// drawer.draw(theAST);
|
||||||
// }
|
// }
|
||||||
System.out.println("Contextual Analysis ...");
|
System.out.println("Contextual Analysis ...");
|
||||||
checker.check(theAST); // 2nd pass
|
checker.check(theAST); // 2nd pass
|
||||||
if (showingAST) {
|
if (showingAST) {
|
||||||
drawer.draw(theAST);
|
drawer.draw(theAST);
|
||||||
}
|
}
|
||||||
if (reporter.numErrors == 0) {
|
if (reporter.numErrors == 0) {
|
||||||
System.out.println("Code Generation ...");
|
System.out.println("Code Generation ...");
|
||||||
encoder.encodeRun(theAST, showingTable); // 3rd pass
|
encoder.encodeRun(theAST, showingTable); // 3rd pass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean successful = (reporter.numErrors == 0);
|
boolean successful = (reporter.numErrors == 0);
|
||||||
if (successful) {
|
if (successful) {
|
||||||
encoder.saveObjectProgram(objectName);
|
encoder.saveObjectProgram(objectName);
|
||||||
System.out.println("Compilation was successful.");
|
System.out.println("Compilation was successful.");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Compilation was unsuccessful.");
|
System.out.println("Compilation was unsuccessful.");
|
||||||
}
|
}
|
||||||
return successful;
|
return successful;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triangle compiler main program.
|
* Triangle compiler main program.
|
||||||
*
|
*
|
||||||
* @param args the only command-line argument to the program specifies
|
* @param args the only command-line argument to the program specifies the
|
||||||
* the source filename.
|
* source filename.
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
boolean compiledOK;
|
|
||||||
|
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
System.out.println("Usage: tc filename");
|
System.out.println("Usage: tc filename");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String sourceName = args[0];
|
String sourceName = args[0];
|
||||||
compiledOK = compileProgram(sourceName, objectName, false, false);
|
var compiledOK = compileProgram(sourceName, objectName, false, false);
|
||||||
}
|
|
||||||
|
System.exit(compiledOK ? 0 : 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -18,16 +18,16 @@ import Triangle.AbstractSyntaxTrees.Declaration;
|
|||||||
|
|
||||||
public class IdEntry {
|
public class IdEntry {
|
||||||
|
|
||||||
protected String id;
|
protected String id;
|
||||||
protected Declaration attr;
|
protected Declaration attr;
|
||||||
protected int level;
|
protected int level;
|
||||||
protected IdEntry previous;
|
protected IdEntry previous;
|
||||||
|
|
||||||
IdEntry(String id, Declaration attr, int level, IdEntry previous) {
|
IdEntry(String id, Declaration attr, int level, IdEntry previous) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.attr = attr;
|
this.attr = attr;
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.previous = previous;
|
this.previous = previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,91 +18,91 @@ import Triangle.AbstractSyntaxTrees.Declaration;
|
|||||||
|
|
||||||
public final class IdentificationTable {
|
public final class IdentificationTable {
|
||||||
|
|
||||||
private int level;
|
private int level;
|
||||||
private IdEntry latest;
|
private IdEntry latest;
|
||||||
|
|
||||||
public IdentificationTable() {
|
public IdentificationTable() {
|
||||||
level = 0;
|
level = 0;
|
||||||
latest = null;
|
latest = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opens a new level in the identification table, 1 higher than the
|
// Opens a new level in the identification table, 1 higher than the
|
||||||
// current topmost level.
|
// current topmost level.
|
||||||
|
|
||||||
public void openScope() {
|
public void openScope() {
|
||||||
|
|
||||||
level++;
|
level++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Closes the topmost level in the identification table, discarding
|
// Closes the topmost level in the identification table, discarding
|
||||||
// all entries belonging to that level.
|
// all entries belonging to that level.
|
||||||
|
|
||||||
public void closeScope() {
|
public void closeScope() {
|
||||||
|
|
||||||
IdEntry entry, local;
|
IdEntry entry, local;
|
||||||
|
|
||||||
// Presumably, idTable.level > 0.
|
// Presumably, idTable.level > 0.
|
||||||
entry = this.latest;
|
entry = this.latest;
|
||||||
while (entry.level == this.level) {
|
while (entry.level == this.level) {
|
||||||
local = entry;
|
local = entry;
|
||||||
entry = local.previous;
|
entry = local.previous;
|
||||||
}
|
}
|
||||||
this.level--;
|
this.level--;
|
||||||
this.latest = entry;
|
this.latest = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Makes a new entry in the identification table for the given identifier
|
// Makes a new entry in the identification table for the given identifier
|
||||||
// and attribute. The new entry belongs to the current level.
|
// and attribute. The new entry belongs to the current level.
|
||||||
// duplicated is set to to true iff there is already an entry for the
|
// duplicated is set to to true iff there is already an entry for the
|
||||||
// same identifier at the current level.
|
// same identifier at the current level.
|
||||||
|
|
||||||
public void enter(String id, Declaration attr) {
|
public void enter(String id, Declaration attr) {
|
||||||
|
|
||||||
IdEntry entry = this.latest;
|
IdEntry entry = this.latest;
|
||||||
boolean present = false, searching = true;
|
boolean present = false, searching = true;
|
||||||
|
|
||||||
// Check for duplicate entry ...
|
// Check for duplicate entry ...
|
||||||
while (searching) {
|
while (searching) {
|
||||||
if (entry == null || entry.level < this.level)
|
if (entry == null || entry.level < this.level)
|
||||||
searching = false;
|
searching = false;
|
||||||
else if (entry.id.equals(id)) {
|
else if (entry.id.equals(id)) {
|
||||||
present = true;
|
present = true;
|
||||||
searching = false;
|
searching = false;
|
||||||
} else
|
} else
|
||||||
entry = entry.previous;
|
entry = entry.previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
attr.duplicated = present;
|
attr.duplicated = present;
|
||||||
// Add new entry ...
|
// Add new entry ...
|
||||||
entry = new IdEntry(id, attr, this.level, this.latest);
|
entry = new IdEntry(id, attr, this.level, this.latest);
|
||||||
this.latest = entry;
|
this.latest = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finds an entry for the given identifier in the identification table,
|
// Finds an entry for the given identifier in the identification table,
|
||||||
// if any. If there are several entries for that identifier, finds the
|
// if any. If there are several entries for that identifier, finds the
|
||||||
// entry at the highest level, in accordance with the scope rules.
|
// entry at the highest level, in accordance with the scope rules.
|
||||||
// Returns null iff no entry is found.
|
// Returns null iff no entry is found.
|
||||||
// otherwise returns the attribute field of the entry found.
|
// otherwise returns the attribute field of the entry found.
|
||||||
|
|
||||||
public Declaration retrieve(String id) {
|
public Declaration retrieve(String id) {
|
||||||
|
|
||||||
IdEntry entry;
|
IdEntry entry;
|
||||||
Declaration attr = null;
|
Declaration attr = null;
|
||||||
boolean present = false, searching = true;
|
boolean present = false, searching = true;
|
||||||
|
|
||||||
entry = this.latest;
|
entry = this.latest;
|
||||||
while (searching) {
|
while (searching) {
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
searching = false;
|
searching = false;
|
||||||
else if (entry.id.equals(id)) {
|
else if (entry.id.equals(id)) {
|
||||||
present = true;
|
present = true;
|
||||||
searching = false;
|
searching = false;
|
||||||
attr = entry.attr;
|
attr = entry.attr;
|
||||||
} else
|
} else
|
||||||
entry = entry.previous;
|
entry = entry.previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,25 +18,25 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
|
|||||||
|
|
||||||
public class ErrorReporter {
|
public class ErrorReporter {
|
||||||
|
|
||||||
int numErrors;
|
int numErrors;
|
||||||
|
|
||||||
ErrorReporter() {
|
ErrorReporter() {
|
||||||
numErrors = 0;
|
numErrors = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reportError(String message, String tokenName, SourcePosition pos) {
|
public void reportError(String message, String tokenName, SourcePosition pos) {
|
||||||
System.out.print("ERROR: ");
|
System.out.print("ERROR: ");
|
||||||
|
|
||||||
for (int p = 0; p < message.length(); p++)
|
for (int p = 0; p < message.length(); p++)
|
||||||
if (message.charAt(p) == '%')
|
if (message.charAt(p) == '%')
|
||||||
System.out.print(tokenName);
|
System.out.print(tokenName);
|
||||||
else
|
else
|
||||||
System.out.print(message.charAt(p));
|
System.out.print(message.charAt(p));
|
||||||
System.out.println(" " + pos.start + ".." + pos.finish);
|
System.out.println(" " + pos.start + ".." + pos.finish);
|
||||||
numErrors++;
|
numErrors++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reportRestriction(String message) {
|
public void reportRestriction(String message) {
|
||||||
System.out.println("RESTRICTION: " + message);
|
System.out.println("RESTRICTION: " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user