diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..4a04201
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
index bd28bc9..019f64b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@ tmp/
.gradle/
+/build/
diff --git a/.project b/.project
new file mode 100644
index 0000000..2df18f6
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+
+
+ Triangle-Tools
+ Project Triangle-Tools created by Buildship.
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.buildship.core.gradleprojectbuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.buildship.core.gradleprojectnature
+
+
diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs
new file mode 100644
index 0000000..e479558
--- /dev/null
+++ b/.settings/org.eclipse.buildship.core.prefs
@@ -0,0 +1,13 @@
+arguments=
+auto.sync=false
+build.scans.enabled=false
+connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
+connection.project.dir=
+eclipse.preferences.version=1
+gradle.user.home=
+java.home=
+jvm.arguments=
+offline.mode=false
+override.workspace.settings=false
+show.console.view=false
+show.executions.view=false
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..18ad895
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
+org.eclipse.jdt.core.compiler.compliance=11
+org.eclipse.jdt.core.compiler.source=11
diff --git a/Triangle.AbstractMachine.Disassembler/.settings/org.eclipse.buildship.core.prefs b/Triangle.AbstractMachine.Disassembler/.settings/org.eclipse.buildship.core.prefs
new file mode 100644
index 0000000..b1886ad
--- /dev/null
+++ b/Triangle.AbstractMachine.Disassembler/.settings/org.eclipse.buildship.core.prefs
@@ -0,0 +1,2 @@
+connection.project.dir=..
+eclipse.preferences.version=1
diff --git a/Triangle.AbstractMachine.Disassembler/.settings/org.eclipse.jdt.core.prefs b/Triangle.AbstractMachine.Disassembler/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..18ad895
--- /dev/null
+++ b/Triangle.AbstractMachine.Disassembler/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
+org.eclipse.jdt.core.compiler.compliance=11
+org.eclipse.jdt.core.compiler.source=11
diff --git a/Triangle.AbstractMachine.Disassembler/bin/.gitignore b/Triangle.AbstractMachine.Disassembler/bin/.gitignore
new file mode 100644
index 0000000..ddf9c65
--- /dev/null
+++ b/Triangle.AbstractMachine.Disassembler/bin/.gitignore
@@ -0,0 +1 @@
+/main/
diff --git a/Triangle.AbstractMachine.Interpreter/.settings/org.eclipse.buildship.core.prefs b/Triangle.AbstractMachine.Interpreter/.settings/org.eclipse.buildship.core.prefs
new file mode 100644
index 0000000..b1886ad
--- /dev/null
+++ b/Triangle.AbstractMachine.Interpreter/.settings/org.eclipse.buildship.core.prefs
@@ -0,0 +1,2 @@
+connection.project.dir=..
+eclipse.preferences.version=1
diff --git a/Triangle.AbstractMachine.Interpreter/.settings/org.eclipse.jdt.core.prefs b/Triangle.AbstractMachine.Interpreter/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..18ad895
--- /dev/null
+++ b/Triangle.AbstractMachine.Interpreter/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
+org.eclipse.jdt.core.compiler.compliance=11
+org.eclipse.jdt.core.compiler.source=11
diff --git a/Triangle.AbstractMachine.Interpreter/bin/.gitignore b/Triangle.AbstractMachine.Interpreter/bin/.gitignore
new file mode 100644
index 0000000..ddf9c65
--- /dev/null
+++ b/Triangle.AbstractMachine.Interpreter/bin/.gitignore
@@ -0,0 +1 @@
+/main/
diff --git a/Triangle.AbstractMachine/.settings/org.eclipse.buildship.core.prefs b/Triangle.AbstractMachine/.settings/org.eclipse.buildship.core.prefs
new file mode 100644
index 0000000..b1886ad
--- /dev/null
+++ b/Triangle.AbstractMachine/.settings/org.eclipse.buildship.core.prefs
@@ -0,0 +1,2 @@
+connection.project.dir=..
+eclipse.preferences.version=1
diff --git a/Triangle.AbstractMachine/.settings/org.eclipse.jdt.core.prefs b/Triangle.AbstractMachine/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..18ad895
--- /dev/null
+++ b/Triangle.AbstractMachine/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
+org.eclipse.jdt.core.compiler.compliance=11
+org.eclipse.jdt.core.compiler.source=11
diff --git a/Triangle.AbstractMachine/bin/.gitignore b/Triangle.AbstractMachine/bin/.gitignore
new file mode 100644
index 0000000..ddf9c65
--- /dev/null
+++ b/Triangle.AbstractMachine/bin/.gitignore
@@ -0,0 +1 @@
+/main/
diff --git a/Triangle.Compiler/.project b/Triangle.Compiler/.project
index dca5b8c..955dfe7 100644
--- a/Triangle.Compiler/.project
+++ b/Triangle.Compiler/.project
@@ -20,4 +20,11 @@
org.eclipse.jdt.core.javanature
org.eclipse.buildship.core.gradleprojectnature
+
+
+ programs
+ 2
+ /home/simon/Documents/Uni/CS/CSCU9A5-2/Triangle-Tools/programs
+
+
diff --git a/Triangle.Compiler/.settings/org.eclipse.buildship.core.prefs b/Triangle.Compiler/.settings/org.eclipse.buildship.core.prefs
new file mode 100644
index 0000000..b1886ad
--- /dev/null
+++ b/Triangle.Compiler/.settings/org.eclipse.buildship.core.prefs
@@ -0,0 +1,2 @@
+connection.project.dir=..
+eclipse.preferences.version=1
diff --git a/Triangle.Compiler/.settings/org.eclipse.jdt.core.prefs b/Triangle.Compiler/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..18ad895
--- /dev/null
+++ b/Triangle.Compiler/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
+org.eclipse.jdt.core.compiler.compliance=11
+org.eclipse.jdt.core.compiler.source=11
diff --git a/Triangle.Compiler/bin/.gitignore b/Triangle.Compiler/bin/.gitignore
new file mode 100644
index 0000000..7eed456
--- /dev/null
+++ b/Triangle.Compiler/bin/.gitignore
@@ -0,0 +1,2 @@
+/main/
+/test/
diff --git a/Triangle.Compiler/src/main/java/triangle/abstractSyntaxTrees/commands/RepeatCommand.java b/Triangle.Compiler/src/main/java/triangle/abstractSyntaxTrees/commands/RepeatCommand.java
new file mode 100644
index 0000000..5026cd8
--- /dev/null
+++ b/Triangle.Compiler/src/main/java/triangle/abstractSyntaxTrees/commands/RepeatCommand.java
@@ -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 RepeatCommand extends Command {
+
+ public RepeatCommand(Expression eAST, Command cAST, SourcePosition position) {
+ super(position);
+ E = eAST;
+ C = cAST;
+ }
+
+ public TResult visit(CommandVisitor v, TArg arg) {
+ return v.visitRepeatCommand(this, arg);
+ }
+
+ public Expression E;
+ public final Command C;
+}
diff --git a/Triangle.Compiler/src/main/java/triangle/abstractSyntaxTrees/visitors/CommandVisitor.java b/Triangle.Compiler/src/main/java/triangle/abstractSyntaxTrees/visitors/CommandVisitor.java
index 336c97d..5820d75 100644
--- a/Triangle.Compiler/src/main/java/triangle/abstractSyntaxTrees/visitors/CommandVisitor.java
+++ b/Triangle.Compiler/src/main/java/triangle/abstractSyntaxTrees/visitors/CommandVisitor.java
@@ -5,6 +5,7 @@ import triangle.abstractSyntaxTrees.commands.CallCommand;
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
import triangle.abstractSyntaxTrees.commands.IfCommand;
import triangle.abstractSyntaxTrees.commands.LetCommand;
+import triangle.abstractSyntaxTrees.commands.RepeatCommand;
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
import triangle.abstractSyntaxTrees.commands.WhileCommand;
@@ -24,4 +25,6 @@ public interface CommandVisitor {
TResult visitWhileCommand(WhileCommand ast, TArg arg);
+ TResult visitRepeatCommand(RepeatCommand ast, TArg arg);
+
}
diff --git a/Triangle.Compiler/src/main/java/triangle/codeGenerator/Encoder.java b/Triangle.Compiler/src/main/java/triangle/codeGenerator/Encoder.java
index 2224aa6..3dd4d74 100644
--- a/Triangle.Compiler/src/main/java/triangle/codeGenerator/Encoder.java
+++ b/Triangle.Compiler/src/main/java/triangle/codeGenerator/Encoder.java
@@ -38,6 +38,7 @@ import triangle.abstractSyntaxTrees.commands.CallCommand;
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
import triangle.abstractSyntaxTrees.commands.IfCommand;
import triangle.abstractSyntaxTrees.commands.LetCommand;
+import triangle.abstractSyntaxTrees.commands.RepeatCommand;
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
import triangle.abstractSyntaxTrees.commands.WhileCommand;
import triangle.abstractSyntaxTrees.declarations.BinaryOperatorDeclaration;
@@ -180,6 +181,11 @@ public final class Encoder implements ActualParameterVisitor,
emitter.emit(OpCode.JUMPIF, Machine.trueRep, Register.CB, loopAddr);
return null;
}
+
+ @Override
+ public Void visitRepeatCommand(RepeatCommand ast, Frame frame) {
+ return null;
+ }
// Expressions
@Override
diff --git a/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java b/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java
index 863b992..8b05b53 100644
--- a/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java
+++ b/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java
@@ -34,6 +34,7 @@ import triangle.abstractSyntaxTrees.commands.CallCommand;
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
import triangle.abstractSyntaxTrees.commands.IfCommand;
import triangle.abstractSyntaxTrees.commands.LetCommand;
+import triangle.abstractSyntaxTrees.commands.RepeatCommand;
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
import triangle.abstractSyntaxTrees.commands.WhileCommand;
import triangle.abstractSyntaxTrees.declarations.BinaryOperatorDeclaration;
@@ -184,6 +185,11 @@ public final class Checker implements ActualParameterVisitor' || c == '\\'
- || c == '&' || c == '@' || c == '%' || c == '^' || c == '?');
+ || c == '&' || c == '@' || c == '%' || c == '^' || c == '?' || c == '|'); //[PRAC2:P2:6] added |
}
///////////////////////////////////////////////////////////////////////////////
@@ -65,14 +65,25 @@ public final class Scanner {
switch (currentChar) {
// comment
- case '!': {
+ case '#': //[PRAC2:P2:3]
+ case '!':
takeIt();
while ((currentChar != SourceFile.EOL) && (currentChar != SourceFile.EOT))
takeIt();
if (currentChar == SourceFile.EOL)
takeIt();
- }
break;
+
+ // multi-line comments
+ // Similar to the single line comment but we are ignoring new lines
+ case '$':
+ takeIt();
+ while ((currentChar != '$') && (currentChar != SourceFile.EOT))
+ takeIt();
+ if(currentChar == '$')
+ takeIt();
+ break;
+
// whitespace
case ' ':
@@ -173,6 +184,7 @@ public final class Scanner {
case '%':
case '^':
case '?':
+ case '|': //[PRAC2:P2:6]
takeIt();
while (isOperator(currentChar))
takeIt();
@@ -252,7 +264,7 @@ public final class Scanner {
currentlyScanningToken = false;
// skip any whitespace or comments
while (currentChar == '!' || currentChar == ' ' || currentChar == '\n' || currentChar == '\r'
- || currentChar == '\t')
+ || currentChar == '\t' || currentChar == '#' || currentChar == '$') //[PRAC2:P2:3 && 5]
scanSeparator();
currentlyScanningToken = true;
diff --git a/Triangle.Compiler/src/main/java/triangle/syntacticAnalyzer/Token.java b/Triangle.Compiler/src/main/java/triangle/syntacticAnalyzer/Token.java
index 51f3203..16be03f 100644
--- a/Triangle.Compiler/src/main/java/triangle/syntacticAnalyzer/Token.java
+++ b/Triangle.Compiler/src/main/java/triangle/syntacticAnalyzer/Token.java
@@ -64,20 +64,20 @@ final class Token extends Object {
// reserved words - must be in alphabetical order...
ARRAY = 4, BEGIN = 5, CONST = 6, DO = 7, ELSE = 8, END = 9, FUNC = 10, IF = 11, IN = 12, LET = 13, OF = 14,
- PROC = 15, RECORD = 16, THEN = 17, TYPE = 18, VAR = 19, WHILE = 20,
+ PROC = 15, RECORD = 16, REPEAT = 17, THEN = 18, TYPE = 19, UNTIL = 20, VAR = 21, WHILE = 22,
// punctuation...
- DOT = 21, COLON = 22, SEMICOLON = 23, COMMA = 24, BECOMES = 25, IS = 26,
+ DOT = 23, COLON = 24, SEMICOLON = 25, COMMA = 26, BECOMES = 27, IS = 28,
// brackets...
- LPAREN = 27, RPAREN = 28, LBRACKET = 29, RBRACKET = 30, LCURLY = 31, RCURLY = 32,
+ LPAREN = 29, RPAREN = 30, LBRACKET = 31, RBRACKET = 32, LCURLY = 33, RCURLY = 34,
// special tokens...
- EOT = 33, ERROR = 34;
+ EOT = 35, ERROR = 36;
private static String[] tokenTable = new String[] { "", "", "", "", "array",
- "begin", "const", "do", "else", "end", "func", "if", "in", "let", "of", "proc", "record", "then", "type",
- "var", "while", ".", ":", ";", ",", ":=", "~", "(", ")", "[", "]", "{", "}", "", "" };
+ "begin", "const", "do", "else", "end", "func", "if", "in", "let", "of", "proc", "record", "repeat", "then", "type",
+ "until", "var", "while", ".", ":", ";", ",", ":=", "~", "(", ")", "[", "]", "{", "}", "", "" };
private final static int firstReservedWord = Token.ARRAY, lastReservedWord = Token.WHILE;
diff --git a/Triangle.Compiler/src/main/java/triangle/treeDrawer/LayoutVisitor.java b/Triangle.Compiler/src/main/java/triangle/treeDrawer/LayoutVisitor.java
index dfa4b35..d521635 100644
--- a/Triangle.Compiler/src/main/java/triangle/treeDrawer/LayoutVisitor.java
+++ b/Triangle.Compiler/src/main/java/triangle/treeDrawer/LayoutVisitor.java
@@ -33,6 +33,7 @@ import triangle.abstractSyntaxTrees.commands.CallCommand;
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
import triangle.abstractSyntaxTrees.commands.IfCommand;
import triangle.abstractSyntaxTrees.commands.LetCommand;
+import triangle.abstractSyntaxTrees.commands.RepeatCommand;
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
import triangle.abstractSyntaxTrees.commands.WhileCommand;
import triangle.abstractSyntaxTrees.declarations.BinaryOperatorDeclaration;
@@ -158,6 +159,11 @@ public class LayoutVisitor implements ActualParameterVisitor,
var d2 = ast.C.visit(this);
return layoutBinary("WhileCom.", d1, d2);
}
+
+ @Override
+ public DrawingTree visitRepeatCommand(RepeatCommand ast, Void obj) {
+ return null;
+ }
// Expressions
@Override
diff --git a/Triangle.Compiler/src/test/java/triangle/syntacticAnalyser/TestScanner.java b/Triangle.Compiler/src/test/java/triangle/syntacticAnalyser/TestScanner.java
index ab10811..53a779f 100644
--- a/Triangle.Compiler/src/test/java/triangle/syntacticAnalyser/TestScanner.java
+++ b/Triangle.Compiler/src/test/java/triangle/syntacticAnalyser/TestScanner.java
@@ -22,28 +22,32 @@ public class TestScanner {
@Test
public void testHiNewComment() {
- compileExpectFailure("/hi-newcomment.tri");
+ compileExpectSuccess("/hi-newcomment.tri");
}
-
+ //[PRAC2:P2:5]
@Test
public void testHiNewComment2() {
- compileExpectFailure("/hi-newcomment2.tri");
+ compileExpectSuccess("/hi-newcomment2.tri");
}
@Test
public void testBarDemo() {
- compileExpectFailure("/bardemo.tri");
+ compileExpectSuccess("/bardemo.tri");
}
@Test
public void testRepeatUntil() {
- compileExpectFailure("/repeatuntil.tri");
+ compileExpectSuccess("/repeatuntil.tri");
}
-
+ //[PRAC2:P1:8]
+ @Test
+ public void testAdd() {
+ compileExpectSuccess("/add.tri");
+ }
private void compileExpectSuccess(String filename) {
// build.gradle has a line sourceSets.test.resources.srcDir file("$rootDir/programs")
diff --git a/build/libs/Triangle-Tools.jar b/build/libs/Triangle-Tools.jar
index 3d2dbf7..8343cc0 100644
Binary files a/build/libs/Triangle-Tools.jar and b/build/libs/Triangle-Tools.jar differ
diff --git a/programs/add.tam b/programs/add.tam
new file mode 100644
index 0000000..61ec9bb
Binary files /dev/null and b/programs/add.tam differ
diff --git a/programs/add.tri b/programs/add.tri
new file mode 100644
index 0000000..aa5e539
--- /dev/null
+++ b/programs/add.tri
@@ -0,0 +1,22 @@
+let
+ var a: Integer;
+ var b: Integer
+in
+begin
+ ! Get user input for both values
+ put('>'); put(' '); getint(var a);
+ put('>'); put(' '); getint(var b);
+
+ ! Sum
+ putint(a+b);
+ puteol();
+
+ ! Prod.
+ putint(a*b);
+ puteol();
+
+ ! Check if the same
+ if a = b
+ then begin put('S'); put('a'); put('m'); put('e'); put('!'); end
+ else !nothing
+end
diff --git a/programs/adddeep.tam b/programs/adddeep.tam
new file mode 100644
index 0000000..2daa905
Binary files /dev/null and b/programs/adddeep.tam differ
diff --git a/programs/errors.tri b/programs/errors.tri
index ed0e097..69e6e69 100644
--- a/programs/errors.tri
+++ b/programs/errors.tri
@@ -7,7 +7,7 @@ let
var me: Name;
var silly : maxint;
- var silly: Rec;
+ ! var silly: Rec; ! [PRAC2:5] Fixed error about "silly"
proc putstr (s: String) ~
let var i: Integer
diff --git a/programs/hi-newcomment.tam b/programs/hi-newcomment.tam
new file mode 100644
index 0000000..26e8273
Binary files /dev/null and b/programs/hi-newcomment.tam differ
diff --git a/programs/hi-newcomment2.tam b/programs/hi-newcomment2.tam
new file mode 100644
index 0000000..26e8273
Binary files /dev/null and b/programs/hi-newcomment2.tam differ
diff --git a/programs/repeatuntil.tam b/programs/repeatuntil.tam
new file mode 100644
index 0000000..7091eac
Binary files /dev/null and b/programs/repeatuntil.tam differ
diff --git a/programs/triangle.tri b/programs/triangle.tri
index 555ea81..af80255 100644
--- a/programs/triangle.tri
+++ b/programs/triangle.tri
@@ -1,5 +1,4 @@
let
-
proc putmany (n: Integer, c: Char) ~
let
var i: Integer