From 7477cb4c0d7781f75fc5623e975cfcf515f2c1c4 Mon Sep 17 00:00:00 2001 From: AntoHesse Date: Thu, 16 Feb 2017 17:35:44 +0100 Subject: [PATCH] debug exec ou parsing --- 42sh/Makefile | 1 + 42sh/includes/parser.h | 14 ++------------ 42sh/sample/stack.sh | 2 +- 42sh/src/main/shell_script.c | 14 ++++++++------ 42sh/src/parser/ft_parse.c | 2 +- 42sh/src/parser/old_parse.c | 5 +++-- 42sh/src/parser/parse_word.c | 2 ++ 42sh/src/parser/read_stack.c | 2 ++ 8 files changed, 20 insertions(+), 22 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index 91ab3226..0b41f6bb 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -170,6 +170,7 @@ main/shell_script.c\ main/sig_handler.c\ parser/parse.c\ parser/ft_parse.c\ +parser/old_parse.c\ parser/produce_sym.c\ parser/eval_sym.c\ parser/aggregate_sym.c\ diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 1526281c..9830855d 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -158,15 +158,7 @@ typedef struct s_stackmatch t_stackmatch; extern t_stackmatch g_stackmatch[]; -struct s_treematch g_treemacth[]; -{ - t_type token; - void (*add)(t_btree **ast, t_type ) -}; - -typedef struct s_treematch t_treematch; - -extern t_treematch g_treematch[]; +int ft_parse2(t_btree **ast, t_list **token); int ft_parse(t_btree **ast, t_list **token); int produce_sym(t_sym stack, t_sym *new_sym, t_list **lst); @@ -193,7 +185,7 @@ char *read_state(t_sym current); struct s_treematch { t_type type; - int (*add)(t_btree **ast, t_list **lst); + int (*add)(t_btree **ast, t_list **lst); }; typedef struct s_treematch t_treematch; @@ -208,8 +200,6 @@ int add_cmd(t_btree **ast, t_list **lst); int join_ast(t_btree **ast, t_btree **new_node); int gen_node(t_btree **ast); - - /* * Build AST * diff --git a/42sh/sample/stack.sh b/42sh/sample/stack.sh index b3bc3407..30cde0b2 100644 --- a/42sh/sample/stack.sh +++ b/42sh/sample/stack.sh @@ -1 +1 @@ -ls | cat +ls diff --git a/42sh/src/main/shell_script.c b/42sh/src/main/shell_script.c index 994a89b9..bdb13254 100644 --- a/42sh/src/main/shell_script.c +++ b/42sh/src/main/shell_script.c @@ -23,21 +23,23 @@ int shell_script() ast = NULL; list_ast = NULL; script = &data_singleton()->script; - while (script->size) - { +// while (script->size) +// { if (ft_lexer(&token, &data_singleton()->script.buffer) || !token) return (1); DG("after post_tokenize"); token_print(token); +// if (ft_parse2(&ast, &token)) +// return (1); if (ft_parse(&ast, &token)) return (1); btree_print(STDBUG, ast, &ft_putast); - if (ft_exec(&ast)) - return (1); - ast = NULL; + if (ft_exec(&ast)) + return (1); + ast = NULL; script->size = 0; get_script_content(script); - } +// } close(script->fd); return (0); } diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index b8a0f105..745b48aa 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -12,7 +12,7 @@ #include "parser.h" -int ft_parse(t_btree **ast, t_list **token) +int ft_parse2(t_btree **ast, t_list **token) { t_sym *new_sym; t_sym *stack; diff --git a/42sh/src/parser/old_parse.c b/42sh/src/parser/old_parse.c index b5310530..00969352 100644 --- a/42sh/src/parser/old_parse.c +++ b/42sh/src/parser/old_parse.c @@ -14,7 +14,6 @@ t_parser g_parser[] = { - {INSTRUCTION, &get_sub_instruction}, {TK_AND_IF | TK_OR_IF, &parse_separator}, {TK_AMP, &parse_separator}, {TK_PIPE, &parse_separator}, @@ -25,7 +24,7 @@ t_parser g_parser[] = {TK_LESSAND, &parse_lessand}, {TK_GREATAND, &parse_greatand}, {TK_SUBSHELL, &parse_subshell}, - {TK_WORD, &parse_word}, + {TK_N_WORD, &parse_word}, {0, 0}, }; @@ -35,6 +34,7 @@ int ft_parse(t_btree **ast, t_list **start) t_astnode item; int i; + DG("old parser"); i = 0; if (!*start) return (0); @@ -48,6 +48,7 @@ int ft_parse(t_btree **ast, t_list **start) { if ((lst = ft_lst_find(*start, &g_parser[i].type, &token_cmp_type))) { + DG("match : %s", read_state(g_parser[i].type)); if (g_parser[i].f) (*g_parser[i].f)(ast, start, &lst); return (0); diff --git a/42sh/src/parser/parse_word.c b/42sh/src/parser/parse_word.c index eba9cfdf..8df72e27 100644 --- a/42sh/src/parser/parse_word.c +++ b/42sh/src/parser/parse_word.c @@ -18,6 +18,7 @@ int parse_word(t_btree **ast, t_list **start, t_list **lst) t_token *token; char **my_tab; + DG("parse word begin"); my_tab = NULL; token = (*lst)->content; node = (*ast)->item; @@ -27,5 +28,6 @@ int parse_word(t_btree **ast, t_list **start, t_list **lst) ft_ld_pushback(&node->data.token, my_tab); ft_parse(ast, &(*lst)->next); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); + DG("parse word end"); return (0); } diff --git a/42sh/src/parser/read_stack.c b/42sh/src/parser/read_stack.c index 2e9ccf35..dec9d797 100644 --- a/42sh/src/parser/read_stack.c +++ b/42sh/src/parser/read_stack.c @@ -14,6 +14,8 @@ char *read_state(t_sym current) { + if (current == TK_DLESS) + return ("TK_DLESS"); if (current == CMD_SUPERIOR) return ("CMD_SUPERIOR"); if (current == TK_IO_NUMBER)