From e09358f3648445bbf9747f40497af6221d933a99 Mon Sep 17 00:00:00 2001
From: L0P0P <grassoemanuele@live.com>
Date: Wed, 26 Jun 2024 11:54:57 +0200
Subject: Introduction to recursive function

---
 progs/test.py                  |  6 +-----
 src/ast/nodes/BlockNode.java   | 15 +++++++++++++++
 src/ast/nodes/FuncdefNode.java |  2 ++
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/progs/test.py b/progs/test.py
index 97e316f..f9140c6 100644
--- a/progs/test.py
+++ b/progs/test.py
@@ -1,6 +1,2 @@
 def unibo(a):
-    if a == 3:
-        print("UNIBO")
-    
-a = 3
-unibo(a)
+    unibo(a)
diff --git a/src/ast/nodes/BlockNode.java b/src/ast/nodes/BlockNode.java
index 2c85025..a38b4ea 100644
--- a/src/ast/nodes/BlockNode.java
+++ b/src/ast/nodes/BlockNode.java
@@ -3,6 +3,8 @@ package ast.nodes;
 import java.util.ArrayList;
 
 import ast.types.*;
+import semanticanalysis.SemanticError;
+import semanticanalysis.SymbolTable;
 
 /**
  * Node for `block` statement of the grammar.
@@ -13,6 +15,19 @@ public class BlockNode extends RootNode {
         super(childs);
     }
 
+    @Override
+    public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
+        ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+
+        // Check semantics for each child
+        for (Node child : childs) {
+            errors.addAll(child.checkSemantics(ST, _nesting));
+        }
+
+        return errors;
+    }
+
+
     @Override
     public Type typeCheck() {
         return new VoidType();
diff --git a/src/ast/nodes/FuncdefNode.java b/src/ast/nodes/FuncdefNode.java
index f3be1d9..4c8f92f 100644
--- a/src/ast/nodes/FuncdefNode.java
+++ b/src/ast/nodes/FuncdefNode.java
@@ -33,6 +33,8 @@ public class FuncdefNode implements Node {
 
         ST.add(HM);
 
+        ST.insert(this.name.toString(), this.block.typeCheck(), _nesting + 1, "");
+
         if (paramlist != null) {
             errors.addAll(paramlist.checkSemantics(ST, _nesting + 1));
         }
-- 
cgit v1.2.3-18-g5258