From fd85e9980c0305c6dfb91aaeb199430a89163c3e Mon Sep 17 00:00:00 2001 From: geno Date: Thu, 27 Jun 2024 20:49:56 +0200 Subject: fixed comp_for and added reseved word type --- src/ast/nodes/TestlistCompNode.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/ast/nodes/TestlistCompNode.java') diff --git a/src/ast/nodes/TestlistCompNode.java b/src/ast/nodes/TestlistCompNode.java index 070b1a1..bcaca83 100644 --- a/src/ast/nodes/TestlistCompNode.java +++ b/src/ast/nodes/TestlistCompNode.java @@ -11,17 +11,28 @@ import semanticanalysis.SymbolTable; public class TestlistCompNode implements Node { private final ArrayList exprs; + private final CompForNode comp; - public TestlistCompNode(ArrayList _exprs) { - this.exprs = _exprs; + public TestlistCompNode(ArrayList exprs, Node comp) { + this.exprs = exprs; + this.comp = (CompForNode) comp; } @Override public ArrayList checkSemantics(SymbolTable ST, int _nesting) { ArrayList errors = new ArrayList(); - for (var param : exprs) { - errors.addAll(param.checkSemantics(ST, _nesting)); + if (comp != null) { + // if comp is set, then we save the atom in the ST (we assume the first expr is an atom) + String id = ((ExprNode) exprs.get(0)).getId(); + Type t = ((ExprNode) exprs.get(0)).typeCheck(); + ST.insert(id, t, _nesting, ""); + // errors.addAll(comp.checkSemantics(ST, _nesting)); + } else { + // if comp is not set, then exprs is a list of 1 or more element + for (var param : exprs) { + errors.addAll(param.checkSemantics(ST, _nesting)); + } } return errors; -- cgit v1.2.3-18-g5258