From 5e5a4a122a3b144ef479409c08e4a7fa57223565 Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Thu, 9 Mar 2017 19:48:34 +0100 Subject: [PATCH] parsing tk_bang && brace_clause} --- 42sh/error | 30 ------------------------------ 42sh/file3 | 0 42sh/ret2 | 0 42sh/src/lexer/lexer_sep.c | 4 +++- 42sh/src/main/ft_putast.c | 6 +++++- 42sh/src/main/main.c | 2 +- 42sh/src/parser/add_cmd.c | 2 +- 42sh/src/parser/add_subshell.c | 4 +++- 42sh/src/parser/aggregate_sym.c | 9 +++++---- 42sh/src/parser/build_tree.c | 2 +- 42sh/src/parser/eval_sym.c | 7 ++++--- 11 files changed, 23 insertions(+), 43 deletions(-) delete mode 100644 42sh/error delete mode 100644 42sh/file3 delete mode 100644 42sh/ret2 diff --git a/42sh/error b/42sh/error deleted file mode 100644 index 4c17682f..00000000 --- a/42sh/error +++ /dev/null @@ -1,30 +0,0 @@ -42sh -Makefile -STDBUG -TESTSHELL -donovan_segaults_06-02 -error -includes -libft -objs -pdf -sample -src -test_framework.sh -testmake -update_makefile.sh -42sh -Makefile -STDBUG -TESTSHELL -donovan_segaults_06-02 -error -includes -libft -objs -pdf -sample -src -test_framework.sh -testmake -update_makefile.sh diff --git a/42sh/file3 b/42sh/file3 deleted file mode 100644 index e69de29b..00000000 diff --git a/42sh/ret2 b/42sh/ret2 deleted file mode 100644 index e69de29b..00000000 diff --git a/42sh/src/lexer/lexer_sep.c b/42sh/src/lexer/lexer_sep.c index 980aad75..76c6b7e8 100644 --- a/42sh/src/lexer/lexer_sep.c +++ b/42sh/src/lexer/lexer_sep.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */ -/* Updated: 2017/03/08 17:11:35 by jhalford ### ########.fr */ +/* Updated: 2017/03/09 18:48:00 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,6 +31,8 @@ int lexer_sep(t_list **alst, t_lexer *lexer) token->type = cn == '|' ? TK_OR_IF : TK_PIPE; else if (c == ';') token->type = cn == ';' ? TK_DSEMI : TK_SEMI; + else if (c == '!') + token->type = TK_BANG; if (token->type == TK_AND_IF || token->type == TK_OR_IF || token->type == TK_DSEMI) lexer->pos++; diff --git a/42sh/src/main/ft_putast.c b/42sh/src/main/ft_putast.c index b223e7e3..2c6fe982 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/03/07 23:35:32 by ariard ### ########.fr */ +/* Updated: 2017/03/09 18:54:07 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,8 +17,12 @@ char *ft_putast(void *nodein) t_astnode *node; node = nodein; + if (node->type == TK_BANG) + return ("TK_BANG"); if (node->type == MATH) return ("MATH"); + if (node->type == MATH_PLUS) + return ("MATH_PLUS"); if (node->type == TK_DSEMI) return ("TK_DSEMI"); if (node->type == WORDLIST) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 50fb92eb..152691b1 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/09 17:37:38 by ariard ### ########.fr */ +/* Updated: 2017/03/09 19:46:24 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 64e1931d..c6c28d3d 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/03/09 16:04:46 by ariard ### ########.fr */ +/* Updated: 2017/03/09 19:44:51 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_subshell.c b/42sh/src/parser/add_subshell.c index 88f25c43..dcbe85f4 100644 --- a/42sh/src/parser/add_subshell.c +++ b/42sh/src/parser/add_subshell.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 18:41:50 by ariard #+# #+# */ -/* Updated: 2017/03/07 22:46:36 by ariard ### ########.fr */ +/* Updated: 2017/03/09 19:46:44 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,8 @@ int issubshell(t_btree **ast, t_list **lst) node = (*ast)->item; if (node->type == SUBSHELL && node->full == 0) return (1); + if (node->type == TK_LBRACE && node->full == 0) + return (1); } return (0); } diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 25ea1ce6..4bdf4ec9 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -97,6 +97,7 @@ t_aggrematch g_aggrematch[] = {NEWLINE_LIST, TK_ELIF, TK_ELIF, TK_ELIF}, {NEWLINE_LIST, TK_ELSE, TK_ELSE, TK_ELSE}, {NEWLINE_LIST, TK_WHILE, TK_WHILE, TK_WHILE}, + {NEWLINE_LIST, TK_LBRACE, TK_LBRACE, TK_LBRACE}, {NEWLINE_LIST, TK_UNTIL, TK_UNTIL, TK_UNTIL}, {NEWLINE_LIST, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS}, {NEWLINE_LIST, NEWLINE_LIST, NEWLINE_LIST, NEWLINE}, @@ -367,21 +368,21 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state) return (1); i = 0; head = (*stack)->content; -// DG("aggregate head %s && sym %s", -// read_state(*head), read_state(*new_sym)); + DG("aggregate head %s && sym %s", + read_state(*head), read_state(*new_sym)); while (g_aggrematch[i].top) { if (*new_sym == g_aggrematch[i].top && MATCH_STACK(*head, g_aggrematch[i].under)) { -// DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); + DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); *new_sym = g_aggrematch[i].new_sym; if (g_aggrematch[i].erase_sym) { pop_stack(stack, g_aggrematch[i].erase_sym); head = (*stack)->content; -// DG("stack after pop: %s", read_state(*head)); + DG("stack after pop: %s", read_state(*head)); } if (eval_sym(stack, *new_sym)) { diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index 803e384e..f8cc9635 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/09 18:33:05 by ariard ### ########.fr */ +/* Updated: 2017/03/09 19:45:53 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 5626f27d..9ca21d4a 100644 --- a/42sh/src/parser/eval_sym.c +++ b/42sh/src/parser/eval_sym.c @@ -429,6 +429,7 @@ t_stackmatch g_stackmatch[] = // watch ! {TK_PAREN_OPEN, AND_OR_MAJOR}, {TK_PAREN_OPEN, TK_WHILE}, + {TK_PAREN_OPEN, TK_LBRACE}, {TK_PAREN_OPEN, FUNC_NAME}, {TK_PAREN_OPEN, TK_UNTIL}, {TK_PAREN_OPEN, TK_DO}, @@ -817,6 +818,7 @@ t_stackmatch g_stackmatch[] = {WHILE_CLAUSE, TK_DO}, {WHILE_CLAUSE, TK_PAREN_CLOSE}, {WHILE_CLAUSE, TK_WHILE}, + {WHILE_CLAUSE, TK_LBRACE}, {WHILE_CLAUSE, FUNC_NAME}, {WHILE_CLAUSE, TK_UNTIL}, {WHILE_CLAUSE, TK_IF}, @@ -954,6 +956,7 @@ t_stackmatch g_stackmatch[] = {SUBSHELL, SEPARATOR_OP}, {SUBSHELL, NEWLINE_LIST}, {SUBSHELL, SEQUENCE}, + {SUBSHELL, TK_LBRACE}, // watch ! {SUBSHELL, SEPARATOR_OP}, {SUBSHELL, NEWLINE_LIST}, @@ -1059,8 +1062,6 @@ t_stackmatch g_stackmatch[] = {TK_BANG, TK_PAREN_OPEN}, {TK_BANG, TK_LBRACE}, {TK_BANG, COMPLETE_COMMANDS}, - {TK_BANG, TK_BANG}, - {TK_BANG, TK_BANG}, {TK_BANG, SEPARATOR_OP}, {TK_BANG, NEWLINE_LIST}, {TK_BANG, AND_OR_MAJOR}, @@ -1191,7 +1192,7 @@ int eval_sym(t_list **stack, t_sym new_sym) if (!*stack) return (1); head = (*stack)->content; -// DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); + DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); i = 0; while (g_stackmatch[i].top) {