diff options
Diffstat (limited to 'src/parse')
| -rw-r--r-- | src/parse/parse.c | 44 | ||||
| -rw-r--r-- | src/parse/parse_error.c | 45 |
2 files changed, 38 insertions, 51 deletions
diff --git a/src/parse/parse.c b/src/parse/parse.c index 740726c..610b640 100644 --- a/src/parse/parse.c +++ b/src/parse/parse.c @@ -6,7 +6,7 @@ /* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/17 18:09:04 by nahaddac #+# #+# */ -/* Updated: 2020/06/23 08:35:29 by charles ### ########.fr */ +/* Updated: 2020/07/13 14:54:37 by nahaddac ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,6 @@ #include "parser.h" #include "lexer.h" - t_ftlst *push_token(t_ftlst **tokens, t_token *pushed) { t_ftlst *tmp; @@ -99,10 +98,8 @@ t_ret *parse_op(t_ftlst *input) enum e_token_tag tag; left_ret = parse_expr(input); - /* printf("%p\n", left_ret); */ input = left_ret->rest; - - if (input == NULL || ((t_token*)input->data)->tag == TAG_PARENT_CLOSE) + if (input == NULL || ((t_token*)input->data)->tag & TAG_PARENT_CLOSE) return ret_wrap_ast(left_ret->ast, input); tag = ((t_token*)input->data)->tag; @@ -121,18 +118,19 @@ t_ret *parse_expr(t_ftlst *input) { t_ret *tmp; enum e_token_tag tag; + t_ast *new_ast; tag = ((t_token*)input->data)->tag; - if (tag == TAG_PARENT_OPEN) + if (tag & TAG_PARENT_OPEN) { tmp = parse_op(input->next); input = tmp->rest; tag = ((t_token*)input->data)->tag; - if (tag != TAG_PARENT_CLOSE) + if (!(tag & TAG_PARENT_CLOSE)) return (NULL); input = input->next; - t_ast *new_ast = ast_new(AST_PARENT); + new_ast = ast_new(AST_PARENT); new_ast->parent_ast = tmp->ast; tmp->ast = new_ast; if (input == NULL) @@ -158,8 +156,6 @@ t_ret *parse_expr(t_ftlst *input) break; tag = ((t_token*)input->data)->tag; } - /* token_debug(input->data); */ - tmp->rest = input; return tmp; } @@ -169,19 +165,21 @@ t_ret *parse_expr(t_ftlst *input) t_ret *parse(t_ftlst *input) { t_ret *ret; - /* t_ftlst *in_f; */ - - /* in_f = input; */ - /* if (input == NULL) */ - /* return NULL; */ - /* if (!(ret = malloc(sizeof(t_ret) * 1))) */ - /* return (NULL); */ - /* ret->ast = NULL; */ - /* ret->rest = NULL; */ - /* if((ret->unexpected = error_syntax_simple(input)) != NULL) */ - /* printf("%s\n", ret->unexpected->content); */ + t_ftlst *in_f; + + in_f = input; + if (input == NULL) + return NULL; + if (!(ret = malloc(sizeof(t_ret) * 1))) + return (NULL); + ret->ast = NULL; + ret->rest = NULL; + + if((ret->unexpected = error_syntax_simple(input))) + return (ret); + printf("%s\n",((t_token *)ret->unexpected)->content); ret = parse_op(input); - /* ast_destroy(ret->ast); */ - /* ft_lstdestroy(&ret->rest, (void (*)(void*))token_destroy); */ + //ast_destroy(ret->ast); + //ft_lstdestroy(&ret->rest, (void (*)(void*))token_destroy); return (ret); } diff --git a/src/parse/parse_error.c b/src/parse/parse_error.c index b721c28..e48eda2 100644 --- a/src/parse/parse_error.c +++ b/src/parse/parse_error.c @@ -6,38 +6,27 @@ /* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/18 15:09:48 by nahaddac #+# #+# */ -/* Updated: 2020/06/19 12:46:56 by nahaddac ### ########.fr */ +/* Updated: 2020/07/13 14:30:39 by nahaddac ### ########.fr */ /* */ /* ************************************************************************** */ #include "parser.h" -t_token *error_syntax_parent(t_ftlst *in) -{ - int op; - int cl; - t_token *tk; - - op = 0; - cl = 0; - while(in != NULL) - { - tk = in->data; - if (tk->tag & TAG_PARENT_OPEN) - op++; - if(tk->tag & TAG_PARENT_CLOSE) - cl++; - if (cl && op == 0) - { - tk->content = ft_strjoin3( - "minishell: syntax error near unexpected token `", - tk->content, "'"); - return tk; - } - in = in->next; - } - return NULL; -} +// t_token *error_syntax_parent(t_ftlst *in) +// { +// t_token *tk; +// t_ftlst *first; +// +// first = in; +// while(in != NULL) +// { +// tk = in->data; +// if (tk->tag & TAG_PARENT_OPEN || tk->tag & TAG_PARENT_CLOSE) +// printf("%s\n", "coucouc"); +// in = in->next; +// } +// return first; +// } int out_error_first(t_token *tk) { @@ -101,6 +90,6 @@ t_token *error_syntax_simple(t_ftlst *in) } in = in->next; } - return error_syntax_parent(first); + return first; } |
