#ifndef DLANG_STATEMENTS_HPP #define DLANG_STATEMENTS_HPP #include #include #include "expressions.hpp" struct Statement { virtual ~Statement() = default; virtual void Print(int indent = 0) const = 0; }; struct VariableDeclaration : Statement { std::string name; std::unique_ptr initializer; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "VariableDeclaration: " << name << '\n'; initializer->Print(indent + 2); } }; struct Assignment : Statement { std::unique_ptr lhs; std::unique_ptr value; std::string assignmentOperator; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "Assignment" << '\n'; lhs->Print(indent + 2); value->Print(indent + 2); } }; struct ExpressionStatement : Statement { std::unique_ptr expression; void Print(int indent = 0) const override { expression->Print(indent); } }; struct WhileStatement : Statement { std::unique_ptr condition; std::vector> body; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "WhileStatement\n"; std::cout << std::string(indent + 2, ' ') << "Condition:\n"; condition->Print(indent + 4); std::cout << std::string(indent + 2, ' ') << "Body:\n"; for (const auto& stmt : body) { stmt->Print(indent + 4); } } }; struct ForStatement : Statement { std::string var; double from; double to; double step = 1; std::vector> body; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "ForStatement\n"; std::cout << std::string(indent + 2, ' ') << "var: " << var << "\n"; std::cout << std::string(indent + 2, ' ') << "from: " << from << "\n"; std::cout << std::string(indent + 2, ' ') << "to: " << to << "\n"; std::cout << std::string(indent + 2, ' ') << "step: " << step << "\n"; for (const auto& stmt : body) { stmt->Print(indent + 4); } } }; struct ForeachStatement : Statement { std::string var; std::string list; std::vector> body; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "ForeachStatement\n"; std::cout << std::string(indent + 2, ' ') << "var: " << var << "\n"; std::cout << std::string(indent + 2, ' ') << "list: " << list << "\n"; for (const auto& stmt : body) { stmt->Print(indent + 4); } } }; struct ForeachTableStatement : Statement { std::string varKey; std::string varValue; std::string table; std::vector> body; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "ForeachTableStatement\n"; std::cout << std::string(indent + 2, ' ') << "var key: " << varKey << "\n"; std::cout << std::string(indent + 2, ' ') << "var value: " << varValue << "\n"; std::cout << std::string(indent + 2, ' ') << "table: " << table << "\n"; for (const auto& stmt : body) { stmt->Print(indent + 4); } } }; struct IfStatement : Statement { std::unique_ptr expression; std::vector> body; std::vector> elseBody; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "IfStatement\n"; std::cout << std::string(indent + 2, ' ') << "expression:\n"; expression->Print(indent + 4); std::cout << std::string(indent + 2, ' ') << "Body:\n"; for (const auto& stmt : body) stmt->Print(indent + 4); std::cout << std::string(indent + 2, ' ') << "Else Body:\n"; for (const auto& stmt : elseBody) stmt->Print(indent + 4); } }; struct FunctionStatement : Statement { std::string name; std::vector parameters; std::vector> body; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "FunctionStatement\n"; std::cout << std::string(indent + 2, ' ') << "name: " << name << "\n"; std::cout << std::string(indent + 2, ' ') << "Paramters:\n"; for (const auto& param : parameters) std::cout << std::string(indent + 4, ' ') << param << "\n"; std::cout << std::string(indent + 2, ' ') << "Body:\n"; for (const auto& stmt : body) stmt->Print(indent + 4); } }; struct FunctionExpression : Expression { std::vector parameters; std::vector> body; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "FunctionExpression\n"; std::cout << std::string(indent + 2, ' ') << "Paramters:\n"; for (const auto& param : parameters) std::cout << std::string(indent + 4, ' ') << param << "\n"; std::cout << std::string(indent + 2, ' ') << "Body:\n"; for (const auto& stmt : body) stmt->Print(indent + 4); } }; struct ReturnStatement : Statement { std::unique_ptr expression; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "ReturnStatement\n"; std::cout << std::string(indent + 2, ' ') << "Expression:\n"; if(expression) expression->Print(indent + 4); } }; struct IncludeStatement : Statement { std::string path; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "IncludeStatement\n"; std::cout << std::string(indent + 2, ' ') << "Path: " << path << "\n"; } }; #endif