From 06671f5aed68753435a762bc3be43e83094156d1 Mon Sep 17 00:00:00 2001 From: geno Date: Wed, 26 Jun 2024 14:53:05 +0200 Subject: exercise 1 completed 1.b now works 1.c implened error for "function takes N positional arguments but M were given" --- src/ast/nodes/FuncdefNode.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/ast/nodes/FuncdefNode.java') diff --git a/src/ast/nodes/FuncdefNode.java b/src/ast/nodes/FuncdefNode.java index 4c8f92f..8985e08 100644 --- a/src/ast/nodes/FuncdefNode.java +++ b/src/ast/nodes/FuncdefNode.java @@ -13,6 +13,7 @@ import org.antlr.v4.runtime.tree.TerminalNode; * Node for the `funcdef` statement of the grammar. */ public class FuncdefNode implements Node { + private TerminalNode name; private Node paramlist; private Node block; @@ -26,14 +27,17 @@ public class FuncdefNode implements Node { @Override public ArrayList checkSemantics(SymbolTable ST, int _nesting) { ArrayList errors = new ArrayList(); - - ST.insert(this.name.toString(), this.block.typeCheck(), _nesting, ""); + int paramNumber = ((ParamlistNode) paramlist).getParamNumber(); + Type returnType = this.block.typeCheck(); + FunctionType ft = new FunctionType(paramNumber, returnType); + + ST.insert(this.name.toString(), ft, _nesting, ""); HashMap HM = new HashMap(); ST.add(HM); - ST.insert(this.name.toString(), this.block.typeCheck(), _nesting + 1, ""); + ST.insert(this.name.toString(), ft, _nesting + 1, ""); if (paramlist != null) { errors.addAll(paramlist.checkSemantics(ST, _nesting + 1)); -- cgit v1.2.3-18-g5258