summaryrefslogtreecommitdiff
path: root/src/ast/nodes/BlockNode.java
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2024-06-30 13:45:57 +0200
committerGitHub <noreply@github.com>2024-06-30 13:45:57 +0200
commit8aa8b5834953cab15c0687608f4fafea2e6c61be (patch)
tree1835ae7c789136b4a6c44c12efd4247a0b96d893 /src/ast/nodes/BlockNode.java
parent7125bb27fedaafd5a56b5122e4251b182448ddac (diff)
parent06d7c8dee25c065b1a569337f34d3cd5e892a31d (diff)
Merge pull request #10 from boozec/check-semantics
Co-Authored-By: geno <gabriele.genovese2@studio.unibo.it> Co-Authored-By: L0P0P <grassoemanuele@live.com>
Diffstat (limited to 'src/ast/nodes/BlockNode.java')
-rw-r--r--src/ast/nodes/BlockNode.java32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/ast/nodes/BlockNode.java b/src/ast/nodes/BlockNode.java
index 6b07f49..d9a151d 100644
--- a/src/ast/nodes/BlockNode.java
+++ b/src/ast/nodes/BlockNode.java
@@ -1,16 +1,29 @@
package ast.nodes;
-import java.util.ArrayList;
-
import ast.types.*;
+import java.util.ArrayList;
+import semanticanalysis.SemanticError;
+import semanticanalysis.SymbolTable;
/**
- * Node for `block` statement of the grammar.
- * It extends the `RootNode`.
+ * Node for `block` statement of the grammar. It extends the `RootNode`.
*/
public class BlockNode extends RootNode {
- public BlockNode(ArrayList<Node> stmts, ArrayList<Node> compoundStmts) {
- super(stmts, compoundStmts);
+
+ public BlockNode(ArrayList<Node> childs) {
+ super(childs);
+ }
+
+ @Override
+ public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
+ ArrayList<SemanticError> errors = new ArrayList();
+
+ // Check semantics for each child
+ for (Node child : childs) {
+ errors.addAll(child.checkSemantics(ST, _nesting));
+ }
+
+ return errors;
}
@Override
@@ -23,11 +36,8 @@ public class BlockNode extends RootNode {
String str = prefix + "Block\n";
prefix += " ";
- for (Node stmt : stmts) {
- str += stmt.toPrint(prefix);
- }
- for (Node stmt : compoundStmts) {
- str += stmt.toPrint(prefix);
+ for (Node child : childs) {
+ str += child.toPrint(prefix);
}
return str;