diff options
author | Emanuele Grasso <96300448+L0P0P@users.noreply.github.com> | 2024-07-14 18:48:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-14 18:48:09 +0200 |
commit | ce49d20a5fe3726e1800bc495a25c7617212abf4 (patch) | |
tree | 5a1a79efa79e7bf6dcf3d3151aec2edf6a47b3e7 /src/ast/nodes/CompForNode.java | |
parent | 57599a42b863cc48050c137de2ec108aa1d59a44 (diff) |
Reaching definition analysis (#17)
Co-authored-by: Santo Cariotti <santo@dcariotti.me>
Co-authored-by: geno <gabriele.genovese2@studio.unibo.it>
Co-authored-by: geno <gabrigeno@gmail.com>
Diffstat (limited to 'src/ast/nodes/CompForNode.java')
-rw-r--r-- | src/ast/nodes/CompForNode.java | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/ast/nodes/CompForNode.java b/src/ast/nodes/CompForNode.java index 1f51af5..df86a74 100644 --- a/src/ast/nodes/CompForNode.java +++ b/src/ast/nodes/CompForNode.java @@ -12,12 +12,12 @@ import semanticanalysis.SymbolTable; public class CompForNode implements Node { protected ExprListNode exprlist; - protected ExprNode single_expr; + protected ExprNode expr; protected CompIterNode comp_iter; - public CompForNode(Node exprlist, Node single_expr, Node comp_iter) { + public CompForNode(Node exprlist, Node expr, Node comp_iter) { this.exprlist = (ExprListNode) exprlist; - this.single_expr = (ExprNode) single_expr; + this.expr = (ExprNode) expr; this.comp_iter = (CompIterNode) comp_iter; } @@ -26,7 +26,7 @@ public class CompForNode implements Node { ArrayList<SemanticError> errors = new ArrayList<>(); errors.addAll(exprlist.checkSemantics(ST, _nesting, ft)); - errors.addAll(single_expr.checkSemantics(ST, _nesting, ft)); + errors.addAll(expr.checkSemantics(ST, _nesting, ft)); if (comp_iter != null) { errors.addAll(comp_iter.checkSemantics(ST, _nesting, ft)); } @@ -47,13 +47,27 @@ public class CompForNode implements Node { } @Override - public String toPrint(String prefix) { + public String printAST(String prefix) { String str = prefix + "CompForNode\n"; prefix += " "; - str += exprlist.toPrint(prefix); - str += single_expr.toPrint(prefix); - str += comp_iter.toPrint(prefix); + str += exprlist.printAST(prefix); + str += expr.printAST(prefix); + str += comp_iter.printAST(prefix); + return str; + } + + @Override + public String toPrint(String prefix) { + String str = prefix + "for"; + + for (int i = 0; i < exprlist.getExprs().size(); i++) { + str += exprlist.getExprs().get(i).toPrint(""); + } + + str += " in " + expr.toPrint("") + "\n"; + str += comp_iter.toPrint(prefix + "\t"); + return str; } |