diff options
Diffstat (limited to 'src/ast/nodes/WhileStmtNode.java')
-rw-r--r-- | src/ast/nodes/WhileStmtNode.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/ast/nodes/WhileStmtNode.java b/src/ast/nodes/WhileStmtNode.java new file mode 100644 index 0000000..a84d60e --- /dev/null +++ b/src/ast/nodes/WhileStmtNode.java @@ -0,0 +1,46 @@ +package com.clp.project.ast.nodes; + +import java.util.ArrayList; + +import com.clp.project.semanticanalysis.SemanticError; +import com.clp.project.semanticanalysis.SymbolTable; +import com.clp.project.ast.types.*; + +/** + * Node for the `while_stmt` statement of the grammar. + */ +public class WhileStmtNode implements Node { + private Node expr; + private Node block; + + public WhileStmtNode(Node expr, Node block) { + this.expr = expr; + this.block = block; + } + + @Override + public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) { + ArrayList<SemanticError> errors = new ArrayList<SemanticError>(); + + errors.addAll(expr.checkSemantics(ST, _nesting)); + errors.addAll(block.checkSemantics(ST, _nesting)); + + return errors; + } + + @Override + public Type typeCheck() { + return new VoidType(); + } + + // TODO: add code generation for while + @Override + public String codeGeneration() { + return ""; + } + + @Override + public String toPrint(String prefix) { + return prefix + "While\n" + expr.toPrint(prefix + " ") + block.toPrint(prefix + " "); + } +} |