Skip to content

Commit

Permalink
Introduction to recursive function
Browse files Browse the repository at this point in the history
  • Loading branch information
L0P0P committed Jun 26, 2024
1 parent 9e6c17c commit e09358f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
6 changes: 1 addition & 5 deletions progs/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
def unibo(a):
if a == 3:
print("UNIBO")

a = 3
unibo(a)
unibo(a)
15 changes: 15 additions & 0 deletions src/ast/nodes/BlockNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.ArrayList;

import ast.types.*;
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;

/**
* Node for `block` statement of the grammar.
Expand All @@ -13,6 +15,19 @@ public BlockNode(ArrayList<Node> childs) {
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();
Expand Down
2 changes: 2 additions & 0 deletions src/ast/nodes/FuncdefNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {

ST.add(HM);

ST.insert(this.name.toString(), this.block.typeCheck(), _nesting + 1, "");

if (paramlist != null) {
errors.addAll(paramlist.checkSemantics(ST, _nesting + 1));
}
Expand Down

0 comments on commit e09358f

Please sign in to comment.