From fd85e9980c0305c6dfb91aaeb199430a89163c3e Mon Sep 17 00:00:00 2001 From: geno Date: Thu, 27 Jun 2024 20:49:56 +0200 Subject: fixed comp_for and added reseved word type --- src/ast/nodes/CompForNode.java | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/ast/nodes/CompForNode.java (limited to 'src/ast/nodes/CompForNode.java') diff --git a/src/ast/nodes/CompForNode.java b/src/ast/nodes/CompForNode.java new file mode 100644 index 0000000..d5c50d6 --- /dev/null +++ b/src/ast/nodes/CompForNode.java @@ -0,0 +1,59 @@ +package ast.nodes; + +import ast.types.*; +import java.util.ArrayList; +import java.util.Arrays; +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 checkSemantics(SymbolTable ST, int _nesting) { + ArrayList 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; + } + +} -- cgit v1.2.3-18-g5258