From 8103cadfc95fb76539bfccc893a2101ccb89ea90 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Fri, 28 Jun 2024 15:09:32 +0200 Subject: Add data structures for tokenizing and parsing * Add data structures and helper functions for ast * Add data structures for tokenizing * Add helper functions for token structures * Include token.h in minishell.h * Add new/free functions for nodes/tokens to Makefile * Add UNREACHABLE macro to debug_tools.h--- src/new_node.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/new_node.c (limited to 'src/new_node.c') diff --git a/src/new_node.c b/src/new_node.c new file mode 100644 index 0000000..4cdbf9a --- /dev/null +++ b/src/new_node.c @@ -0,0 +1,72 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* new_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser type = type; + return (node); +} + +t_node *new_assign_node(char *var, char *value) +{ + t_node *node; + + node = new_node(ASSIGN_NODE); + if (node == NULL) + return (NULL); + node->content.assign.var = var; + node->content.assign.value = value; + return (node); +} + +t_node *new_pipe_node(t_node *left, t_node *right) +{ + t_node *node; + + node = new_node(PIPE_NODE); + if (node == NULL) + return (NULL); + node->content.pipe.left = left; + node->content.pipe.right = right; + return (node); +} + +t_node *new_cmd_node(char **args, t_redirection redirs[2]) +{ + t_node *node; + + node = new_node(CMD_NODE); + if (node == NULL) + return (NULL); + node->content.cmd.args = args; + node->content.cmd.redirs[0] = redirs[0]; + node->content.cmd.redirs[1] = redirs[1]; + return (node); +} + +t_node *new_string_node(char *string) +{ + t_node *node; + + node = new_node(STRING_NODE); + if (node == NULL) + return (NULL); + node->content.string = string; + return (node); +} -- cgit v1.2.3