You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.5 KiB

#ifndef PRINT_C
#define PRINT_C
#include "print.h"
/*
Author: xerox
Updated: 1/20/2020
creates a print statement given variable type and value.
*/
static node_info *create_print_statement(variable_type operation, void* value)
{
node_info* new_print_stmt = (node_info*)malloc(sizeof(node_info));
print* new_print = malloc(sizeof(print));
if (!new_print_stmt || !new_print)
return NULL;
memset(new_print_stmt, NULL, sizeof(*new_print_stmt));
memset(new_print, NULL, sizeof(*new_print));
new_print_stmt->operation = PRINT_OPERATION;
new_print_stmt->operation_type.print = PRINT_CONSTANT;
new_print->type = operation;
new_print->value = value;
new_print_stmt->print_expr = new_print;
new_print_stmt->next = NULL;
return new_print_stmt;
}
/*
Author: xerox
Updated: 1/19/2020
create print variable from variable name.
*/
static node_info* create_print_variable(char* var_name)
{
node_info* new_print_stmt = (node_info*)malloc(sizeof(node_info));
if (!new_print_stmt || !var_name)
return NULL;
memset(new_print_stmt, NULL, sizeof(*new_print_stmt));
new_print_stmt->var = malloc(sizeof(variable));
if (!new_print_stmt->var)
return NULL;
memset(new_print_stmt->var, NULL, sizeof(*new_print_stmt->var));
new_print_stmt->operation = PRINT_OPERATION;
new_print_stmt->operation_type.print = PRINT_VARIABLE;
new_print_stmt->var->name = var_name;
new_print_stmt->next = NULL;
return new_print_stmt;
}
#endif