Compare commits

...

6 Commits

Author SHA1 Message Date
simonkellet befe8f93a2 eclipse and gradle changes 2 years ago
simonkellet 7c64cb7eff added new tri files 2 years ago
simonkellet a4c304f58d changes to tam 2 years ago
simonkellet 36f3fac111 added build folder ignore 2 years ago
simonkellet cd280e3c4b added test case for new comment 2 years ago
simonkellet d28b3c7403 added new comment 2 years ago
  1. 6
      .classpath
  2. 3
      .gitignore
  3. 6
      .project
  4. 7
      Triangle.Compiler/.project
  5. 12
      Triangle.Compiler/src/main/java/triangle/syntacticAnalyzer/Scanner.java
  6. 8
      Triangle.Compiler/src/test/java/triangle/syntacticAnalyser/TestScanner.java
  7. BIN
      build/libs/Triangle-Tools.jar
  8. 46
      programs/add.tri
  9. 30
      programs/errorsfix.tri
  10. 3
      tam

@ -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>

3
.gitignore vendored

@ -63,3 +63,6 @@ local.properties
# tam files
*.tam
# Build folder
/build/

@ -5,6 +5,11 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
@ -12,6 +17,7 @@
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>

@ -20,4 +20,11 @@
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<linkedResources>
<link>
<name>programs</name>
<type>2</type>
<location>/home/simon/Documents/Uni/CS/CSCU9A5/Triangle-Tools/programs</location>
</link>
</linkedResources>
</projectDescription>

@ -73,6 +73,16 @@ public final class Scanner {
takeIt();
}
break;
// new type of comment, the # comment, same as before when it comes to code
case '#':{
takeIt();
while((currentChar != SourceFile.EOL) && (currentChar != SourceFile.EOT))
takeIt();
if(currentChar == SourceFile.EOL)
takeIt();
}
break;
// whitespace
case ' ':
@ -252,7 +262,7 @@ public final class Scanner {
currentlyScanningToken = false;
// skip any whitespace or comments
while (currentChar == '!' || currentChar == ' ' || currentChar == '\n' || currentChar == '\r'
|| currentChar == '\t')
|| currentChar == '\t' || currentChar == '#')
scanSeparator();
currentlyScanningToken = true;

@ -22,7 +22,7 @@ public class TestScanner {
@Test
public void testHiNewComment() {
compileExpectFailure("/hi-newcomment.tri");
compileExpectSuccess("/hi-newcomment.tri");
}
@ -43,6 +43,12 @@ public class TestScanner {
compileExpectFailure("/repeatuntil.tri");
}
@Test
public void testAdd() {
//compileExpectFailure("/addd.tri"); //fail here!
compileExpectFailure("/add.tri");
}
private void compileExpectSuccess(String filename) {

Binary file not shown.

@ -0,0 +1,46 @@
! Program that will: read two ints, print their sum and their product. If they are the same, print "Same"
! Global Consts, Funcs.
let
type String ~ array 6 of Char; ! String type implemented, not used yet
var num1 : Integer;
var num2 : Integer;
func sum(x : Integer, y : Integer) : Integer ~
x + y; ! Return x + y
func product(x : Integer, y : Integer) : Integer ~
x * y; ! Return x * y
func isSame(x : Integer, y : Integer) : Boolean ~
if x = y then true else false
! Main Loop
in
begin
num1 := 0;
num2 := 0; ! Init. values to 0
getint(var num1);
getint(var num2); ! Get user input
! Sum
putint(num1); put('+'); put(' '); putint(num2); put(' '); put('='); put(' ');
putint(sum(num1, num2)); puteol();
puteol();
! Product
putint(num1); put(' '); put('*'); put(' '); putint(num2); put(' '); put('='); put(' ');
putint(product(num1, num2)); puteol();
if isSame(num1, num2) = true then
put('S'); put('a'); put('m'); put('e'); puteol();
else
puteol();
end

@ -0,0 +1,30 @@
! Program with a variety of contextual errors.
let
type String ~ array 4 of Char;
type Name ~ array 3 of String;
type Rec ~ record x: Integer, x: Integer end;
var me: Name;
var silly : maxint;
var silly: Rec;
proc putstr (s: String) ~
let var i: Integer
in
begin
s[4] := ' ';
i := 0;
while i do
begin i := i+true;
put (s[\i])
end
end
in
begin
me[true] := ['T','i','n','y'];
me[2][2] := 0;
put (me[1]); put (4); put ();
putstr (initials (me)); puteol ()
end

3
tam

@ -16,7 +16,8 @@ fi
printf "${GRN}Compiling file: $1.tri to $1.tam ...${NC}\n"
# Compile to tam
java -cp build/libs/Triangle-Tools.jar triangle.Compiler programs/$1.tri -o=$1.tam &> /dev/null
#java -cp build/libs/Triangle-Tools.jar triangle.Compiler programs/$1.tri -o=$1.tam &> /dev/null #Quiet output, not handy!
java -cp build/libs/Triangle-Tools.jar triangle.Compiler programs/$1.tri -o=$1.tam
printf "${GRN}Running file: $1.tam ...${NC}\n"
# Run the Program