From 6bdf1fc6c1b7afe18ffcae05f8fb11eca0f51258 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 25 Jun 2024 11:33:41 +0200 Subject: wip --- src/ast/nodes/RootNode.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/ast/nodes/RootNode.java') diff --git a/src/ast/nodes/RootNode.java b/src/ast/nodes/RootNode.java index e0989e8..fd33e30 100644 --- a/src/ast/nodes/RootNode.java +++ b/src/ast/nodes/RootNode.java @@ -1,6 +1,7 @@ package ast.nodes; import java.util.ArrayList; +import java.util.HashMap; import semanticanalysis.SemanticError; import semanticanalysis.SymbolTable; @@ -24,13 +25,20 @@ public class RootNode implements Node { public ArrayList checkSemantics(SymbolTable ST, int _nesting) { ArrayList errors = new ArrayList(); - for (Node stmt : stmts) { + HashMap HM = new HashMap(); + + ST.add(HM); + + for (Node stmt : compoundStmts) { errors.addAll(stmt.checkSemantics(ST, _nesting)); } - for (Node stmt : compoundStmts) { + + for (Node stmt : stmts) { errors.addAll(stmt.checkSemantics(ST, _nesting)); } + ST.remove(); + return errors; } -- cgit v1.2.3-18-g5258 From da554f4281da45a22f7101f26cfdf274149c7966 Mon Sep 17 00:00:00 2001 From: L0P0P Date: Tue, 25 Jun 2024 11:41:32 +0200 Subject: Fixed import problems --- src/ast/nodes/RootNode.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/ast/nodes/RootNode.java') diff --git a/src/ast/nodes/RootNode.java b/src/ast/nodes/RootNode.java index fd33e30..4b7e579 100644 --- a/src/ast/nodes/RootNode.java +++ b/src/ast/nodes/RootNode.java @@ -3,8 +3,7 @@ package ast.nodes; import java.util.ArrayList; import java.util.HashMap; -import semanticanalysis.SemanticError; -import semanticanalysis.SymbolTable; +import semanticanalysis.*; import ast.types.*; /** -- cgit v1.2.3-18-g5258 From b12c01732860f9727626829e0b25a273de5fe5c7 Mon Sep 17 00:00:00 2001 From: geno Date: Tue, 25 Jun 2024 16:04:07 +0200 Subject: check semantic of defined and undefined variables implemented do not check for built-in function works on the example --- src/ast/nodes/RootNode.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ast/nodes/RootNode.java') diff --git a/src/ast/nodes/RootNode.java b/src/ast/nodes/RootNode.java index 4b7e579..45d20db 100644 --- a/src/ast/nodes/RootNode.java +++ b/src/ast/nodes/RootNode.java @@ -1,15 +1,15 @@ package ast.nodes; +import ast.types.*; import java.util.ArrayList; import java.util.HashMap; - import semanticanalysis.*; -import ast.types.*; /** * Node for the `root` statement of the grammar. */ public class RootNode implements Node { + // stms and compundStmts are protected because they are reused for a // BlockNode protected ArrayList stmts; @@ -28,11 +28,11 @@ public class RootNode implements Node { ST.add(HM); - for (Node stmt : compoundStmts) { + for (Node stmt : stmts) { errors.addAll(stmt.checkSemantics(ST, _nesting)); } - for (Node stmt : stmts) { + for (Node stmt : compoundStmts) { errors.addAll(stmt.checkSemantics(ST, _nesting)); } -- cgit v1.2.3-18-g5258 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 From afff6a80cd58f7787efa1398f7c8cbdce8989323 Mon Sep 17 00:00:00 2001 From: geno Date: Sun, 30 Jun 2024 13:36:37 +0200 Subject: fixed warnings, better formatting, final added where possible --- src/ast/nodes/RootNode.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ast/nodes/RootNode.java') diff --git a/src/ast/nodes/RootNode.java b/src/ast/nodes/RootNode.java index 4b29e8d..5bbce8c 100644 --- a/src/ast/nodes/RootNode.java +++ b/src/ast/nodes/RootNode.java @@ -20,10 +20,10 @@ public class RootNode implements Node { @Override public ArrayList checkSemantics(SymbolTable ST, int _nesting) { - ArrayList errors = new ArrayList(); + ArrayList errors = new ArrayList(); // Create a new HashMap for the current scope - HashMap HM = new HashMap(); + HashMap HM = new HashMap(); // Add the HashMap to the SymbolTable ST.add(HM); -- cgit v1.2.3-18-g5258