|
|
|
@ -8,7 +8,8 @@ extern node_info *_temp_statement_head;
|
|
|
|
|
//struct variable *_var_head = NULL;
|
|
|
|
|
extern map_void_t *_function_list;
|
|
|
|
|
|
|
|
|
|
node_info* create_var_assignment_string(char *p_name, char *value) {
|
|
|
|
|
node_info* create_var_assignment_string(char *p_name, char *value)
|
|
|
|
|
{
|
|
|
|
|
node_info *new_node = malloc(sizeof(node_info));
|
|
|
|
|
variable *new_var = make_variable_string(p_name, value);
|
|
|
|
|
newNode->type = ASSIGNMENT;
|
|
|
|
@ -17,7 +18,8 @@ node_info* create_var_assignment_string(char *p_name, char *value) {
|
|
|
|
|
return new_node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node_info* create_var_assignment_int(char *p_name, int value) {
|
|
|
|
|
node_info* create_var_assignment_int(char *p_name, int value)
|
|
|
|
|
{
|
|
|
|
|
node_info *new_node = malloc(sizeof(node_info));
|
|
|
|
|
variable *new_var = make_variable_int(p_name, value);
|
|
|
|
|
newNode->type = ASSIGNMENT;
|
|
|
|
@ -26,7 +28,8 @@ node_info* create_var_assignment_int(char *p_name, int value) {
|
|
|
|
|
return new_node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node_info* create_var_assignment_char(char *p_name, char value) {
|
|
|
|
|
node_info* create_var_assignment_char(char *p_name, char value)
|
|
|
|
|
{
|
|
|
|
|
node_info *new_node = malloc(sizeof(node_info));
|
|
|
|
|
variable *new_var = make_variable_char(p_name, value);
|
|
|
|
|
newNode->type = ASSIGNMENT;
|
|
|
|
@ -35,7 +38,8 @@ node_info* create_var_assignment_char(char *p_name, char value) {
|
|
|
|
|
return new_node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node_info* create_var_assignment_double(char *p_name, double value) {
|
|
|
|
|
node_info* create_var_assignment_double(char *p_name, double value)
|
|
|
|
|
{
|
|
|
|
|
node_info *new_node = malloc(sizeof(node_info));
|
|
|
|
|
variable *new_var = make_variable_double(p_name, value);
|
|
|
|
|
//new node stuff
|
|
|
|
@ -52,20 +56,19 @@ Adds statement to linked list.
|
|
|
|
|
@param nodeInfo link to be added.
|
|
|
|
|
@return head of linked list.
|
|
|
|
|
*/
|
|
|
|
|
node_info* add_to_compound_statement(node_info *new_statement, node_info *statement_head) {
|
|
|
|
|
|
|
|
|
|
if(statement_head == NULL) {
|
|
|
|
|
|
|
|
|
|
node_info* add_to_compound_statement(node_info *new_statement, node_info *statement_head)
|
|
|
|
|
{
|
|
|
|
|
if(!statement_head)
|
|
|
|
|
{
|
|
|
|
|
statement_head = malloc(sizeof(node_info));
|
|
|
|
|
statement_head->opperation = 5;
|
|
|
|
|
statement_head->next = new_statement;
|
|
|
|
|
statement_head->next->next = NULL;
|
|
|
|
|
statement_head->statement_list = NULL;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
node_info *p = statement_head; //make a temp of list head, so we can traverse it.
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
node_info *p = statement_head; //make a temp of list head, so we can traverse it
|
|
|
|
|
//TODO replace with double linked list end
|
|
|
|
|
while (p->statement_list)
|
|
|
|
|
p = p->statement_list;
|
|
|
|
@ -88,29 +91,30 @@ Executes a statment.
|
|
|
|
|
@return void.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//TODO return bool or int detailing the status of execution.
|
|
|
|
|
void ex(node_info *n)
|
|
|
|
|
{
|
|
|
|
|
switch(n->opperation)
|
|
|
|
|
//TODO break this switch up into multiple functions
|
|
|
|
|
//TODO return status code possibly.
|
|
|
|
|
void ex(node_info *exec_node)
|
|
|
|
|
{
|
|
|
|
|
switch(exec_node->opperation)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
add_var(n->var->name, n->var->value, _var_map);
|
|
|
|
|
add_var(exec_node->var->name, exec_node->var->value, _var_map);
|
|
|
|
|
break;
|
|
|
|
|
//TODO expression stuff
|
|
|
|
|
case 2:
|
|
|
|
|
break;
|
|
|
|
|
//print
|
|
|
|
|
case 3:
|
|
|
|
|
switch(n->printExpression.opperation) {
|
|
|
|
|
switch(exec_node->printExpression.opperation) {
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
printf("%d\n", (int) n->printExpression.value);
|
|
|
|
|
printf("%d\n", (int) exec_node->printExpression.value);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
printf("%s\n", n->printExpression.string);
|
|
|
|
|
printf("%s\n", exec_node->printExpression.string);
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
printf("%s%lf\n", n->printExpression.string, n->printExpression.value);
|
|
|
|
|
printf("%s%lf\n", exec_node->printExpression.string, exec_node->printExpression.value);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("{ERROR} CHECK YACC FILE FOR INCORRECT PRINT\n");
|
|
|
|
@ -118,29 +122,29 @@ void ex(node_info *n)
|
|
|
|
|
break;
|
|
|
|
|
//logic (if, while, for, etc)
|
|
|
|
|
case 4:
|
|
|
|
|
switch(n->logicalExpression.opperation) {
|
|
|
|
|
switch(exec_node->logicalExpression.opperation) {
|
|
|
|
|
case 1:
|
|
|
|
|
if (n->logicalExpression.expr == 1)
|
|
|
|
|
ex(n->logicalExpression.if_true);
|
|
|
|
|
if (exec_node->logicalExpression.expr == 1)
|
|
|
|
|
ex(exec_node->logicalExpression.if_true);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
while (n->logicalExpression.expr == 1)
|
|
|
|
|
ex(n->logicalExpression.while_true);
|
|
|
|
|
while (exec_node->logicalExpression.expr == 1)
|
|
|
|
|
ex(exec_node->logicalExpression.while_true);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("{ERROR} SOMETHING WRONG WITH LOGICAL EXPRESSION CHECK YACC\n");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
while(n->next != NULL)
|
|
|
|
|
while(exec_node->next != NULL)
|
|
|
|
|
{
|
|
|
|
|
n = n->next;
|
|
|
|
|
ex(n);
|
|
|
|
|
exec_node = exec_node->next;
|
|
|
|
|
ex(exec_node);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
;
|
|
|
|
|
variable_values *value = get_value(n->name, _var_map);
|
|
|
|
|
variable_values *value = get_value(exec_node->name, _var_map);
|
|
|
|
|
switch(value->type)
|
|
|
|
|
{
|
|
|
|
|
case VAR_STRING:
|
|
|
|
@ -165,12 +169,12 @@ void ex(node_info *n)
|
|
|
|
|
//TODO update default to case 7 for functions
|
|
|
|
|
default:
|
|
|
|
|
;
|
|
|
|
|
switch(n->type)
|
|
|
|
|
switch(exec_node->type)
|
|
|
|
|
{
|
|
|
|
|
case FUNCTION_CALL:
|
|
|
|
|
;
|
|
|
|
|
//gets the statements of a function with the provided name
|
|
|
|
|
node_info *_stmts = *map_get(&*((map_void_t* ) _function_list), n->name);
|
|
|
|
|
node_info *_stmts = *map_get(&*((map_void_t* ) _function_list), exec_node->name);
|
|
|
|
|
while (_stmts->next != NULL) { //loop over all the statements and execute them
|
|
|
|
|
_stmts = _stmts->next;
|
|
|
|
|
ex(_stmts);
|
|
|
|
@ -182,15 +186,15 @@ void ex(node_info *n)
|
|
|
|
|
if (!_function_list)
|
|
|
|
|
{
|
|
|
|
|
_function_list = malloc(sizeof(map_void_t));
|
|
|
|
|
n->_var_list = malloc(sizeof(node_info));
|
|
|
|
|
n->next = NULL;
|
|
|
|
|
n->local_list = NULL;
|
|
|
|
|
exec_node->_var_list = malloc(sizeof(node_info));
|
|
|
|
|
exec_node->next = NULL;
|
|
|
|
|
exec_node->local_list = NULL;
|
|
|
|
|
map_init(&*((map_void_t *) _function_list));
|
|
|
|
|
map_init(&*((map_void_t *) n->_var_list));
|
|
|
|
|
map_init(&*((map_void_t *) exec_node->_var_list));
|
|
|
|
|
//put the function in the hashmap
|
|
|
|
|
map_set(&*((map_void_t* ) _function_list), n->name, &*n->_function_body);
|
|
|
|
|
map_set(&*((map_void_t* ) _function_list), exec_node->name, &*exec_node->_function_body);
|
|
|
|
|
} else //else we dont malloc, we just put the function inside of the hashmap.
|
|
|
|
|
map_set(&*((map_void_t* ) _function_list), n->name, &*n->_function_body);
|
|
|
|
|
map_set(&*((map_void_t* ) _function_list), exec_node->name, &*exec_node->_function_body);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
;
|
|
|
|
|