45 lines
826 B
C
45 lines
826 B
C
#include "ast_word.h"
|
|
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
struct ast *ast_create_word(char *word)
|
|
{
|
|
struct ast_word *ast_node = malloc(sizeof(struct ast_word));
|
|
if (ast_node == NULL)
|
|
return NULL;
|
|
|
|
ast_node->type = AST_WORD;
|
|
ast_node->word = strdup(word);
|
|
struct ast *res = ast_create(AST_WORD, ast_node);
|
|
if (res == NULL)
|
|
{
|
|
free(ast_node);
|
|
return NULL;
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
struct ast_word *ast_get_word(struct ast *node)
|
|
{
|
|
if (node == NULL || node->type != AST_WORD)
|
|
return NULL;
|
|
|
|
return node->data;
|
|
}
|
|
|
|
bool ast_is_word(struct ast *node)
|
|
{
|
|
return node && node->type == AST_WORD;
|
|
}
|
|
|
|
void ast_free_word(struct ast_word *ast_node)
|
|
{
|
|
if (ast_node == NULL)
|
|
return;
|
|
|
|
free(ast_node->word);
|
|
free(ast_node);
|
|
}
|