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/WhileStmtNode.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/WhileStmtNode.java')
-rw-r--r-- | src/ast/nodes/WhileStmtNode.java | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/ast/nodes/WhileStmtNode.java b/src/ast/nodes/WhileStmtNode.java index d371046..43bf5ff 100644 --- a/src/ast/nodes/WhileStmtNode.java +++ b/src/ast/nodes/WhileStmtNode.java @@ -33,14 +33,33 @@ public class WhileStmtNode implements Node { return new VoidType(); } - // TODO: add cgen per while (but it's not requested from the exercise) + /** + * NOTE: It is not a part for this project. + */ @Override public String codeGeneration() { return ""; } @Override + public String printAST(String prefix) { + return prefix + "While\n" + expr.printAST(prefix + " ") + block.printAST(prefix + " "); + } + + @Override public String toPrint(String prefix) { - return prefix + "While\n" + expr.toPrint(prefix + " ") + block.toPrint(prefix + " "); + String str = prefix + "while "; + str += expr.toPrint("") + ":\n"; + str += block.toPrint(prefix + "\t") + "\n"; + return str; + } + + public Node getBlock() { + return block; + } + + public Node getExpr() { + return expr; } + } |