aboutsummaryrefslogtreecommitdiff
path: root/src/new_node.c
diff options
context:
space:
mode:
authorDominik Kaiser2024-06-28 15:09:32 +0200
committerGitHub2024-06-28 15:09:32 +0200
commit8103cadfc95fb76539bfccc893a2101ccb89ea90 (patch)
treeb46379099324f76f2496909b4de3cd71de8b772a /src/new_node.c
parent031685832d8267acc2fa46ea9732b8e95eb34463 (diff)
downloadminishell-8103cadfc95fb76539bfccc893a2101ccb89ea90.tar.gz
minishell-8103cadfc95fb76539bfccc893a2101ccb89ea90.zip
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
Diffstat (limited to 'src/new_node.c')
-rw-r--r--src/new_node.c72
1 files changed, 72 insertions, 0 deletions
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 <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/06/27 11:21:03 by dkaiser #+# #+# */
+/* Updated: 2024/06/28 15:04:15 by dkaiser ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ast.h"
+
+t_node *new_node(int type)
+{
+ t_node *node;
+
+ node = malloc(sizeof(t_node));
+ if (node == NULL)
+ return (NULL);
+ node->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);
+}