Archived
1
0
Fork 0

Variable constructor made

This commit is contained in:
Brandon Rozek 2018-09-28 12:32:19 -04:00
parent 6022898e2b
commit 7514b3a088
2 changed files with 5 additions and 26 deletions

View file

@ -2,19 +2,6 @@
#include <string> #include <string>
#include "variable.hpp" #include "variable.hpp"
/* creates a new variable and returns it */
struct Variable* make_variable(std::string id, struct Value* value) {
/* allocate space */
struct Variable* var = new Variable();
/* set properties */
var->id = id;
var->value = value;
/* return new variable */
return var;
}
void set_value(struct Variable* var, struct Value* value) { void set_value(struct Variable* var, struct Value* value) {
if (!var) { std::cerr << "Error: Invalid Variable" << std::endl; return; } if (!var) { std::cerr << "Error: Invalid Variable" << std::endl; return; }
var->value = value; var->value = value;

View file

@ -7,10 +7,14 @@
struct Variable { struct Variable {
std::string id; std::string id;
struct Value* value; struct Value* value;
Variable(std::string s, struct Value* val) {
id = s;
value = val;
}
}; };
// Variable Functions // Variable Functions
struct Variable* make_variable(std::string id, struct Value* value);
void set_value(struct Variable* var, struct Value* value); void set_value(struct Variable* var, struct Value* value);
struct Value* get_value(struct Variable* var); struct Value* get_value(struct Variable* var);
struct Value* make_long(long num); struct Value* make_long(long num);
@ -21,15 +25,3 @@ struct Value* make_boolean(int x);
struct Value* make_expression(struct Node* expr); struct Value* make_expression(struct Node* expr);
#endif #endif
// /* creates a new variable and returns it */
// struct Variable* make_variable(char* id, struct Value* value) {
// /* allocate space */
// struct Variable* var = new Variable();
// /* set properties */
// strcpy(var->id, id);
// var->value = value;
// /* return new variable */
// return var;
// }