From 8e7089a5d6ba1f4f50a90133bb50bc5c6c554aff Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 13 Jun 2024 11:00:06 +0200 Subject: Set up visitor (#3) Co-authored-by: geno --- src/ast/nodes/SimpleStmtsNode.java | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/ast/nodes/SimpleStmtsNode.java (limited to 'src/ast/nodes/SimpleStmtsNode.java') diff --git a/src/ast/nodes/SimpleStmtsNode.java b/src/ast/nodes/SimpleStmtsNode.java new file mode 100644 index 0000000..c8013a3 --- /dev/null +++ b/src/ast/nodes/SimpleStmtsNode.java @@ -0,0 +1,54 @@ +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 `simple_stmts` statement of the grammar. + */ +public class SimpleStmtsNode implements Node { + private ArrayList stmts; + + public SimpleStmtsNode(ArrayList stmts) { + this.stmts = stmts; + } + + @Override + public ArrayList checkSemantics(SymbolTable ST, int _nesting) { + ArrayList errors = new ArrayList(); + + for (Node stmt : stmts) { + errors.addAll(stmt.checkSemantics(ST, _nesting)); + } + + return errors; + } + + @Override + public Type typeCheck() { + return new VoidType(); + } + + // TODO: Code generation for SimpleStmtsNode + @Override + public String codeGeneration() { + return ""; + } + + @Override + public String toPrint(String prefix) { + String str = prefix + "SimpleStmts\n"; + + prefix += " "; + + for (Node stmt : stmts) { + str += stmt.toPrint(prefix); + } + + return str; + } + +} -- cgit v1.2.3-18-g5258