diff options
author | Santo Cariotti <santo@dcariotti.me> | 2024-06-30 13:45:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-30 13:45:57 +0200 |
commit | 8aa8b5834953cab15c0687608f4fafea2e6c61be (patch) | |
tree | 1835ae7c789136b4a6c44c12efd4247a0b96d893 /src/ast/nodes/CompForNode.java | |
parent | 7125bb27fedaafd5a56b5122e4251b182448ddac (diff) | |
parent | 06d7c8dee25c065b1a569337f34d3cd5e892a31d (diff) |
Merge pull request #10 from boozec/check-semantics
Co-Authored-By: geno <gabriele.genovese2@studio.unibo.it>
Co-Authored-By: L0P0P <grassoemanuele@live.com>
Diffstat (limited to 'src/ast/nodes/CompForNode.java')
-rw-r--r-- | src/ast/nodes/CompForNode.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/ast/nodes/CompForNode.java b/src/ast/nodes/CompForNode.java new file mode 100644 index 0000000..b7c6924 --- /dev/null +++ b/src/ast/nodes/CompForNode.java @@ -0,0 +1,58 @@ +package ast.nodes; + +import ast.types.*; +import java.util.ArrayList; +import semanticanalysis.SemanticError; +import semanticanalysis.SymbolTable; + +/** + * Node for the `comp_for` statement of the grammar. 'for' exprlist 'in' expr + * comp_iter? + */ +public class CompForNode implements Node { + + protected ExprListNode exprlist; + protected ExprNode single_expr; + protected CompIterNode comp_iter; + + public CompForNode(Node exprlist, Node single_expr, Node comp_iter) { + this.exprlist = (ExprListNode) exprlist; + this.single_expr = (ExprNode) single_expr; + this.comp_iter = (CompIterNode) comp_iter; + } + + @Override + public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) { + ArrayList<SemanticError> errors = new ArrayList(); + + errors.addAll(exprlist.checkSemantics(ST, _nesting)); + errors.addAll(single_expr.checkSemantics(ST, _nesting)); + if (comp_iter != null) { + errors.addAll(comp_iter.checkSemantics(ST, _nesting)); + } + return errors; + } + + @Override + public Type typeCheck() { + return new VoidType(); + } + + // TODO: add code generation for arglist node + @Override + public String codeGeneration() { + return ""; + } + + @Override + public String toPrint(String prefix) { + String str = prefix + "CompForNode\n"; + + prefix += " "; + str += exprlist.toPrint(prefix); + str += single_expr.toPrint(prefix); + str += comp_iter.toPrint(prefix); + return str; + } + +} |