parent
3c134ed3b5
commit
a607f09f6b
@ -0,0 +1,62 @@ |
|||||||
|
.metadata |
||||||
|
bin/ |
||||||
|
tmp/ |
||||||
|
*.tmp |
||||||
|
*.bak |
||||||
|
*.swp |
||||||
|
*~.nib |
||||||
|
local.properties |
||||||
|
.settings/ |
||||||
|
.loadpath |
||||||
|
.recommenders |
||||||
|
.vscode |
||||||
|
|
||||||
|
# External tool builders |
||||||
|
.externalToolBuilders/ |
||||||
|
|
||||||
|
# Locally stored "Eclipse launch configurations" |
||||||
|
*.launch |
||||||
|
|
||||||
|
# PyDev specific (Python IDE for Eclipse) |
||||||
|
*.pydevproject |
||||||
|
|
||||||
|
# CDT-specific (C/C++ Development Tooling) |
||||||
|
.cproject |
||||||
|
|
||||||
|
# CDT- autotools |
||||||
|
.autotools |
||||||
|
|
||||||
|
# Java annotation processor (APT) |
||||||
|
.factorypath |
||||||
|
|
||||||
|
# PDT-specific (PHP Development Tools) |
||||||
|
.buildpath |
||||||
|
|
||||||
|
# sbteclipse plugin |
||||||
|
.target |
||||||
|
|
||||||
|
# Tern plugin |
||||||
|
.tern-project |
||||||
|
|
||||||
|
# TeXlipse plugin |
||||||
|
.texlipse |
||||||
|
|
||||||
|
# STS (Spring Tool Suite) |
||||||
|
.springBeans |
||||||
|
|
||||||
|
# Code Recommenders |
||||||
|
.recommenders/ |
||||||
|
|
||||||
|
# Annotation Processing |
||||||
|
.apt_generated/ |
||||||
|
.apt_generated_test/ |
||||||
|
|
||||||
|
# Scala IDE specific (Scala & Java development for Eclipse) |
||||||
|
.cache-main |
||||||
|
.scala_dependencies |
||||||
|
.worksheet |
||||||
|
|
||||||
|
# Uncomment this line if you wish to ignore the project description file. |
||||||
|
# Typically, this file would be tracked if it contains build/dependency configurations: |
||||||
|
#.project |
||||||
|
/.gradle/ |
@ -0,0 +1,17 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<projectDescription> |
||||||
|
<name>a5-triangle-tools</name> |
||||||
|
<comment>Project a5-triangle-tools created by Buildship.</comment> |
||||||
|
<projects> |
||||||
|
</projects> |
||||||
|
<buildSpec> |
||||||
|
<buildCommand> |
||||||
|
<name>org.eclipse.buildship.core.gradleprojectbuilder</name> |
||||||
|
<arguments> |
||||||
|
</arguments> |
||||||
|
</buildCommand> |
||||||
|
</buildSpec> |
||||||
|
<natures> |
||||||
|
<nature>org.eclipse.buildship.core.gradleprojectnature</nature> |
||||||
|
</natures> |
||||||
|
</projectDescription> |
@ -0,0 +1,21 @@ |
|||||||
|
MIT License |
||||||
|
|
||||||
|
Copyright (c) 2022 deryckb |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||||
|
of this software and associated documentation files (the "Software"), to deal |
||||||
|
in the Software without restriction, including without limitation the rights |
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||||
|
copies of the Software, and to permit persons to whom the Software is |
||||||
|
furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all |
||||||
|
copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||||
|
SOFTWARE. |
@ -0,0 +1,3 @@ |
|||||||
|
/target/ |
||||||
|
/.classpath |
||||||
|
/build/ |
@ -0,0 +1,23 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<projectDescription> |
||||||
|
<name>Triangle.AbstractMachine.Disassembler</name> |
||||||
|
<comment></comment> |
||||||
|
<projects> |
||||||
|
</projects> |
||||||
|
<buildSpec> |
||||||
|
<buildCommand> |
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name> |
||||||
|
<arguments> |
||||||
|
</arguments> |
||||||
|
</buildCommand> |
||||||
|
<buildCommand> |
||||||
|
<name>org.eclipse.buildship.core.gradleprojectbuilder</name> |
||||||
|
<arguments> |
||||||
|
</arguments> |
||||||
|
</buildCommand> |
||||||
|
</buildSpec> |
||||||
|
<natures> |
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature> |
||||||
|
<nature>org.eclipse.buildship.core.gradleprojectnature</nature> |
||||||
|
</natures> |
||||||
|
</projectDescription> |
@ -0,0 +1,12 @@ |
|||||||
|
apply plugin: 'java' |
||||||
|
apply plugin: 'application' |
||||||
|
|
||||||
|
sourceCompatibility = 11 |
||||||
|
|
||||||
|
dependencies { |
||||||
|
implementation project(':Triangle.AbstractMachine') |
||||||
|
} |
||||||
|
|
||||||
|
application { |
||||||
|
mainClass = 'Triangle.AbstractMachine.Disassembler' |
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<artifactId>triangle-disassembler</artifactId> |
||||||
|
<parent> |
||||||
|
<groupId>triangle.tools</groupId> |
||||||
|
<artifactId>triangle-tools</artifactId> |
||||||
|
<version>2.1</version> |
||||||
|
<relativePath>../</relativePath> |
||||||
|
</parent> |
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>triangle.tools</groupId> |
||||||
|
<artifactId>triangle-abstractmachine</artifactId> |
||||||
|
<version>2.1</version> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
</project> |
@ -0,0 +1,355 @@ |
|||||||
|
/* |
||||||
|
* @(#)Disassembler.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractMachine; |
||||||
|
|
||||||
|
import java.io.DataInputStream; |
||||||
|
import java.io.FileInputStream; |
||||||
|
import java.io.FileNotFoundException; |
||||||
|
import java.io.IOException; |
||||||
|
|
||||||
|
/** |
||||||
|
* Disassembles the TAM code in the given file, and displays the instructions on |
||||||
|
* standard output. |
||||||
|
* |
||||||
|
* For example: |
||||||
|
* |
||||||
|
* <pre> |
||||||
|
* java TAM.Disassembler obj.tam |
||||||
|
* </pre> |
||||||
|
* |
||||||
|
* <p> |
||||||
|
* Copyright 1991 David A. Watt, University of Glasgow<br> |
||||||
|
* Copyright 1998 Deryck F. Brown, The Robert Gordon University<br> |
||||||
|
* </p> |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
public class Disassembler { |
||||||
|
|
||||||
|
static String objectName; |
||||||
|
|
||||||
|
static int CT; |
||||||
|
|
||||||
|
/** |
||||||
|
* Writes the r-field of an instruction in the form "l<I>reg</I>r", where l and |
||||||
|
* r are the bracket characters to use. |
||||||
|
* |
||||||
|
* @param leftbracket the character to print before the register. |
||||||
|
* @param r the number of the register. |
||||||
|
* @param rightbracket the character to print after the register. |
||||||
|
*/ |
||||||
|
private static void writeR(char leftbracket, Register r, char rightbracket) { |
||||||
|
|
||||||
|
System.out.print(leftbracket); |
||||||
|
System.out.print(r.toString()); |
||||||
|
System.out.print(rightbracket); |
||||||
|
} |
||||||
|
|
||||||
|
private static void writeR(char leftBracket, int r, char rightBracket) { |
||||||
|
var register = Register.values()[r]; |
||||||
|
writeR(leftBracket, register, rightBracket); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Writes a void n-field of an instruction. |
||||||
|
*/ |
||||||
|
private static void blankN() { |
||||||
|
System.out.print(" "); |
||||||
|
} |
||||||
|
|
||||||
|
// Writes the n-field of an instruction.
|
||||||
|
/** |
||||||
|
* Writes the n-field of an instruction in the form "(n)". |
||||||
|
* |
||||||
|
* @param n the integer to write. |
||||||
|
*/ |
||||||
|
private static void writeN(int n) { |
||||||
|
System.out.print("(" + n + ") "); |
||||||
|
if (n < 10) { |
||||||
|
System.out.print(" "); |
||||||
|
} else if (n < 100) { |
||||||
|
System.out.print(" "); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Writes the d-field of an instruction. |
||||||
|
* |
||||||
|
* @param d the integer to write. |
||||||
|
*/ |
||||||
|
private static void writeD(int d) { |
||||||
|
System.out.print(d); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Writes the name of primitive routine with relative address d. |
||||||
|
* |
||||||
|
* @param d the displacement of the primitive routine. |
||||||
|
*/ |
||||||
|
private static void writePrimitive(int d) { |
||||||
|
var primitive = Primitive.values()[d]; |
||||||
|
switch (primitive) { |
||||||
|
case ID: |
||||||
|
System.out.print("id "); |
||||||
|
break; |
||||||
|
case NOT: |
||||||
|
System.out.print("not "); |
||||||
|
break; |
||||||
|
case AND: |
||||||
|
System.out.print("and "); |
||||||
|
break; |
||||||
|
case OR: |
||||||
|
System.out.print("or "); |
||||||
|
break; |
||||||
|
case SUCC: |
||||||
|
System.out.print("succ "); |
||||||
|
break; |
||||||
|
case PRED: |
||||||
|
System.out.print("pred "); |
||||||
|
break; |
||||||
|
case NEG: |
||||||
|
System.out.print("neg "); |
||||||
|
break; |
||||||
|
case ADD: |
||||||
|
System.out.print("add "); |
||||||
|
break; |
||||||
|
case SUB: |
||||||
|
System.out.print("sub "); |
||||||
|
break; |
||||||
|
case MULT: |
||||||
|
System.out.print("mult "); |
||||||
|
break; |
||||||
|
case DIV: |
||||||
|
System.out.print("div "); |
||||||
|
break; |
||||||
|
case MOD: |
||||||
|
System.out.print("mod "); |
||||||
|
break; |
||||||
|
case LT: |
||||||
|
System.out.print("lt "); |
||||||
|
break; |
||||||
|
case LE: |
||||||
|
System.out.print("le "); |
||||||
|
break; |
||||||
|
case GE: |
||||||
|
System.out.print("ge "); |
||||||
|
break; |
||||||
|
case GT: |
||||||
|
System.out.print("gt "); |
||||||
|
break; |
||||||
|
case EQ: |
||||||
|
System.out.print("eq "); |
||||||
|
break; |
||||||
|
case NE: |
||||||
|
System.out.print("ne "); |
||||||
|
break; |
||||||
|
case EOL: |
||||||
|
System.out.print("eol "); |
||||||
|
break; |
||||||
|
case EOF: |
||||||
|
System.out.print("eof "); |
||||||
|
break; |
||||||
|
case GET: |
||||||
|
System.out.print("get "); |
||||||
|
break; |
||||||
|
case PUT: |
||||||
|
System.out.print("put "); |
||||||
|
break; |
||||||
|
case GETEOL: |
||||||
|
System.out.print("geteol "); |
||||||
|
break; |
||||||
|
case PUTEOL: |
||||||
|
System.out.print("puteol "); |
||||||
|
break; |
||||||
|
case GETINT: |
||||||
|
System.out.print("getint "); |
||||||
|
break; |
||||||
|
case PUTINT: |
||||||
|
System.out.print("putint "); |
||||||
|
break; |
||||||
|
case NEW: |
||||||
|
System.out.print("new "); |
||||||
|
break; |
||||||
|
case DISPOSE: |
||||||
|
System.out.print("dispose "); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Writes the given instruction in assembly-code format. |
||||||
|
* |
||||||
|
* @param instr the instruction to display. |
||||||
|
*/ |
||||||
|
private static void writeInstruction(Instruction instr) { |
||||||
|
|
||||||
|
switch (instr.opCode) { |
||||||
|
case LOAD: |
||||||
|
System.out.print("LOAD "); |
||||||
|
writeN(instr.length); |
||||||
|
writeD(instr.operand); |
||||||
|
writeR('[', instr.register, ']'); |
||||||
|
break; |
||||||
|
|
||||||
|
case LOADA: |
||||||
|
System.out.print("LOADA "); |
||||||
|
blankN(); |
||||||
|
writeD(instr.operand); |
||||||
|
writeR('[', instr.register, ']'); |
||||||
|
break; |
||||||
|
|
||||||
|
case LOADI: |
||||||
|
System.out.print("LOADI "); |
||||||
|
writeN(instr.length); |
||||||
|
break; |
||||||
|
|
||||||
|
case LOADL: |
||||||
|
System.out.print("LOADL "); |
||||||
|
blankN(); |
||||||
|
writeD(instr.operand); |
||||||
|
break; |
||||||
|
|
||||||
|
case STORE: |
||||||
|
System.out.print("STORE "); |
||||||
|
writeN(instr.length); |
||||||
|
writeD(instr.operand); |
||||||
|
writeR('[', instr.register, ']'); |
||||||
|
break; |
||||||
|
|
||||||
|
case STOREI: |
||||||
|
System.out.print("STOREI"); |
||||||
|
writeN(instr.length); |
||||||
|
break; |
||||||
|
|
||||||
|
case CALL: |
||||||
|
System.out.print("CALL "); |
||||||
|
if (instr.register == Register.PB) { |
||||||
|
blankN(); |
||||||
|
writePrimitive(instr.operand); |
||||||
|
} else { |
||||||
|
writeR('(', instr.length, ')'); |
||||||
|
System.out.print(" "); |
||||||
|
writeD(instr.operand); |
||||||
|
writeR('[', instr.register, ']'); |
||||||
|
} |
||||||
|
break; |
||||||
|
|
||||||
|
case CALLI: |
||||||
|
System.out.print("CALLI "); |
||||||
|
break; |
||||||
|
|
||||||
|
case RETURN: |
||||||
|
System.out.print("RETURN"); |
||||||
|
writeN(instr.length); |
||||||
|
writeD(instr.operand); |
||||||
|
break; |
||||||
|
|
||||||
|
case PUSH: |
||||||
|
System.out.print("PUSH "); |
||||||
|
blankN(); |
||||||
|
writeD(instr.operand); |
||||||
|
break; |
||||||
|
|
||||||
|
case POP: |
||||||
|
System.out.print("POP "); |
||||||
|
writeN(instr.length); |
||||||
|
writeD(instr.operand); |
||||||
|
break; |
||||||
|
|
||||||
|
case JUMP: |
||||||
|
System.out.print("JUMP "); |
||||||
|
blankN(); |
||||||
|
writeD(instr.operand); |
||||||
|
writeR('[', instr.register, ']'); |
||||||
|
break; |
||||||
|
|
||||||
|
case JUMPI: |
||||||
|
System.out.print("JUMPI "); |
||||||
|
break; |
||||||
|
|
||||||
|
case JUMPIF: |
||||||
|
System.out.print("JUMPIF"); |
||||||
|
writeN(instr.length); |
||||||
|
writeD(instr.operand); |
||||||
|
writeR('[', instr.register, ']'); |
||||||
|
break; |
||||||
|
|
||||||
|
case HALT: |
||||||
|
System.out.print("HALT "); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Writes all instructions of the program in code store. |
||||||
|
*/ |
||||||
|
private static void disassembleProgram() { |
||||||
|
for (int addr = Machine.CB; addr < CT; addr++) { |
||||||
|
System.out.print(addr + ": "); |
||||||
|
writeInstruction(Machine.code[addr]); |
||||||
|
System.out.println(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// LOADING
|
||||||
|
|
||||||
|
/** |
||||||
|
* Loads the TAM object program into code store from the named file. |
||||||
|
* |
||||||
|
* @param objectName the name of the file containing the program. |
||||||
|
*/ |
||||||
|
static void loadObjectProgram(String objectName) { |
||||||
|
|
||||||
|
var finished = false; |
||||||
|
|
||||||
|
try (var objectFile = new FileInputStream(objectName)) { |
||||||
|
var objectStream = new DataInputStream(objectFile); |
||||||
|
var addr = Machine.CB; |
||||||
|
while (!finished) { |
||||||
|
Machine.code[addr] = Instruction.read(objectStream); |
||||||
|
if (Machine.code[addr] == null) { |
||||||
|
finished = true; |
||||||
|
} else { |
||||||
|
addr = addr + 1; |
||||||
|
} |
||||||
|
} |
||||||
|
CT = addr; |
||||||
|
} catch (FileNotFoundException s) { |
||||||
|
CT = Machine.CB; |
||||||
|
System.err.println("Error opening object file: " + s); |
||||||
|
} catch (IOException s) { |
||||||
|
CT = Machine.CB; |
||||||
|
System.err.println("Error reading object file: " + s); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// DISASSEMBLE
|
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
System.out.println("********** TAM Disassembler (Sun Version 2.1) **********"); |
||||||
|
|
||||||
|
if (args.length == 1) { |
||||||
|
objectName = args[0]; |
||||||
|
} else { |
||||||
|
objectName = "obj.tam"; |
||||||
|
} |
||||||
|
|
||||||
|
loadObjectProgram(objectName); |
||||||
|
disassembleProgram(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,3 @@ |
|||||||
|
/target/ |
||||||
|
/.classpath |
||||||
|
/build/ |
@ -0,0 +1,23 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<projectDescription> |
||||||
|
<name>Triangle.AbstractMachine.Interpreter</name> |
||||||
|
<comment></comment> |
||||||
|
<projects> |
||||||
|
</projects> |
||||||
|
<buildSpec> |
||||||
|
<buildCommand> |
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name> |
||||||
|
<arguments> |
||||||
|
</arguments> |
||||||
|
</buildCommand> |
||||||
|
<buildCommand> |
||||||
|
<name>org.eclipse.buildship.core.gradleprojectbuilder</name> |
||||||
|
<arguments> |
||||||
|
</arguments> |
||||||
|
</buildCommand> |
||||||
|
</buildSpec> |
||||||
|
<natures> |
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature> |
||||||
|
<nature>org.eclipse.buildship.core.gradleprojectnature</nature> |
||||||
|
</natures> |
||||||
|
</projectDescription> |
@ -0,0 +1,12 @@ |
|||||||
|
apply plugin: 'java' |
||||||
|
apply plugin: 'application' |
||||||
|
|
||||||
|
sourceCompatibility = 11 |
||||||
|
|
||||||
|
dependencies { |
||||||
|
implementation project(':Triangle.AbstractMachine') |
||||||
|
} |
||||||
|
|
||||||
|
application { |
||||||
|
mainClass = 'Triangle.AbstractMachine.Interpreter' |
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<artifactId>triangle-interpreter</artifactId> |
||||||
|
<parent> |
||||||
|
<groupId>triangle.tools</groupId> |
||||||
|
<artifactId>triangle-tools</artifactId> |
||||||
|
<version>2.1</version> |
||||||
|
<relativePath>../</relativePath> |
||||||
|
</parent> |
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>triangle.tools</groupId> |
||||||
|
<artifactId>triangle-abstractmachine</artifactId> |
||||||
|
<version>2.1</version> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
</project> |
@ -0,0 +1,649 @@ |
|||||||
|
/* |
||||||
|
* @(#)Interpreter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractMachine; |
||||||
|
|
||||||
|
import java.io.DataInputStream; |
||||||
|
import java.io.FileInputStream; |
||||||
|
import java.io.FileNotFoundException; |
||||||
|
import java.io.IOException; |
||||||
|
|
||||||
|
public class Interpreter { |
||||||
|
|
||||||
|
static long startTimeNanos = 0; |
||||||
|
|
||||||
|
static String objectName; |
||||||
|
|
||||||
|
// DATA STORE
|
||||||
|
|
||||||
|
static int[] data = new int[1024]; |
||||||
|
|
||||||
|
// DATA STORE REGISTERS AND OTHER REGISTERS
|
||||||
|
|
||||||
|
final static int CB = 0, SB = 0, HB = 1024; // = upper bound of data array + 1
|
||||||
|
|
||||||
|
static int CT, CP, ST, HT, LB, status; |
||||||
|
|
||||||
|
// status values
|
||||||
|
final static int running = 0, halted = 1, failedDataStoreFull = 2, failedInvalidCodeAddress = 3, |
||||||
|
failedInvalidInstruction = 4, failedOverflow = 5, failedZeroDivide = 6, failedIOError = 7; |
||||||
|
|
||||||
|
static long accumulator; |
||||||
|
|
||||||
|
static int content(int r) { |
||||||
|
var register = Register.values()[r]; |
||||||
|
return content(register); |
||||||
|
} |
||||||
|
|
||||||
|
static int content(Register r) { |
||||||
|
// Returns the current content of register r,
|
||||||
|
// even if r is one of the pseudo-registers L1..L6.
|
||||||
|
|
||||||
|
switch (r) { |
||||||
|
case CB: |
||||||
|
return CB; |
||||||
|
case CT: |
||||||
|
return CT; |
||||||
|
case PB: |
||||||
|
return Machine.PB; |
||||||
|
case PT: |
||||||
|
return Machine.PT; |
||||||
|
case SB: |
||||||
|
return SB; |
||||||
|
case ST: |
||||||
|
return ST; |
||||||
|
case HB: |
||||||
|
return HB; |
||||||
|
case HT: |
||||||
|
return HT; |
||||||
|
case LB: |
||||||
|
return LB; |
||||||
|
case L1: |
||||||
|
return data[LB]; |
||||||
|
case L2: |
||||||
|
return data[data[LB]]; |
||||||
|
case L3: |
||||||
|
return data[data[data[LB]]]; |
||||||
|
case L4: |
||||||
|
return data[data[data[data[LB]]]]; |
||||||
|
case L5: |
||||||
|
return data[data[data[data[data[LB]]]]]; |
||||||
|
case L6: |
||||||
|
return data[data[data[data[data[data[LB]]]]]]; |
||||||
|
case CP: |
||||||
|
return CP; |
||||||
|
default: |
||||||
|
return 0; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// PROGRAM STATUS
|
||||||
|
|
||||||
|
static void dump() { |
||||||
|
// Writes a summary of the machine state.
|
||||||
|
|
||||||
|
System.out.println(""); |
||||||
|
System.out.println("State of data store and registers:"); |
||||||
|
System.out.println(""); |
||||||
|
if (HT == HB) { |
||||||
|
System.out.println(" |--------| (heap is empty)"); |
||||||
|
} else { |
||||||
|
System.out.println(" HB-->"); |
||||||
|
System.out.println(" |--------|"); |
||||||
|
for (var addr = HB - 1; addr >= HT; addr--) { |
||||||
|
System.out.print(addr + ":"); |
||||||
|
if (addr == HT) { |
||||||
|
System.out.print(" HT-->"); |
||||||
|
} else { |
||||||
|
System.out.print(" "); |
||||||
|
} |
||||||
|
System.out.println("|" + data[addr] + "|"); |
||||||
|
} |
||||||
|
System.out.println(" |--------|"); |
||||||
|
} |
||||||
|
System.out.println(" |////////|"); |
||||||
|
System.out.println(" |////////|"); |
||||||
|
if (ST == SB) { |
||||||
|
System.out.println(" |--------| (stack is empty)"); |
||||||
|
} else { |
||||||
|
var dynamicLink = LB; |
||||||
|
var staticLink = LB; |
||||||
|
var localRegNum = Register.LB; |
||||||
|
System.out.println(" ST--> |////////|"); |
||||||
|
System.out.println(" |--------|"); |
||||||
|
for (var addr = ST - 1; addr >= SB; addr--) { |
||||||
|
System.out.print(addr + ":"); |
||||||
|
if (addr == SB) { |
||||||
|
System.out.print(" SB-->"); |
||||||
|
} else if (addr == staticLink) { |
||||||
|
switch (localRegNum) { |
||||||
|
case LB: |
||||||
|
System.out.print(" LB-->"); |
||||||
|
break; |
||||||
|
case L1: |
||||||
|
System.out.print(" L1-->"); |
||||||
|
break; |
||||||
|
case L2: |
||||||
|
System.out.print(" L2-->"); |
||||||
|
break; |
||||||
|
case L3: |
||||||
|
System.out.print(" L3-->"); |
||||||
|
break; |
||||||
|
case L4: |
||||||
|
System.out.print(" L4-->"); |
||||||
|
break; |
||||||
|
case L5: |
||||||
|
System.out.print(" L5-->"); |
||||||
|
break; |
||||||
|
case L6: |
||||||
|
System.out.print(" L6-->"); |
||||||
|
break; |
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
staticLink = data[addr]; |
||||||
|
localRegNum = Register.values()[localRegNum.ordinal() + 1]; |
||||||
|
} else { |
||||||
|
System.out.print(" "); |
||||||
|
} |
||||||
|
if (addr == dynamicLink && dynamicLink != SB) { |
||||||
|
System.out.print("|SL=" + data[addr] + "|"); |
||||||
|
} else if (addr == dynamicLink + 1 && dynamicLink != SB) { |
||||||
|
System.out.print("|DL=" + data[addr] + "|"); |
||||||
|
} else if (addr == dynamicLink + 2 && dynamicLink != SB) { |
||||||
|
System.out.print("|RA=" + data[addr] + "|"); |
||||||
|
} else { |
||||||
|
System.out.print("|" + data[addr] + "|"); |
||||||
|
} |
||||||
|
System.out.println(""); |
||||||
|
if (addr == dynamicLink) { |
||||||
|
System.out.println(" |--------|"); |
||||||
|
dynamicLink = data[addr + 1]; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
System.out.println(""); |
||||||
|
} |
||||||
|
|
||||||
|
static void showStatus() { |
||||||
|
// Writes an indication of whether and why the program has terminated.
|
||||||
|
System.out.println(""); |
||||||
|
switch (status) { |
||||||
|
case running: |
||||||
|
System.out.println("Program is running."); |
||||||
|
break; |
||||||
|
case halted: |
||||||
|
System.out.println("Program has halted normally."); |
||||||
|
System.out.println("Total execution time (ns): " + (System.nanoTime() - startTimeNanos)); |
||||||
|
break; |
||||||
|
case failedDataStoreFull: |
||||||
|
System.out.println("Program has failed due to exhaustion of Data Store."); |
||||||
|
break; |
||||||
|
case failedInvalidCodeAddress: |
||||||
|
System.out.println("Program has failed due to an invalid code address."); |
||||||
|
break; |
||||||
|
case failedInvalidInstruction: |
||||||
|
System.out.println("Program has failed due to an invalid instruction."); |
||||||
|
break; |
||||||
|
case failedOverflow: |
||||||
|
System.out.println("Program has failed due to overflow."); |
||||||
|
break; |
||||||
|
case failedZeroDivide: |
||||||
|
System.out.println("Program has failed due to division by zero."); |
||||||
|
break; |
||||||
|
case failedIOError: |
||||||
|
System.out.println("Program has failed due to an IO error."); |
||||||
|
break; |
||||||
|
} |
||||||
|
if (status != halted) { |
||||||
|
dump(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// INTERPRETATION
|
||||||
|
|
||||||
|
static void checkSpace(int spaceNeeded) { |
||||||
|
// Signals failure if there is not enough space to expand the stack or
|
||||||
|
// heap by spaceNeeded.
|
||||||
|
|
||||||
|
if (HT - ST < spaceNeeded) { |
||||||
|
status = failedDataStoreFull; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static boolean isTrue(int datum) { |
||||||
|
// Tests whether the given datum represents true.
|
||||||
|
return (datum == Machine.trueRep); |
||||||
|
} |
||||||
|
|
||||||
|
static boolean equal(int size, int addr1, int addr2) { |
||||||
|
// Tests whether two multi-word objects are equal, given their common
|
||||||
|
// size and their base addresses.
|
||||||
|
|
||||||
|
boolean eq; |
||||||
|
int index; |
||||||
|
|
||||||
|
eq = true; |
||||||
|
index = 0; |
||||||
|
while (eq && (index < size)) { |
||||||
|
if (data[addr1 + index] == data[addr2 + index]) { |
||||||
|
index = index + 1; |
||||||
|
} else { |
||||||
|
eq = false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return eq; |
||||||
|
} |
||||||
|
|
||||||
|
static int overflowChecked(long datum) { |
||||||
|
// Signals failure if the datum is too large to fit into a single word,
|
||||||
|
// otherwise returns the datum as a single word.
|
||||||
|
|
||||||
|
if ((-Machine.maxintRep <= datum) && (datum <= Machine.maxintRep)) { |
||||||
|
return (int) datum; |
||||||
|
} else { |
||||||
|
status = failedOverflow; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static int toInt(boolean b) { |
||||||
|
return b ? Machine.trueRep : Machine.falseRep; |
||||||
|
} |
||||||
|
|
||||||
|
static int currentChar; |
||||||
|
|
||||||
|
static int readInt() throws java.io.IOException { |
||||||
|
int temp = 0; |
||||||
|
int sign = 1; |
||||||
|
|
||||||
|
do { |
||||||
|
currentChar = System.in.read(); |
||||||
|
} while (Character.isWhitespace((char) currentChar)); |
||||||
|
|
||||||
|
if ((currentChar == '-') || (currentChar == '+')) { |
||||||
|
do { |
||||||
|
sign = (currentChar == '-') ? -1 : 1; |
||||||
|
currentChar = System.in.read(); |
||||||
|
} while ((currentChar == '-') || currentChar == '+'); |
||||||
|
} |
||||||
|
|
||||||
|
if (Character.isDigit((char) currentChar)) { |
||||||
|
do { |
||||||
|
temp = temp * 10 + (currentChar - '0'); |
||||||
|
currentChar = System.in.read(); |
||||||
|
} while (Character.isDigit((char) currentChar)); |
||||||
|
} |
||||||
|
|
||||||
|
return sign * temp; |
||||||
|
} |
||||||
|
|
||||||
|
static void callPrimitive(int primitiveDisplacement) { |
||||||
|
// Invokes the given primitive routine.
|
||||||
|
|
||||||
|
int addr, size; |
||||||
|
char ch; |
||||||
|
|
||||||
|
var primitive = Primitive.values()[primitiveDisplacement]; |
||||||
|
switch (primitive) { |
||||||
|
case ID: |
||||||
|
break; // nothing to be done
|
||||||
|
case NOT: |
||||||
|
data[ST - 1] = toInt(!isTrue(data[ST - 1])); |
||||||
|
break; |
||||||
|
case AND: |
||||||
|
ST = ST - 1; |
||||||
|
data[ST - 1] = toInt(isTrue(data[ST - 1]) & isTrue(data[ST])); |
||||||
|
break; |
||||||
|
case OR: |
||||||
|
ST = ST - 1; |
||||||
|
data[ST - 1] = toInt(isTrue(data[ST - 1]) | isTrue(data[ST])); |
||||||
|
break; |
||||||
|
case SUCC: |
||||||
|
data[ST - 1] = overflowChecked(data[ST - 1] + 1); |
||||||
|
break; |
||||||
|
case PRED: |
||||||
|
data[ST - 1] = overflowChecked(data[ST - 1] - 1); |
||||||
|
break; |
||||||
|
case NEG: |
||||||
|
data[ST - 1] = -data[ST - 1]; |
||||||
|
break; |
||||||
|
case ADD: |
||||||
|
ST = ST - 1; |
||||||
|
accumulator = data[ST - 1]; |
||||||
|
data[ST - 1] = overflowChecked(accumulator + data[ST]); |
||||||
|
break; |
||||||
|
case SUB: |
||||||
|
ST = ST - 1; |
||||||
|
accumulator = data[ST - 1]; |
||||||
|
data[ST - 1] = overflowChecked(accumulator - data[ST]); |
||||||
|
break; |
||||||
|
case MULT: |
||||||
|
ST = ST - 1; |
||||||
|
accumulator = data[ST - 1]; |
||||||
|
data[ST - 1] = overflowChecked(accumulator * data[ST]); |
||||||
|
break; |
||||||
|
case DIV: |
||||||
|
ST = ST - 1; |
||||||
|
accumulator = data[ST - 1]; |
||||||
|
if (data[ST] != 0) { |
||||||
|
data[ST - 1] = (int) (accumulator / data[ST]); |
||||||
|
} else { |
||||||
|
status = failedZeroDivide; |
||||||
|
} |
||||||
|
break; |
||||||
|
case MOD: |
||||||
|
ST = ST - 1; |
||||||
|
accumulator = data[ST - 1]; |
||||||
|
if (data[ST] != 0) { |
||||||
|
data[ST - 1] = (int) (accumulator % data[ST]); |
||||||
|
} else { |
||||||
|
status = failedZeroDivide; |
||||||
|
} |
||||||
|
break; |
||||||
|
case LT: |
||||||
|
ST = ST - 1; |
||||||
|
data[ST - 1] = toInt(data[ST - 1] < data[ST]); |
||||||
|
break; |
||||||
|
case LE: |
||||||
|
ST = ST - 1; |
||||||
|
data[ST - 1] = toInt(data[ST - 1] <= data[ST]); |
||||||
|
break; |
||||||
|
case GE: |
||||||
|
ST = ST - 1; |
||||||
|
data[ST - 1] = toInt(data[ST - 1] >= data[ST]); |
||||||
|
break; |
||||||
|
case GT: |
||||||
|
ST = ST - 1; |
||||||
|
data[ST - 1] = toInt(data[ST - 1] > data[ST]); |
||||||
|
break; |
||||||
|
case EQ: |
||||||
|
size = data[ST - 1]; // size of each comparand
|
||||||
|
ST = ST - 2 * size; |
||||||
|
data[ST - 1] = toInt(equal(size, ST - 1, ST - 1 + size)); |
||||||
|
break; |
||||||
|
case NE: |
||||||
|
size = data[ST - 1]; // size of each comparand
|
||||||
|
ST = ST - 2 * size; |
||||||
|
data[ST - 1] = toInt(!equal(size, ST - 1, ST - 1 + size)); |
||||||
|
break; |
||||||
|
case EOL: |
||||||
|
data[ST] = toInt(currentChar == '\n'); |
||||||
|
ST = ST + 1; |
||||||
|
break; |
||||||
|
case EOF: |
||||||
|
data[ST] = toInt(currentChar == -1); |
||||||
|
ST = ST + 1; |
||||||
|
break; |
||||||
|
case GET: |
||||||
|
ST = ST - 1; |
||||||
|
addr = data[ST]; |
||||||
|
try { |
||||||
|
currentChar = System.in.read(); |
||||||
|
} catch (java.io.IOException s) { |
||||||
|
status = failedIOError; |
||||||
|
} |
||||||
|
data[addr] = currentChar; |
||||||
|
break; |
||||||
|
case PUT: |
||||||
|
ST = ST - 1; |
||||||
|
ch = (char) data[ST]; |
||||||
|
System.out.print(ch); |
||||||
|
break; |
||||||
|
case GETEOL: |
||||||
|
try { |
||||||
|
while ((currentChar = System.in.read()) != '\n') |
||||||
|
; |
||||||
|
} catch (java.io.IOException s) { |
||||||
|
status = failedIOError; |
||||||
|
} |
||||||
|
break; |
||||||
|
case PUTEOL: |
||||||
|
System.out.println(""); |
||||||
|
break; |
||||||
|
case GETINT: |
||||||
|
ST = ST - 1; |
||||||
|
addr = data[ST]; |
||||||
|
try { |
||||||
|
accumulator = readInt(); |
||||||
|
} catch (java.io.IOException s) { |
||||||
|
status = failedIOError; |
||||||
|
} |
||||||
|
data[addr] = (int) accumulator; |
||||||
|
break; |
||||||
|
case PUTINT: |
||||||
|
ST = ST - 1; |
||||||
|
accumulator = data[ST]; |
||||||
|
System.out.print(accumulator); |
||||||
|
break; |
||||||
|
case NEW: |
||||||
|
size = data[ST - 1]; |
||||||
|
checkSpace(size); |
||||||
|
HT = HT - size; |
||||||
|
data[ST - 1] = HT; |
||||||
|
break; |
||||||
|
case DISPOSE: |
||||||
|
ST = ST - 1; // no action taken at present
|
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static void interpretProgram() { |
||||||
|
// Runs the program in code store.
|
||||||
|
|
||||||
|
Instruction currentInstr; |
||||||
|
|
||||||
|
// Initialize registers ...
|
||||||
|
ST = SB; |
||||||
|
HT = HB; |
||||||
|
LB = SB; |
||||||
|
CP = CB; |
||||||
|
status = running; |
||||||
|
do { |
||||||
|
// Fetch instruction ...
|
||||||
|
currentInstr = Machine.code[CP]; |
||||||
|
// Decode instruction ...
|
||||||
|
var op = currentInstr.opCode; |
||||||
|
var r = currentInstr.register; |
||||||
|
var n = currentInstr.length; |
||||||
|
var d = currentInstr.operand; |
||||||
|
int addr; |
||||||
|
|
||||||
|
// Execute instruction ...
|
||||||
|
switch (op) { |
||||||
|
case LOAD: |
||||||
|
addr = d + content(r); |
||||||
|
checkSpace(n); |
||||||
|
for (var index = 0; index < n; index++) { |
||||||
|
data[ST + index] = data[addr + index]; |
||||||
|
} |
||||||
|
ST = ST + n; |
||||||
|
CP = CP + 1; |
||||||
|
break; |
||||||
|
case LOADA: |
||||||
|
addr = d + content(r); |
||||||
|
checkSpace(1); |
||||||
|
data[ST] = addr; |
||||||
|
ST = ST + 1; |
||||||
|
CP = CP + 1; |
||||||
|
break; |
||||||
|
case LOADI: |
||||||
|
ST = ST - 1; |
||||||
|
addr = data[ST]; |
||||||
|
checkSpace(n); |
||||||
|
for (var index = 0; index < n; index++) { |
||||||
|
data[ST + index] = data[addr + index]; |
||||||
|
} |
||||||
|
ST = ST + n; |
||||||
|
CP = CP + 1; |
||||||
|
break; |
||||||
|
case LOADL: |
||||||
|
checkSpace(1); |
||||||
|
data[ST] = d; |
||||||
|
ST = ST + 1; |
||||||
|
CP = CP + 1; |
||||||
|
break; |
||||||
|
case STORE: |
||||||
|
addr = d + content(r); |
||||||
|
ST = ST - n; |
||||||
|
for (var index = 0; index < n; index++) { |
||||||
|
data[addr + index] = data[ST + index]; |
||||||
|
} |
||||||
|
CP = CP + 1; |
||||||
|
break; |
||||||
|
case STOREI: |
||||||
|
ST = ST - 1; |
||||||
|
addr = data[ST]; |
||||||
|
ST = ST - n; |
||||||
|
for (var index = 0; index < n; index++) { |
||||||
|
data[addr + index] = data[ST + index]; |
||||||
|
} |
||||||
|
CP = CP + 1; |
||||||
|
break; |
||||||
|
case CALL: |
||||||
|
addr = d + content(r); |
||||||
|
if (addr >= Machine.PB) { |
||||||
|
callPrimitive(addr - Machine.PB); |
||||||
|
CP = CP + 1; |
||||||
|
} else { |
||||||
|
checkSpace(3); |
||||||
|
if (0 <= n && n <= 15) { |
||||||
|
data[ST] = content(n); // static link
|
||||||
|
} else { |
||||||
|
status = failedInvalidInstruction; |
||||||
|
} |
||||||
|
data[ST + 1] = LB; // dynamic link
|
||||||
|
data[ST + 2] = CP + 1; // return address
|
||||||
|
LB = ST; |
||||||
|
ST = ST + 3; |
||||||
|
CP = addr; |
||||||
|
} |
||||||
|
break; |
||||||
|
case CALLI: |
||||||
|
ST = ST - 2; |
||||||
|
addr = data[ST + 1]; |
||||||
|
if (addr >= Machine.PB) { |
||||||
|
callPrimitive(addr - Machine.PB); |
||||||
|
CP = CP + 1; |
||||||
|
} else { |
||||||
|
// data[ST] = static link already
|
||||||
|
data[ST + 1] = LB; // dynamic link
|
||||||
|
data[ST + 2] = CP + 1; // return address
|
||||||
|
LB = ST; |
||||||
|
ST = ST + 3; |
||||||
|
CP = addr; |
||||||
|
} |
||||||
|
break; |
||||||
|
case RETURN: |
||||||
|
addr = LB - d; |
||||||
|
CP = data[LB + 2]; |
||||||
|
LB = data[LB + 1]; |
||||||
|
ST = ST - n; |
||||||
|
for (var index = 0; index < n; index++) { |
||||||
|
data[addr + index] = data[ST + index]; |
||||||
|
} |
||||||
|
ST = addr + n; |
||||||
|
break; |
||||||
|
case PUSH: |
||||||
|
checkSpace(d); |
||||||
|
ST = ST + d; |
||||||
|
CP = CP + 1; |
||||||
|
break; |
||||||
|
case POP: |
||||||
|
addr = ST - n - d; |
||||||
|
ST = ST - n; |
||||||
|
for (var index = 0; index < n; index++) { |
||||||
|
data[addr + index] = data[ST + index]; |
||||||
|
} |
||||||
|
ST = addr + n; |
||||||
|
CP = CP + 1; |
||||||
|
break; |
||||||
|
case JUMP: |
||||||
|
CP = d + content(r); |
||||||
|
break; |
||||||
|
case JUMPI: |
||||||
|
ST = ST - 1; |
||||||
|
CP = data[ST]; |
||||||
|
break; |
||||||
|
case JUMPIF: |
||||||
|
ST = ST - 1; |
||||||
|
if (data[ST] == n) { |
||||||
|
CP = d + content(r); |
||||||
|
} else { |
||||||
|
CP = CP + 1; |
||||||
|
} |
||||||
|
break; |
||||||
|
case HALT: |
||||||
|
status = halted; |
||||||
|
break; |
||||||
|
} |
||||||
|
if (CP < CB || CP >= CT) { |
||||||
|
status = failedInvalidCodeAddress; |
||||||
|
} |
||||||
|
} while (status == running); |
||||||
|
} |
||||||
|
|
||||||
|
// LOADING
|
||||||
|
|
||||||
|
static void loadObjectProgram(String objectName) { |
||||||
|
// Loads the TAM object program into code store from the named file.
|
||||||
|
|
||||||
|
boolean finished = false; |
||||||
|
|
||||||
|
try (var objectFile = new FileInputStream(objectName)) { |
||||||
|
var objectStream = new DataInputStream(objectFile); |
||||||
|
|
||||||
|
var addr = Machine.CB; |
||||||
|
while (!finished) { |
||||||
|
Machine.code[addr] = Instruction.read(objectStream); |
||||||
|
if (Machine.code[addr] == null) { |
||||||
|
finished = true; |
||||||
|
} else { |
||||||
|
addr = addr + 1; |
||||||
|
} |
||||||
|
} |
||||||
|
CT = addr; |
||||||
|
} catch (FileNotFoundException s) { |
||||||
|
CT = CB; |
||||||
|
System.err.println("Error opening object file: " + s); |
||||||
|
} catch (IOException s) { |
||||||
|
CT = CB; |
||||||
|
System.err.println("Error reading object file: " + s); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// RUNNING
|
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
System.out.println("********** TAM Interpreter (Java Version 2.1) **********"); |
||||||
|
|
||||||
|
if (args.length == 1) { |
||||||
|
objectName = args[0]; |
||||||
|
} else { |
||||||
|
objectName = "obj.tam"; |
||||||
|
} |
||||||
|
|
||||||
|
loadObjectProgram(objectName); |
||||||
|
if (CT != CB) { |
||||||
|
startTimeNanos = System.nanoTime(); |
||||||
|
interpretProgram(); |
||||||
|
showStatus(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,3 @@ |
|||||||
|
/target/ |
||||||
|
/.classpath |
||||||
|
/build/ |
@ -0,0 +1,23 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<projectDescription> |
||||||
|
<name>Triangle.AbstractMachine</name> |
||||||
|
<comment></comment> |
||||||
|
<projects> |
||||||
|
</projects> |
||||||
|
<buildSpec> |
||||||
|
<buildCommand> |
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name> |
||||||
|
<arguments> |
||||||
|
</arguments> |
||||||
|
</buildCommand> |
||||||
|
<buildCommand> |
||||||
|
<name>org.eclipse.buildship.core.gradleprojectbuilder</name> |
||||||
|
<arguments> |
||||||
|
</arguments> |
||||||
|
</buildCommand> |
||||||
|
</buildSpec> |
||||||
|
<natures> |
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature> |
||||||
|
<nature>org.eclipse.buildship.core.gradleprojectnature</nature> |
||||||
|
</natures> |
||||||
|
</projectDescription> |
@ -0,0 +1,4 @@ |
|||||||
|
apply plugin: 'java-library' |
||||||
|
apply plugin: 'eclipse' |
||||||
|
|
||||||
|
sourceCompatibility = 11 |
@ -0,0 +1,12 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<artifactId>triangle-abstractmachine</artifactId> |
||||||
|
<packaging>jar</packaging> |
||||||
|
<parent> |
||||||
|
<groupId>triangle.tools</groupId> |
||||||
|
<artifactId>triangle-tools</artifactId> |
||||||
|
<version>2.1</version> |
||||||
|
<relativePath>../</relativePath> |
||||||
|
</parent> |
||||||
|
</project> |
@ -0,0 +1,71 @@ |
|||||||
|
/* |
||||||
|
* @(#)Instruction.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractMachine; |
||||||
|
|
||||||
|
import java.io.DataInputStream; |
||||||
|
import java.io.DataOutputStream; |
||||||
|
import java.io.EOFException; |
||||||
|
import java.io.IOException; |
||||||
|
|
||||||
|
public class Instruction { |
||||||
|
|
||||||
|
// Java has no type synonyms, so the following representations are
|
||||||
|
// assumed:
|
||||||
|
//
|
||||||
|
// type
|
||||||
|
// OpCode = 0..15; {4 bits unsigned}
|
||||||
|
// Length = 0..255; {8 bits unsigned}
|
||||||
|
// Operand = -32767..+32767; {16 bits signed}
|
||||||
|
|
||||||
|
// Represents TAM instructions.
|
||||||
|
final OpCode opCode; |
||||||
|
final Register register; |
||||||
|
final int length; |
||||||
|
int operand; // Not final to allow for patching jump address
|
||||||
|
|
||||||
|
public Instruction(OpCode opcode, Register register, int length, int operand) { |
||||||
|
this.opCode = opcode; |
||||||
|
this.register = register; |
||||||
|
this.length = length; |
||||||
|
this.operand = operand; |
||||||
|
} |
||||||
|
|
||||||
|
public void setOperand(int operand) { |
||||||
|
this.operand = operand; |
||||||
|
} |
||||||
|
|
||||||
|
public void write(DataOutputStream output) throws IOException { |
||||||
|
output.writeInt(opCode.ordinal()); |
||||||
|
output.writeInt(register.ordinal()); |
||||||
|
output.writeInt(length); |
||||||
|
output.writeInt(operand); |
||||||
|
} |
||||||
|
|
||||||
|
public static Instruction read(DataInputStream input) throws IOException { |
||||||
|
try { |
||||||
|
var opCode = OpCode.values()[input.readInt()]; |
||||||
|
var register = Register.values()[input.readInt()]; |
||||||
|
var length = input.readInt(); |
||||||
|
var operand = input.readInt(); |
||||||
|
return new Instruction(opCode, register, length, operand); |
||||||
|
} catch (EOFException s) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,58 @@ |
|||||||
|
/* |
||||||
|
* @(#)Machine.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractMachine; |
||||||
|
|
||||||
|
public final class Machine { |
||||||
|
|
||||||
|
public final static int maxRoutineLevel = 7; |
||||||
|
|
||||||
|
// WORDS AND ADDRESSES
|
||||||
|
|
||||||
|
// Java has no type synonyms, so the following representations are
|
||||||
|
// assumed:
|
||||||
|
//
|
||||||
|
// type
|
||||||
|
// Word = -32767..+32767; {16 bits signed}
|
||||||
|
// DoubleWord = -2147483648..+2147483647; {32 bits signed}
|
||||||
|
// CodeAddress = 0..+32767; {15 bits unsigned}
|
||||||
|
// DataAddress = 0..+32767; {15 bits unsigned}
|
||||||
|
|
||||||
|
// INSTRUCTIONS
|
||||||
|
|
||||||
|
// CODE STORE
|
||||||
|
|
||||||
|
public static Instruction[] code = new Instruction[1024]; |
||||||
|
|
||||||
|
// CODE STORE REGISTERS
|
||||||
|
|
||||||
|
public final static int CB = 0, PB = 1024, // = upper bound of code array + 1
|
||||||
|
PT = 1052; // = PB + 28
|
||||||
|
|
||||||
|
// REGISTER NUMBERS
|
||||||
|
|
||||||
|
// DATA REPRESENTATION
|
||||||
|
|
||||||
|
public final static int booleanSize = 1, characterSize = 1, integerSize = 1, addressSize = 1, |
||||||
|
closureSize = 2 * addressSize, |
||||||
|
|
||||||
|
linkDataSize = 3 * addressSize, |
||||||
|
|
||||||
|
falseRep = 0, trueRep = 1, maxintRep = 32767; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
package triangle.abstractMachine; |
||||||
|
|
||||||
|
public enum OpCode { |
||||||
|
LOAD, LOADA, LOADI, LOADL, STORE, STOREI, CALL, CALLI, RETURN, NOP, PUSH, POP, JUMP, JUMPI, JUMPIF, HALT |
||||||
|
} |
@ -0,0 +1,6 @@ |
|||||||
|
package triangle.abstractMachine; |
||||||
|
|
||||||
|
public enum Primitive { |
||||||
|
ID, NOT, AND, OR, SUCC, PRED, NEG, ADD, SUB, MULT, DIV, MOD, LT, LE, GE, GT, EQ, NE, EOL, EOF, GET, PUT, GETEOL, |
||||||
|
PUTEOL, GETINT, PUTINT, NEW, DISPOSE |
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
package triangle.abstractMachine; |
||||||
|
|
||||||
|
public enum Register { |
||||||
|
CB, CT, PB, PT, SB, ST, HB, HT, LB, L1, L2, L3, L4, L5, L6, CP |
||||||
|
} |
@ -0,0 +1,4 @@ |
|||||||
|
/target/ |
||||||
|
/.classpath |
||||||
|
/.editorconfig |
||||||
|
/build/ |
@ -0,0 +1,23 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<projectDescription> |
||||||
|
<name>Triangle.Compiler</name> |
||||||
|
<comment></comment> |
||||||
|
<projects> |
||||||
|
</projects> |
||||||
|
<buildSpec> |
||||||
|
<buildCommand> |
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name> |
||||||
|
<arguments> |
||||||
|
</arguments> |
||||||
|
</buildCommand> |
||||||
|
<buildCommand> |
||||||
|
<name>org.eclipse.buildship.core.gradleprojectbuilder</name> |
||||||
|
<arguments> |
||||||
|
</arguments> |
||||||
|
</buildCommand> |
||||||
|
</buildSpec> |
||||||
|
<natures> |
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature> |
||||||
|
<nature>org.eclipse.buildship.core.gradleprojectnature</nature> |
||||||
|
</natures> |
||||||
|
</projectDescription> |
@ -0,0 +1,24 @@ |
|||||||
|
apply plugin: 'java' |
||||||
|
apply plugin: 'application' |
||||||
|
|
||||||
|
sourceCompatibility = 11 |
||||||
|
|
||||||
|
repositories { |
||||||
|
mavenCentral() |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
dependencies { |
||||||
|
implementation project(':Triangle.AbstractMachine') |
||||||
|
// Task 2 |
||||||
|
implementation group: 'com.github.spullara.cli-parser', name: 'cli-parser', version: '1.1.5' |
||||||
|
// |
||||||
|
testImplementation group: 'junit', name: 'junit', version: '4.13.2' |
||||||
|
} |
||||||
|
|
||||||
|
application { |
||||||
|
mainClass = 'Triangle.Compiler' |
||||||
|
} |
||||||
|
|
||||||
|
// allow access to programs for unit tests |
||||||
|
sourceSets.test.resources.srcDir file("$rootDir/programs") |
@ -0,0 +1,18 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<artifactId>triangle-compiler</artifactId> |
||||||
|
<parent> |
||||||
|
<groupId>triangle.tools</groupId> |
||||||
|
<artifactId>triangle-tools</artifactId> |
||||||
|
<version>2.1</version> |
||||||
|
<relativePath>../</relativePath> |
||||||
|
</parent> |
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>triangle.tools</groupId> |
||||||
|
<artifactId>triangle-abstractmachine</artifactId> |
||||||
|
<version>2.1</version> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
</project> |
@ -0,0 +1,183 @@ |
|||||||
|
/* |
||||||
|
* @(#)Compiler.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.Program; |
||||||
|
import triangle.codeGenerator.Emitter; |
||||||
|
import triangle.codeGenerator.Encoder; |
||||||
|
import triangle.contextualAnalyzer.Checker; |
||||||
|
import triangle.optimiser.ConstantFolder; |
||||||
|
import triangle.syntacticAnalyzer.Parser; |
||||||
|
import triangle.syntacticAnalyzer.Scanner; |
||||||
|
import triangle.syntacticAnalyzer.SourceFile; |
||||||
|
import triangle.treeDrawer.Drawer; |
||||||
|
|
||||||
|
// Task 2
|
||||||
|
import com.sampullara.cli.Args; |
||||||
|
import com.sampullara.cli.Argument; |
||||||
|
|
||||||
|
/** |
||||||
|
* The main driver class for the Triangle compiler. |
||||||
|
* |
||||||
|
* @version 2.1 7 Oct 2003 |
||||||
|
* @author Deryck F. Brown |
||||||
|
*/ |
||||||
|
public class Compiler { |
||||||
|
|
||||||
|
/** The filename for the object program, normally obj.tam. */ |
||||||
|
//static String objectNIame = "obj.tam";
|
||||||
|
//static boolean showTree = false;
|
||||||
|
//static boolean folding = false; //Better implementation below
|
||||||
|
|
||||||
|
private static Scanner scanner; |
||||||
|
private static Parser parser; |
||||||
|
private static Checker checker; |
||||||
|
private static Encoder encoder; |
||||||
|
private static Emitter emitter; |
||||||
|
private static ErrorReporter reporter; |
||||||
|
private static Drawer drawer; |
||||||
|
|
||||||
|
/** The AST representing the source program. */ |
||||||
|
private static Program theAST; |
||||||
|
|
||||||
|
//Task 2
|
||||||
|
|
||||||
|
@Argument(alias = "file", description="Name of file you want to compile", required = true) |
||||||
|
static String sourceName = ""; |
||||||
|
|
||||||
|
@Argument(alias = "obj", description="Object file name", required = true) |
||||||
|
static String objectName = "obj.tam"; //default
|
||||||
|
|
||||||
|
@Argument(alias = "tree", description="Enable AST") |
||||||
|
static boolean showTree = false; |
||||||
|
|
||||||
|
@Argument(alias = "fold", description="Enable folding") |
||||||
|
static boolean folding = false; |
||||||
|
|
||||||
|
@Argument(alias = "tfold", description="Enable AST after folding") |
||||||
|
static boolean showTreeAfterFolding = false; |
||||||
|
|
||||||
|
//Task 5b
|
||||||
|
@Argument(alias = "stats", description="Enable stats (Char and Int Expr count)") |
||||||
|
static boolean showStats = false; |
||||||
|
|
||||||
|
/** |
||||||
|
* Compile the source program to TAM machine code. |
||||||
|
* |
||||||
|
* @param sourceName the name of the file containing the source program. |
||||||
|
* @param objectName the name of the file containing the object program. |
||||||
|
* @param showingAST true iff the AST is to be displayed after contextual |
||||||
|
* analysis |
||||||
|
* @param showingTable true iff the object description details are to be |
||||||
|
* displayed during code generation (not currently |
||||||
|
* implemented). |
||||||
|
* @param showAfterFolding show the AST after folding is complete |
||||||
|
* @param showStats show stats, these only (so far) inlcude char and int expressions |
||||||
|
* @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, boolean showAfterFolding, boolean showStats) { |
||||||
|
|
||||||
|
System.out.println("********** " + "Triangle Compiler (Java Version 2.1)" + " **********"); |
||||||
|
|
||||||
|
System.out.println("Syntactic Analysis ..."); |
||||||
|
SourceFile source = SourceFile.ofPath(sourceName); |
||||||
|
|
||||||
|
if (source == null) { |
||||||
|
System.out.println("Can't access source file " + sourceName); |
||||||
|
System.exit(1); |
||||||
|
} |
||||||
|
|
||||||
|
scanner = new Scanner(source); |
||||||
|
reporter = new ErrorReporter(false); |
||||||
|
parser = new Parser(scanner, reporter); |
||||||
|
checker = new Checker(reporter); |
||||||
|
emitter = new Emitter(reporter); |
||||||
|
encoder = new Encoder(emitter, reporter); |
||||||
|
drawer = new Drawer(); |
||||||
|
|
||||||
|
//Task 5b
|
||||||
|
stats = new SummaryStats(); |
||||||
|
|
||||||
|
theAST = parser.parseProgram(); // 1st pass
|
||||||
|
if (reporter.getNumErrors() == 0) { |
||||||
|
System.out.println("Contextual Analysis ..."); |
||||||
|
checker.check(theAST); // 2nd pass
|
||||||
|
|
||||||
|
if (showingAST && !showAfterFolding) { |
||||||
|
drawer.draw(theAST); |
||||||
|
} |
||||||
|
if (folding) { |
||||||
|
theAST.visit(new ConstantFolder()); |
||||||
|
if (showingAST && showAfterFolding) { |
||||||
|
drawer.draw(theAST); //if folding then also show tree
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
if (reporter.getNumErrors() == 0) { |
||||||
|
System.out.println("Code Generation ..."); |
||||||
|
encoder.encodeRun(theAST, showingTable); // 3rd pass
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
boolean successful = (reporter.getNumErrors() == 0); |
||||||
|
if (successful) { |
||||||
|
emitter.saveObjectProgram(objectName); |
||||||
|
System.out.println("Compilation was successful."); |
||||||
|
//Task 5b
|
||||||
|
System.out.println("[STATS] CharExpr: " + stats.getCharExprCount() + "!"); |
||||||
|
System.out.println("[STATS] IntExpr: " + stats.getIntExprCount() + "!"); |
||||||
|
} else { |
||||||
|
System.out.println("Compilation was unsuccessful."); |
||||||
|
} |
||||||
|
return successful; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Triangle compiler main program. |
||||||
|
* |
||||||
|
* @param args the only command-line argument to the program specifies the |
||||||
|
* source filename. |
||||||
|
*/ |
||||||
|
public static void main(String[] args) { |
||||||
|
|
||||||
|
//Task 2
|
||||||
|
Args.parseOrExit(Compiler.class, args); |
||||||
|
var compiledOK = compileProgram(Compiler.sourceName, Compiler.objectName, Compiler.showTree, false, Compiler.showTreeAfterFolding); |
||||||
|
|
||||||
|
if (!showTree) { |
||||||
|
System.exit(compiledOK ? 0 : 1); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/* No longer needed */ |
||||||
|
private static void parseArgs(String[] args) { |
||||||
|
for (String s : args) { |
||||||
|
var sl = s.toLowerCase(); |
||||||
|
if (sl.equals("tree")) { |
||||||
|
showTree = true; |
||||||
|
} else if (sl.startsWith("-o=")) { |
||||||
|
objectName = s.substring(3); |
||||||
|
} else if (sl.equals("folding")) { |
||||||
|
folding = true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,65 @@ |
|||||||
|
/* |
||||||
|
* @(#)ErrorReporter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle; |
||||||
|
|
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class ErrorReporter { |
||||||
|
|
||||||
|
private int numErrors; |
||||||
|
|
||||||
|
private boolean throwExceptions; |
||||||
|
|
||||||
|
/** |
||||||
|
* @param throwExceptions if true, throw exceptions (good for unit tests) otherwise write to stdout |
||||||
|
*/ |
||||||
|
public ErrorReporter(boolean throwExceptions) { |
||||||
|
numErrors = 0; |
||||||
|
this.throwExceptions = throwExceptions; |
||||||
|
} |
||||||
|
|
||||||
|
public void reportError(String message, String tokenName, SourcePosition pos) { |
||||||
|
|
||||||
|
numErrors++; |
||||||
|
|
||||||
|
String s = ("ERROR: "); |
||||||
|
|
||||||
|
for (int p = 0; p < message.length(); p++) |
||||||
|
if (message.charAt(p) == '%') |
||||||
|
s += tokenName; |
||||||
|
else |
||||||
|
s += message.charAt(p); |
||||||
|
s += (" " + pos.start + ".." + pos.finish); |
||||||
|
|
||||||
|
if (throwExceptions) { |
||||||
|
throw new RuntimeException(s); |
||||||
|
} else { |
||||||
|
System.out.println(s); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void reportRestriction(String message) { |
||||||
|
System.out.println("RESTRICTION: " + message); |
||||||
|
} |
||||||
|
|
||||||
|
public int getNumErrors() { |
||||||
|
return numErrors; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
/* |
||||||
|
* @(#)StdEnvironment.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.declarations.BinaryOperatorDeclaration; |
||||||
|
import triangle.abstractSyntaxTrees.declarations.ConstDeclaration; |
||||||
|
import triangle.abstractSyntaxTrees.declarations.FuncDeclaration; |
||||||
|
import triangle.abstractSyntaxTrees.declarations.ProcDeclaration; |
||||||
|
import triangle.abstractSyntaxTrees.declarations.UnaryOperatorDeclaration; |
||||||
|
import triangle.abstractSyntaxTrees.types.TypeDeclaration; |
||||||
|
import triangle.abstractSyntaxTrees.types.TypeDenoter; |
||||||
|
|
||||||
|
public final class StdEnvironment { |
||||||
|
|
||||||
|
// These are small ASTs representing standard types.
|
||||||
|
|
||||||
|
public static TypeDenoter booleanType, charType, integerType, anyType, errorType; |
||||||
|
|
||||||
|
public static TypeDeclaration booleanDecl, charDecl, integerDecl; |
||||||
|
|
||||||
|
// These are small ASTs representing "declarations" of standard entities.
|
||||||
|
|
||||||
|
public static ConstDeclaration falseDecl, trueDecl, maxintDecl; |
||||||
|
|
||||||
|
public static UnaryOperatorDeclaration notDecl; |
||||||
|
|
||||||
|
public static BinaryOperatorDeclaration andDecl, orDecl, addDecl, subtractDecl, multiplyDecl, divideDecl, |
||||||
|
moduloDecl, equalDecl, unequalDecl, lessDecl, notlessDecl, greaterDecl, notgreaterDecl; |
||||||
|
|
||||||
|
public static ProcDeclaration getDecl, putDecl, getintDecl, putintDecl, geteolDecl, puteolDecl; |
||||||
|
|
||||||
|
public static FuncDeclaration chrDecl, ordDecl, eolDecl, eofDecl; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
/* |
||||||
|
* @(#)AST.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees; |
||||||
|
|
||||||
|
import triangle.codeGenerator.entities.RuntimeEntity; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public abstract class AbstractSyntaxTree { |
||||||
|
|
||||||
|
private final SourcePosition position; |
||||||
|
|
||||||
|
public AbstractSyntaxTree(SourcePosition position) { |
||||||
|
this.position = position; |
||||||
|
entity = null; |
||||||
|
} |
||||||
|
|
||||||
|
public SourcePosition getPosition() { |
||||||
|
return position; |
||||||
|
} |
||||||
|
|
||||||
|
public RuntimeEntity entity; |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
/* |
||||||
|
* @(#)Program.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.commands.Command; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ProgramVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class Program extends AbstractSyntaxTree { |
||||||
|
|
||||||
|
public Program(Command cAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
C = cAST; |
||||||
|
} |
||||||
|
|
||||||
|
public Command C; |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ProgramVisitor<TArg, TResult> visitor, TArg arg) { |
||||||
|
return visitor.visitProgram(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public <TResult> TResult visit(ProgramVisitor<Void, TResult> visitor) { |
||||||
|
return visit(visitor, null); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
/* |
||||||
|
* @(#)ActualParameter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.actuals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.AbstractSyntaxTree; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ActualParameterVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public abstract class ActualParameter extends AbstractSyntaxTree { |
||||||
|
|
||||||
|
public ActualParameter(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
} |
||||||
|
|
||||||
|
public abstract <TArg, TResult> TResult visit(ActualParameterVisitor<TArg, TResult> visitor, TArg arg); |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ActualParameterVisitor<TArg, TResult> visitor) { |
||||||
|
return visit(visitor, null); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
/* |
||||||
|
* @(#)ActualParameterSequence.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.actuals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.AbstractSyntaxTree; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ActualParameterSequenceVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public abstract class ActualParameterSequence extends AbstractSyntaxTree { |
||||||
|
|
||||||
|
public ActualParameterSequence(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
} |
||||||
|
|
||||||
|
public abstract <TArg, TResult> TResult visit(ActualParameterSequenceVisitor<TArg, TResult> v, TArg arg); |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ActualParameterSequenceVisitor<TArg, TResult> v) { |
||||||
|
return visit(v, null); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
/* |
||||||
|
* @(#)ConstActualParameter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.actuals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.expressions.Expression; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ActualParameterVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class ConstActualParameter extends ActualParameter { |
||||||
|
|
||||||
|
public ConstActualParameter(Expression eAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
E = eAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ActualParameterVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitConstActualParameter(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public Expression E; |
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
/* |
||||||
|
* @(#)EmptyActualParameterSequence.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.actuals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.ActualParameterSequenceVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class EmptyActualParameterSequence extends ActualParameterSequence { |
||||||
|
|
||||||
|
public EmptyActualParameterSequence(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ActualParameterSequenceVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitEmptyActualParameterSequence(this, arg); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
/* |
||||||
|
* @(#)FuncActualParameter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.actuals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.terminals.Identifier; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ActualParameterVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class FuncActualParameter extends ActualParameter { |
||||||
|
|
||||||
|
public FuncActualParameter(Identifier iAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
I = iAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ActualParameterVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitFuncActualParameter(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Identifier I; |
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
/* |
||||||
|
* @(#)MultipleActualParameterSequence.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.actuals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.ActualParameterSequenceVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class MultipleActualParameterSequence extends ActualParameterSequence { |
||||||
|
|
||||||
|
public MultipleActualParameterSequence(ActualParameter apAST, ActualParameterSequence apsAST, |
||||||
|
SourcePosition position) { |
||||||
|
super(position); |
||||||
|
AP = apAST; |
||||||
|
APS = apsAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ActualParameterSequenceVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitMultipleActualParameterSequence(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final ActualParameter AP; |
||||||
|
public final ActualParameterSequence APS; |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
/* |
||||||
|
* @(#)ProcActualParameter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.actuals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.terminals.Identifier; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ActualParameterVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class ProcActualParameter extends ActualParameter { |
||||||
|
|
||||||
|
public ProcActualParameter(Identifier iAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
I = iAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ActualParameterVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitProcActualParameter(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Identifier I; |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
/* |
||||||
|
* @(#)SingleActualParameterSequence.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.actuals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.ActualParameterSequenceVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class SingleActualParameterSequence extends ActualParameterSequence { |
||||||
|
|
||||||
|
public SingleActualParameterSequence(ActualParameter apAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
AP = apAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ActualParameterSequenceVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitSingleActualParameterSequence(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final ActualParameter AP; |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
/* |
||||||
|
* @(#)VarActualParameter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.actuals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.ActualParameterVisitor; |
||||||
|
import triangle.abstractSyntaxTrees.vnames.Vname; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class VarActualParameter extends ActualParameter { |
||||||
|
|
||||||
|
public VarActualParameter(Vname vAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
V = vAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ActualParameterVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitVarActualParameter(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Vname V; |
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
/* |
||||||
|
* @(#)ArrayAggregate.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.aggregates; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.AbstractSyntaxTree; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ArrayAggregateVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public abstract class ArrayAggregate extends AbstractSyntaxTree { |
||||||
|
|
||||||
|
public ArrayAggregate(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
elemCount = 0; |
||||||
|
} |
||||||
|
|
||||||
|
public int elemCount; |
||||||
|
|
||||||
|
public abstract <TArg, TResult> TResult visit(ArrayAggregateVisitor<TArg, TResult> visitor, TArg arg); |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ArrayAggregateVisitor<TArg, TResult> visitor) { |
||||||
|
return visit(visitor, null); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
/* |
||||||
|
* @(#)MultipleArrayAggregate.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.aggregates; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.expressions.Expression; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ArrayAggregateVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class MultipleArrayAggregate extends ArrayAggregate { |
||||||
|
|
||||||
|
public MultipleArrayAggregate(Expression eAST, ArrayAggregate aaAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
E = eAST; |
||||||
|
AA = aaAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ArrayAggregateVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitMultipleArrayAggregate(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public Expression E; |
||||||
|
public final ArrayAggregate AA; |
||||||
|
} |
@ -0,0 +1,42 @@ |
|||||||
|
/* |
||||||
|
* @(#)MultipleRecordAggregate.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.aggregates; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.expressions.Expression; |
||||||
|
import triangle.abstractSyntaxTrees.terminals.Identifier; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.RecordAggregateVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class MultipleRecordAggregate extends RecordAggregate { |
||||||
|
|
||||||
|
public MultipleRecordAggregate(Identifier iAST, Expression eAST, RecordAggregate raAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
I = iAST; |
||||||
|
E = eAST; |
||||||
|
RA = raAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(RecordAggregateVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitMultipleRecordAggregate(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Identifier I; |
||||||
|
public Expression E; |
||||||
|
public final RecordAggregate RA; |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
/* |
||||||
|
* @(#)RecordAggregate.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.aggregates; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.AbstractSyntaxTree; |
||||||
|
import triangle.abstractSyntaxTrees.types.FieldTypeDenoter; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.RecordAggregateVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public abstract class RecordAggregate extends AbstractSyntaxTree { |
||||||
|
|
||||||
|
public RecordAggregate(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
type = null; |
||||||
|
} |
||||||
|
|
||||||
|
public FieldTypeDenoter type; |
||||||
|
|
||||||
|
public abstract <TArg, TResult> TResult visit(RecordAggregateVisitor<TArg, TResult> visitor, TArg arg); |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(RecordAggregateVisitor<TArg, TResult> visitor) { |
||||||
|
return visit(visitor, null); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
/* |
||||||
|
* @(#)SingleArrayAggregate.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.aggregates; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.expressions.Expression; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ArrayAggregateVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class SingleArrayAggregate extends ArrayAggregate { |
||||||
|
|
||||||
|
public SingleArrayAggregate(Expression eAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
E = eAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ArrayAggregateVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitSingleArrayAggregate(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public Expression E; |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
/* |
||||||
|
* @(#)SingleRecordAggregate.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.aggregates; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.expressions.Expression; |
||||||
|
import triangle.abstractSyntaxTrees.terminals.Identifier; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.RecordAggregateVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class SingleRecordAggregate extends RecordAggregate { |
||||||
|
|
||||||
|
public SingleRecordAggregate(Identifier iAST, Expression eAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
I = iAST; |
||||||
|
E = eAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(RecordAggregateVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitSingleRecordAggregate(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Identifier I; |
||||||
|
public Expression E; |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
/* |
||||||
|
* @(#)AssignCommand.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.commands; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.expressions.Expression; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.CommandVisitor; |
||||||
|
import triangle.abstractSyntaxTrees.vnames.Vname; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class AssignCommand extends Command { |
||||||
|
|
||||||
|
public AssignCommand(Vname vAST, Expression eAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
V = vAST; |
||||||
|
E = eAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitAssignCommand(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Vname V; |
||||||
|
public Expression E; |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
/* |
||||||
|
* @(#)CallCommand.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.commands; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.actuals.ActualParameterSequence; |
||||||
|
import triangle.abstractSyntaxTrees.terminals.Identifier; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.CommandVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class CallCommand extends Command { |
||||||
|
|
||||||
|
public CallCommand(Identifier iAST, ActualParameterSequence apsAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
I = iAST; |
||||||
|
APS = apsAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitCallCommand(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Identifier I; |
||||||
|
public final ActualParameterSequence APS; |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
/* |
||||||
|
* @(#)Command.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.commands; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.AbstractSyntaxTree; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.CommandVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public abstract class Command extends AbstractSyntaxTree { |
||||||
|
|
||||||
|
public Command(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
} |
||||||
|
|
||||||
|
public abstract <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> visitor, TArg arg); |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> visitor) { |
||||||
|
return visit(visitor, null); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
/* |
||||||
|
* @(#)EmptyCommand.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.commands; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.CommandVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class EmptyCommand extends Command { |
||||||
|
|
||||||
|
public EmptyCommand(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitEmptyCommand(this, arg); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
/* |
||||||
|
* @(#)IfCommand.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.commands; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.expressions.Expression; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.CommandVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class IfCommand extends Command { |
||||||
|
|
||||||
|
public IfCommand(Expression eAST, Command c1AST, Command c2AST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
E = eAST; |
||||||
|
C1 = c1AST; |
||||||
|
C2 = c2AST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitIfCommand(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public Expression E; |
||||||
|
public final Command C1, C2; |
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
/* |
||||||
|
* @(#)LetCommand.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.commands; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.declarations.Declaration; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.CommandVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class LetCommand extends Command { |
||||||
|
|
||||||
|
public LetCommand(Declaration dAST, Command cAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
D = dAST; |
||||||
|
C = cAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitLetCommand(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Declaration D; |
||||||
|
public final Command C; |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
/* |
||||||
|
* @(#)SequentialCommand.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.commands; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.CommandVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class SequentialCommand extends Command { |
||||||
|
|
||||||
|
public SequentialCommand(Command c1AST, Command c2AST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
C1 = c1AST; |
||||||
|
C2 = c2AST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitSequentialCommand(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Command C1, C2; |
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
/* |
||||||
|
* @(#)WhileCommand.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.commands; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.expressions.Expression; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.CommandVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class WhileCommand extends Command { |
||||||
|
|
||||||
|
public WhileCommand(Expression eAST, Command cAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
E = eAST; |
||||||
|
C = cAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitWhileCommand(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public Expression E; |
||||||
|
public final Command C; |
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
/* |
||||||
|
* @(#)BinaryOperatorDeclaration.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.declarations; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.terminals.Operator; |
||||||
|
import triangle.abstractSyntaxTrees.types.TypeDenoter; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class BinaryOperatorDeclaration extends Declaration { |
||||||
|
|
||||||
|
public BinaryOperatorDeclaration(Operator oAST, TypeDenoter arg1AST, TypeDenoter arg2AST, TypeDenoter resultAST, |
||||||
|
SourcePosition position) { |
||||||
|
super(position); |
||||||
|
O = oAST; |
||||||
|
ARG1 = arg1AST; |
||||||
|
ARG2 = arg2AST; |
||||||
|
RES = resultAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitBinaryOperatorDeclaration(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Operator O; |
||||||
|
public final TypeDenoter ARG1, ARG2, RES; |
||||||
|
} |
@ -0,0 +1,46 @@ |
|||||||
|
/* |
||||||
|
* @(#)ConstDeclaration.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.declarations; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.expressions.Expression; |
||||||
|
import triangle.abstractSyntaxTrees.terminals.Identifier; |
||||||
|
import triangle.abstractSyntaxTrees.types.TypeDenoter; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class ConstDeclaration extends Declaration implements ConstantDeclaration { |
||||||
|
|
||||||
|
public ConstDeclaration(Identifier iAST, Expression eAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
I = iAST; |
||||||
|
E = eAST; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public TypeDenoter getType() { |
||||||
|
return E.type; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitConstDeclaration(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Identifier I; |
||||||
|
public Expression E; |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
package triangle.abstractSyntaxTrees.declarations; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.types.TypeDenoter; |
||||||
|
|
||||||
|
public interface ConstantDeclaration { |
||||||
|
|
||||||
|
TypeDenoter getType(); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
/* |
||||||
|
* @(#)Declaration.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.declarations; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.AbstractSyntaxTree; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public abstract class Declaration extends AbstractSyntaxTree { |
||||||
|
|
||||||
|
public Declaration(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
duplicated = false; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean duplicated; |
||||||
|
|
||||||
|
public abstract <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> visitor, TArg arg); |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> visitor) { |
||||||
|
return visit(visitor, null); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,57 @@ |
|||||||
|
/* |
||||||
|
* @(#)FuncDeclaration.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.declarations; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.expressions.Expression; |
||||||
|
import triangle.abstractSyntaxTrees.formals.FormalParameterSequence; |
||||||
|
import triangle.abstractSyntaxTrees.terminals.Identifier; |
||||||
|
import triangle.abstractSyntaxTrees.types.TypeDenoter; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class FuncDeclaration extends Declaration implements FunctionDeclaration { |
||||||
|
|
||||||
|
public FuncDeclaration(Identifier iAST, FormalParameterSequence fpsAST, TypeDenoter tAST, Expression eAST, |
||||||
|
SourcePosition position) { |
||||||
|
super(position); |
||||||
|
I = iAST; |
||||||
|
FPS = fpsAST; |
||||||
|
T = tAST; |
||||||
|
E = eAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitFuncDeclaration(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public FormalParameterSequence getFormals() { |
||||||
|
return FPS; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public TypeDenoter getType() { |
||||||
|
return T; |
||||||
|
} |
||||||
|
|
||||||
|
public final Identifier I; |
||||||
|
public final FormalParameterSequence FPS; |
||||||
|
public TypeDenoter T; |
||||||
|
public Expression E; |
||||||
|
} |
@ -0,0 +1,12 @@ |
|||||||
|
package triangle.abstractSyntaxTrees.declarations; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.formals.FormalParameterSequence; |
||||||
|
import triangle.abstractSyntaxTrees.types.TypeDenoter; |
||||||
|
|
||||||
|
public interface FunctionDeclaration { |
||||||
|
|
||||||
|
FormalParameterSequence getFormals(); |
||||||
|
|
||||||
|
TypeDenoter getType(); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
/* |
||||||
|
* @(#)ProcDeclaration.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.declarations; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.commands.Command; |
||||||
|
import triangle.abstractSyntaxTrees.formals.FormalParameterSequence; |
||||||
|
import triangle.abstractSyntaxTrees.terminals.Identifier; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class ProcDeclaration extends Declaration implements ProcedureDeclaration { |
||||||
|
|
||||||
|
public ProcDeclaration(Identifier iAST, FormalParameterSequence fpsAST, Command cAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
I = iAST; |
||||||
|
FPS = fpsAST; |
||||||
|
C = cAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitProcDeclaration(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public FormalParameterSequence getFormals() { |
||||||
|
return FPS; |
||||||
|
} |
||||||
|
|
||||||
|
public final Identifier I; |
||||||
|
public final FormalParameterSequence FPS; |
||||||
|
public final Command C; |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
package triangle.abstractSyntaxTrees.declarations; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.formals.FormalParameterSequence; |
||||||
|
|
||||||
|
public interface ProcedureDeclaration { |
||||||
|
|
||||||
|
FormalParameterSequence getFormals(); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
/* |
||||||
|
* @(#)SequentialDeclaration.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.declarations; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class SequentialDeclaration extends Declaration { |
||||||
|
|
||||||
|
public SequentialDeclaration(Declaration d1AST, Declaration d2AST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
D1 = d1AST; |
||||||
|
D2 = d2AST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitSequentialDeclaration(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Declaration D1, D2; |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
/* |
||||||
|
* @(#)UnaryOperatorDeclaration.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.declarations; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.terminals.Operator; |
||||||
|
import triangle.abstractSyntaxTrees.types.TypeDenoter; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class UnaryOperatorDeclaration extends Declaration { |
||||||
|
|
||||||
|
public UnaryOperatorDeclaration(Operator oAST, TypeDenoter argAST, TypeDenoter resultAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
O = oAST; |
||||||
|
ARG = argAST; |
||||||
|
RES = resultAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitUnaryOperatorDeclaration(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Operator O; |
||||||
|
public final TypeDenoter ARG, RES; |
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
/* |
||||||
|
* @(#)VarDeclaration.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.declarations; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.terminals.Identifier; |
||||||
|
import triangle.abstractSyntaxTrees.types.TypeDenoter; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class VarDeclaration extends Declaration implements VariableDeclaration { |
||||||
|
|
||||||
|
public VarDeclaration(Identifier iAST, TypeDenoter tAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
I = iAST; |
||||||
|
T = tAST; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public TypeDenoter getType() { |
||||||
|
return T; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitVarDeclaration(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Identifier I; |
||||||
|
public TypeDenoter T; |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
package triangle.abstractSyntaxTrees.declarations; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.types.TypeDenoter; |
||||||
|
|
||||||
|
public interface VariableDeclaration { |
||||||
|
|
||||||
|
TypeDenoter getType(); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
/* |
||||||
|
* @(#)ArrayExpression.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.expressions; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.aggregates.ArrayAggregate; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ExpressionVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class ArrayExpression extends Expression { |
||||||
|
|
||||||
|
public ArrayExpression(ArrayAggregate aaAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
AA = aaAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitArrayExpression(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final ArrayAggregate AA; |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
/* |
||||||
|
* @(#)BinaryExpression.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.expressions; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.terminals.Operator; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ExpressionVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class BinaryExpression extends Expression { |
||||||
|
|
||||||
|
public BinaryExpression(Expression e1AST, Operator oAST, Expression e2AST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
O = oAST; |
||||||
|
E1 = e1AST; |
||||||
|
E2 = e2AST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitBinaryExpression(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public Expression E1; |
||||||
|
public Expression E2; |
||||||
|
public final Operator O; |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
/* |
||||||
|
* @(#)CallExpression.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.expressions; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.actuals.ActualParameterSequence; |
||||||
|
import triangle.abstractSyntaxTrees.terminals.Identifier; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ExpressionVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class CallExpression extends Expression { |
||||||
|
|
||||||
|
public CallExpression(Identifier iAST, ActualParameterSequence apsAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
I = iAST; |
||||||
|
APS = apsAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitCallExpression(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Identifier I; |
||||||
|
public final ActualParameterSequence APS; |
||||||
|
} |
@ -0,0 +1,47 @@ |
|||||||
|
/* |
||||||
|
* @(#)CharacterExpression.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.expressions; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.terminals.CharacterLiteral; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ExpressionVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class CharacterExpression extends Expression { |
||||||
|
|
||||||
|
public CharacterExpression(CharacterLiteral clAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
CL = clAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitCharacterExpression(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final CharacterLiteral CL; |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isLiteral() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getValue() { |
||||||
|
return CL.getValue(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
/* |
||||||
|
* @(#)EmptyExpression.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.expressions; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.ExpressionVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class EmptyExpression extends Expression { |
||||||
|
|
||||||
|
public EmptyExpression(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitEmptyExpression(this, arg); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
/* |
||||||
|
* @(#)Expression.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.expressions; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.AbstractSyntaxTree; |
||||||
|
import triangle.abstractSyntaxTrees.types.TypeDenoter; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ExpressionVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public abstract class Expression extends AbstractSyntaxTree { |
||||||
|
|
||||||
|
public Expression(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
type = null; |
||||||
|
} |
||||||
|
|
||||||
|
public TypeDenoter type; |
||||||
|
|
||||||
|
public boolean isLiteral() { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
public int getValue() { |
||||||
|
throw new UnsupportedOperationException(); |
||||||
|
} |
||||||
|
|
||||||
|
public abstract <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> visitor, TArg arg); |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> visitor) { |
||||||
|
return visit(visitor, null); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
/* |
||||||
|
* @(#)IfExpression.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.expressions; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.ExpressionVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class IfExpression extends Expression { |
||||||
|
|
||||||
|
public IfExpression(Expression e1AST, Expression e2AST, Expression e3AST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
E1 = e1AST; |
||||||
|
E2 = e2AST; |
||||||
|
E3 = e3AST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitIfExpression(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public Expression E1; |
||||||
|
public Expression E2; |
||||||
|
public Expression E3; |
||||||
|
} |
@ -0,0 +1,47 @@ |
|||||||
|
/* |
||||||
|
* @(#)IntegerExpression.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.expressions; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.terminals.IntegerLiteral; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ExpressionVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class IntegerExpression extends Expression { |
||||||
|
|
||||||
|
public IntegerExpression(IntegerLiteral ilAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
IL = ilAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitIntegerExpression(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final IntegerLiteral IL; |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isLiteral() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getValue() { |
||||||
|
return IL.getValue(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
/* |
||||||
|
* @(#)LetExpression.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.expressions; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.declarations.Declaration; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ExpressionVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class LetExpression extends Expression { |
||||||
|
|
||||||
|
public LetExpression(Declaration dAST, Expression eAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
D = dAST; |
||||||
|
E = eAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitLetExpression(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Declaration D; |
||||||
|
public Expression E; |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
/* |
||||||
|
* @(#)RecordExpression.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.expressions; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.aggregates.RecordAggregate; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ExpressionVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class RecordExpression extends Expression { |
||||||
|
|
||||||
|
public RecordExpression(RecordAggregate raAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
RA = raAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitRecordExpression(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final RecordAggregate RA; |
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
/* |
||||||
|
* @(#)UnaryExpression.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.expressions; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.terminals.Operator; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.ExpressionVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class UnaryExpression extends Expression { |
||||||
|
|
||||||
|
public UnaryExpression(Operator oAST, Expression eAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
O = oAST; |
||||||
|
E = eAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitUnaryExpression(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public Expression E; |
||||||
|
public final Operator O; |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
/* |
||||||
|
* @(#)VnameExpression.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.expressions; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.ExpressionVisitor; |
||||||
|
import triangle.abstractSyntaxTrees.vnames.Vname; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class VnameExpression extends Expression { |
||||||
|
|
||||||
|
public VnameExpression(Vname vAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
V = vAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitVnameExpression(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public final Vname V; |
||||||
|
} |
@ -0,0 +1,55 @@ |
|||||||
|
/* |
||||||
|
* @(#)ConstFormalParameter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.formals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.declarations.ConstantDeclaration; |
||||||
|
import triangle.abstractSyntaxTrees.terminals.Identifier; |
||||||
|
import triangle.abstractSyntaxTrees.types.TypeDenoter; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class ConstFormalParameter extends FormalParameter implements ConstantDeclaration { |
||||||
|
|
||||||
|
public ConstFormalParameter(Identifier iAST, TypeDenoter tAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
I = iAST; |
||||||
|
T = tAST; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public TypeDenoter getType() { |
||||||
|
return T; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitConstFormalParameter(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object fpAST) { |
||||||
|
if (fpAST instanceof ConstFormalParameter) { |
||||||
|
return T.equals(((ConstFormalParameter)fpAST).T); |
||||||
|
} else { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public final Identifier I; |
||||||
|
public TypeDenoter T; |
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
/* |
||||||
|
* @(#)EmptyFormalParameterSequence.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.formals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.FormalParameterSequenceVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class EmptyFormalParameterSequence extends FormalParameterSequence { |
||||||
|
|
||||||
|
public EmptyFormalParameterSequence(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(FormalParameterSequenceVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitEmptyFormalParameterSequence(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object fpsAST) { |
||||||
|
return (fpsAST instanceof EmptyFormalParameterSequence); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
/* |
||||||
|
* @(#)FormalParameter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.formals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.declarations.Declaration; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public abstract class FormalParameter extends Declaration { |
||||||
|
|
||||||
|
public FormalParameter(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public abstract boolean equals(Object fpAST); |
||||||
|
|
||||||
|
public abstract <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> visitor, TArg arg); |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> visitor) { |
||||||
|
return visit(visitor, null); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
/* |
||||||
|
* @(#)FormalParameterSequence.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.formals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.AbstractSyntaxTree; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.FormalParameterSequenceVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public abstract class FormalParameterSequence extends AbstractSyntaxTree { |
||||||
|
|
||||||
|
public FormalParameterSequence(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public abstract boolean equals(Object fpsAST); |
||||||
|
|
||||||
|
public abstract <TArg, TResult> TResult visit(FormalParameterSequenceVisitor<TArg, TResult> visitor, TArg arg); |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(FormalParameterSequenceVisitor<TArg, TResult> visitor) { |
||||||
|
return visit(visitor, null); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,63 @@ |
|||||||
|
/* |
||||||
|
* @(#)FuncFormalParameter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.formals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.declarations.FunctionDeclaration; |
||||||
|
import triangle.abstractSyntaxTrees.terminals.Identifier; |
||||||
|
import triangle.abstractSyntaxTrees.types.TypeDenoter; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class FuncFormalParameter extends FormalParameter implements FunctionDeclaration { |
||||||
|
|
||||||
|
public FuncFormalParameter(Identifier iAST, FormalParameterSequence fpsAST, TypeDenoter tAST, |
||||||
|
SourcePosition position) { |
||||||
|
super(position); |
||||||
|
I = iAST; |
||||||
|
FPS = fpsAST; |
||||||
|
T = tAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitFuncFormalParameter(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public FormalParameterSequence getFormals() { |
||||||
|
return FPS; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public TypeDenoter getType() { |
||||||
|
return T; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object fpAST) { |
||||||
|
if (fpAST instanceof FuncFormalParameter) { |
||||||
|
FuncFormalParameter ffpAST = (FuncFormalParameter) fpAST; |
||||||
|
return FPS.equals(ffpAST.FPS) && T.equals(ffpAST.T); |
||||||
|
} else |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
public final Identifier I; |
||||||
|
public final FormalParameterSequence FPS; |
||||||
|
public TypeDenoter T; |
||||||
|
} |
@ -0,0 +1,49 @@ |
|||||||
|
/* |
||||||
|
* @(#)MultipleFormalParameterSequence.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.formals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.FormalParameterSequenceVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class MultipleFormalParameterSequence extends FormalParameterSequence { |
||||||
|
|
||||||
|
public MultipleFormalParameterSequence(FormalParameter fpAST, FormalParameterSequence fpsAST, |
||||||
|
SourcePosition position) { |
||||||
|
super(position); |
||||||
|
FP = fpAST; |
||||||
|
FPS = fpsAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(FormalParameterSequenceVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitMultipleFormalParameterSequence(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object fpsAST) { |
||||||
|
if (fpsAST instanceof MultipleFormalParameterSequence) { |
||||||
|
MultipleFormalParameterSequence mfpsAST = (MultipleFormalParameterSequence) fpsAST; |
||||||
|
return FP.equals(mfpsAST.FP) && FPS.equals(mfpsAST.FPS); |
||||||
|
} else { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public final FormalParameter FP; |
||||||
|
public final FormalParameterSequence FPS; |
||||||
|
} |
@ -0,0 +1,55 @@ |
|||||||
|
/* |
||||||
|
* @(#)ProcFormalParameter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.formals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.declarations.ProcedureDeclaration; |
||||||
|
import triangle.abstractSyntaxTrees.terminals.Identifier; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class ProcFormalParameter extends FormalParameter implements ProcedureDeclaration { |
||||||
|
|
||||||
|
public ProcFormalParameter(Identifier iAST, FormalParameterSequence fpsAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
I = iAST; |
||||||
|
FPS = fpsAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitProcFormalParameter(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public FormalParameterSequence getFormals() { |
||||||
|
return FPS; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object fpAST) { |
||||||
|
if (fpAST instanceof ProcFormalParameter) { |
||||||
|
ProcFormalParameter pfpAST = (ProcFormalParameter) fpAST; |
||||||
|
return FPS.equals(pfpAST.FPS); |
||||||
|
} else { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public final Identifier I; |
||||||
|
public final FormalParameterSequence FPS; |
||||||
|
} |
@ -0,0 +1,46 @@ |
|||||||
|
/* |
||||||
|
* @(#)SingleFormalParameterSequence.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.formals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.FormalParameterSequenceVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class SingleFormalParameterSequence extends FormalParameterSequence { |
||||||
|
|
||||||
|
public SingleFormalParameterSequence(FormalParameter fpAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
FP = fpAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(FormalParameterSequenceVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitSingleFormalParameterSequence(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object fpsAST) { |
||||||
|
if (fpsAST instanceof SingleFormalParameterSequence) { |
||||||
|
SingleFormalParameterSequence sfpsAST = (SingleFormalParameterSequence) fpsAST; |
||||||
|
return FP.equals(sfpsAST.FP); |
||||||
|
} else { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public final FormalParameter FP; |
||||||
|
} |
@ -0,0 +1,55 @@ |
|||||||
|
/* |
||||||
|
* @(#)ValFormalParameter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.formals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.declarations.VariableDeclaration; |
||||||
|
import triangle.abstractSyntaxTrees.terminals.Identifier; |
||||||
|
import triangle.abstractSyntaxTrees.types.TypeDenoter; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class VarFormalParameter extends FormalParameter implements VariableDeclaration { |
||||||
|
|
||||||
|
public VarFormalParameter(Identifier iAST, TypeDenoter tAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
I = iAST; |
||||||
|
T = tAST; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public TypeDenoter getType() { |
||||||
|
return T; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitVarFormalParameter(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object fpAST) { |
||||||
|
if (fpAST instanceof VarFormalParameter) { |
||||||
|
return T.equals(((VarFormalParameter)fpAST).T); |
||||||
|
} else { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public final Identifier I; |
||||||
|
public TypeDenoter T; |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
/* |
||||||
|
* @(#)CharacterLiteral.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.terminals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.LiteralVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class CharacterLiteral extends Terminal { |
||||||
|
|
||||||
|
public CharacterLiteral(String spelling, SourcePosition position) { |
||||||
|
super(spelling, position); |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(LiteralVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitCharacterLiteral(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(LiteralVisitor<TArg, TResult> visitor) { |
||||||
|
return visit(visitor, null); |
||||||
|
} |
||||||
|
|
||||||
|
public int getValue() { |
||||||
|
return spelling.charAt(1); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,44 @@ |
|||||||
|
/* |
||||||
|
* @(#)Identifier.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.terminals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.AbstractSyntaxTree; |
||||||
|
import triangle.abstractSyntaxTrees.types.TypeDenoter; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.IdentifierVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class Identifier extends Terminal { |
||||||
|
|
||||||
|
public Identifier(String spelling, SourcePosition position) { |
||||||
|
super(spelling, position); |
||||||
|
type = null; |
||||||
|
decl = null; |
||||||
|
} |
||||||
|
|
||||||
|
public TypeDenoter type; |
||||||
|
public AbstractSyntaxTree decl; // Either a Declaration or a FieldTypeDenoter
|
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(IdentifierVisitor<TArg, TResult> visitor, TArg arg) { |
||||||
|
return visitor.visitIdentifier(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(IdentifierVisitor<TArg, TResult> visitor) { |
||||||
|
return visit(visitor, null); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
/* |
||||||
|
* @(#)IntegerLiteral.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.terminals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.LiteralVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class IntegerLiteral extends Terminal { |
||||||
|
|
||||||
|
public IntegerLiteral(String spelling, SourcePosition position) { |
||||||
|
super(spelling, position); |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(LiteralVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitIntegerLiteral(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(LiteralVisitor<TArg, TResult> visitor) { |
||||||
|
return visit(visitor, null); |
||||||
|
} |
||||||
|
|
||||||
|
public int getValue() { |
||||||
|
return Integer.parseInt(spelling); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
/* |
||||||
|
* @(#)Operator.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.terminals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.declarations.Declaration; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.OperatorVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class Operator extends Terminal { |
||||||
|
|
||||||
|
public Operator(String spelling, SourcePosition position) { |
||||||
|
super(spelling, position); |
||||||
|
decl = null; |
||||||
|
} |
||||||
|
|
||||||
|
public Declaration decl; |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(OperatorVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitOperator(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(OperatorVisitor<TArg, TResult> visitor) { |
||||||
|
return visit(visitor, null); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,32 @@ |
|||||||
|
/* |
||||||
|
* @(#)Terminal.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.terminals; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.AbstractSyntaxTree; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public abstract class Terminal extends AbstractSyntaxTree { |
||||||
|
|
||||||
|
public Terminal(String spelling, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
this.spelling = spelling; |
||||||
|
} |
||||||
|
|
||||||
|
public final String spelling; |
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
/* |
||||||
|
* @(#)AnyTypeDenoter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.types; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.TypeDenoterVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class AnyTypeDenoter extends TypeDenoter { |
||||||
|
|
||||||
|
public AnyTypeDenoter(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitAnyTypeDenoter(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object obj) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getSize() { |
||||||
|
return 0; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,56 @@ |
|||||||
|
/* |
||||||
|
* @(#)ArrayTypeDenoter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.types; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.terminals.IntegerLiteral; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.TypeDenoterVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class ArrayTypeDenoter extends TypeDenoter { |
||||||
|
|
||||||
|
public ArrayTypeDenoter(IntegerLiteral ilAST, TypeDenoter tAST, SourcePosition position) { |
||||||
|
super(position); |
||||||
|
IL = ilAST; |
||||||
|
T = tAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitArrayTypeDenoter(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object obj) { |
||||||
|
if (obj != null && obj instanceof ErrorTypeDenoter) { |
||||||
|
return true; |
||||||
|
} else if (obj != null && obj instanceof ArrayTypeDenoter) { |
||||||
|
return this.IL.spelling.compareTo(((ArrayTypeDenoter) obj).IL.spelling) == 0 |
||||||
|
&& this.T.equals(((ArrayTypeDenoter) obj).T); |
||||||
|
} else { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getSize() { |
||||||
|
return IL.getValue() * T.getSize(); |
||||||
|
} |
||||||
|
|
||||||
|
public final IntegerLiteral IL; |
||||||
|
public TypeDenoter T; |
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
/* |
||||||
|
* @(#)BoolTypeDenoter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.types; |
||||||
|
|
||||||
|
import triangle.abstractMachine.Machine; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.TypeDenoterVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class BoolTypeDenoter extends TypeDenoter { |
||||||
|
|
||||||
|
public BoolTypeDenoter(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitBoolTypeDenoter(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getSize() { |
||||||
|
return Machine.booleanSize; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object obj) { |
||||||
|
if ((obj != null) && (obj instanceof ErrorTypeDenoter)) { |
||||||
|
return true; |
||||||
|
} else { |
||||||
|
return ((obj != null) && (obj instanceof BoolTypeDenoter)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
/* |
||||||
|
* @(#)CharTypeDenoter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.types; |
||||||
|
|
||||||
|
import triangle.abstractMachine.Machine; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.TypeDenoterVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class CharTypeDenoter extends TypeDenoter { |
||||||
|
|
||||||
|
public CharTypeDenoter(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitCharTypeDenoter(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getSize() { |
||||||
|
return Machine.characterSize; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object obj) { |
||||||
|
if (obj != null && obj instanceof ErrorTypeDenoter) { |
||||||
|
return true; |
||||||
|
} else { |
||||||
|
return (obj != null && obj instanceof CharTypeDenoter); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
/* |
||||||
|
* @(#)ErrorTypeDenoter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.types; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.visitors.TypeDenoterVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class ErrorTypeDenoter extends TypeDenoter { |
||||||
|
|
||||||
|
public ErrorTypeDenoter(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitErrorTypeDenoter(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getSize() { |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object obj) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
/* |
||||||
|
* @(#)FieldTypeDenoter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.types; |
||||||
|
|
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public abstract class FieldTypeDenoter extends TypeDenoter { |
||||||
|
|
||||||
|
public FieldTypeDenoter(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
/* |
||||||
|
* @(#)IntTypeDenoter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.types; |
||||||
|
|
||||||
|
import triangle.abstractMachine.Machine; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.TypeDenoterVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class IntTypeDenoter extends TypeDenoter { |
||||||
|
|
||||||
|
public IntTypeDenoter(SourcePosition position) { |
||||||
|
super(position); |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitIntTypeDenoter(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getSize() { |
||||||
|
return Machine.integerSize; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object obj) { |
||||||
|
if (obj != null && obj instanceof ErrorTypeDenoter) { |
||||||
|
return true; |
||||||
|
} else { |
||||||
|
return (obj != null && obj instanceof IntTypeDenoter); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,57 @@ |
|||||||
|
/* |
||||||
|
* @(#)MultipleFieldTypeDenoter.java |
||||||
|
* |
||||||
|
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk |
||||||
|
* |
||||||
|
* Original release: |
||||||
|
* |
||||||
|
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown |
||||||
|
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland |
||||||
|
* and School of Computer and Math Sciences, The Robert Gordon University, |
||||||
|
* St. Andrew Street, Aberdeen AB25 1HG, Scotland. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* This software is provided free for educational use only. It may |
||||||
|
* not be used for commercial purposes without the prior written permission |
||||||
|
* of the authors. |
||||||
|
*/ |
||||||
|
|
||||||
|
package triangle.abstractSyntaxTrees.types; |
||||||
|
|
||||||
|
import triangle.abstractSyntaxTrees.terminals.Identifier; |
||||||
|
import triangle.abstractSyntaxTrees.visitors.TypeDenoterVisitor; |
||||||
|
import triangle.syntacticAnalyzer.SourcePosition; |
||||||
|
|
||||||
|
public class MultipleFieldTypeDenoter extends FieldTypeDenoter { |
||||||
|
|
||||||
|
public MultipleFieldTypeDenoter(Identifier iAST, TypeDenoter tAST, FieldTypeDenoter ftAST, |
||||||
|
SourcePosition position) { |
||||||
|
super(position); |
||||||
|
I = iAST; |
||||||
|
T = tAST; |
||||||
|
FT = ftAST; |
||||||
|
} |
||||||
|
|
||||||
|
public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) { |
||||||
|
return v.visitMultipleFieldTypeDenoter(this, arg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getSize() { |
||||||
|
return T.getSize() + FT.getSize(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object obj) { |
||||||
|
if (obj != null && obj instanceof MultipleFieldTypeDenoter) { |
||||||
|
MultipleFieldTypeDenoter ft = (MultipleFieldTypeDenoter) obj; |
||||||
|
return (this.I.spelling.compareTo(ft.I.spelling) == 0) && this.T.equals(ft.T) && this.FT.equals(ft.FT); |
||||||
|
} else { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public final Identifier I; |
||||||
|
public TypeDenoter T; |
||||||
|
public FieldTypeDenoter FT; |
||||||
|
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue