Archived
1
0
Fork 0

Replaced ints with uints and added comments indicating where I'll want delete statements in the future.

This commit is contained in:
Brandon Rozek 2018-09-28 14:11:58 -04:00
parent 9a727aa83b
commit 33bb265d27
5 changed files with 18 additions and 7 deletions

View file

@ -38,6 +38,7 @@ void interpret_file(char* fileName) {
struct Environment* env = new Environment();
eval_statement(result, env);
delete_environment(env);
// delete env;
delete result;
}

View file

@ -15,14 +15,14 @@ void attach_node(struct Node* parent, struct Node* child) {
if (parent->num_children > MAX_CHILDREN) { std::cerr << "Error, max children attached to a node" << std::endl; }
}
void check_num_nodes(struct Node* node, int num_children, std::string error) {
void check_num_nodes(struct Node* node, uint num_children, std::string error) {
if (node && node->num_children != num_children) {
std::cerr << "Error, " << error << std::endl;
}
}
void print_tree(struct Node* node, int tabs) {
int i;
void print_tree(struct Node* node, uint tabs) {
uint i;
/* base case */
if(!node) {
std::cerr << "NO TREE STRUCTURE" << std::endl;
@ -113,6 +113,7 @@ struct Value* eval_expression(struct Node* node, struct Environment* env) {
eval_expression(node->children[1], env)));
tempVal = eval_expression(tempNode->children[1], local_env);
delete_environment(local_env);
// delete local_env;
return tempVal;
break;
case PLUS:

View file

@ -17,19 +17,21 @@ struct Node {
std::string id;
/* at most three children nodes */
int num_children;
uint num_children;
std::array<struct Node*, MAX_CHILDREN> children;
Node(int t, struct Value* v, std::string s) {
type = t;
value = v;
id = s;
for (int i = 0; i < MAX_CHILDREN; i++) {
for (uint i = 0; i < MAX_CHILDREN; i++) {
children[i] = nullptr;
}
}
~Node() {
for (int i = 0; i < num_children; i++) {
if (value) { delete value; }
// delete value;
for (uint i = 0; i < num_children; i++) {
delete children[i];
}
}

View file

@ -70,5 +70,6 @@ void start_shell() {
}
delete_environment(env);
// delete env;
delete result;
}

View file

@ -1,12 +1,18 @@
#ifndef ENVIRONMENT_H
#define ENVIRONMENT_H
#include "variable.hpp"
#include <string>
#include <vector>
struct Environment {
std::vector<struct Variable*> vars;
Environment() { }
// ~Environment() {
// for (uint i = 0; i < size(vars); i++) {
// delete vars[i];
// }
// }
};
// Variable Lookup Functions