summaryrefslogtreecommitdiff
path: root/src/ast
diff options
context:
space:
mode:
authorL0P0P <grassoemanuele@live.com>2024-06-26 11:54:57 +0200
committerL0P0P <grassoemanuele@live.com>2024-06-26 11:54:57 +0200
commite09358f3648445bbf9747f40497af6221d933a99 (patch)
tree50a81c435e6c410503000f71ead6c2ee62bf6111 /src/ast
parent9e6c17cb44bc165e315ec039a0e09183716d2037 (diff)
Introduction to recursive function
Diffstat (limited to 'src/ast')
-rw-r--r--src/ast/nodes/BlockNode.java15
-rw-r--r--src/ast/nodes/FuncdefNode.java2
2 files changed, 17 insertions, 0 deletions
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.
@@ -14,6 +16,19 @@ public class BlockNode extends RootNode {
}
@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));
}