#ifndef INTERPRETER_CONDITIONAL_STATEMENT_NODE_HPP #define INTERPRETER_CONDITIONAL_STATEMENT_NODE_HPP #include #include #include #include "Interpreter/StatementNode.hpp" // Include for unified runtime Exception #include "Interpreter/Interpreter.hpp" #include "Interpreter/ExpressionNode.hpp" namespace Interpreter { /** * @brief Statement node representing an if-else conditional block. */ class ConditionalStatementNode : public StatementNode { std::unique_ptr condition_; std::vector> thenBranch_; std::vector> elseBranch_; public: ConditionalStatementNode( std::unique_ptr condition, std::vector> thenBranch, std::vector> elseBranch, const std::string & file_name, int line, size_t column ) : StatementNode(file_name, line, column), condition_(std::move(condition)), thenBranch_(std::move(thenBranch)), elseBranch_(std::move(elseBranch)) {} void interpret(class Interpreter & interpreter) const override { // Evaluate condition auto val = condition_->evaluate(interpreter); bool cond = false; if (val.getType() == Symbols::Variables::Type::BOOLEAN) { cond = val.get(); } else { throw Exception("Condition did not evaluate to boolean", filename_, line_, column_); } // Execute appropriate branch const auto & branch = cond ? thenBranch_ : elseBranch_; for (const auto & stmt : branch) { stmt->interpret(interpreter); } } std::string toString() const override { return "ConditionalStatementNode at " + filename_ + ":" + std::to_string(line_); } }; } // namespace Interpreter #endif // INTERPRETER_CONDITIONAL_STATEMENT_NODE_HPP