End of Prac2
This commit is contained in:
parent
1a339eb900
commit
841a7c9af2
6
.classpath
Normal file
6
.classpath
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||||
|
<classpathentry kind="output" path="bin/default"/>
|
||||||
|
</classpath>
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ tmp/
|
|||||||
.gradle/
|
.gradle/
|
||||||
|
|
||||||
|
|
||||||
|
/build/
|
||||||
|
23
.project
Normal file
23
.project
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Triangle-Tools</name>
|
||||||
|
<comment>Project Triangle-Tools created by Buildship.</comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
13
.settings/org.eclipse.buildship.core.prefs
Normal file
13
.settings/org.eclipse.buildship.core.prefs
Normal file
@ -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
|
4
.settings/org.eclipse.jdt.core.prefs
Normal file
4
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -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
|
@ -0,0 +1,2 @@
|
|||||||
|
connection.project.dir=..
|
||||||
|
eclipse.preferences.version=1
|
@ -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
|
1
Triangle.AbstractMachine.Disassembler/bin/.gitignore
vendored
Normal file
1
Triangle.AbstractMachine.Disassembler/bin/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/main/
|
@ -0,0 +1,2 @@
|
|||||||
|
connection.project.dir=..
|
||||||
|
eclipse.preferences.version=1
|
@ -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
|
1
Triangle.AbstractMachine.Interpreter/bin/.gitignore
vendored
Normal file
1
Triangle.AbstractMachine.Interpreter/bin/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/main/
|
@ -0,0 +1,2 @@
|
|||||||
|
connection.project.dir=..
|
||||||
|
eclipse.preferences.version=1
|
@ -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
|
1
Triangle.AbstractMachine/bin/.gitignore
vendored
Normal file
1
Triangle.AbstractMachine/bin/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/main/
|
@ -20,4 +20,11 @@
|
|||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
|
<linkedResources>
|
||||||
|
<link>
|
||||||
|
<name>programs</name>
|
||||||
|
<type>2</type>
|
||||||
|
<location>/home/simon/Documents/Uni/CS/CSCU9A5-2/Triangle-Tools/programs</location>
|
||||||
|
</link>
|
||||||
|
</linkedResources>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
connection.project.dir=..
|
||||||
|
eclipse.preferences.version=1
|
4
Triangle.Compiler/.settings/org.eclipse.jdt.core.prefs
Normal file
4
Triangle.Compiler/.settings/org.eclipse.jdt.core.prefs
Normal file
@ -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
|
2
Triangle.Compiler/bin/.gitignore
vendored
Normal file
2
Triangle.Compiler/bin/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/main/
|
||||||
|
/test/
|
@ -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 <TArg, TResult> TResult visit(CommandVisitor<TArg, TResult> v, TArg arg) {
|
||||||
|
return v.visitRepeatCommand(this, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression E;
|
||||||
|
public final Command C;
|
||||||
|
}
|
@ -5,6 +5,7 @@ import triangle.abstractSyntaxTrees.commands.CallCommand;
|
|||||||
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
|
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.IfCommand;
|
import triangle.abstractSyntaxTrees.commands.IfCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.LetCommand;
|
import triangle.abstractSyntaxTrees.commands.LetCommand;
|
||||||
|
import triangle.abstractSyntaxTrees.commands.RepeatCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
|
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.WhileCommand;
|
import triangle.abstractSyntaxTrees.commands.WhileCommand;
|
||||||
|
|
||||||
@ -24,4 +25,6 @@ public interface CommandVisitor<TArg, TResult> {
|
|||||||
|
|
||||||
TResult visitWhileCommand(WhileCommand ast, TArg arg);
|
TResult visitWhileCommand(WhileCommand ast, TArg arg);
|
||||||
|
|
||||||
|
TResult visitRepeatCommand(RepeatCommand ast, TArg arg);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ import triangle.abstractSyntaxTrees.commands.CallCommand;
|
|||||||
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
|
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.IfCommand;
|
import triangle.abstractSyntaxTrees.commands.IfCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.LetCommand;
|
import triangle.abstractSyntaxTrees.commands.LetCommand;
|
||||||
|
import triangle.abstractSyntaxTrees.commands.RepeatCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
|
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.WhileCommand;
|
import triangle.abstractSyntaxTrees.commands.WhileCommand;
|
||||||
import triangle.abstractSyntaxTrees.declarations.BinaryOperatorDeclaration;
|
import triangle.abstractSyntaxTrees.declarations.BinaryOperatorDeclaration;
|
||||||
@ -180,6 +181,11 @@ public final class Encoder implements ActualParameterVisitor<Frame, Integer>,
|
|||||||
emitter.emit(OpCode.JUMPIF, Machine.trueRep, Register.CB, loopAddr);
|
emitter.emit(OpCode.JUMPIF, Machine.trueRep, Register.CB, loopAddr);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void visitRepeatCommand(RepeatCommand ast, Frame frame) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Expressions
|
// Expressions
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,6 +34,7 @@ import triangle.abstractSyntaxTrees.commands.CallCommand;
|
|||||||
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
|
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.IfCommand;
|
import triangle.abstractSyntaxTrees.commands.IfCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.LetCommand;
|
import triangle.abstractSyntaxTrees.commands.LetCommand;
|
||||||
|
import triangle.abstractSyntaxTrees.commands.RepeatCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
|
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.WhileCommand;
|
import triangle.abstractSyntaxTrees.commands.WhileCommand;
|
||||||
import triangle.abstractSyntaxTrees.declarations.BinaryOperatorDeclaration;
|
import triangle.abstractSyntaxTrees.declarations.BinaryOperatorDeclaration;
|
||||||
@ -184,6 +185,11 @@ public final class Checker implements ActualParameterVisitor<FormalParameter, Vo
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void visitRepeatCommand(RepeatCommand ast, Void arg) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Expressions
|
// Expressions
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ import triangle.abstractSyntaxTrees.commands.CallCommand;
|
|||||||
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
|
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.IfCommand;
|
import triangle.abstractSyntaxTrees.commands.IfCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.LetCommand;
|
import triangle.abstractSyntaxTrees.commands.LetCommand;
|
||||||
|
import triangle.abstractSyntaxTrees.commands.RepeatCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
|
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.WhileCommand;
|
import triangle.abstractSyntaxTrees.commands.WhileCommand;
|
||||||
import triangle.abstractSyntaxTrees.declarations.BinaryOperatorDeclaration;
|
import triangle.abstractSyntaxTrees.declarations.BinaryOperatorDeclaration;
|
||||||
@ -495,17 +496,24 @@ public class ConstantFolder implements ActualParameterVisitor<Void, AbstractSynt
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Override
|
||||||
|
public AbstractSyntaxTree visitRepeatCommand(RepeatCommand ast, Void arg) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// TODO uncomment if you've implemented the repeat command
|
// TODO uncomment if you've implemented the repeat command
|
||||||
// @Override
|
@Override
|
||||||
// public AbstractSyntaxTree visitRepeatCommand(RepeatCommand ast, Void arg) {
|
public AbstractSyntaxTree visitRepeatCommand(RepeatCommand ast, Void arg) {
|
||||||
// ast.C.visit(this);
|
ast.C.visit(this);
|
||||||
// AbstractSyntaxTree replacement = ast.E.visit(this);
|
AbstractSyntaxTree replacement = ast.E.visit(this);
|
||||||
// if (replacement != null) {
|
if (replacement != null) {
|
||||||
// ast.E = (Expression) replacement;
|
ast.E = (Expression) replacement;
|
||||||
// }
|
}
|
||||||
// return null;
|
return null;
|
||||||
// }
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractSyntaxTree visitMultipleArrayAggregate(MultipleArrayAggregate ast, Void arg) {
|
public AbstractSyntaxTree visitMultipleArrayAggregate(MultipleArrayAggregate ast, Void arg) {
|
||||||
|
@ -37,6 +37,7 @@ import triangle.abstractSyntaxTrees.commands.Command;
|
|||||||
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
|
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.IfCommand;
|
import triangle.abstractSyntaxTrees.commands.IfCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.LetCommand;
|
import triangle.abstractSyntaxTrees.commands.LetCommand;
|
||||||
|
import triangle.abstractSyntaxTrees.commands.RepeatCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
|
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.WhileCommand;
|
import triangle.abstractSyntaxTrees.commands.WhileCommand;
|
||||||
import triangle.abstractSyntaxTrees.declarations.ConstDeclaration;
|
import triangle.abstractSyntaxTrees.declarations.ConstDeclaration;
|
||||||
@ -330,6 +331,16 @@ public class Parser {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Token.REPEAT: {
|
||||||
|
acceptIt();
|
||||||
|
Command cAST = parseSingleCommand();
|
||||||
|
accept(Token.UNTIL);
|
||||||
|
Expression eAST = parseExpression();
|
||||||
|
finish(commandPos);
|
||||||
|
commandAST = new RepeatCommand(eAST, cAST, commandPos);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case Token.SEMICOLON:
|
case Token.SEMICOLON:
|
||||||
case Token.END:
|
case Token.END:
|
||||||
case Token.ELSE:
|
case Token.ELSE:
|
||||||
|
@ -35,7 +35,7 @@ public final class Scanner {
|
|||||||
|
|
||||||
private boolean isOperator(char c) {
|
private boolean isOperator(char c) {
|
||||||
return (c == '+' || c == '-' || c == '*' || c == '/' || c == '=' || c == '<' || c == '>' || c == '\\'
|
return (c == '+' || c == '-' || c == '*' || c == '/' || c == '=' || c == '<' || c == '>' || 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) {
|
switch (currentChar) {
|
||||||
|
|
||||||
// comment
|
// comment
|
||||||
case '!': {
|
case '#': //[PRAC2:P2:3]
|
||||||
|
case '!':
|
||||||
takeIt();
|
takeIt();
|
||||||
while ((currentChar != SourceFile.EOL) && (currentChar != SourceFile.EOT))
|
while ((currentChar != SourceFile.EOL) && (currentChar != SourceFile.EOT))
|
||||||
takeIt();
|
takeIt();
|
||||||
if (currentChar == SourceFile.EOL)
|
if (currentChar == SourceFile.EOL)
|
||||||
takeIt();
|
takeIt();
|
||||||
}
|
|
||||||
break;
|
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
|
// whitespace
|
||||||
case ' ':
|
case ' ':
|
||||||
@ -173,6 +184,7 @@ public final class Scanner {
|
|||||||
case '%':
|
case '%':
|
||||||
case '^':
|
case '^':
|
||||||
case '?':
|
case '?':
|
||||||
|
case '|': //[PRAC2:P2:6]
|
||||||
takeIt();
|
takeIt();
|
||||||
while (isOperator(currentChar))
|
while (isOperator(currentChar))
|
||||||
takeIt();
|
takeIt();
|
||||||
@ -252,7 +264,7 @@ public final class Scanner {
|
|||||||
currentlyScanningToken = false;
|
currentlyScanningToken = false;
|
||||||
// skip any whitespace or comments
|
// skip any whitespace or comments
|
||||||
while (currentChar == '!' || currentChar == ' ' || currentChar == '\n' || currentChar == '\r'
|
while (currentChar == '!' || currentChar == ' ' || currentChar == '\n' || currentChar == '\r'
|
||||||
|| currentChar == '\t')
|
|| currentChar == '\t' || currentChar == '#' || currentChar == '$') //[PRAC2:P2:3 && 5]
|
||||||
scanSeparator();
|
scanSeparator();
|
||||||
|
|
||||||
currentlyScanningToken = true;
|
currentlyScanningToken = true;
|
||||||
|
@ -64,20 +64,20 @@ final class Token extends Object {
|
|||||||
|
|
||||||
// reserved words - must be in alphabetical order...
|
// 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,
|
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...
|
// 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...
|
// 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...
|
// special tokens...
|
||||||
EOT = 33, ERROR = 34;
|
EOT = 35, ERROR = 36;
|
||||||
|
|
||||||
private static String[] tokenTable = new String[] { "<int>", "<char>", "<identifier>", "<operator>", "array",
|
private static String[] tokenTable = new String[] { "<int>", "<char>", "<identifier>", "<operator>", "array",
|
||||||
"begin", "const", "do", "else", "end", "func", "if", "in", "let", "of", "proc", "record", "then", "type",
|
"begin", "const", "do", "else", "end", "func", "if", "in", "let", "of", "proc", "record", "repeat", "then", "type",
|
||||||
"var", "while", ".", ":", ";", ",", ":=", "~", "(", ")", "[", "]", "{", "}", "", "<error>" };
|
"until", "var", "while", ".", ":", ";", ",", ":=", "~", "(", ")", "[", "]", "{", "}", "", "<error>" };
|
||||||
|
|
||||||
private final static int firstReservedWord = Token.ARRAY, lastReservedWord = Token.WHILE;
|
private final static int firstReservedWord = Token.ARRAY, lastReservedWord = Token.WHILE;
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ import triangle.abstractSyntaxTrees.commands.CallCommand;
|
|||||||
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
|
import triangle.abstractSyntaxTrees.commands.EmptyCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.IfCommand;
|
import triangle.abstractSyntaxTrees.commands.IfCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.LetCommand;
|
import triangle.abstractSyntaxTrees.commands.LetCommand;
|
||||||
|
import triangle.abstractSyntaxTrees.commands.RepeatCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
|
import triangle.abstractSyntaxTrees.commands.SequentialCommand;
|
||||||
import triangle.abstractSyntaxTrees.commands.WhileCommand;
|
import triangle.abstractSyntaxTrees.commands.WhileCommand;
|
||||||
import triangle.abstractSyntaxTrees.declarations.BinaryOperatorDeclaration;
|
import triangle.abstractSyntaxTrees.declarations.BinaryOperatorDeclaration;
|
||||||
@ -158,6 +159,11 @@ public class LayoutVisitor implements ActualParameterVisitor<Void, DrawingTree>,
|
|||||||
var d2 = ast.C.visit(this);
|
var d2 = ast.C.visit(this);
|
||||||
return layoutBinary("WhileCom.", d1, d2);
|
return layoutBinary("WhileCom.", d1, d2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DrawingTree visitRepeatCommand(RepeatCommand ast, Void obj) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Expressions
|
// Expressions
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,28 +22,32 @@ public class TestScanner {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHiNewComment() {
|
public void testHiNewComment() {
|
||||||
compileExpectFailure("/hi-newcomment.tri");
|
compileExpectSuccess("/hi-newcomment.tri");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//[PRAC2:P2:5]
|
||||||
@Test
|
@Test
|
||||||
public void testHiNewComment2() {
|
public void testHiNewComment2() {
|
||||||
compileExpectFailure("/hi-newcomment2.tri");
|
compileExpectSuccess("/hi-newcomment2.tri");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBarDemo() {
|
public void testBarDemo() {
|
||||||
compileExpectFailure("/bardemo.tri");
|
compileExpectSuccess("/bardemo.tri");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRepeatUntil() {
|
public void testRepeatUntil() {
|
||||||
compileExpectFailure("/repeatuntil.tri");
|
compileExpectSuccess("/repeatuntil.tri");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//[PRAC2:P1:8]
|
||||||
|
@Test
|
||||||
|
public void testAdd() {
|
||||||
|
compileExpectSuccess("/add.tri");
|
||||||
|
}
|
||||||
|
|
||||||
private void compileExpectSuccess(String filename) {
|
private void compileExpectSuccess(String filename) {
|
||||||
// build.gradle has a line sourceSets.test.resources.srcDir file("$rootDir/programs")
|
// build.gradle has a line sourceSets.test.resources.srcDir file("$rootDir/programs")
|
||||||
|
Binary file not shown.
BIN
programs/add.tam
Normal file
BIN
programs/add.tam
Normal file
Binary file not shown.
22
programs/add.tri
Normal file
22
programs/add.tri
Normal file
@ -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
|
BIN
programs/adddeep.tam
Normal file
BIN
programs/adddeep.tam
Normal file
Binary file not shown.
@ -7,7 +7,7 @@ let
|
|||||||
|
|
||||||
var me: Name;
|
var me: Name;
|
||||||
var silly : maxint;
|
var silly : maxint;
|
||||||
var silly: Rec;
|
! var silly: Rec; ! [PRAC2:5] Fixed error about "silly"
|
||||||
|
|
||||||
proc putstr (s: String) ~
|
proc putstr (s: String) ~
|
||||||
let var i: Integer
|
let var i: Integer
|
||||||
|
BIN
programs/hi-newcomment.tam
Normal file
BIN
programs/hi-newcomment.tam
Normal file
Binary file not shown.
BIN
programs/hi-newcomment2.tam
Normal file
BIN
programs/hi-newcomment2.tam
Normal file
Binary file not shown.
BIN
programs/repeatuntil.tam
Normal file
BIN
programs/repeatuntil.tam
Normal file
Binary file not shown.
@ -1,5 +1,4 @@
|
|||||||
let
|
let
|
||||||
|
|
||||||
proc putmany (n: Integer, c: Char) ~
|
proc putmany (n: Integer, c: Char) ~
|
||||||
let
|
let
|
||||||
var i: Integer
|
var i: Integer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user