From 4898724edf343650ffb80792caf9e242e5843059 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 27 Jun 2024 19:47:05 +0200 Subject: Fix `for` loop for 1+ params --- src/ast/nodes/ForStmtNode.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/ast/nodes/ForStmtNode.java') diff --git a/src/ast/nodes/ForStmtNode.java b/src/ast/nodes/ForStmtNode.java index 610d0a0..c5301ee 100644 --- a/src/ast/nodes/ForStmtNode.java +++ b/src/ast/nodes/ForStmtNode.java @@ -10,11 +10,11 @@ import semanticanalysis.SymbolTable; */ public class ForStmtNode implements Node { - private ExprListNode exprList; + private Node exprList; private Node block; public ForStmtNode(Node exprList, Node block) { - this.exprList = (ExprListNode) exprList; + this.exprList = exprList; this.block = block; } @@ -22,7 +22,15 @@ public class ForStmtNode implements Node { public ArrayList checkSemantics(SymbolTable ST, int _nesting) { ArrayList errors = new ArrayList(); - // ST.insert(expr.getId(), expr.typeCheck(s), _nesting, ""); + var l = (ExprListNode) exprList; + for (int i = 0; i < l.getSize() - 1; ++i) { + var e = (ExprNode) l.getElem(i); + ST.insert(e.getId(), e.typeCheck(), _nesting, ""); + } + + var left = (ExprNode) l.getElem(l.getSize() - 1); + var atomLeft = (ExprNode) left.getExpr(0); + ST.insert(atomLeft.getId(), atomLeft.typeCheck(), _nesting, ""); errors.addAll(exprList.checkSemantics(ST, _nesting)); errors.addAll(block.checkSemantics(ST, _nesting)); -- cgit v1.2.3-18-g5258