GSC Interpreter
A Turing-complete interpreter developed for a compiler course
|
Represents an environment for variable storage in the GSC interpreter. More...
#include <environment.hpp>
Public Member Functions | |
Environment () | |
Constructs a new Environment. | |
Environment (std::shared_ptr< Environment > enclosing) | |
Constructs a new Environment with an enclosing environment. | |
std::any | get (const Token &name) const |
Retrieves the value of a variable by its name. | |
void | assign (const Token &name, std::any value) |
Assigns a value to a variable by its name. | |
void | define (const std::string &name, std::any value) |
Defines a new variable in the current environment. | |
Private Attributes | |
std::shared_ptr< Environment > | enclosing |
std::map< std::string, std::any > | values |
Represents an environment for variable storage in the GSC interpreter.
Definition at line 15 of file environment.hpp.
Environment::Environment | ( | ) |
Constructs a new Environment.
Definition at line 4 of file environment.cpp.
Environment::Environment | ( | std::shared_ptr< Environment > | enclosing | ) |
Constructs a new Environment with an enclosing environment.
enclosing | A shared pointer to the enclosing environment. |
Definition at line 6 of file environment.cpp.
void Environment::assign | ( | const Token & | name, |
std::any | value | ||
) |
Assigns a value to a variable by its name.
name | The Token representing the variable name. |
value | The value to assign to the variable. |
RuntimeError | if the variable is not defined in this or any enclosing environment. |
Definition at line 21 of file environment.cpp.
void Environment::define | ( | const std::string & | name, |
std::any | value | ||
) |
Defines a new variable in the current environment.
name | The name of the variable to define. |
value | The value to assign to the variable. |
Definition at line 35 of file environment.cpp.
std::any Environment::get | ( | const Token & | name | ) | const |
Retrieves the value of a variable by its name.
name | The Token representing the variable name. |
RuntimeError | if the variable is not defined in this or any enclosing environment. |
Definition at line 9 of file environment.cpp.
|
private |
Definition at line 17 of file environment.hpp.
|
private |
Definition at line 18 of file environment.hpp.