diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-15 13:12:34 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-15 13:12:34 +0200 |
| commit | b8623ff168880845c745da62f7e9a840f0541809 (patch) | |
| tree | 23ca8f41c6bdeb5f4fb3a229ee03a7f76c931eb0 /src/parse | |
| parent | 11a719bab26b3ccccbd219decab2d0cf77021004 (diff) | |
| parent | a7dae7d30b7087bcd9972792a2ee1248e081cfce (diff) | |
| download | minishell-b8623ff168880845c745da62f7e9a840f0541809.tar.gz minishell-b8623ff168880845c745da62f7e9a840f0541809.tar.bz2 minishell-b8623ff168880845c745da62f7e9a840f0541809.zip | |
Merge branch 'parser'
Diffstat (limited to 'src/parse')
| -rwxr-xr-x | src/parse/cmd_parse.c | 31 | ||||
| -rwxr-xr-x[-rw-r--r--] | src/parse/parse.c | 55 | ||||
| -rwxr-xr-x | src/parse/redir_parse.c | 27 |
3 files changed, 111 insertions, 2 deletions
diff --git a/src/parse/cmd_parse.c b/src/parse/cmd_parse.c new file mode 100755 index 0000000..562cea3 --- /dev/null +++ b/src/parse/cmd_parse.c @@ -0,0 +1,31 @@ + + +#include "parser.h" + + +int parse_cmd_str_true_false(enum e_token_tag tag) +{ + if (tag & TAG_STR || tag & TAG_STR_DOUBLE || tag & TAG_STR_SINGLE) + return (1); + return(0); +} + + +t_ast *parse_cmd(t_ast *ast, t_ftlst *rest) +{ + t_ftlst *new; + + new = rest->data; + if (ast == NULL) + { + + ast = ast_new(AST_CMD); + ast->cmd_argv = ft_lstnew((t_token *)rest->data); + } + else + { + new = ft_lstnew((t_token *)rest->data); + ft_lstpush_back(&ast->cmd_argv, (void *)new); + } + return (ast); +} diff --git a/src/parse/parse.c b/src/parse/parse.c index 92797c8..a0d981f 100644..100755 --- a/src/parse/parse.c +++ b/src/parse/parse.c @@ -4,16 +4,67 @@ */ #include "parser.h" +#include "lexer.h" // stdio.h est deja include dans minishell.h temporairement // (comme ca on doit le retirer a un seul endroit a la fin) -t_ret *parse(t_ftlst *input) + +t_ret *parse(t_ftlst *input) { - t_ret *ret; + t_ret *ret; + /* t_ret *first; */ + enum e_token_tag tag; + int i = 0; if(!(ret = malloc(sizeof(t_ret) * 1))) return(NULL); ret->rest = input; + ret->ast = NULL; + ret->unexpected = NULL; + /* first = ret; */ + + while (ret->rest != NULL) + { + tag = ((t_token *)ret->rest->data)->tag; + if (parse_cmd_str_true_false(tag)) + { + ret->ast = parse_cmd(ret->ast, ret->rest); + } + else if (parse_redir_true_false(tag)) + { + ret->ast = parse_redir(ret->ast, ret->rest); + ret->rest = ret->rest->next; + if (ret->rest != NULL) + ret->ast = parse_redir(ret->ast, ret->rest); + /* printf("%s\n","ici" ); */ + ret->rest = ret->rest->next; + if (ret->rest != NULL) + { + tag = ((t_token *)ret->rest->data)->tag; + if(tag & TAG_IS_STR & TAG_STICK) + ret->ast = parse_redir(ret->ast, ret->rest); + } + } + if (ret->rest != NULL) + ret->rest = ret->rest->next; + } + while(ret->ast->cmd_argv != NULL) + { + /* printf("%s\n", ((t_token *)ret->ast->cmd_argv->data)->content); */ + ret->ast->cmd_argv = ret->ast->cmd_argv->next; + } + while(ret->ast->redirs != NULL) + { + if (i == 0) + { + /* printf("redir"); */ + i++; + } + /* printf("%s\n", ((t_token *)ret->ast->redirs->data)->content); */ + ret->ast->redirs = ret->ast->redirs->next; + } + /* ast_destroy(ret->ast); */ + /* ft_lstdestroy(&ret->rest, (void (*)(void*))token_destroy); */ return NULL; } diff --git a/src/parse/redir_parse.c b/src/parse/redir_parse.c new file mode 100755 index 0000000..bdcb3ab --- /dev/null +++ b/src/parse/redir_parse.c @@ -0,0 +1,27 @@ + +#include "parser.h" + +int parse_redir_true_false(enum e_token_tag tag) +{ + if (tag & TAG_IS_REDIR) + return (1); + return (0); +} + +t_ast *parse_redir(t_ast *ast, t_ftlst *rest) +{ + t_ftlst *new; + + new = rest->data; + if (ast == NULL) + { + ast = ast_new(AST_CMD); + ast->redirs = ft_lstnew((t_token *)rest->data); + } + else + { + new = ft_lstnew((t_token *)rest->data); + ft_lstpush_back(&ast->redirs, (void *)new); + } + return (ast); +} |
