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..3beb06b --- /dev/null +++ b/Triangle.Compiler/src/main/java/triangle/abstractSyntaxTrees/commands/RepeatCommand.java @@ -0,0 +1,21 @@ +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 final 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..21bedd4 100644 --- a/Triangle.Compiler/src/main/java/triangle/abstractSyntaxTrees/visitors/CommandVisitor.java +++ b/Triangle.Compiler/src/main/java/triangle/abstractSyntaxTrees/visitors/CommandVisitor.java @@ -5,11 +5,11 @@ 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; public interface CommandVisitor { - TResult visitAssignCommand(AssignCommand ast, TArg arg); TResult visitCallCommand(CallCommand ast, TArg arg); @@ -23,5 +23,7 @@ public interface CommandVisitor { TResult visitSequentialCommand(SequentialCommand ast, TArg arg); TResult visitWhileCommand(WhileCommand ast, TArg arg); + + TResult visitRepeatCommand(RepeatCommand ast, TArg arg); -} +} \ No newline at end of file diff --git a/Triangle.Compiler/src/main/java/triangle/codeGenerator/Encoder.java b/Triangle.Compiler/src/main/java/triangle/codeGenerator/Encoder.java index 3066815..e0d24a9 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 == '|'); } /////////////////////////////////////////////////////////////////////////////// @@ -64,7 +64,7 @@ public final class Scanner { private void scanSeparator() { switch (currentChar) { - // comment + // ! comment case '!': { takeIt(); while ((currentChar != SourceFile.EOL) && (currentChar != SourceFile.EOT)) @@ -199,6 +199,13 @@ public final class Scanner { while (isOperator(currentChar)) takeIt(); return Token.OPERATOR; + + // TODO: Bar operator, week 3 + case '|': + takeIt(); + while(isOperator(currentChar)) + takeIt(); + return Token.OPERATOR; case '\'': takeIt(); 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 0d9a628..e6fa151 100644 --- a/Triangle.Compiler/src/test/java/triangle/syntacticAnalyser/TestScanner.java +++ b/Triangle.Compiler/src/test/java/triangle/syntacticAnalyser/TestScanner.java @@ -34,13 +34,13 @@ public class TestScanner { @Test public void testBarDemo() { - compileExpectFailure("/bardemo.tri"); + compileExpectSuccess("/bardemo.tri"); //TODO: Change this to failure } @Test public void testRepeatUntil() { - compileExpectFailure("/repeatuntil.tri"); + compileExpectSuccess("/repeatuntil.tri"); } @Test diff --git a/build/libs/Triangle-Tools.jar b/build/libs/Triangle-Tools.jar index da61661..4c3d7f4 100644 Binary files a/build/libs/Triangle-Tools.jar and b/build/libs/Triangle-Tools.jar differ