45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <map>
|
|
#include <optional>
|
|
#include <variant>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "../parser/parser.h"
|
|
|
|
class Object {
|
|
public:
|
|
bool isCustomObject = false;
|
|
std::variant<ASTValue, ASTFunction> value;
|
|
std::map<std::string, std::variant<Object, ASTFunction, ASTValue>> children;
|
|
Object(ASTValue value);
|
|
Object(ASTFunction function);
|
|
Object();
|
|
};
|
|
|
|
/**
|
|
* @class Executor
|
|
* @brief Responsible for executing a sequence of operations defined in an abstract syntax tree (AST).
|
|
*
|
|
* This class provides execution functionality for ASTCodeBlock objects.
|
|
* It maintains a mapping of variables and functions that can be used within the
|
|
* context of execution. The class implements mechanisms for traversing AST nodes
|
|
* and consuming or peeking at individual nodes.
|
|
*/
|
|
|
|
class Executor {
|
|
private:
|
|
std::map<std::string, Object> variables;
|
|
ASTCodeBlock code;
|
|
size_t iterator = 0;
|
|
std::optional<ASTNode> consume();
|
|
std::optional<ASTNode> peek(int ahead = 1);
|
|
void printValue(const ASTValue& arg);
|
|
ASTValue evaluateOperator(const std::shared_ptr<ASTOperator>& op);
|
|
public:
|
|
explicit Executor(ASTCodeBlock in, bool isInitCall = false, std::map<std::string, Object> scopeVals = {}, std::vector<Object> args = {});
|
|
std::map<std::string, Object> getVariables();
|
|
};
|
|
|