diff --git a/42sh/Makefile b/42sh/Makefile index a60aa4ea..2012337d 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -199,7 +199,8 @@ parser/build_tree.c\ parser/tree_wrapper.c\ parser/add_sep.c\ parser/add_cmd.c\ -parser/add_file.c +parser/add_file.c\ +parser/add_loop.c SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE)) OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o)) diff --git a/42sh/file1 b/42sh/file1 index e75bc531..3e9b5839 100644 --- a/42sh/file1 +++ b/42sh/file1 @@ -1,3 +1,4 @@ +42sh Makefile blind.text debug @@ -5,6 +6,7 @@ file1 grammar includes libft +objs pdf sample script.sh diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index d40032d1..1be71b53 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */ -/* Updated: 2017/02/17 18:49:28 by ariard ### ########.fr */ +/* Updated: 2017/02/17 23:18:23 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -120,6 +120,7 @@ enum e_sym CMD_SUPERIOR, AND_OR_MAJOR, AND_OR_MINOR, + END_COMMAND, ALL = 200, }; @@ -201,6 +202,9 @@ 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); +int isloop(t_btree **ast); int isdir(t_btree **ast); int join_ast(t_btree **ast, t_btree **new_node); @@ -245,6 +249,7 @@ union u_astdata t_ld *token; char **sstr; char *str; + int loop; }; struct s_astnode diff --git a/42sh/sample/dir.sh b/42sh/sample/dir.sh new file mode 100644 index 00000000..f413e465 --- /dev/null +++ b/42sh/sample/dir.sh @@ -0,0 +1 @@ +file1 +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/16 16:23:26 by wescande #+# #+# */ -/* Updated: 2017/01/05 14:16:53 by wescande ### ########.fr */ +/* Updated: 2017/02/17 23:31:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/glob/lib_perso/ft_ld_pushback.c b/42sh/src/glob/lib_perso/ft_ld_pushback.c index 25a1d019..5ec29624 100644 --- a/42sh/src/glob/lib_perso/ft_ld_pushback.c +++ b/42sh/src/glob/lib_perso/ft_ld_pushback.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/16 15:59:38 by wescande #+# #+# */ -/* Updated: 2017/01/05 14:17:40 by wescande ### ########.fr */ +/* Updated: 2017/02/17 23:33:37 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/ft_putast.c b/42sh/src/main/ft_putast.c index 2b5e4e7b..c4d1f46c 100644 --- a/42sh/src/main/ft_putast.c +++ b/42sh/src/main/ft_putast.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */ -/* Updated: 2017/02/06 20:37:16 by ariard ### ########.fr */ +/* Updated: 2017/02/17 23:41:26 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,8 @@ char *ft_putast(void *nodein) t_type type; }; node = nodein; + if (node->type == TK_DO) + return ("TK_DO"); if (node->type == TK_AMP) return (" & "); else if (node->type == TK_N_WORD) diff --git a/42sh/src/main/shell_script.c b/42sh/src/main/shell_script.c index d7273002..5b907c72 100644 --- a/42sh/src/main/shell_script.c +++ b/42sh/src/main/shell_script.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/22 23:06:34 by ariard #+# #+# */ -/* Updated: 2017/02/17 17:22:03 by ariard ### ########.fr */ +/* Updated: 2017/02/17 23:27:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,7 +31,7 @@ int shell_script() token_print(token); if (ft_parse2(&ast, &token)) return (1); - btree_print(STDBUG, ast, &ft_putast); +// btree_print(STDBUG, ast, &ft_putast); // if (ft_exec(&ast)) // return (1); ast = NULL; diff --git a/42sh/src/parser/.eval_sym.c.swn b/42sh/src/parser/.eval_sym.c.swn deleted file mode 100644 index 4e796003..00000000 Binary files a/42sh/src/parser/.eval_sym.c.swn and /dev/null differ diff --git a/42sh/src/parser/.read_stack.c.swn b/42sh/src/parser/.read_stack.c.swn index d4ee5d04..2644ddb7 100644 Binary files a/42sh/src/parser/.read_stack.c.swn and b/42sh/src/parser/.read_stack.c.swn differ diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 1c21999e..74532346 100644 --- a/42sh/src/parser/add_cmd.c +++ b/42sh/src/parser/add_cmd.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ -/* Updated: 2017/02/17 17:46:18 by ariard ### ########.fr */ +/* Updated: 2017/02/17 23:40:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,18 +18,26 @@ int add_cmd(t_btree **ast, t_list **lst) t_astnode *node; char **my_tab; + DG("add cmd"); if (!*ast) gen_node(ast); else if (isdir(ast)) - return (add_file(ast, lst)); + return (add_file(ast, lst)); + else if (isloop(ast)) + return (add_loop_cmd(ast, lst)); else return (add_cmd(&(*ast)->right, lst)); + DG("insert data cmd"); my_tab = NULL; token = (*lst)->content; node = (*ast)->item; node->type = token->type; - my_tab = ft_sstradd(my_tab, token->data); - my_tab = ft_sstradd(my_tab, (char *)token->esc); - ft_ld_pushback(&node->data.token, my_tab); + if (token->type == TK_N_WORD) + { + my_tab = ft_sstradd(my_tab, token->data); + my_tab = ft_sstradd(my_tab, (char *)token->esc); +// ft_ld_pushback(&node->data.token, my_tab); + DG("still alive"); + } return (0); } diff --git a/42sh/src/parser/add_file.c b/42sh/src/parser/add_file.c index 1eed2a89..23660275 100644 --- a/42sh/src/parser/add_file.c +++ b/42sh/src/parser/add_file.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 16:39:05 by ariard #+# #+# */ -/* Updated: 2017/02/17 17:19:35 by ariard ### ########.fr */ +/* Updated: 2017/02/17 23:24:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_loop.c b/42sh/src/parser/add_loop.c new file mode 100644 index 00000000..2709e6f6 --- /dev/null +++ b/42sh/src/parser/add_loop.c @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* add_loop.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/02/17 22:17:14 by ariard #+# #+# */ +/* Updated: 2017/02/17 23:38:25 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "parser.h" + +int isloop(t_btree **ast) +{ + t_astnode *node; + + node = NULL; + if (*ast) + { + DG("end isloop"); + node = (*ast)->item; + if (node->data.loop == 1) + return (2); + if (node->type == TK_WHILE) + return (1); + } + return (0); +} + +int add_loop_cmd(t_btree **ast, t_list **lst) +{ + t_token *token; + t_astnode *node; + + DG("add loop cmd"); + token = (*lst)->content; + node = (*ast)->item; + if (token->type == TK_DONE) + return ((node->data.loop = 1)); + else if (token->type == TK_DO) + return (add_cmd(&(*ast)->right, lst)); + else if (!(*ast)->right && isloop(&(*ast)->left) != 2) + return (add_cmd(&(*ast)->left, lst)); + else + return (add_cmd(&(*ast)->right, lst)); + return (0); +} + +int add_loop_sep(t_btree **ast, t_list **lst) +{ + DG("add loop sep"); + if (!(*ast)->right) + return (add_sep(&(*ast)->left, lst)); + else + return (add_sep(&(*ast)->right, lst)); + return (0); +} diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c index 3bbf1028..a7cb461a 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/02/17 17:09:31 by ariard ### ########.fr */ +/* Updated: 2017/02/17 23:34:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,9 @@ int add_sep(t_btree **ast, t_list **lst) t_astnode *node; t_btree *new_node; + DG("add sep"); + if (isloop(&(*ast)->right) == 1 || isloop(ast)) + return (add_loop_sep(ast, lst)); new_node = NULL; gen_node(&new_node); join_ast(ast, &new_node); @@ -25,4 +28,4 @@ int add_sep(t_btree **ast, t_list **lst) node = (new_node)->item; node->type = token->type; return (0); -} +} diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 3f0a83d2..3315be3c 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:39:18 by ariard #+# #+# */ -/* Updated: 2017/02/17 19:48:12 by ariard ### ########.fr */ +/* Updated: 2017/02/17 21:35:09 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,7 +34,7 @@ t_aggrematch g_aggrematch[] = //watch this {SEPARATOR_OP, CMD_SUPERIOR, SEPARATOR, 0}, {SEPARATOR_OP, COMPOUND_LIST, SEPARATOR, 0}, - {SEPARATOR, CMD_SUPERIOR, SIMPLE_COMMAND, CMD_SUPERIOR}, + {SEPARATOR, CMD_SUPERIOR, END_COMMAND, CMD_SUPERIOR}, {SEPARATOR, COMPOUND_LIST, COMPOUND_LIST, COMPOUND_LIST}, {LINEBREAK, SEPARATOR_OP, SEPARATOR, SEPARATOR_OP}, {LINEBREAK, TK_SEMI, SEQUENTIAL_SEP, TK_SEMI}, @@ -47,7 +47,7 @@ t_aggrematch g_aggrematch[] = {LINEBREAK, COMPLETE_COMMANDS, PROGRAM, LINEBREAK}, {LINEBREAK, TK_PIPE, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE}, {LINEBREAK, COMPLETE_COMMANDS, PROGRAM, LINEBREAK}, - {LINEBREAK, CMD_SUPERIOR, SIMPLE_COMMAND, CMD_SUPERIOR}, + {LINEBREAK, CMD_SUPERIOR, SEPARATOR_OP, 0}, {LINEBREAK, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE, PIPE_SEMI_SEQUENCE}, {LINEBREAK, COMPOUND_LIST, COMPOUND_LIST, COMPOUND_LIST}, {NEWLINE_LIST, CMD_NAME, CMD_SUPERIOR, CMD_NAME}, @@ -102,6 +102,8 @@ t_aggrematch g_aggrematch[] = {CMD_NAME, SEPARATOR_OP, CMD_SUPERIOR, 0}, {CMD_NAME, NEWLINE_LIST, CMD_SUPERIOR, 0}, {CMD_NAME, TK_WHILE, CMD_SUPERIOR, 0}, + {CMD_NAME, TK_DO, CMD_SUPERIOR, 0}, + {CMD_NAME, COMPOUND_LIST, CMD_SUPERIOR, 0}, {CMD_NAME, TK_PIPE, CMD_SUPERIOR, 0}, {CMD_NAME, PIPE_SEMI_SEQUENCE, CMD_SUPERIOR, 0}, {CMD_NAME, AND_OR_MAJOR, CMD_SUPERIOR, 0}, @@ -130,31 +132,44 @@ t_aggrematch g_aggrematch[] = {TERM, LINEBREAK, COMPOUND_LIST, LINEBREAK}, {COMPOUND_LIST, TK_ELSE, ELSE_PART, TK_ELSE}, {COMPOUND_LIST, TK_THEN, ELSE_PART, TK_ELIF}, + {COMPOUND_LIST, COMPOUND_LIST, COMPOUND_LIST, COMPOUND_LIST}, {SUBSHELL, ALL, COMPOUND_COMMAND, 0}, {COMPOUND_COMMAND, ALL, COMMAND, 0}, {AND_OR_MINOR, PIPE_SEMI_SEQUENCE, AND_OR_MAJOR, PIPE_SEMI_SEQUENCE}, {AND_OR_MINOR, LINEBREAK, AND_OR_MAJOR, 0}, {AND_OR_MINOR, AND_OR_MAJOR, AND_OR_MAJOR, 0}, {COMMAND, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE}, + {COMMAND, COMPOUND_LIST, PIPE_SEMI_SEQUENCE, 0}, {COMMAND, TK_WHILE, PIPE_SEMI_SEQUENCE, 0}, + {COMMAND, TK_DO, PIPE_SEMI_SEQUENCE, 0}, {COMMAND, TK_BANG, PIPE_SEMI_SEQUENCE, 0}, {COMMAND, SEPARATOR_OP, PIPE_SEMI_SEQUENCE, 0}, {COMMAND, NEWLINE_LIST, PIPE_SEMI_SEQUENCE, 0}, {COMMAND, LINEBREAK, PIPE_SEMI_SEQUENCE, 0}, {COMMAND, AND_OR_MAJOR, PIPE_SEMI_SEQUENCE, 0}, + {END_COMMAND, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE, PIPE_SEMI_SEQUENCE}, + {END_COMMAND, TK_WHILE, PIPE_SEQUENCE, 0}, + {END_COMMAND, LINEBREAK, PIPE_SEQUENCE, 0}, + {END_COMMAND, TK_DO, PIPE_SEQUENCE, 0}, {PIPE_SEQUENCE, TK_WHILE, PIPELINE, 0}, {PIPE_SEQUENCE, TK_BANG, PIPELINE, TK_BANG}, {PIPE_SEQUENCE, SEPARATOR_OP, PIPELINE, 0}, {PIPE_SEQUENCE, NEWLINE_LIST, PIPELINE, 0}, {PIPE_SEQUENCE, LINEBREAK, PIPELINE, 0}, {PIPE_SEQUENCE, AND_OR_MAJOR, PIPELINE, 0}, + {PIPE_SEQUENCE, TK_DO, PIPELINE, 0}, + {PIPE_SEQUENCE, COMPOUND_LIST, PIPELINE, 0}, {PIPELINE, TK_WHILE, AND_OR, 0}, + {PIPELINE, TK_DO, AND_OR, 0}, + {PIPELINE, COMPOUND_LIST, AND_OR, 0}, {PIPELINE, LINEBREAK, AND_OR, 0}, // {PIPELINE, LINEBREAK, AND_OR, AND_OR}, {PIPELINE, SEPARATOR_OP, AND_OR, 0}, {PIPELINE, AND_OR_MAJOR, AND_OR, AND_OR_MAJOR}, {AND_OR_MAJOR, AND_OR_MAJOR, AND_OR_MAJOR, AND_OR_MAJOR}, + {AND_OR, TK_DO, COMPOUND_LIST, 0}, {AND_OR, TK_WHILE, COMPOUND_LIST, 0}, + {AND_OR, COMPOUND_LIST, COMPOUND_LIST, 0}, {AND_OR, SEPARATOR_OP, LIST, LIST}, {AND_OR, NEWLINE_LIST, LIST, 0}, {AND_OR, LINEBREAK, LIST, 0}, diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index 43f5bb4b..df2a2152 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/02/17 18:48:56 by ariard ### ########.fr */ +/* Updated: 2017/02/17 23:34:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,9 @@ t_treematch g_treematch[] = {TK_LESS, &add_sep}, {TK_OR_IF, &add_sep}, {TK_AND_IF, &add_sep}, + {TK_WHILE, &add_cmd}, + {TK_DO, &add_cmd}, + {TK_DONE, &add_cmd}, {0, NULL}, }; @@ -36,8 +39,8 @@ int build_tree(t_btree **ast, t_list **lst) if (g_treematch[i].type == token->type) { -// DG("func TK : '%s' TK : '%s'", -// read_state(g_treematch[i].type) ,read_state(token->type)); + DG("func TK : '%s' TK : '%s'", + read_state(g_treematch[i].type) ,read_state(token->type)); return (g_treematch[i].add(ast, lst)); } i++; diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 709f9a91..77833aa1 100644 --- a/42sh/src/parser/eval_sym.c +++ b/42sh/src/parser/eval_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 16:26:30 by ariard #+# #+# */ -/* Updated: 2017/02/17 19:43:28 by ariard ### ########.fr */ +/* Updated: 2017/02/17 21:35:11 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -181,6 +181,7 @@ t_stackmatch g_stackmatch[] = {TK_DO, SEQUENTIAL_SEP}, {TK_DONE, CMD_SUPERIOR}, {TK_DONE, COMPOUND_LIST}, + {TK_DONE, END_COMMAND}, {TK_CASE, LINEBREAK}, {TK_CASE, TK_BANG}, {TK_CASE, NEWLINE_LIST}, @@ -238,6 +239,10 @@ t_stackmatch g_stackmatch[] = {SEQUENTIAL_SEP, NAME}, {SEQUENTIAL_SEP, IN}, {SEQUENTIAL_SEP, WORDLIST}, + {END_COMMAND, PIPE_SEMI_SEQUENCE}, + {END_COMMAND, TK_WHILE}, + {END_COMMAND, TK_DO}, + {END_COMMAND, LINEBREAK}, {SEPARATOR, CMD_SUPERIOR}, {SEPARATOR, TERM}, {SEPARATOR, COMPOUND_LIST}, @@ -328,9 +333,11 @@ t_stackmatch g_stackmatch[] = {CMD_NAME, AND_OR_MAJOR}, {CMD_NAME, TK_WHILE}, {CMD_NAME, TK_DO}, + {CMD_NAME, COMPOUND_LIST}, {CMD_SUPERIOR, TK_WHILE}, {CMD_SUPERIOR, TK_DO}, + {CMD_SUPERIOR, COMPOUND_LIST}, {CMD_SUPERIOR, LINEBREAK,}, {CMD_SUPERIOR, TK_BANG}, {CMD_SUPERIOR, SEPARATOR_OP}, @@ -340,6 +347,8 @@ t_stackmatch g_stackmatch[] = {CMD_SUPERIOR, AND_OR_MAJOR}, {SIMPLE_COMMAND, TK_WHILE}, + {SIMPLE_COMMAND, TK_DO}, + {SIMPLE_COMMAND, COMPOUND_LIST}, {SIMPLE_COMMAND, LINEBREAK}, {SIMPLE_COMMAND, TK_BANG}, {SIMPLE_COMMAND, SEPARATOR_OP}, @@ -414,6 +423,7 @@ t_stackmatch g_stackmatch[] = {COMPOUND_LIST, TK_ELIF}, {COMPOUND_LIST, TK_ELSE}, {COMPOUND_LIST, TK_IF}, + {COMPOUND_LIST, COMPOUND_LIST}, {SUBSHELL, LINEBREAK}, {SUBSHELL, TK_BANG}, {SUBSHELL, SEPARATOR_OP}, @@ -427,6 +437,8 @@ t_stackmatch g_stackmatch[] = {COMPOUND_COMMAND, FUNC}, {COMMAND, TK_WHILE}, {COMMAND, LINEBREAK}, + {COMMAND, TK_DO}, + {COMMAND, COMPOUND_LIST}, {COMMAND, TK_BANG}, {COMMAND, SEPARATOR_OP}, {COMMAND, NEWLINE_LIST}, @@ -436,25 +448,33 @@ t_stackmatch g_stackmatch[] = {AND_OR_MINOR, LINEBREAK}, {AND_OR_MINOR, AND_OR_MAJOR}, {PIPE_SEQUENCE, TK_WHILE}, + {PIPE_SEQUENCE, TK_DO}, + {PIPE_SEQUENCE, COMPOUND_LIST}, {PIPE_SEQUENCE, LINEBREAK}, {PIPE_SEQUENCE, TK_BANG}, {PIPE_SEQUENCE, SEPARATOR_OP}, {PIPE_SEQUENCE, NEWLINE_LIST}, {PIPE_SEQUENCE, AND_OR_MAJOR}, {PIPE_SEMI_SEQUENCE, TK_WHILE}, + {PIPE_SEMI_SEQUENCE, TK_DO}, + {PIPE_SEMI_SEQUENCE, COMPOUND_LIST}, {PIPE_SEMI_SEQUENCE, LINEBREAK}, {PIPE_SEMI_SEQUENCE, TK_BANG}, {PIPE_SEMI_SEQUENCE, SEPARATOR_OP}, {PIPE_SEMI_SEQUENCE, NEWLINE_LIST}, {PIPE_SEMI_SEQUENCE, AND_OR_MAJOR}, {PIPELINE, TK_WHILE}, + {PIPELINE, TK_DO}, + {PIPELINE, COMPOUND_LIST}, {PIPELINE, LINEBREAK}, {PIPELINE, SEPARATOR_OP}, {PIPELINE, NEWLINE_LIST}, {PIPELINE, AND_OR_MAJOR}, {AND_OR_MAJOR, LINEBREAK}, {AND_OR_MAJOR, AND_OR_MAJOR}, + {AND_OR, TK_DO}, {AND_OR, TK_WHILE}, + {AND_OR, COMPOUND_LIST}, {AND_OR, LINEBREAK}, {AND_OR, SEPARATOR_OP}, {AND_OR, NEWLINE_LIST}, diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index 7e00865d..f56dd3fb 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 14:30:22 by ariard #+# #+# */ -/* Updated: 2017/02/17 19:48:01 by ariard ### ########.fr */ +/* Updated: 2017/02/17 23:39:18 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,6 +57,7 @@ int ft_parse2(t_btree **ast, t_list **token) if (state == SUCCESS) ft_putstr("success"); build_tree(ast, token); + btree_print(STDBUG, *ast, &ft_putast); if (end_instruction(*stack) && !(*token)->next) insert_linebreak(token); else diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index 6b70555f..af01c929 100644 --- a/42sh/src/parser/produce_sym.c +++ b/42sh/src/parser/produce_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:58:34 by ariard #+# #+# */ -/* Updated: 2017/02/17 19:48:06 by ariard ### ########.fr */ +/* Updated: 2017/02/17 21:29:20 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,6 +31,7 @@ t_prodmatch g_prodmatch[] = {TK_N_WORD, AND_OR_MAJOR, CMD_NAME}, {TK_N_WORD, TK_WHILE, CMD_NAME}, {TK_N_WORD, TK_DO, CMD_NAME}, + {TK_N_WORD, COMPOUND_LIST, CMD_NAME}, {TK_N_WORD, NEWLINE_LIST, CMD_NAME}, {TK_N_WORD, TK_BANG, CMD_NAME}, @@ -58,11 +59,9 @@ t_prodmatch g_prodmatch[] = {TK_SEMI, CMD_SUPERIOR, SEPARATOR_OP}, {TK_SEMI, TERM, SEPARATOR_OP}, {TK_SEMI, LIST, SEPARATOR_OP}, - {TK_SEMI, COMPOUND_LIST, SEPARATOR_OP}, {TK_AMP, CMD_SUPERIOR, SEPARATOR_OP}, {TK_AMP, TERM, SEPARATOR_OP}, {TK_AMP, LIST, SEPARATOR_OP}, - {TK_AMP, COMPOUND_LIST, SEPARATOR_OP}, {0, 0, 0}, }; diff --git a/42sh/src/parser/read_stack.c b/42sh/src/parser/read_stack.c index 893f9f94..8068646c 100644 --- a/42sh/src/parser/read_stack.c +++ b/42sh/src/parser/read_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */ -/* Updated: 2017/02/17 19:40:45 by ariard ### ########.fr */ +/* Updated: 2017/02/17 23:40:50 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,12 @@ char *read_state(t_sym current) { + if (current == TK_DONE) + return ("DONE"); + if (current == TK_DO) + return ("TK_DO"); + if (current == END_COMMAND) + return ("END_COMMAND"); if (current == SEQUENTIAL_SEP) return ("SEQUENTIAL_SEP"); if (current == SEPARATOR) diff --git a/42sh/src/parser/tree_wrapper.c b/42sh/src/parser/tree_wrapper.c index 56235151..6d3d6d36 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/02/17 17:19:41 by ariard ### ########.fr */ +/* Updated: 2017/02/17 23:38:47 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,6 +28,7 @@ int gen_node(t_btree **ast) *ast = btree_create_node(&item, sizeof(item)); ((t_astnode *)(*ast)->item)->data.token = NULL; ((t_astnode *)(*ast)->item)->data.redir.word.word = NULL; + ((t_astnode *)(*ast)->item)->data.loop = 0; } return (0); }