diff options
author | geno <gabriele.genovese2@studio.unibo.it> | 2024-06-26 14:53:05 +0200 |
---|---|---|
committer | geno <gabriele.genovese2@studio.unibo.it> | 2024-06-26 14:53:05 +0200 |
commit | 06671f5aed68753435a762bc3be43e83094156d1 (patch) | |
tree | 56f251596cf57f6f13a7921e7dad6e795989329d /src/ast/nodes/ArglistNode.java | |
parent | e09358f3648445bbf9747f40497af6221d933a99 (diff) |
exercise 1 completed
1.b now works
1.c implened error for "function takes N positional arguments but M were given"
Diffstat (limited to 'src/ast/nodes/ArglistNode.java')
-rw-r--r-- | src/ast/nodes/ArglistNode.java | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/ast/nodes/ArglistNode.java b/src/ast/nodes/ArglistNode.java index 71bcdce..cd1a403 100644 --- a/src/ast/nodes/ArglistNode.java +++ b/src/ast/nodes/ArglistNode.java @@ -1,15 +1,15 @@ package ast.nodes; +import ast.types.*; import java.util.ArrayList; - import semanticanalysis.SemanticError; import semanticanalysis.SymbolTable; -import ast.types.*; /** * Node for the `arglist` statement of the grammar. */ public class ArglistNode implements Node { + protected ArrayList<Node> arguments; public ArglistNode(ArrayList<Node> arguments) { @@ -19,14 +19,14 @@ public class ArglistNode implements Node { @Override public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) { ArrayList<SemanticError> errors = new ArrayList<SemanticError>(); - + for (var arg : arguments) { ExprNode argExpr = (ExprNode) arg; String argName = argExpr.getId(); // TODO: check fucking IntType for params // TODO: remove fucking comments - if (!ST.top_lookup(argName) && argExpr.typeCheck() instanceof AtomType){ + if (argName != null && !ST.top_lookup(argName) && argExpr.typeCheck() instanceof AtomType) { // System.out.println(!(this.typeCheck() instanceof IntType) + " " + !ST.top_lookup(this.getId())); errors.add(new SemanticError("'" + argName + "' is not defined.")); } else { @@ -37,6 +37,10 @@ public class ArglistNode implements Node { return errors; } + public int getArgumentNumber() { + return arguments.size(); + } + @Override public Type typeCheck() { return new VoidType(); |