Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d6bf5a7

Browse filesBrowse files
committed
Minor Bugfixes
1 parent 644bb22 commit d6bf5a7
Copy full SHA for d6bf5a7

File tree

5 files changed

+116
-155
lines changed
Filter options

5 files changed

+116
-155
lines changed

‎ASTTypechecker.java

Copy file name to clipboardExpand all lines: ASTTypechecker.java
+38-5Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@ public class ASTTypeChecker extends DepthFirstAdapter {
88
private HashMap<String, String> symbolTable = new HashMap<String, String>();
99
private String result;
1010

11+
/**
12+
* Check if break is only used in a while context
13+
*/
14+
public void caseABreakExpr(ABreakExpr node) {
15+
Node parent = node.parent();
16+
String parentName;
17+
18+
do {
19+
parent = parent.parent();
20+
parentName = parent.getClass().getSimpleName().replaceAll(" ","");
21+
22+
if (parentName.equals("AWhileExpr")) break;
23+
24+
} while (!parentName.equals("AStartExpr"));
25+
26+
if (parentName.equals("AStartExpr")) {
27+
System.out.println("# Error: User 'break' only in a 'while' context!");
28+
System.exit(1);
29+
} else {
30+
printValidOperation("break");
31+
}
32+
}
33+
1134
/**
1235
* Look up all the declarations and put it into the HashMap
1336
*/
@@ -159,14 +182,24 @@ public void caseAMinusExpr(AMinusExpr node) {
159182
}
160183
@Override
161184
public void caseAUnaryMinusExpr(AUnaryMinusExpr node) {
162-
String operation = "unaryminus";
185+
String operation = "unary -";
163186
node.getExpr().apply(this);
164187

165-
System.out.println("+ "+node.getExpr().getClass().getSimpleName());
188+
if (!result.equals("integer") && !node.getExpr().getClass().getSimpleName().equals("AIdentifierExpr") && !node.getExpr().getClass().getSimpleName().equals("ANumberExpr")) {
189+
System.out.println("# Error: Syntax of '"+operation+"' is '"+operation+"' 'integer' = 'integer'.");
190+
System.exit(1);
191+
} else
192+
printValidOperation(operation);
193+
}
194+
@Override
195+
public void caseAUnaryPlusExpr(AUnaryPlusExpr node) {
196+
String operation = "unary +";
197+
node.getExpr().apply(this);
166198

167-
if (!result.equals("integer") || !node.getExpr().getClass().getSimpleName().equals("AIdentifierExpr"))
168-
printErrorArithmeticOperation(operation);
169-
else
199+
if (!result.equals("integer") && !node.getExpr().getClass().getSimpleName().equals("AIdentifierExpr") && !node.getExpr().getClass().getSimpleName().equals("ANumberExpr")) {
200+
System.out.println("# Error: Syntax of '"+operation+"' is '"+operation+"' 'integer' = 'integer'.");
201+
System.exit(1);
202+
} else
170203
printValidOperation(operation);
171204
}
172205
@Override

‎Pascal.pas

Copy file name to clipboardExpand all lines: Pascal.pas
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
var b: integer;
44
var temp : integer ;
55
var c : boolean;
6-
76
begin
87

9-
//if 2=2 and not 2<>2 then writeln(1);
8+
if 1<2 then begin writeln(1); end else writeln(2)
9+
1010
// c := true = 1<2;
11-
a := 1;
11+
{a := 1;
1212
b := 1;
1313
while True do
1414
begin
1515
writeln(a);
16-
temp := -b;
1716
b := a + b;
17+
1818
a := temp;
19-
end
19+
end}
2020
end.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.