aboutsummaryrefslogtreecommitdiff
path: root/include/ast.h
diff options
context:
space:
mode:
authorDominik Kaiser2024-06-28 15:09:32 +0200
committerGitHub2024-06-28 15:09:32 +0200
commit8103cadfc95fb76539bfccc893a2101ccb89ea90 (patch)
treeb46379099324f76f2496909b4de3cd71de8b772a /include/ast.h
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 'include/ast.h')
-rw-r--r--include/ast.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/include/ast.h b/include/ast.h
new file mode 100644
index 0000000..e6ad25d
--- /dev/null
+++ b/include/ast.h
@@ -0,0 +1,79 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ast.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/06/27 11:48:27 by dkaiser #+# #+# */
+/* Updated: 2024/06/28 14:56:55 by dkaiser ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "stdlib.h"
+#include "debug_tools.h"
+
+typedef struct s_sequence
+{
+ struct s_node **nodes;
+} t_sequence;
+
+enum e_node_type
+{
+ ASSIGN_NODE,
+ PIPE_NODE,
+ CMD_NODE,
+ STRING_NODE
+};
+
+typedef struct s_assign
+{
+ char *var;
+ char *value;
+} t_assign;
+
+typedef struct s_pipe
+{
+ struct s_node *left;
+ struct s_node *right;
+} t_pipe;
+
+enum e_redirection_type
+{
+ INPUT_FILE,
+ INPUT_LIMITER,
+ OUTPUT_OVERRIDE,
+ OUTPUT_APPEND
+};
+
+typedef struct s_redirection
+{
+ int type;
+ char *specifier;
+} t_redirection;
+
+typedef struct s_cmd
+{
+ char **args;
+ struct s_redirection redirs[2];
+} t_cmd;
+
+union u_node_content
+{
+ struct s_assign assign;
+ struct s_pipe pipe;
+ struct s_cmd cmd;
+ char *string;
+};
+
+typedef struct s_node
+{
+ int type;
+ union u_node_content content;
+} t_node;
+
+t_node *new_node(int type);
+t_node *new_assign_node(char *var, char *value);
+t_node *new_pipe_node(t_node *left, t_node *right);
+t_node *new_cmd_node(char **args, t_redirection redirs[2]);
+t_node *new_string_node(char *string);