Programming-Language-Design / src / ast / statement / classes / IfElse.java
IfElse.java
Raw
package ast.statement.classes;

import ast.expression.Expression;
import ast.statement.AbstractStatement;
import ast.statement.Statement;
import visitor.Visitor;

import java.util.ArrayList;
import java.util.List;

public class IfElse extends AbstractStatement {

    Expression condition;
    List<Statement> ifStmts;
    List<Statement> elseStmts;

    public IfElse(int line, int column, Expression condition, List<Statement> ifStmts, List<Statement> elseStmts) {
        super(line, column);
        this.condition = condition;
        this.ifStmts = new ArrayList<>(ifStmts);
        this.elseStmts = new ArrayList<>(elseStmts);
    }

    public Expression getCondition() {
        return condition;
    }

    public List<Statement> getIfStmts() {
        return ifStmts;
    }

    public List<Statement> getElseStmts() {
        return elseStmts;
    }

    @Override
    public String toString() {
        return "if (" + getCondition() + ")" + getIfStmts() + " else" + getElseStmts();
    }

    @Override
    public <TP, TR> TR accept(Visitor<TP, TR> v, TP param) {
        return v.visit(this, param);
    }
}