diff options
author | geno <gabriele.genovese2@studio.unibo.it> | 2024-06-27 20:49:56 +0200 |
---|---|---|
committer | geno <gabriele.genovese2@studio.unibo.it> | 2024-06-27 20:49:56 +0200 |
commit | fd85e9980c0305c6dfb91aaeb199430a89163c3e (patch) | |
tree | 724d7184c11ad3acb8a8b0d2e15f1922f5b36059 /src/ast/nodes/TestlistCompNode.java | |
parent | 4898724edf343650ffb80792caf9e242e5843059 (diff) |
fixed comp_for and added reseved word type
Diffstat (limited to 'src/ast/nodes/TestlistCompNode.java')
-rw-r--r-- | src/ast/nodes/TestlistCompNode.java | 19 |
1 files changed, 15 insertions, 4 deletions
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<Node> exprs; + private final CompForNode comp; - public TestlistCompNode(ArrayList<Node> _exprs) { - this.exprs = _exprs; + public TestlistCompNode(ArrayList<Node> exprs, Node comp) { + this.exprs = exprs; + this.comp = (CompForNode) comp; } @Override public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) { ArrayList<SemanticError> 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; |