Skip to content

Commit 644bb22

Browse files
committed
Corrected separating semicolons
1 parent 9eb8fd6 commit 644bb22

22 files changed

+764
-642
lines changed

ASTTypechecker.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public void caseAOrExpr(AOrExpr node) {
8383
String operation = "or";
8484
node.getLeft().apply(this);
8585
String left = this.result;
86-
node.getRight().apply(this);
8786
String right = this.result;
8887

8988
if (!left.equals(right))
@@ -159,6 +158,18 @@ public void caseAMinusExpr(AMinusExpr node) {
159158
printValidOperation(operation);
160159
}
161160
@Override
161+
public void caseAUnaryMinusExpr(AUnaryMinusExpr node) {
162+
String operation = "unaryminus";
163+
node.getExpr().apply(this);
164+
165+
System.out.println("+ "+node.getExpr().getClass().getSimpleName());
166+
167+
if (!result.equals("integer") || !node.getExpr().getClass().getSimpleName().equals("AIdentifierExpr"))
168+
printErrorArithmeticOperation(operation);
169+
else
170+
printValidOperation(operation);
171+
}
172+
@Override
162173
public void caseAModExpr(AModExpr node) {
163174
String operation = "mod";
164175
node.getLeft().apply(this);

Pascal.pas

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
var a : integer;
33
var b: integer;
44
var temp : integer ;
5+
var c : boolean;
56

67
begin
8+
9+
//if 2=2 and not 2<>2 then writeln(1);
10+
// c := true = 1<2;
711
a := 1;
812
b := 1;
913
while True do
1014
begin
1115
writeln(a);
12-
temp := b;
16+
temp := -b;
1317
b := a + b;
1418
a := temp;
15-
;
1619
end
1720
end.

StupsCompiler.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,47 @@
99
public class StupsCompiler {
1010

1111
public static void main(String[] args) throws LexerException, IOException, ParserException {
12-
String input = "";
13-
String zeile;
14-
FileReader fr = new FileReader(args[0]);
15-
BufferedReader br = new BufferedReader(fr);
16-
17-
zeile = br.readLine();
18-
while (zeile != null) {
19-
input += zeile+"\n";
12+
if (args.length < 2) {
13+
System.out.println("# Error: Not enough arguments.\n# Usage: > java StupsCompiler -compile <Filename.pas>");
14+
} else if (args[0].equals("-compile")) {
15+
String input = "";
16+
String zeile;
17+
FileReader fr = new FileReader(args[1]);
18+
BufferedReader br = new BufferedReader(fr);
19+
2020
zeile = br.readLine();
21+
while (zeile != null) {
22+
input += zeile+"\n";
23+
zeile = br.readLine();
24+
}
25+
br.close();
26+
27+
System.out.println("############################################################################");
28+
System.out.println("# Input: \n"+input);
29+
System.out.println("############################################################################");
30+
parse(input);
31+
} else if (args[0].equals("-liveness")) {
32+
// Write something about liveness...
33+
} else {
34+
System.out.println("# Error: Wrong usage of StupsCompiler.\n# Usage: > java StupsCompiler -compile <Filename.pas>");
2135
}
22-
br.close();
23-
24-
System.out.println("############################################################################");
25-
System.out.println("# Input: \n"+input);
26-
System.out.println("############################################################################");
27-
parse(input);
2836
}
2937

3038
private static void parse(String input) throws ParserException, LexerException, IOException {
3139
StringReader reader = new StringReader(input);
3240
PushbackReader r = new PushbackReader(reader, 100);
33-
System.out.println("# Starting Lexing and Parsing...");
41+
System.out.println("# Start Lexing and Parsing...");
3442
Lexer l = new Lexer(r);
3543
Parser parser = new Parser(l);
3644
Start start = parser.parse();
3745
System.out.println("# Lexing and Parsing: Finished with no errors.\n");
3846

39-
System.out.println("# Starting print the AST...");
47+
System.out.println("# Start printing the AST...");
4048
ASTPrinter printer = new ASTPrinter();
4149
start.apply(printer);
4250
System.out.println("# AST: Finished with no errors.\n");
4351

44-
System.out.println("# Starting TypeChecker...");
52+
System.out.println("# Start TypeChecker...");
4553
ASTTypeChecker interpreter = new ASTTypeChecker();
4654
start.apply(interpreter);
4755
System.out.println("# TypeChecker: Finished with no errors.\n");

analysis/Analysis.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public interface Analysis extends Switch
1414
void caseStart(Start node);
1515
void caseAStartExpr(AStartExpr node);
1616
void caseAStatementExpr(AStatementExpr node);
17+
void caseAStatementListExpr(AStatementListExpr node);
1718
void caseADeclarationExpr(ADeclarationExpr node);
1819
void caseAPrintExpr(APrintExpr node);
1920
void caseAAssignmentExpr(AAssignmentExpr node);
@@ -27,6 +28,8 @@ public interface Analysis extends Switch
2728
void caseADivExpr(ADivExpr node);
2829
void caseAAndExpr(AAndExpr node);
2930
void caseANotExpr(ANotExpr node);
31+
void caseAUnaryMinusExpr(AUnaryMinusExpr node);
32+
void caseAUnaryPlusExpr(AUnaryPlusExpr node);
3033
void caseAWhileExpr(AWhileExpr node);
3134
void caseAIfThenExpr(AIfThenExpr node);
3235
void caseAIfThenElseExpr(AIfThenElseExpr node);

analysis/AnalysisAdapter.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ public void caseAStatementExpr(AStatementExpr node)
8686
defaultCase(node);
8787
}
8888

89+
@Override
90+
public void caseAStatementListExpr(AStatementListExpr node)
91+
{
92+
defaultCase(node);
93+
}
94+
8995
@Override
9096
public void caseADeclarationExpr(ADeclarationExpr node)
9197
{
@@ -164,6 +170,18 @@ public void caseANotExpr(ANotExpr node)
164170
defaultCase(node);
165171
}
166172

173+
@Override
174+
public void caseAUnaryMinusExpr(AUnaryMinusExpr node)
175+
{
176+
defaultCase(node);
177+
}
178+
179+
@Override
180+
public void caseAUnaryPlusExpr(AUnaryPlusExpr node)
181+
{
182+
defaultCase(node);
183+
}
184+
167185
@Override
168186
public void caseAWhileExpr(AWhileExpr node)
169187
{

analysis/DepthFirstAdapter.java

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,9 @@ public void caseAStartExpr(AStartExpr node)
6161
e.apply(this);
6262
}
6363
}
64+
if(node.getStatementList() != null)
6465
{
65-
List<PExpr> copy = new ArrayList<PExpr>(node.getStatement());
66-
for(PExpr e : copy)
67-
{
68-
e.apply(this);
69-
}
66+
node.getStatementList().apply(this);
7067
}
7168
outAStartExpr(node);
7269
}
@@ -95,6 +92,34 @@ public void caseAStatementExpr(AStatementExpr node)
9592
outAStatementExpr(node);
9693
}
9794

95+
public void inAStatementListExpr(AStatementListExpr node)
96+
{
97+
defaultIn(node);
98+
}
99+
100+
public void outAStatementListExpr(AStatementListExpr node)
101+
{
102+
defaultOut(node);
103+
}
104+
105+
@Override
106+
public void caseAStatementListExpr(AStatementListExpr node)
107+
{
108+
inAStatementListExpr(node);
109+
if(node.getList() != null)
110+
{
111+
node.getList().apply(this);
112+
}
113+
{
114+
List<PExpr> copy = new ArrayList<PExpr>(node.getSingle());
115+
for(PExpr e : copy)
116+
{
117+
e.apply(this);
118+
}
119+
}
120+
outAStatementListExpr(node);
121+
}
122+
98123
public void inADeclarationExpr(ADeclarationExpr node)
99124
{
100125
defaultIn(node);
@@ -416,6 +441,48 @@ public void caseANotExpr(ANotExpr node)
416441
outANotExpr(node);
417442
}
418443

444+
public void inAUnaryMinusExpr(AUnaryMinusExpr node)
445+
{
446+
defaultIn(node);
447+
}
448+
449+
public void outAUnaryMinusExpr(AUnaryMinusExpr node)
450+
{
451+
defaultOut(node);
452+
}
453+
454+
@Override
455+
public void caseAUnaryMinusExpr(AUnaryMinusExpr node)
456+
{
457+
inAUnaryMinusExpr(node);
458+
if(node.getExpr() != null)
459+
{
460+
node.getExpr().apply(this);
461+
}
462+
outAUnaryMinusExpr(node);
463+
}
464+
465+
public void inAUnaryPlusExpr(AUnaryPlusExpr node)
466+
{
467+
defaultIn(node);
468+
}
469+
470+
public void outAUnaryPlusExpr(AUnaryPlusExpr node)
471+
{
472+
defaultOut(node);
473+
}
474+
475+
@Override
476+
public void caseAUnaryPlusExpr(AUnaryPlusExpr node)
477+
{
478+
inAUnaryPlusExpr(node);
479+
if(node.getExpr() != null)
480+
{
481+
node.getExpr().apply(this);
482+
}
483+
outAUnaryPlusExpr(node);
484+
}
485+
419486
public void inAWhileExpr(AWhileExpr node)
420487
{
421488
defaultIn(node);

analysis/ReversedDepthFirstAdapter.java

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,9 @@ public void outAStartExpr(AStartExpr node)
5050
public void caseAStartExpr(AStartExpr node)
5151
{
5252
inAStartExpr(node);
53+
if(node.getStatementList() != null)
5354
{
54-
List<PExpr> copy = new ArrayList<PExpr>(node.getStatement());
55-
Collections.reverse(copy);
56-
for(PExpr e : copy)
57-
{
58-
e.apply(this);
59-
}
55+
node.getStatementList().apply(this);
6056
}
6157
{
6258
List<PExpr> copy = new ArrayList<PExpr>(node.getDeclaration());
@@ -98,6 +94,35 @@ public void caseAStatementExpr(AStatementExpr node)
9894
outAStatementExpr(node);
9995
}
10096

97+
public void inAStatementListExpr(AStatementListExpr node)
98+
{
99+
defaultIn(node);
100+
}
101+
102+
public void outAStatementListExpr(AStatementListExpr node)
103+
{
104+
defaultOut(node);
105+
}
106+
107+
@Override
108+
public void caseAStatementListExpr(AStatementListExpr node)
109+
{
110+
inAStatementListExpr(node);
111+
{
112+
List<PExpr> copy = new ArrayList<PExpr>(node.getSingle());
113+
Collections.reverse(copy);
114+
for(PExpr e : copy)
115+
{
116+
e.apply(this);
117+
}
118+
}
119+
if(node.getList() != null)
120+
{
121+
node.getList().apply(this);
122+
}
123+
outAStatementListExpr(node);
124+
}
125+
101126
public void inADeclarationExpr(ADeclarationExpr node)
102127
{
103128
defaultIn(node);
@@ -419,6 +444,48 @@ public void caseANotExpr(ANotExpr node)
419444
outANotExpr(node);
420445
}
421446

447+
public void inAUnaryMinusExpr(AUnaryMinusExpr node)
448+
{
449+
defaultIn(node);
450+
}
451+
452+
public void outAUnaryMinusExpr(AUnaryMinusExpr node)
453+
{
454+
defaultOut(node);
455+
}
456+
457+
@Override
458+
public void caseAUnaryMinusExpr(AUnaryMinusExpr node)
459+
{
460+
inAUnaryMinusExpr(node);
461+
if(node.getExpr() != null)
462+
{
463+
node.getExpr().apply(this);
464+
}
465+
outAUnaryMinusExpr(node);
466+
}
467+
468+
public void inAUnaryPlusExpr(AUnaryPlusExpr node)
469+
{
470+
defaultIn(node);
471+
}
472+
473+
public void outAUnaryPlusExpr(AUnaryPlusExpr node)
474+
{
475+
defaultOut(node);
476+
}
477+
478+
@Override
479+
public void caseAUnaryPlusExpr(AUnaryPlusExpr node)
480+
{
481+
inAUnaryPlusExpr(node);
482+
if(node.getExpr() != null)
483+
{
484+
node.getExpr().apply(this);
485+
}
486+
outAUnaryPlusExpr(node);
487+
}
488+
422489
public void inAWhileExpr(AWhileExpr node)
423490
{
424491
defaultIn(node);

0 commit comments

Comments
 (0)