diff options
| -rw-r--r-- | include/ast.h | 13 | ||||
| -rw-r--r-- | include/eval.h | 6 | ||||
| -rw-r--r-- | include/parser.h | 5 | ||||
| -rw-r--r-- | src/ast.c | 14 | ||||
| -rw-r--r-- | src/main.c | 8 | ||||
| -rwxr-xr-x | src/parse/cmd_parse.c | 1 | ||||
| -rwxr-xr-x | src/parse/parse.c | 90 |
7 files changed, 84 insertions, 53 deletions
diff --git a/include/ast.h b/include/ast.h index bcb5e11..317e1b8 100644 --- a/include/ast.h +++ b/include/ast.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ast.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:05:38 by charles #+# #+# */ -/* Updated: 2020/06/14 17:47:10 by charles ### ########.fr */ +/* Updated: 2020/06/17 16:43:12 by nahaddac ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,12 +33,12 @@ struct s_ast; */ -typedef struct s_line +typedef struct s_op { struct s_ast *left; struct s_ast *right; enum e_token_tag sep; -} t_line; +} t_op; /* ** \brief AST node tag (type) @@ -49,7 +49,8 @@ typedef struct s_line enum e_ast_tag { AST_CMD, - AST_LINE, + AST_OP, + AST_OP_PARENT, }; /* @@ -67,7 +68,7 @@ typedef struct s_ast enum e_ast_tag tag; union { - t_line line; + t_op op; t_ftlst *cmd_argv; }; t_ftlst *redirs; diff --git a/include/eval.h b/include/eval.h index f834d45..bde0cd7 100644 --- a/include/eval.h +++ b/include/eval.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* eval.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:05:30 by charles #+# #+# */ -/* Updated: 2020/06/15 11:09:49 by charles ### ########.fr */ +/* Updated: 2020/06/17 15:49:49 by nahaddac ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,7 +44,7 @@ typedef struct s_eval_status typedef struct { t_eval_state *state; - t_line *line; + t_op *op; int fd_in; int fd_out; } t_fork_param_line; diff --git a/include/parser.h b/include/parser.h index 2bfa9d5..bc1e549 100644 --- a/include/parser.h +++ b/include/parser.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* parser.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 09:00:00 by cacharle #+# #+# */ -/* Updated: 2020/06/14 10:31:20 by charles ### ########.fr */ +/* Updated: 2020/06/17 18:03:33 by nahaddac ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,6 +38,7 @@ */ t_ret *parse(t_ftlst *input); +t_ret *parse_c(t_ftlst *input); t_ast *push_cmd(t_ast *ast, t_ftlst *ret); t_ast *push_redir(t_ast *ast, t_ftlst *rest); @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ast.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:05:42 by charles #+# #+# */ -/* Updated: 2020/06/15 13:01:20 by charles ### ########.fr */ +/* Updated: 2020/06/17 15:48:56 by nahaddac ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,8 +31,8 @@ t_ast *ast_new(enum e_ast_tag tag) return (NULL); ast->tag = tag; ast->redirs = NULL; - ast->line.left = NULL; - ast->line.right = NULL; + ast->op.left = NULL; + ast->op.right = NULL; ast->cmd_argv = NULL; return (ast); } @@ -52,10 +52,10 @@ void ast_destroy(t_ast *ast) ft_lstdestroy(&ast->cmd_argv, (void (*)(void*))token_destroy); ft_lstdestroy(&ast->redirs, (void (*)(void*))token_destroy); } - else if (ast->tag == AST_LINE) + else if (ast->tag == AST_OP) { - ast_destroy(ast->line.left); - ast_destroy(ast->line.right); + ast_destroy(ast->op.left); + ast_destroy(ast->op.right); } free(ast); } @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */ -/* Updated: 2020/06/16 14:49:59 by charles ### ########.fr */ +/* Updated: 2020/06/17 15:50:33 by nahaddac ### ########.fr */ /* */ /* ************************************************************************** */ @@ -52,8 +52,8 @@ int main(int argc, char **argv, char **envp) /* printf("===redirs===\n"); */ /* ft_lstiter(parser_out->ast->redirs, token_debug); */ - int eval_out = eval_cmd(env, path, parser_out->ast); - (void)eval_out; + //int eval_out = eval_cmd(env, path, parser_out->ast); + //(void)eval_out; } ft_htdestroy(path, free); diff --git a/src/parse/cmd_parse.c b/src/parse/cmd_parse.c index ef5a518..15a5054 100755 --- a/src/parse/cmd_parse.c +++ b/src/parse/cmd_parse.c @@ -10,7 +10,6 @@ int parse_cmd_str_true_false(enum e_token_tag tag) return(0); } - t_ast *push_cmd(t_ast *ast, t_ftlst *rest) { t_ftlst *new; diff --git a/src/parse/parse.c b/src/parse/parse.c index 1fc24be..b9bb156 100755 --- a/src/parse/parse.c +++ b/src/parse/parse.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/06/17 18:09:04 by nahaddac #+# #+# */ +/* Updated: 2020/06/17 18:36:54 by nahaddac ### ########.fr */ +/* */ +/* ************************************************************************** */ + /* ** \file parse.c ** \brief Parser @@ -11,11 +23,43 @@ +t_ast *cmd_push_ast(t_ftlst *rest) +{ + enum e_token_tag tag; + t_ast *ast; + + ast = NULL; + while (rest != NULL) + { + tag = ((t_token *)rest->data)->tag; + if (parse_cmd_str_true_false(tag)) + { + ast = push_cmd(ast, rest); + } + else if (parse_redir_true_false(tag)) + { + while(rest != NULL) + { + ast = push_redir(ast, rest); + if (tag & TAG_IS_STR && tag & TAG_STICK) + rest = rest->next; + else if (tag & TAG_IS_REDIR) + rest = rest->next; + else + break; + tag = ((t_token *)rest->data)->tag; + } + } + rest = rest->next; + } + return ast; +} + t_ret *parse(t_ftlst *input) { t_ret *ret; t_ret *first; - enum e_token_tag tag; + t_ast *new_ast; if(!(ret = malloc(sizeof(t_ret) * 1))) return(NULL); @@ -24,38 +68,24 @@ t_ret *parse(t_ftlst *input) ret->unexpected = NULL; first = ret; - while (ret->rest != NULL) + if(!(new_ast = malloc(sizeof(t_ast) * 1))) + return(0); + new_ast = cmd_push_ast(ret->rest); + printf("%s\n",((t_token *)ret->rest->data)->content); + if (ret->ast) { - tag = ((t_token *)ret->rest->data)->tag; - if (parse_cmd_str_true_false(tag)) - ret->ast = push_cmd(ret->ast, ret->rest); - else if (parse_redir_true_false(tag)) + 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) { - while(ret->rest != NULL) - { - ret->ast = push_redir(ret->ast, ret->rest); - if (tag & TAG_IS_STR && tag & TAG_STICK) - ret->rest = ret->rest->next; - else if (tag & TAG_IS_REDIR) - ret->rest = ret->rest->next; - else - break; - tag = ((t_token *)ret->rest->data)->tag; - } + printf("[%s]\n", ((t_token *)ret->ast->redirs->data)->content); + ret->ast->redirs = ret->ast->redirs->next; } - 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) */ - /* { */ - /* 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); */ + ast_destroy(ret->ast); + ft_lstdestroy(&ret->rest, (void (*)(void*))token_destroy); return first; } |
