Skip to content

Commit ca2dd5d

Browse files
committed
Automated all the testcases
1 parent 8fc6041 commit ca2dd5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+2747
-763
lines changed

Diff for: CodeGenerator.class

8 KB
Binary file not shown.

Diff for: CodeGenerator.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
/**
77
* Need to test:
8-
* - UnaryMinus
98
* - UnaryPlus not necessary?
109
*/
1110

@@ -44,7 +43,13 @@ public void outAXorExpr(AXorExpr node) {
4443
}
4544
@Override
4645
public void outANotExpr(ANotExpr node) {
47-
code += "\tineg\n";
46+
int temp = countLabels++;
47+
code += "\tifeq LabelNotTrue"+temp+"\n";
48+
code += "\tbipush 0\n";
49+
code += "\tgoto LabelNotEnd"+temp+"\n";
50+
code += "LabelNotTrue"+temp+":\n";
51+
code += "\tbipush 1\n";
52+
code += "\tLabelNotEnd"+temp+":\n";
4853
type = "boolean";
4954
}
5055
// Arithmetic operations
@@ -115,7 +120,11 @@ public void caseAAssignmentExpr(AAssignmentExpr node) {
115120
}
116121
@Override
117122
public void caseANumberExpr(ANumberExpr node) {
118-
code += "\tbipush "+node.getNumber().toString().replaceAll(" ","")+"\n";
123+
int number = Integer.parseInt(node.getNumber().toString().replaceAll(" ", ""));
124+
if (number > 255)
125+
code += "\tldc "+number+"\n";
126+
else
127+
code += "\tbipush "+number+"\n";
119128
stackHeight++;
120129
type = "integer";
121130
}
@@ -144,7 +153,6 @@ public void caseAPrintExpr(APrintExpr node) {
144153
// While loop
145154
@Override
146155
public void caseAWhileExpr(AWhileExpr node) {
147-
breakCounter = countLabels;
148156
int temp = countLabels++;
149157
code += "LabelWhileUp"+temp+":\n";
150158
node.getLeft().apply(this);
@@ -153,12 +161,13 @@ public void caseAWhileExpr(AWhileExpr node) {
153161
node.getRight().apply(this);
154162
code += "\tgoto LabelWhileUp"+temp+"\n";
155163
code += "LabelWhileDown"+temp+":\n";
164+
code += "LabelBreakDown"+(breakCounter++)+":\n";
156165
}
157166

158167
// Break
159168
@Override
160169
public void caseABreakExpr(ABreakExpr node) {
161-
code += "\tgoto LabelWhileDown"+breakCounter+"\n";
170+
code += "\tgoto LabelBreakDown"+breakCounter+"\n";
162171
}
163172

164173
// If-then Part
@@ -180,8 +189,10 @@ public void caseAIfThenElseExpr(AIfThenElseExpr node) {
180189
code += "\tifeq LabelIfElse"+temp+"\n";
181190
stackHeight--;
182191
node.getThen().apply(this);
192+
code += "\tgoto LabelIfElseEnd"+temp+"\n";
183193
code += "LabelIfElse"+temp+":\n";
184194
node.getElse().apply(this);
195+
code += "LabelIfElseEnd"+temp+":\n";
185196
}
186197

187198
// Comparisons

Diff for: CodeGeneratorException.class

401 Bytes
Binary file not shown.

Diff for: Liveness.java

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Created with IntelliJ IDEA.
3+
* User: cmeter
4+
* Date: 10.01.13
5+
* Time: 19:53
6+
* To change this template use File | Settings | File Templates.
7+
*/
8+
public class Liveness {
9+
10+
}

Diff for: Pascal.class

-6 Bytes
Binary file not shown.

Diff for: Pascal.j

+39-50
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
return
1010
.end method
1111
.method public static main([Ljava/lang/String;)V
12-
.limit stack 17
13-
.limit locals 5
14-
bipush 1
15-
istore 2
12+
.limit stack 14
13+
.limit locals 4
1614
bipush 1
15+
istore 1
16+
iload 1
1717
istore 3
1818
iload 3
19+
iload 1
20+
iadd
1921
istore 2
20-
bipush 1
21-
istore 4
2222
LabelWhileUp0:
23-
iload 2
24-
bipush 100
23+
iload 1
24+
bipush 10
2525
isub
2626
iflt LabelTrue0
2727
bipush 0
@@ -30,73 +30,62 @@ LabelTrue0:
3030
bipush 1
3131
LabelCompEnd0:
3232
ifeq LabelWhileDown0
33-
getstatic java/lang/System/out Ljava/io/PrintStream;
34-
iload 2
35-
invokevirtual java/io/PrintStream/println(I)V
36-
iload 3
33+
iload 1
34+
bipush 1
35+
iadd
3736
istore 1
38-
iload 2
37+
LabelWhileUp1:
3938
iload 3
40-
iadd
41-
istore 3
42-
iload 1
43-
istore 2
44-
iload 2
45-
bipush 34
39+
bipush 10
4640
isub
47-
ifgt LabelTrue1
41+
iflt LabelTrue1
4842
bipush 0
4943
goto LabelCompEnd1
5044
LabelTrue1:
5145
bipush 1
5246
LabelCompEnd1:
53-
ifeq LabelIfElse1
54-
goto LabelWhileDown0
55-
LabelIfElse1:
56-
getstatic java/lang/System/out Ljava/io/PrintStream;
57-
iload 2
58-
invokevirtual java/io/PrintStream/println(I)V
47+
ifeq LabelWhileDown1
48+
iload 3
5949
bipush 1
60-
bipush 2
50+
iadd
51+
istore 3
52+
goto LabelWhileUp1
53+
LabelWhileDown1:
54+
LabelBreakDown0:
55+
LabelWhileUp2:
56+
iload 2
57+
bipush 10
6158
isub
6259
iflt LabelTrue2
6360
bipush 0
6461
goto LabelCompEnd2
6562
LabelTrue2:
6663
bipush 1
6764
LabelCompEnd2:
68-
ifeq LabelIfElse2
65+
ifeq LabelWhileDown2
6966
getstatic java/lang/System/out Ljava/io/PrintStream;
70-
bipush 0
67+
iload 2
7168
invokevirtual java/io/PrintStream/println(I)V
72-
LabelIfElse2:
69+
goto LabelBreakDown1
7370
getstatic java/lang/System/out Ljava/io/PrintStream;
74-
bipush 100
71+
ldc 111111
7572
invokevirtual java/io/PrintStream/println(I)V
76-
LabelWhileUp3:
77-
iload 4
78-
bipush 5
79-
isub
80-
iflt LabelTrue3
81-
bipush 0
82-
goto LabelCompEnd3
83-
LabelTrue3:
84-
bipush 1
85-
LabelCompEnd3:
86-
ifeq LabelWhileDown3
73+
goto LabelWhileUp2
74+
LabelWhileDown2:
75+
LabelBreakDown1:
76+
goto LabelBreakDown2
8777
getstatic java/lang/System/out Ljava/io/PrintStream;
88-
iload 4
78+
ldc 222222
79+
invokevirtual java/io/PrintStream/println(I)V
80+
goto LabelBreakDown2
81+
getstatic java/lang/System/out Ljava/io/PrintStream;
82+
ldc 333333
8983
invokevirtual java/io/PrintStream/println(I)V
90-
iload 4
91-
bipush 1
92-
iadd
93-
istore 4
94-
goto LabelWhileUp3
95-
LabelWhileDown3:
9684
goto LabelWhileUp0
9785
LabelWhileDown0:
86+
LabelBreakDown2:
9887
getstatic java/lang/System/out Ljava/io/PrintStream;
99-
bipush 10
88+
ldc 999999
10089
invokevirtual java/io/PrintStream/println(I)V
10190
return
10291
.end method

Diff for: Pascal.pas

+25-26
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
program fibonacci;
2-
var a : integer;
3-
var b,D: integer;
4-
var temp : integer;
1+
program parenthesis;
2+
var a,c,b : integer;
53
begin
6-
a := 1;
7-
b := 1;
8-
a := b;
9-
d := 1;
10-
while a < 100 do
11-
begin
12-
writeln(a);
13-
temp := b;
14-
b := a + b;
15-
a := temp ;
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;
26-
end;
27-
writeln(10)
4+
a := 1;
5+
b := a;
6+
c := b+a;
7+
8+
while a < 10 do
9+
begin
10+
a := a+1;
11+
while b < 10 do
12+
b := b+1;
13+
begin
14+
while c < 10 do
15+
begin
16+
writeln(c);
17+
break;
18+
writeln(111111);
19+
end;
20+
break;
21+
writeln(222222);
22+
end;
23+
break;
24+
writeln(333333);
25+
end
26+
writeln(999999);
2827
end.

Diff for: StupsCompiler.class

27 Bytes
Binary file not shown.

Diff for: StupsCompiler.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@ public static void main(String[] args) throws LexerException, IOException, Parse
3333
fileName = args[1];
3434
}
3535
try {
36-
if (args[0].equals("-compile")) { // Compile section
37-
String zeile;
38-
fileName = args[1];
39-
FileReader fr = new FileReader(fileName);
40-
BufferedReader br = new BufferedReader(fr);
36+
String zeile;
37+
fileName = args[1];
38+
FileReader fr = new FileReader(fileName);
39+
BufferedReader br = new BufferedReader(fr);
4140

41+
zeile = br.readLine();
42+
while (zeile != null) {
43+
input += zeile+"\n";
4244
zeile = br.readLine();
43-
while (zeile != null) {
44-
input += zeile+"\n";
45-
zeile = br.readLine();
46-
}
47-
br.close();
45+
}
46+
br.close();
47+
48+
if (args[0].equals("-compile")) { // Compile section
4849
parse(input, fileName.substring(0, fileName.lastIndexOf('.')));
4950

5051
} else if (args[0].equals("-liveness")) {
@@ -71,9 +72,9 @@ private static void printErrorLine(String message, String input) {
7172
int pos = Integer.parseInt(message.substring(message.indexOf(',') + 1, message.indexOf(']')));
7273
String[] split = input.split("\n");
7374

75+
if (line > split.length) line--;
7476
System.out.println("# "+split[line-1]);
7577
System.out.print("#");
76-
pos += 0;
7778
while (pos != 0) {
7879
System.out.print(" ");
7980
pos--;
@@ -105,7 +106,6 @@ private static void parse(String input, String fileName) throws ParserException,
105106
start.apply(codeGenerator);
106107

107108
output = createOutput(codeGenerator, fileName);
108-
// System.out.println(output);
109109

110110
Writer wout = new BufferedWriter( // Write everything to the outputfile.j
111111
new OutputStreamWriter(

Diff for: TypeChecker.class

-82 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)