diff options
Diffstat (limited to 'test_mini/parse')
| -rw-r--r-- | test_mini/parse/parse.c | 25 | ||||
| -rw-r--r-- | test_mini/parse/parse.h | 89 | ||||
| -rw-r--r-- | test_mini/parse/utils_parse.c | 35 |
3 files changed, 149 insertions, 0 deletions
diff --git a/test_mini/parse/parse.c b/test_mini/parse/parse.c new file mode 100644 index 0000000..4f2be38 --- /dev/null +++ b/test_mini/parse/parse.c @@ -0,0 +1,25 @@ + +#include "parse.h" +#include <stdio.h> + + +t_return *parse(t_return *nw, char **input) +{ + int i; + + i = 0; + verif_part(input, ';'); + //printf("%s\n","salut"); + return (nw); +} + +t_return *parse_nw(char **input) +{ + t_return *nw; + + if (!(nw = malloc(sizeof(t_ast)))) + exit(0); + nw->rest = input; + parse(nw, input); + return (nw); +} diff --git a/test_mini/parse/parse.h b/test_mini/parse/parse.h new file mode 100644 index 0000000..b5fe817 --- /dev/null +++ b/test_mini/parse/parse.h @@ -0,0 +1,89 @@ + + +# include <stdlib.h> +# include <stdlib.h> +# include <stdbool.h> + + +typedef enum e_sep +{ + SEP_END, + SEP_PIPE, + SEP_AND, + SEP_OR, +} t_sep; + +struct s_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 s_line +{ + struct s_ast *left; + struct s_ast *right; + struct s_ast *parent; + 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 s_cmd +{ + char *str; + char *in; + char *out; + bool is_append; +} t_cmd; + +/* +** \brief AST node tag (type) +** \param TAG_CMD Command AST node +** \param TAG_LINE Line AST node +*/ + +typedef enum e_ast_tag +{ + TAG_CMD, + TAG_LINE, +} t_ast_tag; + +/* +** \brief AST node struct +** \param tag Node tag +** \param cmd Command struct +** \param line Line struct +*/ + +typedef struct s_ast +{ + t_ast_tag tag; + union + { + t_line line; + t_cmd cmd; + } ; +} t_ast; + +typedef struct s_return +{ + t_ast *result; + char **rest; +} t_return; + +t_return *parse_nw(char **input); +t_return *parse(t_return *nw, char **input); + +/* utils*/ +int verif_part(char **input, char chr); diff --git a/test_mini/parse/utils_parse.c b/test_mini/parse/utils_parse.c new file mode 100644 index 0000000..c469810 --- /dev/null +++ b/test_mini/parse/utils_parse.c @@ -0,0 +1,35 @@ + + +#include <stdio.h> + +static int pass_parenthese(char **input, int i, int j) +{ + while(input[i][j++]) + if (input[i][j] == ')') + return (i); + return (i); +} + +int verif_part(char **input, char chr) +{ + int i; + int j; + + i = 0; + while (input[i]) + { + + j = 0; + while (input[i][j]) + { + if (input[i][j] == '(') + pass_parenthese(input, i, j); + if (input[i][j] == chr) + return (i); + j++; + } + + i++; + } + return (0); +} |
