#ifndef DLANG_EXPRESSIONS_HPP #define DLANG_EXPRESSIONS_HPP #include #include #include "../types/include.hpp" struct Expression { virtual ~Expression() = default; virtual void Print(int indent = 0) const = 0; }; struct NumberExpression : Expression { double value; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "Number: " << value << '\n'; } }; struct BooleanExpression : Expression { bool value; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "Boolean: " << (value ? "true" : "false") << '\n'; } }; struct StringExpression : Expression { std::string value; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "string: " << value << '\n'; } }; struct IdentifierExpression : Expression { std::string name; std::string keyName; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "Identifier: " << name << '\n'; } }; struct BinaryExpression : Expression { std::unique_ptr left; std::string op; std::unique_ptr right; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "Binary: " << op << '\n'; left->Print(indent + 2); right->Print(indent + 2); } }; struct CallExpression : Expression { std::unique_ptr callee; std::vector< std::unique_ptr> expressions; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << " Call" << "\n"; callee->Print(indent + 2); for (const auto& expr : expressions) expr->Print(indent + 2); } }; struct TableLiteralExpression : Expression { std::vector>> fields; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "TableLiteral {\n"; for (const auto& [key, expr] : fields) { std::cout << std::string(indent + 2, ' ') << key << ":\n"; if (expr) { expr->Print(indent + 4); } } std::cout << std::string(indent, ' ') << "}\n"; } }; struct ListLiteralExpression : Expression { std::vector> fields; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "TableLiteral {\n"; for (const auto& val : fields) val->Print(indent + 2); std::cout << std::string(indent, ' ') << "}\n"; } }; struct MemberAccessExpression : Expression { std::unique_ptr object; std::string memberName; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "MemberAccess: ." << memberName << '\n'; if (object) { object->Print(indent + 2); } } }; struct IndexAccessExpression : Expression { std::unique_ptr object; std::unique_ptr memberIndex; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "IndexAccess: ." << '\n'; memberIndex->Print(indent); if (object) { object->Print(indent + 2); } } }; struct SizeExpression : Expression { std::string identifier; void Print(int indent = 0) const override { std::cout << std::string(indent, ' ') << "Identifier: " << identifier << '\n'; } }; #endif