Archived
Renamed packages to match Java guidelines.
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* @(#)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.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";
|
||||
|
||||
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 (not currently implemented).
|
||||
* @param showingTable true iff the object description details are to be
|
||||
* displayed during code generation (not currently
|
||||
* implemented).
|
||||
* @return true iff the source program is free of compile-time errors, otherwise
|
||||
* false.
|
||||
*/
|
||||
static boolean compileProgram(String sourceName, String objectName, boolean showingAST, boolean showingTable) {
|
||||
|
||||
System.out.println("********** " + "Triangle Compiler (Java Version 2.1)" + " **********");
|
||||
|
||||
System.out.println("Syntactic Analysis ...");
|
||||
SourceFile source = SourceFile.ofPath(sourceName);
|
||||
|
||||
if (source == null) {
|
||||
System.out.println("Can't access source file " + sourceName);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
scanner = new Scanner(source);
|
||||
reporter = new ErrorReporter();
|
||||
parser = new Parser(scanner, reporter);
|
||||
checker = new Checker(reporter);
|
||||
encoder = new Encoder(emitter, reporter);
|
||||
emitter = new Emitter(reporter);
|
||||
drawer = new Drawer();
|
||||
|
||||
// scanner.enableDebugging();
|
||||
theAST = parser.parseProgram(); // 1st pass
|
||||
if (reporter.numErrors == 0) {
|
||||
// if (showingAST) {
|
||||
// drawer.draw(theAST);
|
||||
// }
|
||||
System.out.println("Contextual Analysis ...");
|
||||
checker.check(theAST); // 2nd pass
|
||||
if (showingAST) {
|
||||
drawer.draw(theAST);
|
||||
}
|
||||
if (reporter.numErrors == 0) {
|
||||
System.out.println("Code Generation ...");
|
||||
encoder.encodeRun(theAST, showingTable); // 3rd pass
|
||||
}
|
||||
}
|
||||
|
||||
boolean successful = (reporter.numErrors == 0);
|
||||
if (successful) {
|
||||
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");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
String sourceName = args[0];
|
||||
var compiledOK = compileProgram(sourceName, objectName, false, false);
|
||||
|
||||
System.exit(compiledOK ? 0 : 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* @(#)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 {
|
||||
|
||||
int numErrors;
|
||||
|
||||
ErrorReporter() {
|
||||
numErrors = 0;
|
||||
}
|
||||
|
||||
public void reportError(String message, String tokenName, SourcePosition pos) {
|
||||
System.out.print("ERROR: ");
|
||||
|
||||
for (int p = 0; p < message.length(); p++)
|
||||
if (message.charAt(p) == '%')
|
||||
System.out.print(tokenName);
|
||||
else
|
||||
System.out.print(message.charAt(p));
|
||||
System.out.println(" " + pos.start + ".." + pos.finish);
|
||||
numErrors++;
|
||||
}
|
||||
|
||||
public void reportRestriction(String message) {
|
||||
System.out.println("RESTRICTION: " + message);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
+32
@@ -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);
|
||||
}
|
||||
}
|
||||
+32
@@ -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 <TResult> TResult visit(ActualParameterSequenceVisitor<Void, TResult> v) {
|
||||
return visit(v, null);
|
||||
}
|
||||
}
|
||||
+33
@@ -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 final Expression E;
|
||||
}
|
||||
+29
@@ -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);
|
||||
}
|
||||
}
|
||||
+33
@@ -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;
|
||||
}
|
||||
+35
@@ -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;
|
||||
}
|
||||
+33
@@ -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;
|
||||
}
|
||||
+32
@@ -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;
|
||||
}
|
||||
+33
@@ -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;
|
||||
}
|
||||
+35
@@ -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);
|
||||
}
|
||||
}
|
||||
+35
@@ -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 final Expression E;
|
||||
public final ArrayAggregate AA;
|
||||
}
|
||||
+38
@@ -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 final Expression E;
|
||||
public final RecordAggregate RA;
|
||||
}
|
||||
+36
@@ -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);
|
||||
}
|
||||
}
|
||||
+33
@@ -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 final Expression E;
|
||||
}
|
||||
+36
@@ -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 final Expression E;
|
||||
}
|
||||
+36
@@ -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 final Expression E;
|
||||
}
|
||||
+36
@@ -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);
|
||||
}
|
||||
}
|
||||
+29
@@ -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 final 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;
|
||||
}
|
||||
+33
@@ -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;
|
||||
}
|
||||
+35
@@ -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 final Expression E;
|
||||
public final Command C;
|
||||
}
|
||||
+39
@@ -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;
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* @(#)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.visitors.DeclarationVisitor;
|
||||
import triangle.syntacticAnalyzer.SourcePosition;
|
||||
|
||||
public class ConstDeclaration extends Declaration {
|
||||
|
||||
public ConstDeclaration(Identifier iAST, Expression eAST, SourcePosition position) {
|
||||
super(position);
|
||||
I = iAST;
|
||||
E = eAST;
|
||||
}
|
||||
|
||||
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
|
||||
return v.visitConstDeclaration(this, arg);
|
||||
}
|
||||
|
||||
public final Identifier I;
|
||||
public final Expression E;
|
||||
}
|
||||
+35
@@ -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);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* @(#)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 {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public final Identifier I;
|
||||
public final FormalParameterSequence FPS;
|
||||
public TypeDenoter T;
|
||||
public final Expression E;
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* @(#)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 {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public final Identifier I;
|
||||
public final FormalParameterSequence FPS;
|
||||
public final Command C;
|
||||
}
|
||||
+33
@@ -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;
|
||||
}
|
||||
+37
@@ -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;
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* @(#)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 {
|
||||
|
||||
public VarDeclaration(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.visitVarDeclaration(this, arg);
|
||||
}
|
||||
|
||||
public final Identifier I;
|
||||
public TypeDenoter T;
|
||||
}
|
||||
+33
@@ -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;
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* @(#)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 final Expression E1, E2;
|
||||
public final Operator O;
|
||||
}
|
||||
+36
@@ -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;
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* @(#)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;
|
||||
}
|
||||
+29
@@ -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);
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* @(#)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 abstract <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> visitor, TArg arg);
|
||||
|
||||
public <TArg, TResult> TResult visit(ExpressionVisitor<TArg, TResult> visitor) {
|
||||
return visit(visitor, null);
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* @(#)IfExpression.java 2.1 2003/10/07
|
||||
*
|
||||
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
|
||||
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
|
||||
* and School of Computer and Math Sciences, The Robert Gordon University,
|
||||
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is provided free for educational use only. It may
|
||||
* not be used for commercial purposes without the prior written permission
|
||||
* of the authors.
|
||||
*/
|
||||
|
||||
package triangle.abstractSyntaxTrees.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 final Expression E1, E2, E3;
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* @(#)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;
|
||||
}
|
||||
+35
@@ -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 final Expression E;
|
||||
}
|
||||
+33
@@ -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;
|
||||
}
|
||||
+35
@@ -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 final Expression E;
|
||||
public final Operator O;
|
||||
}
|
||||
+33
@@ -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;
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* @(#)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.terminals.Identifier;
|
||||
import triangle.abstractSyntaxTrees.types.TypeDenoter;
|
||||
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor;
|
||||
import triangle.syntacticAnalyzer.SourcePosition;
|
||||
|
||||
public class ConstFormalParameter extends FormalParameter {
|
||||
|
||||
public ConstFormalParameter(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.visitConstFormalParameter(this, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object fpAST) {
|
||||
if (fpAST instanceof ConstFormalParameter) {
|
||||
var cfpAST = (ConstFormalParameter) fpAST;
|
||||
return T.equals(cfpAST.T);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public final Identifier I;
|
||||
public TypeDenoter T;
|
||||
}
|
||||
+34
@@ -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);
|
||||
}
|
||||
}
|
||||
+35
@@ -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);
|
||||
}
|
||||
}
|
||||
+35
@@ -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);
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* @(#)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.terminals.Identifier;
|
||||
import triangle.abstractSyntaxTrees.types.TypeDenoter;
|
||||
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor;
|
||||
import triangle.syntacticAnalyzer.SourcePosition;
|
||||
|
||||
public class FuncFormalParameter extends FormalParameter {
|
||||
|
||||
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 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;
|
||||
}
|
||||
+45
@@ -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;
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* @(#)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.terminals.Identifier;
|
||||
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor;
|
||||
import triangle.syntacticAnalyzer.SourcePosition;
|
||||
|
||||
public class ProcFormalParameter extends FormalParameter {
|
||||
|
||||
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 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;
|
||||
}
|
||||
+42
@@ -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;
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* @(#)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.terminals.Identifier;
|
||||
import triangle.abstractSyntaxTrees.types.TypeDenoter;
|
||||
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor;
|
||||
import triangle.syntacticAnalyzer.SourcePosition;
|
||||
|
||||
public class VarFormalParameter extends FormalParameter {
|
||||
|
||||
public VarFormalParameter(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.visitVarFormalParameter(this, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object fpAST) {
|
||||
if (fpAST instanceof VarFormalParameter) {
|
||||
VarFormalParameter vfpAST = (VarFormalParameter) fpAST;
|
||||
return T.equals(vfpAST.T);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public final Identifier I;
|
||||
public TypeDenoter T;
|
||||
}
|
||||
+37
@@ -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);
|
||||
}
|
||||
}
|
||||
+40
@@ -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);
|
||||
}
|
||||
}
|
||||
+37
@@ -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;
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* @(#)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;
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* @(#)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;
|
||||
}
|
||||
}
|
||||
|
||||
public final IntegerLiteral IL;
|
||||
public TypeDenoter T;
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* @(#)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.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 boolean equals(Object obj) {
|
||||
if ((obj != null) && (obj instanceof ErrorTypeDenoter)) {
|
||||
return true;
|
||||
} else {
|
||||
return ((obj != null) && (obj instanceof BoolTypeDenoter));
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* @(#)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.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 boolean equals(Object obj) {
|
||||
if (obj != null && obj instanceof ErrorTypeDenoter) {
|
||||
return true;
|
||||
} else {
|
||||
return (obj != null && obj instanceof CharTypeDenoter);
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* @(#)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 boolean equals(Object obj) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+24
@@ -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);
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* @(#)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.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 boolean equals(Object obj) {
|
||||
if (obj != null && obj instanceof ErrorTypeDenoter) {
|
||||
return true;
|
||||
} else {
|
||||
return (obj != null && obj instanceof IntTypeDenoter);
|
||||
}
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* @(#)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 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;
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* @(#)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 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;
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* @(#)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 boolean equals(Object obj) {
|
||||
return false; // should not happen
|
||||
}
|
||||
|
||||
public final Identifier I;
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* @(#)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 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;
|
||||
}
|
||||
+36
@@ -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,35 @@
|
||||
/*
|
||||
* @(#)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);
|
||||
}
|
||||
}
|
||||
+15
@@ -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);
|
||||
|
||||
}
|
||||
+18
@@ -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);
|
||||
|
||||
}
|
||||
+12
@@ -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);
|
||||
|
||||
}
|
||||
+27
@@ -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);
|
||||
|
||||
}
|
||||
+30
@@ -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);
|
||||
|
||||
}
|
||||
+39
@@ -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);
|
||||
|
||||
}
|
||||
+12
@@ -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);
|
||||
|
||||
}
|
||||
+15
@@ -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);
|
||||
|
||||
}
|
||||
+18
@@ -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);
|
||||
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package triangle.abstractSyntaxTrees.visitors;
|
||||
|
||||
import triangle.abstractSyntaxTrees.terminals.Identifier;
|
||||
|
||||
public interface IdentifierVisitor<TArg, TResult> {
|
||||
|
||||
TResult visitIdentifier(Identifier ast, TArg arg);
|
||||
|
||||
}
|
||||
+12
@@ -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);
|
||||
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package triangle.abstractSyntaxTrees.visitors;
|
||||
|
||||
import triangle.abstractSyntaxTrees.terminals.Operator;
|
||||
|
||||
public interface OperatorVisitor<TArg, TResult> {
|
||||
|
||||
TResult visitOperator(Operator ast, TArg arg);
|
||||
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package triangle.abstractSyntaxTrees.visitors;
|
||||
|
||||
import triangle.abstractSyntaxTrees.Program;
|
||||
|
||||
public interface ProgramVisitor<TArg, TResult> {
|
||||
|
||||
TResult visitProgram(Program ast, TArg arg);
|
||||
|
||||
}
|
||||
+12
@@ -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);
|
||||
|
||||
}
|
||||
+30
@@ -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);
|
||||
|
||||
}
|
||||
+15
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* @(#)SimpleVname.java 2.1 2003/10/07
|
||||
*
|
||||
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
|
||||
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
|
||||
* and School of Computer and Math Sciences, The Robert Gordon University,
|
||||
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is provided free for educational use only. It may
|
||||
* not be used for commercial purposes without the prior written permission
|
||||
* of the authors.
|
||||
*/
|
||||
|
||||
package triangle.abstractSyntaxTrees.vnames;
|
||||
|
||||
import triangle.abstractSyntaxTrees.terminals.Identifier;
|
||||
import triangle.abstractSyntaxTrees.visitors.VnameVisitor;
|
||||
import triangle.syntacticAnalyzer.SourcePosition;
|
||||
|
||||
public class SimpleVname extends Vname {
|
||||
|
||||
public SimpleVname(Identifier iAST, SourcePosition position) {
|
||||
super(position);
|
||||
I = iAST;
|
||||
}
|
||||
|
||||
public <TArg, TResult> TResult visit(VnameVisitor<TArg, TResult> v, TArg arg) {
|
||||
return v.visitSimpleVname(this, arg);
|
||||
}
|
||||
|
||||
public final Identifier I;
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* @(#)SubscriptVname.java 2.1 2003/10/07
|
||||
*
|
||||
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
|
||||
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
|
||||
* and School of Computer and Math Sciences, The Robert Gordon University,
|
||||
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is provided free for educational use only. It may
|
||||
* not be used for commercial purposes without the prior written permission
|
||||
* of the authors.
|
||||
*/
|
||||
|
||||
package triangle.abstractSyntaxTrees.vnames;
|
||||
|
||||
import triangle.abstractSyntaxTrees.expressions.Expression;
|
||||
import triangle.abstractSyntaxTrees.visitors.VnameVisitor;
|
||||
import triangle.syntacticAnalyzer.SourcePosition;
|
||||
|
||||
public class SubscriptVname extends Vname {
|
||||
|
||||
public SubscriptVname(Vname vAST, Expression eAST, SourcePosition position) {
|
||||
super(position);
|
||||
V = vAST;
|
||||
E = eAST;
|
||||
}
|
||||
|
||||
public <TArg, TResult> TResult visit(VnameVisitor<TArg, TResult> v, TArg arg) {
|
||||
return v.visitSubscriptVname(this, arg);
|
||||
}
|
||||
|
||||
public final Expression E;
|
||||
public final Vname V;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* @(#)Vname.java 2.1 2003/10/07
|
||||
*
|
||||
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
|
||||
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
|
||||
* and School of Computer and Math Sciences, The Robert Gordon University,
|
||||
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is provided free for educational use only. It may
|
||||
* not be used for commercial purposes without the prior written permission
|
||||
* of the authors.
|
||||
*/
|
||||
|
||||
package triangle.abstractSyntaxTrees.vnames;
|
||||
|
||||
import triangle.abstractSyntaxTrees.AbstractSyntaxTree;
|
||||
import triangle.abstractSyntaxTrees.types.TypeDenoter;
|
||||
import triangle.abstractSyntaxTrees.visitors.VnameVisitor;
|
||||
import triangle.syntacticAnalyzer.SourcePosition;
|
||||
|
||||
public abstract class Vname extends AbstractSyntaxTree {
|
||||
|
||||
public Vname(SourcePosition position) {
|
||||
super(position);
|
||||
variable = false;
|
||||
type = null;
|
||||
}
|
||||
|
||||
public boolean variable, indexed;
|
||||
public int offset;
|
||||
public TypeDenoter type;
|
||||
|
||||
public abstract <TArg, TResult> TResult visit(VnameVisitor<TArg, TResult> visitor, TArg arg);
|
||||
|
||||
public <TArg, TResult> TResult visit(VnameVisitor<TArg, TResult> visitor) {
|
||||
return visit(visitor, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package triangle.codeGenerator;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import triangle.ErrorReporter;
|
||||
import triangle.abstractMachine.Instruction;
|
||||
import triangle.abstractMachine.Machine;
|
||||
import triangle.abstractMachine.OpCode;
|
||||
import triangle.abstractMachine.Primitive;
|
||||
import triangle.abstractMachine.Register;
|
||||
|
||||
public class Emitter {
|
||||
|
||||
// OBJECT CODE
|
||||
|
||||
// Implementation notes:
|
||||
// Object code is generated directly into the TAM Code Store, starting at
|
||||
// CB.
|
||||
// The address of the next instruction is held in nextInstrAddr.
|
||||
|
||||
ErrorReporter errorReporter;
|
||||
|
||||
int nextInstrAddr;
|
||||
|
||||
public Emitter(ErrorReporter errorReporter) {
|
||||
this.errorReporter = errorReporter;
|
||||
nextInstrAddr = Machine.CB;
|
||||
}
|
||||
|
||||
public int getNextInstrAddr() {
|
||||
return nextInstrAddr;
|
||||
}
|
||||
|
||||
public int emit(OpCode op) {
|
||||
return emit(op, 0, Register.CB, 0);
|
||||
}
|
||||
|
||||
public int emit(OpCode op, int operand) {
|
||||
return emit(op, 0, Register.CB, operand);
|
||||
}
|
||||
|
||||
public int emit(OpCode op, int length, int operand) {
|
||||
return emit(op, length, Register.CB, operand);
|
||||
}
|
||||
|
||||
public int emit(OpCode op, Register staticRegister, Register register, int operand) {
|
||||
return emit(op, staticRegister.ordinal(), register, operand);
|
||||
}
|
||||
|
||||
public int emit(OpCode op, Register register, int operand) {
|
||||
return emit(op, 0, register, operand);
|
||||
}
|
||||
|
||||
public int emit(OpCode op, Register register) {
|
||||
return emit(op, 0, register, 0);
|
||||
}
|
||||
|
||||
public int emit(OpCode op, int length, Register register) {
|
||||
return emit(op, length, register, 0);
|
||||
}
|
||||
|
||||
public int emit(OpCode op, Register register, Primitive primitive) {
|
||||
return emit(op, 0, register, primitive.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an instruction, with the given fields, to the object code.
|
||||
*
|
||||
* @param op the opcode
|
||||
* @param length the length field
|
||||
* @param register the register field
|
||||
* @param operand the operand field
|
||||
* @return the code address of the new instruction
|
||||
**/
|
||||
public int emit(OpCode op, int length, Register register, int operand) {
|
||||
|
||||
if (length > 255) {
|
||||
errorReporter.reportRestriction("length of operand can't exceed 255 words");
|
||||
length = 255; // to allow code generation to continue
|
||||
}
|
||||
|
||||
var nextInstr = new Instruction(op, register, length, operand);
|
||||
|
||||
var currentInstrAddr = nextInstrAddr;
|
||||
if (nextInstrAddr == Machine.PB) {
|
||||
errorReporter.reportRestriction("too many instructions for code segment");
|
||||
} else {
|
||||
Machine.code[nextInstrAddr++] = nextInstr;
|
||||
}
|
||||
return currentInstrAddr;
|
||||
|
||||
}
|
||||
|
||||
// Patches the d-field of the instruction at address addr with the next
|
||||
// instruction address.
|
||||
public void patch(int addr) {
|
||||
Machine.code[addr].setOperand(nextInstrAddr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the object program in the given object file.
|
||||
*
|
||||
* @param objectFile the object file
|
||||
*/
|
||||
public void saveObjectProgram(String objectFileName) {
|
||||
try (var objectFile = new FileOutputStream(objectFileName)) {
|
||||
var objectStream = new DataOutputStream(objectFile);
|
||||
for (var addr = Machine.CB; addr < nextInstrAddr; addr++) {
|
||||
Machine.code[addr].write(objectStream);
|
||||
}
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
System.err.println("Error opening object file: " + fnfe);
|
||||
} catch (IOException ioe) {
|
||||
System.err.println("Error writing object file: " + ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,859 @@
|
||||
/*
|
||||
* @(#)Encoder.java 2.1 2003/10/07
|
||||
*
|
||||
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
|
||||
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
|
||||
* and School of Computer and Math Sciences, The Robert Gordon University,
|
||||
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is provided free for educational use only. It may
|
||||
* not be used for commercial purposes without the prior written permission
|
||||
* of the authors.
|
||||
*/
|
||||
|
||||
package triangle.codeGenerator;
|
||||
|
||||
import triangle.ErrorReporter;
|
||||
import triangle.StdEnvironment;
|
||||
import triangle.abstractMachine.Machine;
|
||||
import triangle.abstractMachine.OpCode;
|
||||
import triangle.abstractMachine.Primitive;
|
||||
import triangle.abstractMachine.Register;
|
||||
import triangle.abstractSyntaxTrees.AbstractSyntaxTree;
|
||||
import triangle.abstractSyntaxTrees.Program;
|
||||
import triangle.abstractSyntaxTrees.actuals.ConstActualParameter;
|
||||
import triangle.abstractSyntaxTrees.actuals.EmptyActualParameterSequence;
|
||||
import triangle.abstractSyntaxTrees.actuals.FuncActualParameter;
|
||||
import triangle.abstractSyntaxTrees.actuals.MultipleActualParameterSequence;
|
||||
import triangle.abstractSyntaxTrees.actuals.ProcActualParameter;
|
||||
import triangle.abstractSyntaxTrees.actuals.SingleActualParameterSequence;
|
||||
import triangle.abstractSyntaxTrees.actuals.VarActualParameter;
|
||||
import triangle.abstractSyntaxTrees.aggregates.MultipleArrayAggregate;
|
||||
import triangle.abstractSyntaxTrees.aggregates.MultipleRecordAggregate;
|
||||
import triangle.abstractSyntaxTrees.aggregates.SingleArrayAggregate;
|
||||
import triangle.abstractSyntaxTrees.aggregates.SingleRecordAggregate;
|
||||
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;
|
||||
import triangle.abstractSyntaxTrees.declarations.BinaryOperatorDeclaration;
|
||||
import triangle.abstractSyntaxTrees.declarations.ConstDeclaration;
|
||||
import triangle.abstractSyntaxTrees.declarations.Declaration;
|
||||
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.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;
|
||||
import triangle.abstractSyntaxTrees.formals.ConstFormalParameter;
|
||||
import triangle.abstractSyntaxTrees.formals.EmptyFormalParameterSequence;
|
||||
import triangle.abstractSyntaxTrees.formals.FuncFormalParameter;
|
||||
import triangle.abstractSyntaxTrees.formals.MultipleFormalParameterSequence;
|
||||
import triangle.abstractSyntaxTrees.formals.ProcFormalParameter;
|
||||
import triangle.abstractSyntaxTrees.formals.SingleFormalParameterSequence;
|
||||
import triangle.abstractSyntaxTrees.formals.VarFormalParameter;
|
||||
import triangle.abstractSyntaxTrees.terminals.CharacterLiteral;
|
||||
import triangle.abstractSyntaxTrees.terminals.Identifier;
|
||||
import triangle.abstractSyntaxTrees.terminals.IntegerLiteral;
|
||||
import triangle.abstractSyntaxTrees.terminals.Operator;
|
||||
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.MultipleFieldTypeDenoter;
|
||||
import triangle.abstractSyntaxTrees.types.RecordTypeDenoter;
|
||||
import triangle.abstractSyntaxTrees.types.SimpleTypeDenoter;
|
||||
import triangle.abstractSyntaxTrees.types.SingleFieldTypeDenoter;
|
||||
import triangle.abstractSyntaxTrees.types.TypeDeclaration;
|
||||
import triangle.abstractSyntaxTrees.visitors.ActualParameterSequenceVisitor;
|
||||
import triangle.abstractSyntaxTrees.visitors.ActualParameterVisitor;
|
||||
import triangle.abstractSyntaxTrees.visitors.ArrayAggregateVisitor;
|
||||
import triangle.abstractSyntaxTrees.visitors.CommandVisitor;
|
||||
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor;
|
||||
import triangle.abstractSyntaxTrees.visitors.ExpressionVisitor;
|
||||
import triangle.abstractSyntaxTrees.visitors.FormalParameterSequenceVisitor;
|
||||
import triangle.abstractSyntaxTrees.visitors.FormalParameterVisitor;
|
||||
import triangle.abstractSyntaxTrees.visitors.IdentifierVisitor;
|
||||
import triangle.abstractSyntaxTrees.visitors.LiteralVisitor;
|
||||
import triangle.abstractSyntaxTrees.visitors.OperatorVisitor;
|
||||
import triangle.abstractSyntaxTrees.visitors.ProgramVisitor;
|
||||
import triangle.abstractSyntaxTrees.visitors.RecordAggregateVisitor;
|
||||
import triangle.abstractSyntaxTrees.visitors.TypeDenoterVisitor;
|
||||
import triangle.abstractSyntaxTrees.visitors.VnameVisitor;
|
||||
import triangle.abstractSyntaxTrees.vnames.DotVname;
|
||||
import triangle.abstractSyntaxTrees.vnames.SimpleVname;
|
||||
import triangle.abstractSyntaxTrees.vnames.SubscriptVname;
|
||||
import triangle.abstractSyntaxTrees.vnames.Vname;
|
||||
import triangle.codeGenerator.entities.AddressableEntity;
|
||||
import triangle.codeGenerator.entities.EqualityRoutine;
|
||||
import triangle.codeGenerator.entities.FetchableEntity;
|
||||
import triangle.codeGenerator.entities.Field;
|
||||
import triangle.codeGenerator.entities.KnownAddress;
|
||||
import triangle.codeGenerator.entities.KnownRoutine;
|
||||
import triangle.codeGenerator.entities.KnownValue;
|
||||
import triangle.codeGenerator.entities.PrimitiveRoutine;
|
||||
import triangle.codeGenerator.entities.RuntimeEntity;
|
||||
import triangle.codeGenerator.entities.TypeRepresentation;
|
||||
import triangle.codeGenerator.entities.UnknownAddress;
|
||||
import triangle.codeGenerator.entities.UnknownRoutine;
|
||||
import triangle.codeGenerator.entities.UnknownValue;
|
||||
|
||||
public final class Encoder
|
||||
implements ActualParameterVisitor<Frame, Integer>, ActualParameterSequenceVisitor<Frame, Integer>,
|
||||
ArrayAggregateVisitor<Frame, Integer>, CommandVisitor<Frame, Void>, DeclarationVisitor<Frame, Integer>,
|
||||
ExpressionVisitor<Frame, Integer>, FormalParameterVisitor<Frame, Integer>,
|
||||
FormalParameterSequenceVisitor<Frame, Integer>, IdentifierVisitor<Frame, Void>, LiteralVisitor<Void, Void>,
|
||||
OperatorVisitor<Frame, Void>, ProgramVisitor<Frame, Void>, RecordAggregateVisitor<Frame, Integer>,
|
||||
TypeDenoterVisitor<Frame, Integer>, VnameVisitor<Frame, RuntimeEntity> {
|
||||
|
||||
// Commands
|
||||
@Override
|
||||
public Void visitAssignCommand(AssignCommand ast, Frame frame) {
|
||||
var valSize = ast.E.visit(this, frame);
|
||||
encodeStore(ast.V, frame.expand(valSize), valSize);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitCallCommand(CallCommand ast, Frame frame) {
|
||||
var argsSize = ast.APS.visit(this, frame);
|
||||
ast.I.visit(this, frame.replace(argsSize));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitEmptyCommand(EmptyCommand ast, Frame frame) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitIfCommand(IfCommand ast, Frame frame) {
|
||||
ast.E.visit(this, frame);
|
||||
var jumpifAddr = emitter.emit(OpCode.JUMPIF, Machine.falseRep, Register.CB, 0);
|
||||
ast.C1.visit(this, frame);
|
||||
var jumpAddr = emitter.emit(OpCode.JUMP, 0, Register.CB, 0);
|
||||
emitter.patch(jumpifAddr);
|
||||
ast.C2.visit(this, frame);
|
||||
emitter.patch(jumpAddr);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitLetCommand(LetCommand ast, Frame frame) {
|
||||
var extraSize = ast.D.visit(this, frame);
|
||||
ast.C.visit(this, frame.expand(extraSize));
|
||||
if (extraSize > 0) {
|
||||
emitter.emit(OpCode.POP, extraSize);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitSequentialCommand(SequentialCommand ast, Frame frame) {
|
||||
ast.C1.visit(this, frame);
|
||||
ast.C2.visit(this, frame);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitWhileCommand(WhileCommand ast, Frame frame) {
|
||||
var jumpAddr = emitter.emit(OpCode.JUMP, 0, Register.CB, 0);
|
||||
var loopAddr = emitter.getNextInstrAddr();
|
||||
ast.C.visit(this, frame);
|
||||
emitter.patch(jumpAddr);
|
||||
ast.E.visit(this, frame);
|
||||
emitter.emit(OpCode.JUMPIF, Machine.trueRep, Register.CB, loopAddr);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Expressions
|
||||
@Override
|
||||
public Integer visitArrayExpression(ArrayExpression ast, Frame frame) {
|
||||
ast.type.visit(this, frame);
|
||||
return ast.AA.visit(this, frame);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitBinaryExpression(BinaryExpression ast, Frame frame) {
|
||||
var valSize = ast.type.visit(this);
|
||||
var valSize1 = ast.E1.visit(this, frame);
|
||||
var frame1 = frame.expand(valSize1);
|
||||
var valSize2 = ast.E2.visit(this, frame1);
|
||||
var frame2 = frame.replace(valSize1 + valSize2);
|
||||
ast.O.visit(this, frame2);
|
||||
return valSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitCallExpression(CallExpression ast, Frame frame) {
|
||||
var valSize = ast.type.visit(this);
|
||||
var argsSize = ast.APS.visit(this, frame);
|
||||
ast.I.visit(this, frame.replace(argsSize));
|
||||
return valSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitCharacterExpression(CharacterExpression ast, Frame frame) {
|
||||
var valSize = ast.type.visit(this);
|
||||
emitter.emit(OpCode.LOADL, ast.CL.spelling.charAt(1));
|
||||
return valSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitEmptyExpression(EmptyExpression ast, Frame frame) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitIfExpression(IfExpression ast, Frame frame) {
|
||||
ast.type.visit(this);
|
||||
ast.E1.visit(this, frame);
|
||||
var jumpifAddr = emitter.emit(OpCode.JUMPIF, Machine.falseRep, Register.CB, 0);
|
||||
var valSize = ast.E2.visit(this, frame);
|
||||
var jumpAddr = emitter.emit(OpCode.JUMP, 0, Register.CB, 0);
|
||||
emitter.patch(jumpifAddr);
|
||||
valSize = ast.E3.visit(this, frame);
|
||||
emitter.patch(jumpAddr);
|
||||
return valSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitIntegerExpression(IntegerExpression ast, Frame frame) {
|
||||
var valSize = ast.type.visit(this);
|
||||
emitter.emit(OpCode.LOADL, Integer.parseInt(ast.IL.spelling));
|
||||
return valSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitLetExpression(LetExpression ast, Frame frame) {
|
||||
ast.type.visit(this);
|
||||
var extraSize = ast.D.visit(this, frame);
|
||||
var frame1 = frame.expand(extraSize);
|
||||
var valSize = ast.E.visit(this, frame1);
|
||||
if (extraSize > 0) {
|
||||
emitter.emit(OpCode.POP, valSize, extraSize);
|
||||
}
|
||||
return valSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitRecordExpression(RecordExpression ast, Frame frame) {
|
||||
ast.type.visit(this);
|
||||
return ast.RA.visit(this, frame);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitUnaryExpression(UnaryExpression ast, Frame frame) {
|
||||
var valSize = ast.type.visit(this);
|
||||
ast.E.visit(this, frame);
|
||||
ast.O.visit(this, frame.replace(valSize));
|
||||
return valSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitVnameExpression(VnameExpression ast, Frame frame) {
|
||||
var valSize = ast.type.visit(this);
|
||||
encodeFetch(ast.V, frame, valSize);
|
||||
return valSize;
|
||||
}
|
||||
|
||||
// Declarations
|
||||
@Override
|
||||
public Integer visitBinaryOperatorDeclaration(BinaryOperatorDeclaration ast, Frame frame) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitConstDeclaration(ConstDeclaration ast, Frame frame) {
|
||||
var extraSize = 0;
|
||||
if (ast.E instanceof CharacterExpression) {
|
||||
var CL = ((CharacterExpression) ast.E).CL;
|
||||
ast.entity = new KnownValue(Machine.characterSize, CL.getValue());
|
||||
} else if (ast.E instanceof IntegerExpression) {
|
||||
var IL = ((IntegerExpression) ast.E).IL;
|
||||
ast.entity = new KnownValue(Machine.integerSize, IL.getValue());
|
||||
} else {
|
||||
var valSize = ast.E.visit(this, frame);
|
||||
ast.entity = new UnknownValue(valSize, frame.getLevel(), frame.getSize());
|
||||
extraSize = valSize;
|
||||
}
|
||||
writeTableDetails(ast);
|
||||
return extraSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitFuncDeclaration(FuncDeclaration ast, Frame frame) {
|
||||
var argsSize = 0;
|
||||
var valSize = 0;
|
||||
|
||||
var jumpAddr = emitter.emit(OpCode.JUMP, 0, Register.CB, 0);
|
||||
ast.entity = new KnownRoutine(Machine.closureSize, frame.getLevel(), emitter.getNextInstrAddr());
|
||||
writeTableDetails(ast);
|
||||
if (frame.getLevel() == Machine.maxRoutineLevel) {
|
||||
reporter.reportRestriction("can't nest routines more than 7 deep");
|
||||
} else {
|
||||
var frame1 = frame.push(0);
|
||||
argsSize = ast.FPS.visit(this, frame1);
|
||||
var frame2 = frame.push(Machine.linkDataSize);
|
||||
valSize = ast.E.visit(this, frame2);
|
||||
}
|
||||
emitter.emit(OpCode.RETURN, valSize, argsSize);
|
||||
emitter.patch(jumpAddr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitProcDeclaration(ProcDeclaration ast, Frame frame) {
|
||||
var argsSize = 0;
|
||||
var jumpAddr = emitter.emit(OpCode.JUMP, 0, Register.CB, 0);
|
||||
ast.entity = new KnownRoutine(Machine.closureSize, frame.getLevel(), emitter.getNextInstrAddr());
|
||||
writeTableDetails(ast);
|
||||
if (frame.getLevel() == Machine.maxRoutineLevel) {
|
||||
reporter.reportRestriction("can't nest routines so deeply");
|
||||
} else {
|
||||
var frame1 = frame.push(0);
|
||||
argsSize = ast.FPS.visit(this, frame1);
|
||||
var frame2 = frame.push(Machine.linkDataSize);
|
||||
ast.C.visit(this, frame2);
|
||||
}
|
||||
emitter.emit(OpCode.RETURN, argsSize);
|
||||
emitter.patch(jumpAddr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitSequentialDeclaration(SequentialDeclaration ast, Frame frame) {
|
||||
var extraSize1 = ast.D1.visit(this, frame);
|
||||
var frame1 = frame.expand(extraSize1);
|
||||
var extraSize2 = ast.D2.visit(this, frame1);
|
||||
return extraSize1 + extraSize2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitTypeDeclaration(TypeDeclaration ast, Frame frame) {
|
||||
// just to ensure the type's representation is decided
|
||||
ast.T.visit(this);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitUnaryOperatorDeclaration(UnaryOperatorDeclaration ast, Frame frame) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitVarDeclaration(VarDeclaration ast, Frame frame) {
|
||||
var extraSize = ast.T.visit(this);
|
||||
emitter.emit(OpCode.PUSH, extraSize);
|
||||
ast.entity = new KnownAddress(Machine.addressSize, frame.getLevel(), frame.getSize());
|
||||
writeTableDetails(ast);
|
||||
return extraSize;
|
||||
}
|
||||
|
||||
// Array Aggregates
|
||||
@Override
|
||||
public Integer visitMultipleArrayAggregate(MultipleArrayAggregate ast, Frame frame) {
|
||||
var elemSize = ast.E.visit(this, frame);
|
||||
var frame1 = frame.expand(elemSize);
|
||||
var arraySize = ast.AA.visit(this, frame1);
|
||||
return elemSize + arraySize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitSingleArrayAggregate(SingleArrayAggregate ast, Frame frame) {
|
||||
return ast.E.visit(this, frame);
|
||||
}
|
||||
|
||||
// Record Aggregates
|
||||
@Override
|
||||
public Integer visitMultipleRecordAggregate(MultipleRecordAggregate ast, Frame frame) {
|
||||
var fieldSize = ast.E.visit(this, frame);
|
||||
var frame1 = frame.expand(fieldSize);
|
||||
var recordSize = ast.RA.visit(this, frame1);
|
||||
return fieldSize + recordSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitSingleRecordAggregate(SingleRecordAggregate ast, Frame frame) {
|
||||
return ast.E.visit(this, frame);
|
||||
}
|
||||
|
||||
// Formal Parameters
|
||||
@Override
|
||||
public Integer visitConstFormalParameter(ConstFormalParameter ast, Frame frame) {
|
||||
var valSize = ast.T.visit(this);
|
||||
ast.entity = new UnknownValue(valSize, frame.getLevel(), -frame.getSize() - valSize);
|
||||
writeTableDetails(ast);
|
||||
return valSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitFuncFormalParameter(FuncFormalParameter ast, Frame frame) {
|
||||
var argsSize = Machine.closureSize;
|
||||
ast.entity = new UnknownRoutine(Machine.closureSize, frame.getLevel(), -frame.getSize() - argsSize);
|
||||
writeTableDetails(ast);
|
||||
return argsSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitProcFormalParameter(ProcFormalParameter ast, Frame frame) {
|
||||
var argsSize = Machine.closureSize;
|
||||
ast.entity = new UnknownRoutine(Machine.closureSize, frame.getLevel(), -frame.getSize() - argsSize);
|
||||
writeTableDetails(ast);
|
||||
return argsSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitVarFormalParameter(VarFormalParameter ast, Frame frame) {
|
||||
ast.T.visit(this);
|
||||
ast.entity = new UnknownAddress(Machine.addressSize, frame.getLevel(), -frame.getSize() - Machine.addressSize);
|
||||
writeTableDetails(ast);
|
||||
return Machine.addressSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitEmptyFormalParameterSequence(EmptyFormalParameterSequence ast, Frame frame) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitMultipleFormalParameterSequence(MultipleFormalParameterSequence ast, Frame frame) {
|
||||
var argsSize1 = ast.FPS.visit(this, frame);
|
||||
var frame1 = frame.expand(argsSize1);
|
||||
var argsSize2 = ast.FP.visit(this, frame1);
|
||||
return argsSize1 + argsSize2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitSingleFormalParameterSequence(SingleFormalParameterSequence ast, Frame frame) {
|
||||
return ast.FP.visit(this, frame);
|
||||
}
|
||||
|
||||
// Actual Parameters
|
||||
@Override
|
||||
public Integer visitConstActualParameter(ConstActualParameter ast, Frame frame) {
|
||||
return ast.E.visit(this, frame);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitFuncActualParameter(FuncActualParameter ast, Frame frame) {
|
||||
if (ast.I.decl.entity instanceof KnownRoutine) {
|
||||
var address = ((KnownRoutine) ast.I.decl.entity).getAddress();
|
||||
// static link, code address
|
||||
emitter.emit(OpCode.LOADA, 0, frame.getDisplayRegister(address), 0);
|
||||
emitter.emit(OpCode.LOADA, 0, Register.CB, address.getDisplacement());
|
||||
} else if (ast.I.decl.entity instanceof UnknownRoutine) {
|
||||
var address = ((UnknownRoutine) ast.I.decl.entity).getAddress();
|
||||
emitter.emit(OpCode.LOAD, Machine.closureSize, frame.getDisplayRegister(address),
|
||||
address.getDisplacement());
|
||||
} else if (ast.I.decl.entity instanceof PrimitiveRoutine) {
|
||||
var primitive = ((PrimitiveRoutine) ast.I.decl.entity).getPrimitive();
|
||||
// static link, code address
|
||||
emitter.emit(OpCode.LOADA, 0, Register.SB, 0);
|
||||
emitter.emit(OpCode.LOADA, Register.PB, primitive);
|
||||
}
|
||||
return Machine.closureSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitProcActualParameter(ProcActualParameter ast, Frame frame) {
|
||||
if (ast.I.decl.entity instanceof KnownRoutine) {
|
||||
var address = ((KnownRoutine) ast.I.decl.entity).getAddress();
|
||||
// static link, code address
|
||||
emitter.emit(OpCode.LOADA, 0, frame.getDisplayRegister(address), 0);
|
||||
emitter.emit(OpCode.LOADA, 0, Register.CB, address.getDisplacement());
|
||||
} else if (ast.I.decl.entity instanceof UnknownRoutine) {
|
||||
var address = ((UnknownRoutine) ast.I.decl.entity).getAddress();
|
||||
emitter.emit(OpCode.LOAD, Machine.closureSize, frame.getDisplayRegister(address),
|
||||
address.getDisplacement());
|
||||
} else if (ast.I.decl.entity instanceof PrimitiveRoutine) {
|
||||
var primitive = ((PrimitiveRoutine) ast.I.decl.entity).getPrimitive();
|
||||
// static link, code address
|
||||
emitter.emit(OpCode.LOADA, 0, Register.SB, 0);
|
||||
emitter.emit(OpCode.LOADA, Register.PB, primitive);
|
||||
}
|
||||
return Machine.closureSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitVarActualParameter(VarActualParameter ast, Frame frame) {
|
||||
encodeFetchAddress(ast.V, frame);
|
||||
return Machine.addressSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitEmptyActualParameterSequence(EmptyActualParameterSequence ast, Frame frame) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitMultipleActualParameterSequence(MultipleActualParameterSequence ast, Frame frame) {
|
||||
var argsSize1 = ast.AP.visit(this, frame);
|
||||
var frame1 = frame.expand(argsSize1);
|
||||
var argsSize2 = ast.APS.visit(this, frame1);
|
||||
return argsSize1 + argsSize2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitSingleActualParameterSequence(SingleActualParameterSequence ast, Frame frame) {
|
||||
return ast.AP.visit(this, frame);
|
||||
}
|
||||
|
||||
// Type Denoters
|
||||
@Override
|
||||
public Integer visitAnyTypeDenoter(AnyTypeDenoter ast, Frame frame) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitArrayTypeDenoter(ArrayTypeDenoter ast, Frame frame) {
|
||||
int typeSize;
|
||||
if (ast.entity == null) {
|
||||
var elemSize = ast.T.visit(this);
|
||||
typeSize = Integer.parseInt(ast.IL.spelling) * elemSize;
|
||||
ast.entity = new TypeRepresentation(typeSize);
|
||||
writeTableDetails(ast);
|
||||
} else {
|
||||
typeSize = ast.entity.getSize();
|
||||
}
|
||||
return typeSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitBoolTypeDenoter(BoolTypeDenoter ast, Frame frame) {
|
||||
if (ast.entity == null) {
|
||||
ast.entity = new TypeRepresentation(Machine.booleanSize);
|
||||
writeTableDetails(ast);
|
||||
}
|
||||
return Machine.booleanSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitCharTypeDenoter(CharTypeDenoter ast, Frame frame) {
|
||||
if (ast.entity == null) {
|
||||
ast.entity = new TypeRepresentation(Machine.characterSize);
|
||||
writeTableDetails(ast);
|
||||
}
|
||||
return Machine.characterSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitErrorTypeDenoter(ErrorTypeDenoter ast, Frame frame) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitSimpleTypeDenoter(SimpleTypeDenoter ast, Frame frame) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitIntTypeDenoter(IntTypeDenoter ast, Frame frame) {
|
||||
if (ast.entity == null) {
|
||||
ast.entity = new TypeRepresentation(Machine.integerSize);
|
||||
writeTableDetails(ast);
|
||||
}
|
||||
return Machine.integerSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitRecordTypeDenoter(RecordTypeDenoter ast, Frame frame) {
|
||||
int typeSize;
|
||||
if (ast.entity == null) {
|
||||
typeSize = ast.FT.visit(this, null);
|
||||
ast.entity = new TypeRepresentation(typeSize);
|
||||
writeTableDetails(ast);
|
||||
} else {
|
||||
typeSize = ast.entity.getSize();
|
||||
}
|
||||
return typeSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitMultipleFieldTypeDenoter(MultipleFieldTypeDenoter ast, Frame frame) {
|
||||
var offset = frame.getSize();
|
||||
int fieldSize;
|
||||
if (ast.entity == null) {
|
||||
fieldSize = ast.T.visit(this);
|
||||
ast.entity = new Field(fieldSize, offset);
|
||||
writeTableDetails(ast);
|
||||
} else {
|
||||
fieldSize = ast.entity.getSize();
|
||||
}
|
||||
|
||||
var offset1 = frame.replace(offset + fieldSize);
|
||||
var recSize = ast.FT.visit(this, offset1);
|
||||
return fieldSize + recSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitSingleFieldTypeDenoter(SingleFieldTypeDenoter ast, Frame frame) {
|
||||
var offset = frame.getSize();
|
||||
int fieldSize;
|
||||
if (ast.entity == null) {
|
||||
fieldSize = ast.T.visit(this);
|
||||
ast.entity = new Field(fieldSize, offset);
|
||||
writeTableDetails(ast);
|
||||
} else {
|
||||
fieldSize = ast.entity.getSize();
|
||||
}
|
||||
|
||||
return fieldSize;
|
||||
}
|
||||
|
||||
// Literals, Identifiers and Operators
|
||||
@Override
|
||||
public Void visitCharacterLiteral(CharacterLiteral ast, Void arg) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitIdentifier(Identifier ast, Frame frame) {
|
||||
if (ast.decl.entity instanceof KnownRoutine) {
|
||||
var address = ((KnownRoutine) ast.decl.entity).getAddress();
|
||||
emitter.emit(OpCode.CALL, frame.getDisplayRegister(address), Register.CB, address.getDisplacement());
|
||||
} else if (ast.decl.entity instanceof UnknownRoutine) {
|
||||
var address = ((UnknownRoutine) ast.decl.entity).getAddress();
|
||||
emitter.emit(OpCode.LOAD, Machine.closureSize, frame.getDisplayRegister(address),
|
||||
address.getDisplacement());
|
||||
emitter.emit(OpCode.CALLI, 0);
|
||||
} else if (ast.decl.entity instanceof PrimitiveRoutine) {
|
||||
var primitive = ((PrimitiveRoutine) ast.decl.entity).getPrimitive();
|
||||
if (primitive != Primitive.ID)
|
||||
emitter.emit(OpCode.CALL, Register.PB, primitive);
|
||||
} else if (ast.decl.entity instanceof EqualityRoutine) { // "=" or "\="
|
||||
var primitive = ((EqualityRoutine) ast.decl.entity).getPrimitive();
|
||||
emitter.emit(OpCode.LOADL, 0, frame.getSize() / 2);
|
||||
emitter.emit(OpCode.CALL, Register.PB, primitive);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitIntegerLiteral(IntegerLiteral ast, Void arg) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitOperator(Operator ast, Frame frame) {
|
||||
if (ast.decl.entity instanceof KnownRoutine) {
|
||||
var address = ((KnownRoutine) ast.decl.entity).getAddress();
|
||||
emitter.emit(OpCode.CALL, frame.getDisplayRegister(address), Register.CB, address.getDisplacement());
|
||||
} else if (ast.decl.entity instanceof UnknownRoutine) {
|
||||
var address = ((UnknownRoutine) ast.decl.entity).getAddress();
|
||||
emitter.emit(OpCode.LOAD, Machine.closureSize, frame.getDisplayRegister(address),
|
||||
address.getDisplacement());
|
||||
emitter.emit(OpCode.CALLI, 0);
|
||||
} else if (ast.decl.entity instanceof PrimitiveRoutine) {
|
||||
var primitive = ((PrimitiveRoutine) ast.decl.entity).getPrimitive();
|
||||
if (primitive != Primitive.ID)
|
||||
emitter.emit(OpCode.CALL, Register.PB, primitive);
|
||||
} else if (ast.decl.entity instanceof EqualityRoutine) { // "=" or "\="
|
||||
var primitive = ((EqualityRoutine) ast.decl.entity).getPrimitive();
|
||||
emitter.emit(OpCode.LOADL, 0, frame.getSize() / 2);
|
||||
emitter.emit(OpCode.CALL, Register.PB, primitive);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Value-or-variable names
|
||||
@Override
|
||||
public RuntimeEntity visitDotVname(DotVname ast, Frame frame) {
|
||||
var baseObject = ast.V.visit(this, frame);
|
||||
ast.offset = ast.V.offset + ((Field) ast.I.decl.entity).getFieldOffset();
|
||||
// I.decl points to the appropriate record field
|
||||
ast.indexed = ast.V.indexed;
|
||||
return baseObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeEntity visitSimpleVname(SimpleVname ast, Frame frame) {
|
||||
ast.offset = 0;
|
||||
ast.indexed = false;
|
||||
return ast.I.decl.entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeEntity visitSubscriptVname(SubscriptVname ast, Frame frame) {
|
||||
var baseObject = ast.V.visit(this, frame);
|
||||
ast.offset = ast.V.offset;
|
||||
ast.indexed = ast.V.indexed;
|
||||
var elemSize = ast.type.visit(this);
|
||||
if (ast.E instanceof IntegerExpression) {
|
||||
var IL = ((IntegerExpression) ast.E).IL;
|
||||
ast.offset = ast.offset + Integer.parseInt(IL.spelling) * elemSize;
|
||||
} else {
|
||||
// v-name is indexed by a proper expression, not a literal
|
||||
if (ast.indexed) {
|
||||
frame = frame.expand(Machine.integerSize);
|
||||
}
|
||||
ast.E.visit(this, frame);
|
||||
if (elemSize != 1) {
|
||||
emitter.emit(OpCode.LOADL, 0, elemSize);
|
||||
emitter.emit(OpCode.CALL, Register.PB, Primitive.MULT);
|
||||
}
|
||||
if (ast.indexed)
|
||||
emitter.emit(OpCode.CALL, Register.PB, Primitive.ADD);
|
||||
else {
|
||||
ast.indexed = true;
|
||||
}
|
||||
}
|
||||
return baseObject;
|
||||
}
|
||||
|
||||
// Programs
|
||||
@Override
|
||||
public Void visitProgram(Program ast, Frame frame) {
|
||||
return ast.C.visit(this, frame);
|
||||
}
|
||||
|
||||
public Encoder(Emitter emitter, ErrorReporter reporter) {
|
||||
this.emitter = emitter;
|
||||
this.reporter = reporter;
|
||||
|
||||
elaborateStdEnvironment();
|
||||
}
|
||||
|
||||
private Emitter emitter;
|
||||
|
||||
private ErrorReporter reporter;
|
||||
|
||||
// Generates code to run a program.
|
||||
// showingTable is true iff entity description details
|
||||
// are to be displayed.
|
||||
public final void encodeRun(Program program, boolean showingTable) {
|
||||
tableDetailsReqd = showingTable;
|
||||
// startCodeGeneration();
|
||||
program.visit(this, Frame.Initial);
|
||||
emitter.emit(OpCode.HALT);
|
||||
}
|
||||
|
||||
// Decides run-time representation of a standard constant.
|
||||
private final void elaborateStdConst(Declaration constDeclaration, int value) {
|
||||
|
||||
if (constDeclaration instanceof ConstDeclaration) {
|
||||
var decl = (ConstDeclaration) constDeclaration;
|
||||
var typeSize = decl.E.type.visit(this);
|
||||
decl.entity = new KnownValue(typeSize, value);
|
||||
writeTableDetails(constDeclaration);
|
||||
}
|
||||
}
|
||||
|
||||
// Decides run-time representation of a standard routine.
|
||||
private final void elaborateStdPrimRoutine(Declaration routineDeclaration, Primitive primitive) {
|
||||
routineDeclaration.entity = new PrimitiveRoutine(Machine.closureSize, primitive);
|
||||
writeTableDetails(routineDeclaration);
|
||||
}
|
||||
|
||||
private final void elaborateStdEqRoutine(Declaration routineDeclaration, Primitive primitive) {
|
||||
routineDeclaration.entity = new EqualityRoutine(Machine.closureSize, primitive);
|
||||
writeTableDetails(routineDeclaration);
|
||||
}
|
||||
|
||||
private final void elaborateStdRoutine(Declaration routineDeclaration, int routineOffset) {
|
||||
routineDeclaration.entity = new KnownRoutine(Machine.closureSize, 0, routineOffset);
|
||||
writeTableDetails(routineDeclaration);
|
||||
}
|
||||
|
||||
private final void elaborateStdEnvironment() {
|
||||
tableDetailsReqd = false;
|
||||
elaborateStdConst(StdEnvironment.falseDecl, Machine.falseRep);
|
||||
elaborateStdConst(StdEnvironment.trueDecl, Machine.trueRep);
|
||||
elaborateStdPrimRoutine(StdEnvironment.notDecl, Primitive.NOT);
|
||||
elaborateStdPrimRoutine(StdEnvironment.andDecl, Primitive.AND);
|
||||
elaborateStdPrimRoutine(StdEnvironment.orDecl, Primitive.OR);
|
||||
elaborateStdConst(StdEnvironment.maxintDecl, Machine.maxintRep);
|
||||
elaborateStdPrimRoutine(StdEnvironment.addDecl, Primitive.ADD);
|
||||
elaborateStdPrimRoutine(StdEnvironment.subtractDecl, Primitive.SUB);
|
||||
elaborateStdPrimRoutine(StdEnvironment.multiplyDecl, Primitive.MULT);
|
||||
elaborateStdPrimRoutine(StdEnvironment.divideDecl, Primitive.DIV);
|
||||
elaborateStdPrimRoutine(StdEnvironment.moduloDecl, Primitive.MOD);
|
||||
elaborateStdPrimRoutine(StdEnvironment.lessDecl, Primitive.LT);
|
||||
elaborateStdPrimRoutine(StdEnvironment.notgreaterDecl, Primitive.LE);
|
||||
elaborateStdPrimRoutine(StdEnvironment.greaterDecl, Primitive.GT);
|
||||
elaborateStdPrimRoutine(StdEnvironment.notlessDecl, Primitive.GE);
|
||||
elaborateStdPrimRoutine(StdEnvironment.chrDecl, Primitive.ID);
|
||||
elaborateStdPrimRoutine(StdEnvironment.ordDecl, Primitive.ID);
|
||||
elaborateStdPrimRoutine(StdEnvironment.eolDecl, Primitive.EOL);
|
||||
elaborateStdPrimRoutine(StdEnvironment.eofDecl, Primitive.EOF);
|
||||
elaborateStdPrimRoutine(StdEnvironment.getDecl, Primitive.GET);
|
||||
elaborateStdPrimRoutine(StdEnvironment.putDecl, Primitive.PUT);
|
||||
elaborateStdPrimRoutine(StdEnvironment.getintDecl, Primitive.GETINT);
|
||||
elaborateStdPrimRoutine(StdEnvironment.putintDecl, Primitive.PUTINT);
|
||||
elaborateStdPrimRoutine(StdEnvironment.geteolDecl, Primitive.GETEOL);
|
||||
elaborateStdPrimRoutine(StdEnvironment.puteolDecl, Primitive.PUTEOL);
|
||||
elaborateStdEqRoutine(StdEnvironment.equalDecl, Primitive.EQ);
|
||||
elaborateStdEqRoutine(StdEnvironment.unequalDecl, Primitive.NE);
|
||||
}
|
||||
|
||||
boolean tableDetailsReqd;
|
||||
|
||||
public static void writeTableDetails(AbstractSyntaxTree ast) {
|
||||
}
|
||||
|
||||
// Generates code to fetch the value of a named constant or variable
|
||||
// and push it on to the stack.
|
||||
// currentLevel is the routine level where the vname occurs.
|
||||
// frameSize is the anticipated size of the local stack frame when
|
||||
// the constant or variable is fetched at run-time.
|
||||
// valSize is the size of the constant or variable's value.
|
||||
|
||||
private void encodeStore(Vname V, Frame frame, int valSize) {
|
||||
|
||||
var baseObject = (AddressableEntity) V.visit(this, frame);
|
||||
// If indexed = true, code will have been generated to load an index value.
|
||||
if (valSize > 255) {
|
||||
reporter.reportRestriction("can't store values larger than 255 words");
|
||||
valSize = 255; // to allow code generation to continue
|
||||
}
|
||||
|
||||
baseObject.encodeStore(emitter, frame, valSize, V);
|
||||
}
|
||||
|
||||
// Generates code to fetch the value of a named constant or variable
|
||||
// and push it on to the stack.
|
||||
// currentLevel is the routine level where the vname occurs.
|
||||
// frameSize is the anticipated size of the local stack frame when
|
||||
// the constant or variable is fetched at run-time.
|
||||
// valSize is the size of the constant or variable's value.
|
||||
|
||||
private void encodeFetch(Vname V, Frame frame, int valSize) {
|
||||
|
||||
var baseObject = (FetchableEntity) V.visit(this, frame);
|
||||
// If indexed = true, code will have been generated to load an index value.
|
||||
if (valSize > 255) {
|
||||
reporter.reportRestriction("can't load values larger than 255 words");
|
||||
valSize = 255; // to allow code generation to continue
|
||||
}
|
||||
|
||||
baseObject.encodeFetch(emitter, frame, valSize, V);
|
||||
}
|
||||
|
||||
// Generates code to compute and push the address of a named variable.
|
||||
// vname is the program phrase that names this variable.
|
||||
// currentLevel is the routine level where the vname occurs.
|
||||
// frameSize is the anticipated size of the local stack frame when
|
||||
// the variable is addressed at run-time.
|
||||
|
||||
private void encodeFetchAddress(Vname V, Frame frame) {
|
||||
|
||||
var baseObject = (AddressableEntity) V.visit(this, frame);
|
||||
baseObject.encodeFetchAddress(emitter, frame, V);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* @(#)Frame.java 2.1 2003/10/07
|
||||
*
|
||||
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
|
||||
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
|
||||
* and School of Computer and Math Sciences, The Robert Gordon University,
|
||||
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is provided free for educational use only. It may
|
||||
* not be used for commercial purposes without the prior written permission
|
||||
* of the authors.
|
||||
*/
|
||||
|
||||
package triangle.codeGenerator;
|
||||
|
||||
import triangle.abstractMachine.Register;
|
||||
import triangle.codeGenerator.entities.ObjectAddress;
|
||||
|
||||
public class Frame {
|
||||
|
||||
public static final Frame Initial = new Frame(0, 0);
|
||||
|
||||
private final int level;
|
||||
|
||||
private final int size;
|
||||
|
||||
private Frame(int level, int size) {
|
||||
this.level = level;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public final int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public final int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public Frame expand(int increment) {
|
||||
return new Frame(level, size + increment);
|
||||
}
|
||||
|
||||
public Frame replace(int size) {
|
||||
return new Frame(level, size);
|
||||
}
|
||||
|
||||
public Frame push(int size) {
|
||||
return new Frame(level + 1, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the display register appropriate for object code at the current
|
||||
* static level to access a data object at the static level of the given
|
||||
* address.
|
||||
*
|
||||
* @param address the address of the data object
|
||||
* @return the display register required for static addressing
|
||||
*/
|
||||
public Register getDisplayRegister(ObjectAddress address) {
|
||||
if (address.getLevel() == 0) {
|
||||
return Register.SB;
|
||||
}
|
||||
|
||||
if (level - address.getLevel() <= 6) {
|
||||
return Register.values()[Register.LB.ordinal() + level - address.getLevel()]; // LB|L1|...|L6
|
||||
}
|
||||
|
||||
// _errorReporter.ReportRestriction("can't access data more than 6 levels out");
|
||||
return Register.L6; // to allow code generation to continue
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package triangle.codeGenerator.entities;
|
||||
|
||||
import triangle.abstractSyntaxTrees.vnames.Vname;
|
||||
import triangle.codeGenerator.Emitter;
|
||||
import triangle.codeGenerator.Frame;
|
||||
|
||||
public abstract class AddressableEntity extends RuntimeEntity implements FetchableEntity {
|
||||
|
||||
protected final ObjectAddress address;
|
||||
|
||||
protected AddressableEntity(int size, int level, int displacement) {
|
||||
super(size);
|
||||
address = new ObjectAddress(level, displacement);
|
||||
}
|
||||
|
||||
protected AddressableEntity(int size, Frame frame) {
|
||||
this(size, frame.getLevel(), frame.getSize());
|
||||
}
|
||||
|
||||
public ObjectAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public abstract void encodeStore(Emitter emitter, Frame frame, int size, Vname vname);
|
||||
|
||||
public abstract void encodeFetchAddress(Emitter emitter, Frame frame, Vname vname);
|
||||
|
||||
public abstract void encodeFetch(Emitter emitter, Frame frame, int size, Vname vname);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* @(#)EqualityRoutine.java 2.1 2003/10/07
|
||||
*
|
||||
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
|
||||
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
|
||||
* and School of Computer and Math Sciences, The Robert Gordon University,
|
||||
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is provided free for educational use only. It may
|
||||
* not be used for commercial purposes without the prior written permission
|
||||
* of the authors.
|
||||
*/
|
||||
|
||||
package triangle.codeGenerator.entities;
|
||||
|
||||
import triangle.abstractMachine.OpCode;
|
||||
import triangle.abstractMachine.Primitive;
|
||||
import triangle.abstractMachine.Register;
|
||||
import triangle.codeGenerator.Emitter;
|
||||
import triangle.codeGenerator.Frame;
|
||||
|
||||
public class EqualityRoutine extends RuntimeEntity implements RoutineEntity {
|
||||
|
||||
private final Primitive primitive;
|
||||
|
||||
public EqualityRoutine(int size, Primitive primitive) {
|
||||
super(size);
|
||||
this.primitive = primitive;
|
||||
}
|
||||
|
||||
public final Primitive getPrimitive() {
|
||||
return primitive;
|
||||
}
|
||||
|
||||
public void encodeCall(Emitter emitter, Frame frame) {
|
||||
emitter.emit(OpCode.LOADL, frame.getSize() / 2);
|
||||
emitter.emit(OpCode.CALL, Register.PB, primitive);
|
||||
}
|
||||
|
||||
public void encodeFetch(Emitter emitter, Frame frame) {
|
||||
emitter.emit(OpCode.LOADA, 0, Register.SB, 0);
|
||||
emitter.emit(OpCode.LOADA, Register.PB, primitive);
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user