diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 296de442..da36d5d1 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -1,5 +1,5 @@ /* ************************************************************************** */ -/* */ /* ::: :::::::: */ +/* */ /* parser.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ @@ -82,13 +82,6 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state); int push_stack(t_list **stack, t_sym new_sym); int pop_stack(t_list **stack, t_sym erase_sym); -/*int produce_sym(t_sym stack, t_sym *new_sym, t_list **lst); -int eval_sym(t_sym stack, t_sym new_sym); -int aggregate_sym(t_sym **stack, t_sym *new_sym, t_parstate *state); - -int push_stack(t_sym *stack, t_sym new_sym); -int pop_stack(t_sym **stack, t_sym erase_sym); -*/ int error_syntax(t_list **token, t_parser *parser, t_btree **ast); int error_EOF(t_list **token, t_parser *parser, t_btree **ast); @@ -113,6 +106,7 @@ int build_tree(t_btree **ast, t_list **lst); int add_sep(t_btree **ast, t_list **lst); int add_cmd(t_btree **ast, t_list **lst); + int add_file(t_btree **ast, t_list **lst); int add_loop_cmd(t_btree **ast, t_list **lst); int add_loop_sep(t_btree **ast, t_list **lst); @@ -132,10 +126,15 @@ int add_func_sep(t_btree **ast, t_list **lst); int add_one_func(t_btree **ast, t_list **lst); int add_pipe(t_btree **ast, t_list **lst); int add_var(t_btree **ast, t_list **lst); +int add_null(t_btree **ast, t_list **lst); int isloop(t_btree **ast, t_list **lst); +int isloop_condition(t_btree **ast, t_list **lst); int iscase(t_btree **ast, t_list **lst); +int iscase_pattern(t_btree **ast, t_list **lst); +int iscase_branch(t_btree **ast, t_list **lst); int iscondition(t_btree **ast, t_list **lst); +int iscondition_branch(t_btree **ast, t_list **lst); int issubshell(t_btree **ast, t_list **lst); int isfunc(t_btree **ast, t_list **lst); int isdir(t_btree **ast); @@ -143,9 +142,19 @@ int iscondition(t_btree **ast, t_list **list); int isdir_sep(t_btree **ast, t_list **list); int isdir_word(t_btree **ast, t_list **list); int isvar(t_btree **ast, t_list **list); +int isnull(t_btree **ast, t_list **list); int join_ast(t_btree **ast, t_btree **new_node); int gen_node(t_btree **ast); +int superflous_token(t_btree **ast, t_list **list); + +struct s_distrostree +{ + int (*test)(t_btree **ast, t_list **lst); + int (*add)(t_btree **ast, t_list **lst); +}; + +extern t_distrostree g_distrostree[]; union u_word { diff --git a/42sh/includes/types.h b/42sh/includes/types.h index d107d0b4..bdf68621 100644 --- a/42sh/includes/types.h +++ b/42sh/includes/types.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ -/* Updated: 2017/03/03 20:07:30 by ariard ### ########.fr */ +/* Updated: 2017/03/04 19:50:36 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,6 +50,7 @@ typedef struct s_prodmatch t_prodmatch; typedef struct s_stackmatch t_stackmatch; typedef struct s_errormatch t_errormatch; typedef struct s_treematch t_treematch; +typedef struct s_distrostree t_distrostree; t_data *data_singleton(); diff --git a/42sh/sample/case/case.sh b/42sh/sample/case/case.sh index d89cd66d..0f288357 100644 --- a/42sh/sample/case/case.sh +++ b/42sh/sample/case/case.sh @@ -1,6 +1,4 @@ case $rental in - ("bus") case $rental in - ("yolo") echo bonjour - esac ;; - ("van") echo yolo ;; + ( "bus" ) echo Hello world ;; + ( "van" ) echo Comment va ? ;; esac diff --git a/42sh/sample/mix/mix.sh b/42sh/sample/mix/mix.sh index 36437d5c..795c1e37 100644 --- a/42sh/sample/mix/mix.sh +++ b/42sh/sample/mix/mix.sh @@ -1,11 +1,21 @@ if ls then - ls ; cat + pwd ; echo "Salut" while ls do - until ls + until pwd do - pwd - done + echo KO SI JE M AFFICHE + done + if cat faux + then + echo BONJOUR MAKEFILE + elif [ -f Makefile ] + then + echo BONJOUR MAKEFILE + else + echo KO SI JE M M AFFICHE + fi + echo "Encore une" done fi diff --git a/42sh/sample/until/01_until.sh b/42sh/sample/until/01_until.sh index 4233c43f..2a531998 100644 --- a/42sh/sample/until/01_until.sh +++ b/42sh/sample/until/01_until.sh @@ -1,11 +1,11 @@ -until ls +until cat wefwef do - until ls - do - pwd | cat - done until ls do pwd ; ls done + until cat eqwfewf + do + ls | cat + done done diff --git a/42sh/sample/while/while01.sh b/42sh/sample/while/while01.sh index 2c1dad18..403f8702 100644 --- a/42sh/sample/while/while01.sh +++ b/42sh/sample/while/while01.sh @@ -1,4 +1,4 @@ -while pwd +while ls do while cat rwgwghe do diff --git a/42sh/src/exec/exec_case.c b/42sh/src/exec/exec_case.c index 29f478ab..0a0cebaa 100644 --- a/42sh/src/exec/exec_case.c +++ b/42sh/src/exec/exec_case.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 18:07:31 by ariard #+# #+# */ -/* Updated: 2017/03/03 16:29:52 by jhalford ### ########.fr */ +/* Updated: 2017/03/04 18:18:29 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,7 @@ int exec_case(t_btree **ast) /* char **av; */ t_exec *exec; + return (0); exec = &data_singleton()->exec; /* data_singleton()->exec.process.case_branch = 0; */ exec->attrs |= EXEC_CASE_BRANCH; diff --git a/42sh/src/exec/exec_case_branch.c b/42sh/src/exec/exec_case_branch.c index 1d45eeb5..0cef16d4 100644 --- a/42sh/src/exec/exec_case_branch.c +++ b/42sh/src/exec/exec_case_branch.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 18:07:31 by ariard #+# #+# */ -/* Updated: 2017/03/03 16:28:15 by jhalford ### ########.fr */ +/* Updated: 2017/03/04 18:23:29 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,7 @@ int exec_case_branch(t_btree **ast) /* char **av; */ t_exec *exec; + return (0); exec = &data_singleton()->exec; /* if (data_singleton()->exec.process.case_branch == 1) */ if (EXEC_IS_CASE_BRANCH(exec->attrs)) diff --git a/42sh/src/exec/exec_else.c b/42sh/src/exec/exec_else.c index 7bc6b172..72e132b1 100644 --- a/42sh/src/exec/exec_else.c +++ b/42sh/src/exec/exec_else.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 18:55:07 by ariard #+# #+# */ -/* Updated: 2017/03/04 18:00:47 by ariard ### ########.fr */ +/* Updated: 2017/03/04 18:06:55 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_for.c b/42sh/src/exec/exec_for.c index 1eed20e7..eba6c713 100644 --- a/42sh/src/exec/exec_for.c +++ b/42sh/src/exec/exec_for.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 20:42:20 by ariard #+# #+# */ -/* Updated: 2017/03/03 16:26:40 by jhalford ### ########.fr */ +/* Updated: 2017/03/04 18:17:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,8 +18,7 @@ int exec_for(t_btree **ast) t_list *temp; // char **av = NULL; char *var; - - + node = (*ast)->item; temp = node->data.wordlist; var = temp->content; diff --git a/42sh/src/exec/exec_until.c b/42sh/src/exec/exec_until.c index e2cf5791..eb0ebff2 100644 --- a/42sh/src/exec/exec_until.c +++ b/42sh/src/exec/exec_until.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 20:42:20 by ariard #+# #+# */ -/* Updated: 2017/03/03 16:30:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/04 18:16:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,9 +15,11 @@ int exec_until(t_btree **ast) { ft_exec(&(*ast)->left); - while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0) + while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "1") == 0) { + DG("before right"); ft_exec(&(*ast)->right); + DG("before left"); ft_exec(&(*ast)->left); } return (0); diff --git a/42sh/src/hash_table/ft_add_hash.c b/42sh/src/hash_table/ft_add_hash.c index ba18cc91..055d7654 100644 --- a/42sh/src/hash_table/ft_add_hash.c +++ b/42sh/src/hash_table/ft_add_hash.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/18 11:20:11 by gwojda #+# #+# */ -/* Updated: 2017/02/18 14:38:21 by gwojda ### ########.fr */ +/* Updated: 2017/03/04 18:51:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/hash_table/hash.c b/42sh/src/hash_table/hash.c index 8a9a1eea..b7022ec5 100644 --- a/42sh/src/hash_table/hash.c +++ b/42sh/src/hash_table/hash.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/18 11:06:19 by gwojda #+# #+# */ -/* Updated: 2017/02/21 20:57:19 by ariard ### ########.fr */ +/* Updated: 2017/03/04 18:50:56 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/hash_table/hash_str.c b/42sh/src/hash_table/hash_str.c index a7aa38f1..6755896a 100644 --- a/42sh/src/hash_table/hash_str.c +++ b/42sh/src/hash_table/hash_str.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/18 11:32:18 by gwojda #+# #+# */ -/* Updated: 2017/02/21 20:57:42 by ariard ### ########.fr */ +/* Updated: 2017/03/04 18:51:14 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_lex.c b/42sh/src/lexer/lexer_lex.c index 75f0e4f1..a9d2b823 100644 --- a/42sh/src/lexer/lexer_lex.c +++ b/42sh/src/lexer/lexer_lex.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */ -/* Updated: 2017/03/03 17:55:55 by jhalford ### ########.fr */ +/* Updated: 2017/03/04 20:51:21 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/lib_line_editing/tool_line.c b/42sh/src/line-editing/lib_line_editing/tool_line.c index 4047df37..f3b07f70 100644 --- a/42sh/src/line-editing/lib_line_editing/tool_line.c +++ b/42sh/src/line-editing/lib_line_editing/tool_line.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/20 18:20:23 by gwojda #+# #+# */ -/* Updated: 2017/02/03 17:50:48 by gwojda ### ########.fr */ +/* Updated: 2017/03/04 18:51:45 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/lib_line_editing/toolz.c b/42sh/src/line-editing/lib_line_editing/toolz.c index 8f872021..6fd315c8 100644 --- a/42sh/src/line-editing/lib_line_editing/toolz.c +++ b/42sh/src/line-editing/lib_line_editing/toolz.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/16 17:06:30 by gwojda #+# #+# */ -/* Updated: 2017/02/04 18:16:34 by gwojda ### ########.fr */ +/* Updated: 2017/03/04 18:52:22 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/lib_line_editing/toolz_termcaps.c b/42sh/src/line-editing/lib_line_editing/toolz_termcaps.c index 637b5aef..856f779f 100644 --- a/42sh/src/line-editing/lib_line_editing/toolz_termcaps.c +++ b/42sh/src/line-editing/lib_line_editing/toolz_termcaps.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/08 12:35:11 by gwojda #+# #+# */ -/* Updated: 2017/02/14 11:13:10 by gwojda ### ########.fr */ +/* Updated: 2017/03/04 18:51:59 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 3a713be8..256f42f2 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/04 17:35:55 by ariard ### ########.fr */ +/* Updated: 2017/03/04 19:29:28 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,7 +62,7 @@ int handle_instruction(int fd) error_syntax(&token, &parser, &ast); } DG("Before execution:"); - btree_print(STDBUG, ast, &ft_putast); +// btree_print(STDBUG, ast, &ft_putast); if (ft_exec(&ast)) return (1); instruction_free(&token, &parser, &ast); diff --git a/42sh/src/parser/add_case.c b/42sh/src/parser/add_case.c index 7eba9636..a6fb19a5 100644 --- a/42sh/src/parser/add_case.c +++ b/42sh/src/parser/add_case.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* add_case.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/04 20:42:13 by ariard #+# #+# */ +/* Updated: 2017/03/04 21:54:21 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "parser.h" int iscase(t_btree **ast, t_list **lst) @@ -5,6 +17,22 @@ int iscase(t_btree **ast, t_list **lst) t_astnode *node; t_token *token; + node = NULL; + token = (*lst)->content; + if (*ast) + { + node = (*ast)->item; + if (node->type == TK_CASE || node->type == TK_PAREN_OPEN) + return (1); + } + return (0); +} + +int iscase_pattern(t_btree **ast, t_list **lst) +{ + t_astnode *node; + t_token *token; + node = NULL; token = (*lst)->content; if (*ast) @@ -13,11 +41,23 @@ int iscase(t_btree **ast, t_list **lst) if ((node->type == TK_CASE || node->type == TK_PAREN_OPEN) && token->type == TK_WORD && node->pattern == 0) return (1); + } + return (0); +} + +int iscase_branch(t_btree **ast, t_list **lst) +{ + t_astnode *node; + t_token *token; + + node = NULL; + token = (*lst)->content; + if (*ast) + { + node = (*ast)->item; if ((node->type == TK_PAREN_OPEN || node->type == TK_CASE) && node->nest == 0 && token->type == TK_PAREN_OPEN) - return (3); - if (node->type == TK_CASE || node->type == TK_PAREN_OPEN) - return (2); + return (1); } return (0); } @@ -43,11 +83,6 @@ int add_case_cmd(t_btree **ast, t_list **lst) return (add_cmd(&(*ast)->right, lst)); } -int add_case_sep(t_btree **ast, t_list **lst) -{ - return (add_sep(&(*ast)->right, lst)); -} - int add_pattern(t_btree **ast, t_list **lst) { t_astnode *node; diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index f4fd2dd8..691cfd9b 100644 --- a/42sh/src/parser/add_cmd.c +++ b/42sh/src/parser/add_cmd.c @@ -6,50 +6,86 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ -/* Updated: 2017/03/04 17:08:04 by ariard ### ########.fr */ +/* Updated: 2017/03/04 22:05:47 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "parser.h" +t_distrostree g_distrostree[] = +{ + {&superflous_token, &add_null}, + {&isdir_sep, &add_redir_type}, + {&isdir_word, &add_redir_word}, + {&isvar, &add_var}, + {&isloop_condition, &add_loop_condition}, + {&isloop, &add_loop_cmd}, + {&iscondition_branch, &add_branch}, + {&iscondition, &add_condition_cmd}, + {&iscase_pattern, &add_pattern}, + {&iscase_branch, &add_branch}, + {&iscase, &add_case_cmd}, + {&issubshell, &add_subshell_cmd}, + {&isfunc, &add_func_cmd}, + {&isnull, &add_null}, + +}; + +int superflous_token(t_btree **ast, t_list **lst) +{ + t_token *token; + + (void)ast; + DG("superflous token"); + if (*lst) + { + token = (*lst)->content; + if (token->type == TK_IN || token->type == TK_PAREN_OPEN) + return (1); + } + return (0); +} + +static int no_del_token(t_btree **ast, t_list **lst) +{ + t_astnode *node; + + (void)lst; + node = NULL; + if (*ast) + { + node = (*ast)->item; + if (node->type != TK_DO && node->type != TK_THEN && node->type != TK_PAREN_CLOSE + && node->type != CMD && node->type != REDIR) + return (1); + } + return (0); +} + int add_cmd(t_btree **ast, t_list **lst) { t_token *token; t_astnode *node; char **my_tab; + int i; - if ((token = (*lst)->content)->type == TK_IN || token->type == TK_PAREN_OPEN) - return (0); - else if (isdir_sep(ast, lst)) - return (add_redir_type(ast, lst)); - else if (!*ast) + i = 0; + DG("add cmd"); + while (i < 14) + { + DG("test"); + if (g_distrostree[i].test(ast, lst) == 1) + { + DG("add : %d", i); + return (g_distrostree[i].add(ast, lst)); + } + i++; + } + if (!*ast) gen_node(ast); - else if (isdir_word(ast, lst)) - return (add_redir_word(ast, lst)); - else if (isvar(ast, lst)) - return (add_var(ast, lst)); - else if (isloop(ast, lst) == 3) - return (add_loop_condition(ast, lst)); - else if (isloop(ast, lst)) - return (add_loop_cmd(ast, lst)); - else if (iscondition(ast, lst) == 1) - return (add_condition_cmd(ast, lst)); - else if (iscondition(ast, lst) == 2) - return (add_branch(ast, lst)); - else if (iscase(ast, lst) == 1) - return (add_pattern(ast, lst)); - else if (iscase(ast, lst) == 2) - return (add_case_cmd(ast, lst)); - else if (iscase(ast, lst) == 3) - return (add_branch(ast, lst)); - else if (issubshell(ast, lst)) - return (add_subshell_cmd(ast, lst)); - else if (isfunc(ast, lst)) - return (add_func_cmd(ast, lst)); - else if ((node = (*ast)->item)->type != TK_DO && node->type != TK_THEN - && node->type != TK_PAREN_CLOSE && node->type != CMD - && node->type != REDIR) + else if (no_del_token(ast, lst)) return (add_cmd(&(*ast)->right, lst)); + token = (*lst)->content; node = (*ast)->item; if (token->type != TK_WORD) node->type = token->type; @@ -57,7 +93,6 @@ int add_cmd(t_btree **ast, t_list **lst) node->type = CMD; if (token->type == TK_WORD || token->type == TK_ASSIGNEMENT_WORD) { - DG("add data"); if ((my_tab = (char **)malloc(sizeof(char *) * 4))) { my_tab[0] = ft_strdup(token->data); diff --git a/42sh/src/parser/add_cmd2.c b/42sh/src/parser/add_cmd2.c new file mode 100644 index 00000000..5f99ca94 --- /dev/null +++ b/42sh/src/parser/add_cmd2.c @@ -0,0 +1,71 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* add_cmd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ +/* Updated: 2017/03/04 21:31:18 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "parser.h" + +int add_cmd(t_btree **ast, t_list **lst) +{ + t_token *token; + t_astnode *node; + char **my_tab; + + if ((token = (*lst)->content)->type == TK_IN || token->type == TK_PAREN_OPEN) + return (0); + else if (isdir_sep(ast, lst)) + return (add_redir_type(ast, lst)); + else if (!*ast) + gen_node(ast); + else if (isdir_word(ast, lst)) + return (add_redir_word(ast, lst)); + else if (isvar(ast, lst)) + return (add_var(ast, lst)); + else if (isloop(ast, lst) == 3) + return (add_loop_condition(ast, lst)); + else if (isloop(ast, lst)) + return (add_loop_cmd(ast, lst)); + else if (iscondition(ast, lst) == 1) + return (add_condition_cmd(ast, lst)); + else if (iscondition(ast, lst) == 2) + return (add_branch(ast, lst)); + else if (iscase(ast, lst) == 1) + return (add_pattern(ast, lst)); + else if (iscase(ast, lst) == 2) + return (add_case_cmd(ast, lst)); + else if (iscase(ast, lst) == 3) + return (add_branch(ast, lst)); + else if (issubshell(ast, lst)) + return (add_subshell_cmd(ast, lst)); + else if (isfunc(ast, lst)) + return (add_func_cmd(ast, lst)); + else if ((node = (*ast)->item)->type != TK_DO && node->type != TK_THEN + && node->type != TK_PAREN_CLOSE && node->type != CMD + && node->type != REDIR) + return (add_cmd(&(*ast)->right, lst)); + node = (*ast)->item; + if (token->type != TK_WORD) + node->type = token->type; + else + node->type = CMD; + if (token->type == TK_WORD || token->type == TK_ASSIGNEMENT_WORD) + { + DG("add data"); + if ((my_tab = (char **)malloc(sizeof(char *) * 4))) + { + my_tab[0] = ft_strdup(token->data); + my_tab[1] = (char *)dup_char_esc(token->esc, token->size >> 3); + my_tab[2] = (char *)dup_char_esc(token->esc2, token->size >> 3); + my_tab[3] = NULL; + } + ft_ld_pushback(&node->data.cmd.token, my_tab); + } + return (0); +} diff --git a/42sh/src/parser/add_condition.c b/42sh/src/parser/add_condition.c index 64aa8a6d..d73dc8d1 100644 --- a/42sh/src/parser/add_condition.c +++ b/42sh/src/parser/add_condition.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/19 18:12:52 by ariard #+# #+# */ -/* Updated: 2017/03/03 14:27:21 by ariard ### ########.fr */ +/* Updated: 2017/03/04 21:51:34 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,27 @@ int iscondition(t_btree **ast, t_list **lst) t_astnode *node; t_token *token; + node = NULL; + token = (*lst)->content; + DG("iscondition"); + if (*ast) + { + node = (*ast)->item; + if ((node->type == TK_IF || node->type == TK_ELIF || node->type == TK_ELSE) + && node->full == 0) + return (1); + if ((node->type == TK_NEWLINE || node->type == TK_SEMI + || node->type == TK_AMP) && iscondition(&(*ast)->right, lst)) + return (1); + } + return (0); +} + +int iscondition_branch(t_btree **ast, t_list **lst) +{ + t_astnode *node; + t_token *token; + node = NULL; token = (*lst)->content; if (*ast) @@ -25,12 +46,6 @@ int iscondition(t_btree **ast, t_list **lst) if ((node->type == TK_IF || iscondition(&(*ast)->right, lst)) && (token->type == TK_ELIF || token->type == TK_ELSE) && node->nest == 0) - return (2); - if ((node->type == TK_IF || node->type == TK_ELIF || node->type == TK_ELSE) - && node->full == 0) - return (1); - if ((node->type == TK_NEWLINE || node->type == TK_SEMI - || node->type == TK_AMP) && iscondition(&(*ast)->right, lst) == 1) return (1); } return (0); @@ -41,6 +56,7 @@ int add_condition_cmd(t_btree **ast, t_list **lst) t_token *token; t_astnode *node; + DG("add condition"); token = (*lst)->content; node = (*ast)->item; if (token->type == TK_IF && (node->type == TK_IF || node->type == TK_ELIF diff --git a/42sh/src/parser/add_loop.c b/42sh/src/parser/add_loop.c index a26d2755..5c39e299 100644 --- a/42sh/src/parser/add_loop.c +++ b/42sh/src/parser/add_loop.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 22:17:14 by ariard #+# #+# */ -/* Updated: 2017/03/03 18:01:55 by ariard ### ########.fr */ +/* Updated: 2017/03/04 22:05:26 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,17 +19,13 @@ int isloop(t_btree **ast, t_list **lst) node = NULL; token = (*lst)->content; + DG("isloop"); if (*ast) { node = (*ast)->item; - if (node->type == TK_FOR && token->type == TK_WORD && node->pattern == 0) - return (3); if ((node->type == TK_NEWLINE || node->type == TK_SEMI || node->type == TK_AMP) && isloop(&(*ast)->right, lst) == 1) return (1); - if ((node->type == TK_WHILE || node->type == TK_UNTIL - || node->type == TK_FOR) && node->full == 1) - return (2); if ((node->type == TK_WHILE || node->type == TK_UNTIL || node->type == TK_FOR) && node->full == 0) return (1); @@ -37,6 +33,23 @@ int isloop(t_btree **ast, t_list **lst) return (0); } +int isloop_condition(t_btree **ast, t_list **lst) +{ + t_astnode *node; + t_token *token; + + node = NULL; + token = (*lst)->content; + if (*ast) + { + node = (*ast)->item; + if (node->type == TK_FOR && token->type == TK_WORD + && node->pattern == 0) + return (1); + } + return (0); +} + int add_loop_cmd(t_btree **ast, t_list **lst) { t_token *token; diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index 7d88688e..6e7eb442 100644 --- a/42sh/src/parser/add_redir.c +++ b/42sh/src/parser/add_redir.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 16:39:05 by ariard #+# #+# */ -/* Updated: 2017/03/03 20:02:22 by ariard ### ########.fr */ +/* Updated: 2017/03/04 20:00:46 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c index 04a6fde0..111c7786 100644 --- a/42sh/src/parser/add_sep.c +++ b/42sh/src/parser/add_sep.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 19:12:07 by ariard #+# #+# */ -/* Updated: 2017/03/03 16:05:24 by ariard ### ########.fr */ +/* Updated: 2017/03/04 21:43:00 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,12 +19,12 @@ int add_sep(t_btree **ast, t_list **lst) t_btree *new_node; DG("add sep"); - if (isloop(ast, lst) == 1) + if (isloop(ast, lst)) return (add_loop_sep(ast, lst)); - else if (iscondition(ast, lst) == 1) + else if (iscondition(ast, lst)) return (add_condition_sep(ast, lst)); - else if (iscase(ast, lst) == 2) - return (add_case_sep(ast, lst)); + else if (iscase(ast, lst)) + return (add_sep(&(*ast)->right, lst)); else if (issubshell(ast, lst)) return (add_subshell_sep(ast, lst)); else if (isfunc(ast, lst)) diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index 246cd41d..1848f810 100644 --- a/42sh/src/parser/build_tree.c +++ b/42sh/src/parser/build_tree.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:32:59 by ariard #+# #+# */ -/* Updated: 2017/03/03 15:08:55 by ariard ### ########.fr */ +/* Updated: 2017/03/04 20:56:42 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index cd00ce9a..c0d40cd6 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -39,7 +39,10 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) produce_sym(&parser->stack, parser->new_sym, token); DG("new sym %s", read_state(*parser->new_sym)); if (eval_sym(&parser->stack, *parser->new_sym)) +{ + DG("ERRROR"); return ((parser->state = ERROR)); +} else { aggregate_sym(&parser->stack, parser->new_sym, &parser->state); @@ -52,7 +55,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) else parser->state = UNDEFINED; build_tree(ast, token); - btree_print(STDBUG, *ast, &ft_putast); +// btree_print(STDBUG, *ast, &ft_putast); if ((end_instruction(&parser->stack) && !(*token)->next)) insert_linebreak(token); else diff --git a/42sh/src/parser/tree_wrapper.c b/42sh/src/parser/tree_wrapper.c index c66b39e3..07be0e9c 100644 --- a/42sh/src/parser/tree_wrapper.c +++ b/42sh/src/parser/tree_wrapper.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:57:44 by ariard #+# #+# */ -/* Updated: 2017/03/03 14:28:14 by ariard ### ########.fr */ +/* Updated: 2017/03/04 21:20:16 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,3 +34,18 @@ int gen_node(t_btree **ast) } return (0); } + +int isnull(t_btree **ast, t_list **lst) +{ + (void)ast; + (void)lst; + return (-1); +} + +int add_null(t_btree **ast, t_list **lst) +{ + (void)ast; + (void)lst; + return (-1); +} +