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.
51 lines
1.3 KiB
51 lines
1.3 KiB
5 years ago
|
#ifndef PRINT_C
|
||
|
#define PRINT_C
|
||
|
#include "print.h"
|
||
|
|
||
|
/*
|
||
|
Author: xerox
|
||
|
Updated: 1/20/2020
|
||
|
|
||
|
creates a print statement given variable type and value.
|
||
|
*/
|
||
|
|
||
5 years ago
|
static node_info* create_print_statement(variable_type operation, void* value)
|
||
5 years ago
|
{
|
||
5 years ago
|
if (!value)
|
||
5 years ago
|
return NULL;
|
||
|
|
||
5 years ago
|
node_info* new_print_stmt = (node_info*)malloc(sizeof(node_info));
|
||
|
print* new_print = malloc(sizeof(print));
|
||
5 years ago
|
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;
|
||
5 years ago
|
new_print_stmt->statement_list = NULL;
|
||
5 years ago
|
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)
|
||
|
{
|
||
5 years ago
|
if (!var_name)
|
||
5 years ago
|
return NULL;
|
||
|
|
||
5 years ago
|
node_info* new_print_stmt = (node_info*)malloc(sizeof(node_info));
|
||
5 years ago
|
new_print_stmt->var = malloc(sizeof(variable));
|
||
|
new_print_stmt->operation = PRINT_OPERATION;
|
||
|
new_print_stmt->operation_type.print = PRINT_VARIABLE;
|
||
|
new_print_stmt->var->name = var_name;
|
||
5 years ago
|
|
||
|
new_print_stmt->statement_list = NULL;
|
||
5 years ago
|
new_print_stmt->next = NULL;
|
||
|
return new_print_stmt;
|
||
|
}
|
||
|
#endif
|