From 808d1499f5708ad4eda3612416e62efe6fdff021 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 31 Mar 2020 21:31:26 +0200 Subject: More specific AST struct and evaluation start --- include/ast.h | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 include/ast.h (limited to 'include/ast.h') diff --git a/include/ast.h b/include/ast.h new file mode 100644 index 0000000..4ee3396 --- /dev/null +++ b/include/ast.h @@ -0,0 +1,80 @@ +#ifndef AST_H +# define AST_H + +/** +** \file ast.h +** \brief AST structs +*/ + +/** +** \brief Separator type +** \param SEP_END Regular command end `;` +** \param SEP_PIPE Pipe output of left to right `|` +** \param SEP_AND Execute right if left status == 0 `&&` +** \param SEP_OR Execute right if left status != 0 `||` +*/ + +typedef enum +{ + SEP_END, + SEP_PIPE, + SEP_AND, + SEP_OR, +} t_sep; + +typedef struct s_ast t_ast; +/** +** \brief Line struct +** \param left AST to the left of separator +** \param right AST to the right of separator +** \param sep Type of separator +*/ + +typedef struct +{ + t_ast *left; + t_ast *right; + t_sep sep; +} t_line; + +/** +** \brief Command struct +** \param argv Array of string, all arguments beginning with executable name +** \param in STDIN redirection filename +** \param out STDOUT redirection filename +** \param is_append True if out redirection is append to file +*/ + +typedef struct +{ + char **argv; + char *in; + char *out; + bool is_append; +} t_cmd; + +typedef enum +{ + TAG_CMD, + TAG_LINE, +} t_ast_tag; + +/** +** \brief AST node struct +** \param type Node type +** \param data Union containning possible node data +** \param data::cmd Command struct +** \param data::line Line struct +*/ + +struct s_ast +{ + t_ast_tag tag; + union + { + t_line line; + t_cmd cmd; + } data; +}; + +#endif -- cgit