Skip to content

Commit 8fc6041

Browse files
committed
Everything done for phase 1
1 parent b396816 commit 8fc6041

16 files changed

+165
-132
lines changed

CodeGenerator.java

-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ public void outAEqExpr(AEqExpr node) {
234234
}
235235

236236
/********************************* Getter and Setter **************************************/
237-
238237
public HashMap<String, Integer> getSymbolTable() {
239238
return symbolTable;
240239
}

Pascal.class

82 Bytes
Binary file not shown.

Pascal.j

+40-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
return
1010
.end method
1111
.method public static main([Ljava/lang/String;)V
12-
.limit stack 9
12+
.limit stack 17
1313
.limit locals 5
1414
bipush 1
1515
istore 2
1616
bipush 1
1717
istore 3
1818
iload 3
1919
istore 2
20+
bipush 1
21+
istore 4
2022
LabelWhileUp0:
2123
iload 2
2224
bipush 100
@@ -52,8 +54,45 @@ LabelCompEnd1:
5254
goto LabelWhileDown0
5355
LabelIfElse1:
5456
getstatic java/lang/System/out Ljava/io/PrintStream;
57+
iload 2
58+
invokevirtual java/io/PrintStream/println(I)V
59+
bipush 1
60+
bipush 2
61+
isub
62+
iflt LabelTrue2
63+
bipush 0
64+
goto LabelCompEnd2
65+
LabelTrue2:
66+
bipush 1
67+
LabelCompEnd2:
68+
ifeq LabelIfElse2
69+
getstatic java/lang/System/out Ljava/io/PrintStream;
70+
bipush 0
71+
invokevirtual java/io/PrintStream/println(I)V
72+
LabelIfElse2:
73+
getstatic java/lang/System/out Ljava/io/PrintStream;
74+
bipush 100
75+
invokevirtual java/io/PrintStream/println(I)V
76+
LabelWhileUp3:
77+
iload 4
78+
bipush 5
79+
isub
80+
iflt LabelTrue3
5581
bipush 0
82+
goto LabelCompEnd3
83+
LabelTrue3:
84+
bipush 1
85+
LabelCompEnd3:
86+
ifeq LabelWhileDown3
87+
getstatic java/lang/System/out Ljava/io/PrintStream;
88+
iload 4
5689
invokevirtual java/io/PrintStream/println(I)V
90+
iload 4
91+
bipush 1
92+
iadd
93+
istore 4
94+
goto LabelWhileUp3
95+
LabelWhileDown3:
5796
goto LabelWhileUp0
5897
LabelWhileDown0:
5998
getstatic java/lang/System/out Ljava/io/PrintStream;

Pascal.pas

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
program fibonacci;;
1+
program fibonacci;
22
var a : integer;
33
var b,D: integer;
44
var temp : integer;
55
begin
66
a := 1;
77
b := 1;
88
a := b;
9+
d := 1;
910
while a < 100 do
1011
begin
1112
writeln(a);
1213
temp := b;
1314
b := a + b;
1415
a := temp ;
15-
if a > 34 then break else writeln(0);
16+
if a > 34 then break else
17+
begin
18+
writeln(a);
19+
if 1 < 2 then writeln(0) else writeln(100);
20+
while d < 5 do
21+
begin
22+
writeln(d);
23+
d := d+1;
24+
end;
25+
end;
1626
end;
1727
writeln(10)
1828
end.

StupsCompiler.class

2.34 KB
Binary file not shown.

StupsCompiler.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* - Catch uninitialized variables *
1010
*************************************************************************/
1111

12-
import com.sun.tools.corba.se.idl.IncludeGen;
1312
import lexer.Lexer;
1413
import lexer.LexerException;
1514
import node.Start;
@@ -22,18 +21,21 @@ public class StupsCompiler {
2221

2322
public static void main(String[] args) throws LexerException, IOException, ParserException {
2423
String input = "";
25-
String fileName = args[1];
24+
String fileName = "";
2625
if (args.length < 2) { // catch valid number of arguments
2726
System.out.println("# Error: Not enough arguments.\n# Usage: > java StupsCompiler -argument <Filename.pas>\n# Valid arguments are: compile, liveness.");
2827
System.exit(1);
2928
}
3029
if (!args[1].endsWith(".pas")) { // catch valid file extension
3130
System.out.println("# Error: Valid file extension is only '.pas'.");
3231
System.exit(1);
32+
} else {
33+
fileName = args[1];
3334
}
3435
try {
3536
if (args[0].equals("-compile")) { // Compile section
3637
String zeile;
38+
fileName = args[1];
3739
FileReader fr = new FileReader(fileName);
3840
BufferedReader br = new BufferedReader(fr);
3941

TypeChecker.class

695 Bytes
Binary file not shown.

TypeChecker.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public void caseAIdentifierExpr(AIdentifierExpr node) {
273273
String identifier = node.getIdentifier().toString().toLowerCase().replaceAll(" ","");
274274
checkDeclared(identifier);
275275
if (varInitialized.get(identifier) == 0) {
276-
System.out.println("# Error: Identifier '"+identifier+"' has not been initialized. Terminating...");
276+
System.out.println("# Error: Identifier '"+identifier+"' has been declared, but not initialized. Terminating...");
277277
System.exit(1);
278278
}
279279
this.result = symbolTable.get(identifier);
@@ -310,4 +310,4 @@ private void printErrorBooleanOperation(String operation) {
310310
public HashMap<String, String> getSymbolTable() {
311311
return symbolTable;
312312
}
313-
}
313+
}

out/production/projekt/.idea/workspace.xml

+55-93
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 Bytes
Binary file not shown.

out/production/projekt/Out.j

-28
This file was deleted.

out/production/projekt/Pascal.j

+40-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
return
1010
.end method
1111
.method public static main([Ljava/lang/String;)V
12-
.limit stack 9
12+
.limit stack 17
1313
.limit locals 5
1414
bipush 1
1515
istore 2
1616
bipush 1
1717
istore 3
1818
iload 3
1919
istore 2
20+
bipush 1
21+
istore 4
2022
LabelWhileUp0:
2123
iload 2
2224
bipush 100
@@ -52,8 +54,45 @@ LabelCompEnd1:
5254
goto LabelWhileDown0
5355
LabelIfElse1:
5456
getstatic java/lang/System/out Ljava/io/PrintStream;
57+
iload 2
58+
invokevirtual java/io/PrintStream/println(I)V
59+
bipush 1
60+
bipush 2
61+
isub
62+
iflt LabelTrue2
63+
bipush 0
64+
goto LabelCompEnd2
65+
LabelTrue2:
66+
bipush 1
67+
LabelCompEnd2:
68+
ifeq LabelIfElse2
69+
getstatic java/lang/System/out Ljava/io/PrintStream;
70+
bipush 0
71+
invokevirtual java/io/PrintStream/println(I)V
72+
LabelIfElse2:
73+
getstatic java/lang/System/out Ljava/io/PrintStream;
74+
bipush 100
75+
invokevirtual java/io/PrintStream/println(I)V
76+
LabelWhileUp3:
77+
iload 4
78+
bipush 5
79+
isub
80+
iflt LabelTrue3
5581
bipush 0
82+
goto LabelCompEnd3
83+
LabelTrue3:
84+
bipush 1
85+
LabelCompEnd3:
86+
ifeq LabelWhileDown3
87+
getstatic java/lang/System/out Ljava/io/PrintStream;
88+
iload 4
5689
invokevirtual java/io/PrintStream/println(I)V
90+
iload 4
91+
bipush 1
92+
iadd
93+
istore 4
94+
goto LabelWhileUp3
95+
LabelWhileDown3:
5796
goto LabelWhileUp0
5897
LabelWhileDown0:
5998
getstatic java/lang/System/out Ljava/io/PrintStream;

out/production/projekt/Pascal.pas

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
program fibonacci;;
1+
program fibonacci;
22
var a : integer;
33
var b,D: integer;
44
var temp : integer;
55
begin
66
a := 1;
77
b := 1;
88
a := b;
9+
d := 1;
910
while a < 100 do
1011
begin
1112
writeln(a);
1213
temp := b;
1314
b := a + b;
1415
a := temp ;
15-
if a > 34 then break else writeln(0);
16+
if a > 34 then break else
17+
begin
18+
writeln(a);
19+
if 1 < 2 then writeln(0) else writeln(100);
20+
while d < 5 do
21+
begin
22+
writeln(d);
23+
d := d+1;
24+
end;
25+
end;
1626
end;
1727
writeln(10)
1828
end.
31 Bytes
Binary file not shown.
14 Bytes
Binary file not shown.

parser/Parser.class

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)