package visitor; import ast.Program; import ast.definition.classes.FuncDefinition; import ast.definition.classes.VarDefinition; import ast.expression.classes.*; import ast.statement.classes.*; import ast.type.RecordField; import ast.type.classes.*; public abstract class AbstractVisitor<TP, TR> implements Visitor<TP, TR> { //PROGRAM @Override public TR visit(Program ast, TP param) { ast.getDefinitions().forEach(definition -> definition.accept(this, null)); return null; } //DEFINITIONS @Override public TR visit(FuncDefinition ast, TP param) { ast.getType().accept(this, null); ast.getFunctionStmts().forEach(stmt -> stmt.accept(this, null)); return null; } @Override public TR visit(VarDefinition ast, TP param) { ast.getType().accept(this, null); return null; } //STATEMENTS @Override public TR visit(Assignment ast, TP param) { ast.getOperand_1().accept(this, null); ast.getOperand_2().accept(this, null); return null; } @Override public TR visit(IfElse ast, TP param) { ast.getCondition().accept(this, null); ast.getIfStmts().forEach(stmt -> stmt.accept(this, null)); ast.getElseStmts().forEach(stmt -> stmt.accept(this, null)); return null; } @Override public TR visit(ReadStatement ast, TP param) { ast.getValue().accept(this, null); return null; } @Override public TR visit(Return ast, TP param) { ast.getValue().accept(this, null); return null; } @Override public TR visit(WhileLoop ast, TP param) { ast.getCondition().accept(this, null); ast.getStatements().forEach(stmt -> stmt.accept(this, null)); return null; } @Override public TR visit(WriteStatement ast, TP param) { ast.getValue().accept(this, null); return null; } //TYPE @Override public TR visit(VoidType ast, TP param) { return null; } @Override public TR visit(RecordType ast, TP param) { return null; } @Override public TR visit(IntType ast, TP param) { return null; } @Override public TR visit(FunctionType ast, TP param) { return null; } @Override public TR visit(ErrorType ast, TP param) { return null; } @Override public TR visit(DoubleType ast, TP param) { return null; } @Override public TR visit(CharType ast, TP param) { return null; } @Override public TR visit(ArrayType ast, TP param) { return null; } @Override public TR visit(RecordField ast, TP param) { return null; } //EXPRESSION @Override public TR visit(Arithmetic ast, TP param) { ast.getOperand_1().accept(this, null); ast.getOperand_2().accept(this, null); return null; } @Override public TR visit(Cast ast, TP param) { ast.getDataType().accept(this, null); ast.getValue().accept(this, null); return null; } @Override public TR visit(ArrayIndexing ast, TP param) { ast.getArray().accept(this, null); ast.getIndex().accept(this, null); return null; } @Override public TR visit(Comparison ast, TP param) { ast.getOperand_1().accept(this, null); ast.getOperand_2().accept(this, null); return null; } @Override public TR visit(Logical ast, TP param) { ast.getOperand_1().accept(this, null); ast.getOperand_2().accept(this, null); return null; } @Override public TR visit(FieldAccess ast, TP param) { ast.getValue().accept(this, null); return null; } @Override public TR visit(FunctionInvocation ast, TP param) { ast.getFunctionName().accept(this, null); ast.getArguments().forEach(arg -> arg.accept(this, null)); return null; } @Override public TR visit(UnaryMinus ast, TP param) { ast.getValue().accept(this, null); return null; } @Override public TR visit(Negation ast, TP param) { ast.getValue().accept(this, null); return null; } @Override public TR visit(CharLiteral ast, TP param) { return null; } @Override public TR visit(DoubleLiteral ast, TP param) { return null; } @Override public TR visit(IntLiteral ast, TP param) { return null; } @Override public TR visit(Variable ast, TP param) { return null; } }