summaryrefslogtreecommitdiff
path: root/src/ast/nodes/ForStmtNode.java
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2024-06-27 19:47:05 +0200
committerSanto Cariotti <santo@dcariotti.me>2024-06-27 19:47:05 +0200
commit4898724edf343650ffb80792caf9e242e5843059 (patch)
tree79664d0e6d0a4c2c721db4c068e52961412c5941 /src/ast/nodes/ForStmtNode.java
parenteb7fb04d2dfadd004fa86f28da42681e0038df06 (diff)
Fix `for` loop for 1+ params
Diffstat (limited to 'src/ast/nodes/ForStmtNode.java')
-rw-r--r--src/ast/nodes/ForStmtNode.java14
1 files changed, 11 insertions, 3 deletions
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<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
- // 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));