From ba9a9199d01b0fdd4bf9a54914f8058bf71f30c5 Mon Sep 17 00:00:00 2001
From: Ferenc Szontágh <szf@fsociety.hu>
Date: Thu, 17 Apr 2025 16:03:01 +0000
Subject: [PATCH] unary and binary operations
---
src/Interpreter/Operation.hpp | 68 ++++++++++++++++++++++++++-------
1 files changed, 53 insertions(+), 15 deletions(-)
diff --git a/src/Interpreter/Operation.hpp b/src/Interpreter/Operation.hpp
index ecbae0b..8804075 100644
--- a/src/Interpreter/Operation.hpp
+++ b/src/Interpreter/Operation.hpp
@@ -2,30 +2,68 @@
#define INTERPRETER_OPERATION_HPP
#include <cstdint>
-
#include <memory>
#include <string>
+#include <unordered_map>
-#include "ExpressionNode.hpp"
+#include "Interpreter/StatementNode.hpp"
-namespace Interpreter {
-enum OperationType : std::uint8_t {
- Assignment,
- Expression,
-
+namespace Operations {
+enum class Type : std::uint8_t {
+ Assignment, // Variable assignment, e.g., $x = 5
+ Expression, // Evaluation of an expression (can be evaluated without side effects)
+ FunctionCall, // Call to a function, e.g., print(x)
+ FuncDeclaration, // declaration of new function
+ Return, // return statement
+ Conditional, // if/else structure
+ Loop, // while/for loop
+ Break, // break out of a loop
+ Continue, // continue with the next iteration of a loop
+ Block, // block of statements, e.g. { ... }
+ Declaration, // declaration of new variable (if different from assignment) int $x = 1
+ Import, // import of another script or module
+ Error, // error or non-interpretable operation (error handling)
};
struct Operation {
- OperationType type;
+ Operation() = default;
+ Operations::Type type;
// Általános mezők
- std::string targetVariable;
- std::unique_ptr<ExpressionNode> expression;
+ std::string targetName;
+ std::unique_ptr<Interpreter::StatementNode> statement;
- Operation(OperationType t, std::string var, std::unique_ptr<ExpressionNode> expr)
- : type(t), targetVariable(std::move(var)), expression(std::move(expr)) {}
+ Operation(Operations::Type t, std::string target_variable, std::unique_ptr<Interpreter::StatementNode> stmt) :
+ type(t),
+ targetName(std::move(target_variable)),
+ statement(std::move(stmt)) {}
+
+ std::string typeToString() const {
+ std::unordered_map<Operations::Type, std::string> types = {
+ { Operations::Type::Assignment, "Assignment" },
+ { Operations::Type::Expression, "Expression" },
+ { Operations::Type::FunctionCall, "FunctionCall" },
+ { Operations::Type::FuncDeclaration, "FuncDeclaration" },
+ { Operations::Type::Return, "Return" },
+ { Operations::Type::Conditional, "Conditional" },
+ { Operations::Type::Loop, "Loop" },
+ { Operations::Type::Break, "Break" },
+ { Operations::Type::Continue, "Continue" },
+ { Operations::Type::Block, "Block" },
+ { Operations::Type::Declaration, "Declaration" },
+ { Operations::Type::Import, "Import" },
+ { Operations::Type::Error, "Error" }
+ };
+ auto it = types.find(type);
+ if (it != types.end()) {
+ return it->second;
+ }
+ return "Unknown type";
+ }
+
+ std::string toString() const {
+ return "Target: " + targetName + " Type: " + this->typeToString() + " Statement: " + statement->toString();
+ }
};
-
-
-}; // namespace Interpreter
+}; // namespace Operations
#endif
--
Gitblit v1.9.3