blob: 2655f35531c6febe277458d999a8fe42e09038b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
package ast.nodes;
import ast.types.*;
import java.util.ArrayList;
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
/**
* Node for the `compound_node` statement of the grammar.
*/
public class CompoundNode implements Node {
private final Node ifNode;
private final Node funcDef;
private final Node forStmt;
private final Node whileStmt;
public CompoundNode(Node ifNode, Node funcDef, Node forStmt, Node whileStmt) {
this.ifNode = ifNode;
this.funcDef = funcDef;
this.forStmt = forStmt;
this.whileStmt = whileStmt;
}
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
ArrayList<SemanticError> errors = new ArrayList<>();
if (ifNode != null) {
errors.addAll(ifNode.checkSemantics(ST, _nesting));
}
if (funcDef != null) {
errors.addAll(funcDef.checkSemantics(ST, _nesting));
}
if (forStmt != null) {
errors.addAll(forStmt.checkSemantics(ST, _nesting));
}
if (whileStmt != null) {
errors.addAll(whileStmt.checkSemantics(ST, _nesting));
}
return errors;
}
@Override
public Type typeCheck() {
return new VoidType();
}
// TODO: add code generation for CompoundNode
@Override
public String codeGeneration() {
return "";
}
@Override
public String toPrint(String prefix) {
String str = prefix + "CompoundNode\n";
prefix += " ";
if (ifNode != null) {
str += ifNode.toPrint(prefix);
}
if (funcDef != null) {
str += funcDef.toPrint(prefix);
}
if (forStmt != null) {
str += forStmt.toPrint(prefix);
}
if (whileStmt != null) {
str += whileStmt.toPrint(prefix);
}
return str;
}
}
|