diff --git a/42sh/includes/.parser.h.swn b/42sh/includes/.parser.h.swn deleted file mode 100644 index 163f04d8..00000000 Binary files a/42sh/includes/.parser.h.swn and /dev/null differ diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 53701f4e..b6a50c7e 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/13 22:33:39 by ariard ### ########.fr */ +/* Updated: 2017/02/14 19:07:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -115,15 +115,13 @@ enum e_sym FUNC, PIPE_SEMI_SEQUENCE, ALL = 200, - PATTERN_CASE, - ALL_SEPERATOR, }; -# define PATTERN_CASE (PATTERN | TK_PAREN_OPEN) -# define ALL_SEPARATOR (TK_NEWLINE | TK_SEMI | TK_AMP) - typedef int t_sym; +# define REDIR (TK_IO_NUMBER | TK_LESS | TK_LESSAND | TK_GREATAND | TK_DGREAT\ + | TK_LESSGREAT | TK_CLOBBER | TK_DLESS | TK_DLESSDASH | TK_WORD) + /* typedef unsigned long long int t_sym; @@ -180,6 +178,11 @@ typedef unsigned long long int t_sym; #define ALL_SYM !0 //#define ALL_SYM -1UL */ + +# define MATCH_STACK(x, y) (x == y || x == ALL) +# define MATCH_NXT_TOKEN(x, y) (x == y || y == ALL || x == 0 || x &~ REDIR) + + typedef int t_parstate; struct s_aggrematch diff --git a/42sh/sample/stack.sh b/42sh/sample/stack.sh index 968d1077..30cde0b2 100644 --- a/42sh/sample/stack.sh +++ b/42sh/sample/stack.sh @@ -1 +1 @@ -ls | cat | cat | cat +ls diff --git a/42sh/src/main/shell_script.c b/42sh/src/main/shell_script.c index 0c33c5b3..1e953693 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/09 20:30:31 by ariard ### ########.fr */ +/* Updated: 2017/02/14 18:29:49 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,10 +31,10 @@ int shell_script() token_print(token); if (ft_parse(&ast, &token)) return (1); -// btree_print(STDBUG, ast, &ft_putast); -// if (ft_exec(&ast)) -// return (1); -// ast = NULL; +// btree_print(STDBUG, ast, &ft_putast); +// if (ft_exec(&ast)) +// return (1); +// ast = NULL; script->size = 0; get_script_content(script); } diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index f4424ef4..a845f0ad 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/13 22:59:11 by ariard ### ########.fr */ +/* Updated: 2017/02/14 19:08:33 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,17 +64,17 @@ t_aggrematch g_aggrematch[] = {REDIRECT_LIST, COMPOUND_COMMAND, COMPOUND_COMMAND, ALL, COMPOUND_COMMAND}, {CMD_SUFFIX, CMD_WORD, SIMPLE_COMMAND, ALL, CMD_PREFIX}, {CMD_SUFFIX, CMD_NAME, SIMPLE_COMMAND, ALL, CMD_NAME}, - {CMD_PREFIX, LINEBREAK, SIMPLE_COMMAND, ALL_SEPARATOR, 0}, - {CMD_PREFIX, TK_BANG, SIMPLE_COMMAND, ALL_SEPARATOR, 0}, - {CMD_PREFIX, SEPARATOR_OP, SIMPLE_COMMAND, ALL_SEPARATOR, 0}, - {CMD_PREFIX, NEWLINE_LIST, SIMPLE_COMMAND, ALL_SEPARATOR, 0}, + {CMD_PREFIX, LINEBREAK, SIMPLE_COMMAND, TK_WORD, 0}, + {CMD_PREFIX, TK_BANG, SIMPLE_COMMAND, TK_WORD, 0}, + {CMD_PREFIX, SEPARATOR_OP, SIMPLE_COMMAND, TK_WORD, 0}, + {CMD_PREFIX, NEWLINE_LIST, SIMPLE_COMMAND, TK_WORD, 0}, {CMD_WORD, CMD_PREFIX, SIMPLE_COMMAND, ALL_SEPARATOR, CMD_PREFIX}, //to check - {CMD_NAME, LINEBREAK, SIMPLE_COMMAND, ALL, 0}, - {CMD_NAME, TK_BANG, SIMPLE_COMMAND, ALL, 0}, - {CMD_NAME, SEPARATOR_OP, SIMPLE_COMMAND, ALL, 0}, - {CMD_NAME, NEWLINE_LIST, SIMPLE_COMMAND, ALL, 0}, - {CMD_NAME, PIPE_SEMI_SEQUENCE, SIMPLE_COMMAND, ALL, 0}, + {CMD_NAME, LINEBREAK, SIMPLE_COMMAND, SUFFIX_NAME, 0}, + {CMD_NAME, TK_BANG, SIMPLE_COMMAND, SUFFIX_NAME, 0}, + {CMD_NAME, SEPARATOR_OP, SIMPLE_COMMAND, SUFFIX_NAME, 0}, + {CMD_NAME, NEWLINE_LIST, SIMPLE_COMMAND, SUFFIX_NAME, 0}, + {CMD_NAME, PIPE_SEMI_SEQUENCE, SIMPLE_COMMAND, SUFFIX_NAME, 0}, {SIMPLE_COMMAND, ALL, COMMAND, ALL, 0}, {DO_GROUP, NAME, FOR_CLAUSE, ALL, TK_FOR}, @@ -140,12 +140,9 @@ int aggregate_sym(t_sym **stack, t_sym *new_sym, read_state(**stack), read_state(*new_sym), read_state(next)); while (g_aggrematch[i].top) { - if (*new_sym == g_aggrematch[i].top && (**stack == g_aggrematch[i].under - || g_aggrematch[i].under == ALL - || g_aggrematch[i].under == ALL_SEPARATOR) - && (next == g_aggrematch[i].next_token || next == 0 - || g_aggrematch[i].next_token == ALL - || (g_aggrematch[i].next_token == ALL_SEPARATOR && next == TK_SEMI))) + if (*new_sym == g_aggrematch[i].top + && MATCH_STACK(**stack, g_aggrematch[i].under) + && MATCH_NXT_TOKEN(next, g_aggrematch[i].next_token)) { DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); *new_sym = g_aggrematch[i].new_sym; diff --git a/42sh/src/parser/parse.c b/42sh/src/parser/parse.c index b96698de..f21dacab 100644 --- a/42sh/src/parser/parse.c +++ b/42sh/src/parser/parse.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/04 16:52:51 by ariard #+# #+# */ -/* Updated: 2017/02/06 19:26:02 by ariard ### ########.fr */ +/* Updated: 2017/02/14 17:48:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,10 +16,9 @@ int parse(t_btree **ast, t_list **token) { t_list *start; - (void)ast; start = *token; - if (get_instruction(token)) - return (1); +// if (get_instruction(token)) +// return (1); if (ft_parse(ast, &start)) return (1); return (0); diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index bf36bd82..4ab45e5f 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/13 22:59:16 by ariard ### ########.fr */ +/* Updated: 2017/02/14 18:26:07 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,10 +26,8 @@ t_prodmatch g_prodmatch[] = {TK_N_WORD, CMD_WORD, CMD_SUFFIX}, {TK_N_WORD, CMD_NAME, CMD_SUFFIX}, {TK_N_WORD, LINEBREAK, CMD_NAME}, - {TK_N_WORD, NEWLINE_LIST, CMD_NAME}, -//to delete - {TK_N_WORD, TK_SEMI, CMD_NAME}, + {TK_N_WORD, NEWLINE_LIST, CMD_NAME}, {TK_N_WORD, TK_BANG, CMD_NAME}, {TK_N_WORD, PIPE_SEMI_SEQUENCE, CMD_NAME}, {TK_N_WORD, SEPARATOR_OP, CMD_NAME}, @@ -49,13 +47,10 @@ t_prodmatch g_prodmatch[] = {TK_NEWLINE, LINEBREAK, NEWLINE_LIST}, {TK_SEMI, TERM, SEPARATOR_OP}, {TK_SEMI, LIST, SEPARATOR_OP}, - {TK_SEMI, COMPLETE_COMMAND, SEPARATOR_OP}, - {TK_SEMI, COMPLETE_COMMANDS, SEPARATOR_OP}, + {TK_SEMI, COMPOUND_LIST, SEPARATOR_OP}, {TK_AMP, TERM, SEPARATOR_OP}, - {TK_AMP, LIST, SEPARATOR_OP}, - {TK_AMP, COMPLETE_COMMAND, SEPARATOR_OP}, - {TK_AMP, COMPLETE_COMMANDS, SEPARATOR_OP}, - + {TK_AMP, LIST, SEPARATOR_OP}, + {TK_AMP, COMPOUND_LIST, SEPARATOR_OP}, {0, 0, 0}, };