-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Katarni/interpreter
Interpreter
- Loading branch information
Showing
31 changed files
with
2,112 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// Created by Timur Akhmetzianov on 22.11.2024 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "PRNGenerator.h" | ||
|
||
|
||
class Interpreter { | ||
public: | ||
explicit Interpreter(PRNGenerator *generator) : generator_(generator), cur_(0) {} | ||
|
||
void global(); | ||
|
||
void callFunc(const std::string& func, const std::vector<std::variant<ReservedMemory*, Literal>>& vars); | ||
|
||
private: | ||
class FunctionCall { | ||
public: | ||
explicit FunctionCall(size_t return_address) : return_address_(return_address) {} | ||
~FunctionCall(); | ||
|
||
ReservedMemory*& getVar(const Identifier& name); | ||
bool findVar(const Identifier& name); | ||
ReservedMemory*& createVar(const Identifier& name); | ||
|
||
void setVar(const std::string& name, ReservedMemory* var_ptr); | ||
void setVar(const std::string& name, const ReservedMemory& var); | ||
|
||
[[nodiscard]] | ||
size_t returnAddress() const; | ||
|
||
private: | ||
size_t return_address_; | ||
std::map<std::string, ReservedMemory*> vars_; | ||
std::map<std::string, bool> is_lvalue_arg_; | ||
}; | ||
|
||
size_t cur_; | ||
|
||
std::stack<std::stack<std::variant<ReservedMemory*, Literal, size_t, std::string>>> calc_stack_; | ||
PRNGenerator *generator_; | ||
|
||
std::map<std::string, ReservedMemory*> global_vars_; | ||
std::stack<FunctionCall> function_stack_; | ||
|
||
void operation(const Token& operation); | ||
void operation(PRNGenerator::SysVals operation); | ||
void lvalueOperation(const Token& operation); | ||
|
||
ReservedMemory*& getVar(const Identifier& name); | ||
ReservedMemory*& createVar(const Identifier& name); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.