From fc712f94a7ed8554d8d44f4965be367354a7e670 Mon Sep 17 00:00:00 2001 From: L0P0P Date: Wed, 26 Jun 2024 10:06:12 +0200 Subject: Using child --- src/ast/nodes/RootNode.java | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'src/ast/nodes/RootNode.java') diff --git a/src/ast/nodes/RootNode.java b/src/ast/nodes/RootNode.java index 45d20db..4b29e8d 100644 --- a/src/ast/nodes/RootNode.java +++ b/src/ast/nodes/RootNode.java @@ -12,30 +12,28 @@ public class RootNode implements Node { // stms and compundStmts are protected because they are reused for a // BlockNode - protected ArrayList stmts; - protected ArrayList compoundStmts; + protected ArrayList childs; - public RootNode(ArrayList stmts, ArrayList compoundStmts) { - this.stmts = stmts; - this.compoundStmts = compoundStmts; + public RootNode(ArrayList childs) { + this.childs = childs; } @Override public ArrayList checkSemantics(SymbolTable ST, int _nesting) { ArrayList errors = new ArrayList(); + // Create a new HashMap for the current scope HashMap HM = new HashMap(); + // Add the HashMap to the SymbolTable ST.add(HM); - for (Node stmt : stmts) { - errors.addAll(stmt.checkSemantics(ST, _nesting)); - } - - for (Node stmt : compoundStmts) { - errors.addAll(stmt.checkSemantics(ST, _nesting)); + // Check semantics for each child + for (Node child : childs) { + errors.addAll(child.checkSemantics(ST, _nesting)); } + // Remove the HashMap from the SymbolTable ST.remove(); return errors; @@ -58,11 +56,8 @@ public class RootNode implements Node { 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; -- cgit v1.2.3-18-g5258