initial push

This commit is contained in:
simonkellet
2023-09-18 15:30:32 +01:00
parent fbd8c5bab0
commit 3655a949f3
202 changed files with 11941 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
/target/
/.classpath
/.editorconfig
/build/
+23
View File
@@ -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>
+21
View File
@@ -0,0 +1,21 @@
apply plugin: 'java'
apply plugin: 'application'
sourceCompatibility = 11
repositories {
mavenCentral()
}
dependencies {
implementation project(':Triangle.AbstractMachine')
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")
+18
View File
@@ -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,152 @@
/*
* @(#)Compiler.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle;
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;
/**
* 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 objectName = "obj.tam";
static boolean showTree = false;
static boolean folding = false;
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;
/**
* 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).
* @return true iff the source program is free of compile-time errors, otherwise
* false.
*/
static boolean compileProgram(String sourceName, String objectName, boolean showingAST, boolean showingTable) {
System.out.println("********** " + "Triangle Compiler (Java Version 2.1)" + " **********");
System.out.println("Syntactic Analysis ...");
SourceFile source = SourceFile.ofPath(sourceName);
if (source == null) {
System.out.println("Can't access source file " + sourceName);
System.exit(1);
}
scanner = new Scanner(source);
reporter = new ErrorReporter(false);
parser = new Parser(scanner, reporter);
checker = new Checker(reporter);
emitter = new Emitter(reporter);
encoder = new Encoder(emitter, reporter);
drawer = new Drawer();
// scanner.enableDebugging();
theAST = parser.parseProgram(); // 1st pass
if (reporter.getNumErrors() == 0) {
// if (showingAST) {
// drawer.draw(theAST);
// }
System.out.println("Contextual Analysis ...");
checker.check(theAST); // 2nd pass
if (showingAST) {
drawer.draw(theAST);
}
if (folding) {
theAST.visit(new ConstantFolder());
}
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.");
} else {
System.out.println("Compilation was unsuccessful.");
}
return successful;
}
/**
* Triangle compiler main program.
*
* @param args the only command-line argument to the program specifies the
* source filename.
*/
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Usage: tc filename [-o=outputfilename] [tree] [folding]");
System.exit(1);
}
parseArgs(args);
String sourceName = args[0];
var compiledOK = compileProgram(sourceName, objectName, showTree, false);
if (!showTree) {
System.exit(compiledOK ? 0 : 1);
}
}
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,61 @@
/*
* @(#)ErrorReporter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle;
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,46 @@
/*
* @(#)StdEnvironment.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle;
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,34 @@
/*
* @(#)AST.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees;
import triangle.codeGenerator.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,37 @@
/*
* @(#)Program.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees;
import triangle.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,32 @@
/*
* @(#)ActualParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,32 @@
/*
* @(#)ActualParameterSequence.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,33 @@
/*
* @(#)ConstActualParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,29 @@
/*
* @(#)EmptyActualParameterSequence.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,33 @@
/*
* @(#)FuncActualParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,35 @@
/*
* @(#)MultipleActualParameterSequence.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,33 @@
/*
* @(#)ProcActualParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,32 @@
/*
* @(#)SingleActualParameterSequence.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,33 @@
/*
* @(#)VarActualParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,35 @@
/*
* @(#)ArrayAggregate.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,35 @@
/*
* @(#)MultipleArrayAggregate.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,38 @@
/*
* @(#)MultipleRecordAggregate.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,36 @@
/*
* @(#)RecordAggregate.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,33 @@
/*
* @(#)SingleArrayAggregate.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,36 @@
/*
* @(#)SingleRecordAggregate.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,36 @@
/*
* @(#)AssignCommand.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,36 @@
/*
* @(#)CallCommand.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,32 @@
/*
* @(#)Command.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,29 @@
/*
* @(#)EmptyCommand.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,36 @@
/*
* @(#)IfCommand.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,35 @@
/*
* @(#)LetCommand.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,33 @@
/*
* @(#)SequentialCommand.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,35 @@
/*
* @(#)WhileCommand.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,39 @@
/*
* @(#)BinaryOperatorDeclaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,42 @@
/*
* @(#)ConstDeclaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,35 @@
/*
* @(#)Declaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,53 @@
/*
* @(#)FuncDeclaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,44 @@
/*
* @(#)ProcDeclaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,33 @@
/*
* @(#)SequentialDeclaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,37 @@
/*
* @(#)UnaryOperatorDeclaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,41 @@
/*
* @(#)VarDeclaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,33 @@
/*
* @(#)ArrayExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,37 @@
/*
* @(#)BinaryExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,36 @@
/*
* @(#)CallExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,43 @@
/*
* @(#)CharacterExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,29 @@
/*
* @(#)EmptyExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,44 @@
/*
* @(#)Expression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,36 @@
/*
* @(#)IfExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,43 @@
/*
* @(#)IntegerExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,35 @@
/*
* @(#)LetExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,33 @@
/*
* @(#)RecordExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,35 @@
/*
* @(#)UnaryExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,33 @@
/*
* @(#)VnameExpression.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,51 @@
/*
* @(#)ConstFormalParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,34 @@
/*
* @(#)EmptyFormalParameterSequence.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,35 @@
/*
* @(#)FormalParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,35 @@
/*
* @(#)FormalParameterSequence.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,59 @@
/*
* @(#)FuncFormalParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,45 @@
/*
* @(#)MultipleFormalParameterSequence.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,51 @@
/*
* @(#)ProcFormalParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,42 @@
/*
* @(#)SingleFormalParameterSequence.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,51 @@
/*
* @(#)ValFormalParameter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,37 @@
/*
* @(#)CharacterLiteral.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,40 @@
/*
* @(#)Identifier.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,37 @@
/*
* @(#)IntegerLiteral.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,37 @@
/*
* @(#)Operator.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,28 @@
/*
* @(#)Terminal.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,39 @@
/*
* @(#)AnyTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,52 @@
/*
* @(#)ArrayTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,44 @@
/*
* @(#)BoolTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,44 @@
/*
* @(#)CharTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,39 @@
/*
* @(#)ErrorTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,24 @@
/*
* @(#)FieldTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.types;
import triangle.syntacticAnalyzer.SourcePosition;
public abstract class FieldTypeDenoter extends TypeDenoter {
public FieldTypeDenoter(SourcePosition position) {
super(position);
}
}
@@ -0,0 +1,44 @@
/*
* @(#)IntTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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,53 @@
/*
* @(#)MultipleFieldTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.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;
}
@@ -0,0 +1,48 @@
/*
* @(#)RecordTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.types;
import triangle.abstractSyntaxTrees.visitors.TypeDenoterVisitor;
import triangle.syntacticAnalyzer.SourcePosition;
public class RecordTypeDenoter extends TypeDenoter {
public RecordTypeDenoter(FieldTypeDenoter ftAST, SourcePosition position) {
super(position);
FT = ftAST;
}
public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) {
return v.visitRecordTypeDenoter(this, arg);
}
@Override
public int getSize() {
return FT.getSize();
}
@Override
public boolean equals(Object obj) {
if (obj != null && obj instanceof ErrorTypeDenoter) {
return true;
} else if (obj != null && obj instanceof RecordTypeDenoter) {
return this.FT.equals(((RecordTypeDenoter) obj).FT);
} else {
return false;
}
}
public FieldTypeDenoter FT;
}
@@ -0,0 +1,43 @@
/*
* @(#)SimpleTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.types;
import triangle.abstractSyntaxTrees.terminals.Identifier;
import triangle.abstractSyntaxTrees.visitors.TypeDenoterVisitor;
import triangle.syntacticAnalyzer.SourcePosition;
public class SimpleTypeDenoter extends TypeDenoter {
public SimpleTypeDenoter(Identifier iAST, SourcePosition position) {
super(position);
I = iAST;
}
public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) {
return v.visitSimpleTypeDenoter(this, arg);
}
@Override
public int getSize() {
return 0;
}
@Override
public boolean equals(Object obj) {
return false; // should not happen
}
public final Identifier I;
}
@@ -0,0 +1,50 @@
/*
* @(#)SingleFieldTypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.types;
import triangle.abstractSyntaxTrees.terminals.Identifier;
import triangle.abstractSyntaxTrees.visitors.TypeDenoterVisitor;
import triangle.syntacticAnalyzer.SourcePosition;
public class SingleFieldTypeDenoter extends FieldTypeDenoter {
public SingleFieldTypeDenoter(Identifier iAST, TypeDenoter tAST, SourcePosition position) {
super(position);
I = iAST;
T = tAST;
}
public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> v, TArg arg) {
return v.visitSingleFieldTypeDenoter(this, arg);
}
@Override
public int getSize() {
return T.getSize();
}
@Override
public boolean equals(Object obj) {
if (obj != null && obj instanceof SingleFieldTypeDenoter) {
SingleFieldTypeDenoter ft = (SingleFieldTypeDenoter) obj;
return (this.I.spelling.compareTo(ft.I.spelling) == 0) && this.T.equals(ft.T);
} else {
return false;
}
}
public final Identifier I;
public TypeDenoter T;
}
@@ -0,0 +1,36 @@
/*
* @(#)TypeDeclaration.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.types;
import triangle.abstractSyntaxTrees.declarations.Declaration;
import triangle.abstractSyntaxTrees.terminals.Identifier;
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor;
import triangle.syntacticAnalyzer.SourcePosition;
public class TypeDeclaration extends Declaration {
public TypeDeclaration(Identifier iAST, TypeDenoter tAST, SourcePosition position) {
super(position);
I = iAST;
T = tAST;
}
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
return v.visitTypeDeclaration(this, arg);
}
public final Identifier I;
public TypeDenoter T;
}
@@ -0,0 +1,37 @@
/*
* @(#)TypeDenoter.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.types;
import triangle.abstractSyntaxTrees.AbstractSyntaxTree;
import triangle.abstractSyntaxTrees.visitors.TypeDenoterVisitor;
import triangle.syntacticAnalyzer.SourcePosition;
public abstract class TypeDenoter extends AbstractSyntaxTree {
public TypeDenoter(SourcePosition position) {
super(position);
}
@Override
public abstract boolean equals(Object obj);
public abstract <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> visitor, TArg arg);
public <TArg, TResult> TResult visit(TypeDenoterVisitor<TArg, TResult> visitor) {
return visit(visitor, null);
}
public abstract int getSize();
}
@@ -0,0 +1,15 @@
package triangle.abstractSyntaxTrees.visitors;
import triangle.abstractSyntaxTrees.actuals.EmptyActualParameterSequence;
import triangle.abstractSyntaxTrees.actuals.MultipleActualParameterSequence;
import triangle.abstractSyntaxTrees.actuals.SingleActualParameterSequence;
public interface ActualParameterSequenceVisitor<TArg, TResult> {
TResult visitEmptyActualParameterSequence(EmptyActualParameterSequence ast, TArg arg);
TResult visitMultipleActualParameterSequence(MultipleActualParameterSequence ast, TArg arg);
TResult visitSingleActualParameterSequence(SingleActualParameterSequence ast, TArg arg);
}
@@ -0,0 +1,18 @@
package triangle.abstractSyntaxTrees.visitors;
import triangle.abstractSyntaxTrees.actuals.ConstActualParameter;
import triangle.abstractSyntaxTrees.actuals.FuncActualParameter;
import triangle.abstractSyntaxTrees.actuals.ProcActualParameter;
import triangle.abstractSyntaxTrees.actuals.VarActualParameter;
public interface ActualParameterVisitor<TArg, TResult> {
TResult visitConstActualParameter(ConstActualParameter ast, TArg arg);
TResult visitFuncActualParameter(FuncActualParameter ast, TArg arg);
TResult visitProcActualParameter(ProcActualParameter ast, TArg arg);
TResult visitVarActualParameter(VarActualParameter ast, TArg arg);
}
@@ -0,0 +1,12 @@
package triangle.abstractSyntaxTrees.visitors;
import triangle.abstractSyntaxTrees.aggregates.MultipleArrayAggregate;
import triangle.abstractSyntaxTrees.aggregates.SingleArrayAggregate;
public interface ArrayAggregateVisitor<TArg, TResult> {
TResult visitMultipleArrayAggregate(MultipleArrayAggregate ast, TArg arg);
TResult visitSingleArrayAggregate(SingleArrayAggregate ast, TArg arg);
}
@@ -0,0 +1,27 @@
package triangle.abstractSyntaxTrees.visitors;
import triangle.abstractSyntaxTrees.commands.AssignCommand;
import triangle.abstractSyntaxTrees.commands.CallCommand;
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
import triangle.abstractSyntaxTrees.commands.IfCommand;
import triangle.abstractSyntaxTrees.commands.LetCommand;
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
import triangle.abstractSyntaxTrees.commands.WhileCommand;
public interface CommandVisitor<TArg, TResult> {
TResult visitAssignCommand(AssignCommand ast, TArg arg);
TResult visitCallCommand(CallCommand ast, TArg arg);
TResult visitEmptyCommand(EmptyCommand ast, TArg arg);
TResult visitIfCommand(IfCommand ast, TArg arg);
TResult visitLetCommand(LetCommand ast, TArg arg);
TResult visitSequentialCommand(SequentialCommand ast, TArg arg);
TResult visitWhileCommand(WhileCommand ast, TArg arg);
}
@@ -0,0 +1,30 @@
package triangle.abstractSyntaxTrees.visitors;
import triangle.abstractSyntaxTrees.declarations.BinaryOperatorDeclaration;
import triangle.abstractSyntaxTrees.declarations.ConstDeclaration;
import triangle.abstractSyntaxTrees.declarations.FuncDeclaration;
import triangle.abstractSyntaxTrees.declarations.ProcDeclaration;
import triangle.abstractSyntaxTrees.declarations.SequentialDeclaration;
import triangle.abstractSyntaxTrees.declarations.UnaryOperatorDeclaration;
import triangle.abstractSyntaxTrees.declarations.VarDeclaration;
import triangle.abstractSyntaxTrees.types.TypeDeclaration;
public interface DeclarationVisitor<TArg, TResult> extends FormalParameterVisitor<TArg, TResult> {
TResult visitBinaryOperatorDeclaration(BinaryOperatorDeclaration ast, TArg arg);
TResult visitConstDeclaration(ConstDeclaration ast, TArg arg);
TResult visitFuncDeclaration(FuncDeclaration ast, TArg arg);
TResult visitProcDeclaration(ProcDeclaration ast, TArg arg);
TResult visitSequentialDeclaration(SequentialDeclaration ast, TArg arg);
TResult visitTypeDeclaration(TypeDeclaration ast, TArg arg);
TResult visitUnaryOperatorDeclaration(UnaryOperatorDeclaration ast, TArg arg);
TResult visitVarDeclaration(VarDeclaration ast, TArg arg);
}
@@ -0,0 +1,39 @@
package triangle.abstractSyntaxTrees.visitors;
import triangle.abstractSyntaxTrees.expressions.ArrayExpression;
import triangle.abstractSyntaxTrees.expressions.BinaryExpression;
import triangle.abstractSyntaxTrees.expressions.CallExpression;
import triangle.abstractSyntaxTrees.expressions.CharacterExpression;
import triangle.abstractSyntaxTrees.expressions.EmptyExpression;
import triangle.abstractSyntaxTrees.expressions.IfExpression;
import triangle.abstractSyntaxTrees.expressions.IntegerExpression;
import triangle.abstractSyntaxTrees.expressions.LetExpression;
import triangle.abstractSyntaxTrees.expressions.RecordExpression;
import triangle.abstractSyntaxTrees.expressions.UnaryExpression;
import triangle.abstractSyntaxTrees.expressions.VnameExpression;
public interface ExpressionVisitor<TArg, TResult> {
TResult visitArrayExpression(ArrayExpression ast, TArg arg);
TResult visitBinaryExpression(BinaryExpression ast, TArg arg);
TResult visitCallExpression(CallExpression ast, TArg arg);
TResult visitCharacterExpression(CharacterExpression ast, TArg arg);
TResult visitEmptyExpression(EmptyExpression ast, TArg arg);
TResult visitIfExpression(IfExpression ast, TArg arg);
TResult visitIntegerExpression(IntegerExpression ast, TArg arg);
TResult visitLetExpression(LetExpression ast, TArg arg);
TResult visitRecordExpression(RecordExpression ast, TArg arg);
TResult visitUnaryExpression(UnaryExpression ast, TArg arg);
TResult visitVnameExpression(VnameExpression ast, TArg arg);
}
@@ -0,0 +1,12 @@
package triangle.abstractSyntaxTrees.visitors;
import triangle.abstractSyntaxTrees.types.MultipleFieldTypeDenoter;
import triangle.abstractSyntaxTrees.types.SingleFieldTypeDenoter;
public interface FieldTypeDenoterVisitor<TArg, TResult> {
TResult visitMultipleFieldTypeDenoter(MultipleFieldTypeDenoter ast, TArg arg);
TResult visitSingleFieldTypeDenoter(SingleFieldTypeDenoter ast, TArg arg);
}
@@ -0,0 +1,15 @@
package triangle.abstractSyntaxTrees.visitors;
import triangle.abstractSyntaxTrees.formals.EmptyFormalParameterSequence;
import triangle.abstractSyntaxTrees.formals.MultipleFormalParameterSequence;
import triangle.abstractSyntaxTrees.formals.SingleFormalParameterSequence;
public interface FormalParameterSequenceVisitor<TArg, TResult> {
TResult visitEmptyFormalParameterSequence(EmptyFormalParameterSequence ast, TArg arg);
TResult visitMultipleFormalParameterSequence(MultipleFormalParameterSequence ast, TArg arg);
TResult visitSingleFormalParameterSequence(SingleFormalParameterSequence ast, TArg arg);
}
@@ -0,0 +1,18 @@
package triangle.abstractSyntaxTrees.visitors;
import triangle.abstractSyntaxTrees.formals.ConstFormalParameter;
import triangle.abstractSyntaxTrees.formals.FuncFormalParameter;
import triangle.abstractSyntaxTrees.formals.ProcFormalParameter;
import triangle.abstractSyntaxTrees.formals.VarFormalParameter;
public interface FormalParameterVisitor<TArg, TResult> {
TResult visitConstFormalParameter(ConstFormalParameter ast, TArg arg);
TResult visitFuncFormalParameter(FuncFormalParameter ast, TArg arg);
TResult visitProcFormalParameter(ProcFormalParameter ast, TArg arg);
TResult visitVarFormalParameter(VarFormalParameter ast, TArg arg);
}
@@ -0,0 +1,9 @@
package triangle.abstractSyntaxTrees.visitors;
import triangle.abstractSyntaxTrees.terminals.Identifier;
public interface IdentifierVisitor<TArg, TResult> {
TResult visitIdentifier(Identifier ast, TArg arg);
}
@@ -0,0 +1,12 @@
package triangle.abstractSyntaxTrees.visitors;
import triangle.abstractSyntaxTrees.terminals.CharacterLiteral;
import triangle.abstractSyntaxTrees.terminals.IntegerLiteral;
public interface LiteralVisitor<TArg, TResult> {
TResult visitCharacterLiteral(CharacterLiteral ast, TArg arg);
TResult visitIntegerLiteral(IntegerLiteral ast, TArg arg);
}
@@ -0,0 +1,9 @@
package triangle.abstractSyntaxTrees.visitors;
import triangle.abstractSyntaxTrees.terminals.Operator;
public interface OperatorVisitor<TArg, TResult> {
TResult visitOperator(Operator ast, TArg arg);
}
@@ -0,0 +1,9 @@
package triangle.abstractSyntaxTrees.visitors;
import triangle.abstractSyntaxTrees.Program;
public interface ProgramVisitor<TArg, TResult> {
TResult visitProgram(Program ast, TArg arg);
}
@@ -0,0 +1,12 @@
package triangle.abstractSyntaxTrees.visitors;
import triangle.abstractSyntaxTrees.aggregates.MultipleRecordAggregate;
import triangle.abstractSyntaxTrees.aggregates.SingleRecordAggregate;
public interface RecordAggregateVisitor<TArg, TResult> {
TResult visitMultipleRecordAggregate(MultipleRecordAggregate ast, TArg arg);
TResult visitSingleRecordAggregate(SingleRecordAggregate ast, TArg arg);
}
@@ -0,0 +1,30 @@
package triangle.abstractSyntaxTrees.visitors;
import triangle.abstractSyntaxTrees.types.AnyTypeDenoter;
import triangle.abstractSyntaxTrees.types.ArrayTypeDenoter;
import triangle.abstractSyntaxTrees.types.BoolTypeDenoter;
import triangle.abstractSyntaxTrees.types.CharTypeDenoter;
import triangle.abstractSyntaxTrees.types.ErrorTypeDenoter;
import triangle.abstractSyntaxTrees.types.IntTypeDenoter;
import triangle.abstractSyntaxTrees.types.RecordTypeDenoter;
import triangle.abstractSyntaxTrees.types.SimpleTypeDenoter;
public interface TypeDenoterVisitor<TArg, TResult> extends FieldTypeDenoterVisitor<TArg, TResult> {
TResult visitAnyTypeDenoter(AnyTypeDenoter ast, TArg arg);
TResult visitArrayTypeDenoter(ArrayTypeDenoter ast, TArg arg);
TResult visitBoolTypeDenoter(BoolTypeDenoter ast, TArg arg);
TResult visitCharTypeDenoter(CharTypeDenoter ast, TArg arg);
TResult visitErrorTypeDenoter(ErrorTypeDenoter ast, TArg arg);
TResult visitSimpleTypeDenoter(SimpleTypeDenoter ast, TArg arg);
TResult visitIntTypeDenoter(IntTypeDenoter ast, TArg arg);
TResult visitRecordTypeDenoter(RecordTypeDenoter ast, TArg arg);
}
@@ -0,0 +1,15 @@
package triangle.abstractSyntaxTrees.visitors;
import triangle.abstractSyntaxTrees.vnames.DotVname;
import triangle.abstractSyntaxTrees.vnames.SimpleVname;
import triangle.abstractSyntaxTrees.vnames.SubscriptVname;
public interface VnameVisitor<TArg, TResult> {
TResult visitDotVname(DotVname ast, TArg arg);
TResult visitSimpleVname(SimpleVname ast, TArg arg);
TResult visitSubscriptVname(SubscriptVname ast, TArg arg);
}
@@ -0,0 +1,35 @@
/*
* @(#)DotVname.java 2.1 2003/10/07
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractSyntaxTrees.vnames;
import triangle.abstractSyntaxTrees.terminals.Identifier;
import triangle.abstractSyntaxTrees.visitors.VnameVisitor;
import triangle.syntacticAnalyzer.SourcePosition;
public class DotVname extends Vname {
public DotVname(Vname vAST, Identifier iAST, SourcePosition position) {
super(position);
V = vAST;
I = iAST;
}
public <TArg, TResult> TResult visit(VnameVisitor<TArg, TResult> v, TArg arg) {
return v.visitDotVname(this, arg);
}
public final Identifier I;
public final Vname V;
}

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