diff --git a/src/variables/environment.cpp b/src/variables/environment.cpp index b5e5f7a..26465e0 100644 --- a/src/variables/environment.cpp +++ b/src/variables/environment.cpp @@ -5,15 +5,11 @@ struct Environment* create_environment(void) { struct Environment* env = new Environment(); - env->num_vars = 0; - for(int i = 0; i < MAX_VARIABLES; i++) { - env->vars[i] = nullptr; - } return env; } struct Variable* find_variable(struct Environment* env, std::string id) { - for (int i = 0; i < env->num_vars; i++) { + for (uint i = 0; i < size(env->vars); i++) { if (id.compare(env->vars[i]->id) == 0) { return env->vars[i]; } @@ -22,11 +18,6 @@ struct Variable* find_variable(struct Environment* env, std::string id) { } void add_variable(struct Environment* env, struct Variable* var) { - if (env->num_vars >= MAX_VARIABLES) { - std::cerr << "Error: Maximum number of variables reached." << std::endl; - return; - } - // If variable exists, replace it struct Variable* temp_var = find_variable(env, var->id); if (temp_var != nullptr) { @@ -36,12 +27,11 @@ void add_variable(struct Environment* env, struct Variable* var) { } // If not, add variable to environment - env->vars[env->num_vars] = var; - env->num_vars += 1; + env->vars.push_back(var); } void delete_environment(struct Environment* env) { - for (int i = 0; i < env->num_vars; i++) { + for (uint i = 0; i < size(env->vars); i++) { free(env->vars[i]); } free(env); diff --git a/src/variables/environment.hpp b/src/variables/environment.hpp index 3f18d15..aa0ea46 100644 --- a/src/variables/environment.hpp +++ b/src/variables/environment.hpp @@ -2,11 +2,10 @@ #define ENVIRONMENT_H #include -#define MAX_VARIABLES 200 +#include struct Environment { - int num_vars; - struct Variable* vars[MAX_VARIABLES]; + std::vector vars; }; // Variable Lookup Functions