aboutsummaryrefslogtreecommitdiff
path: root/src/parse/parse.c
diff options
context:
space:
mode:
authornass1pro <nass1pro@gmail.com>2020-06-17 19:01:25 +0200
committernass1pro <nass1pro@gmail.com>2020-06-17 19:01:25 +0200
commitae510a886b202926b4a5502de02a938054844ad4 (patch)
treebc8d60be16b32d8bdb6f5a0234305149fc420c2d /src/parse/parse.c
parent4a0fc35cbe98d75f64113643768b16c9b29d773f (diff)
downloadminishell-ae510a886b202926b4a5502de02a938054844ad4.tar.gz
minishell-ae510a886b202926b4a5502de02a938054844ad4.tar.bz2
minishell-ae510a886b202926b4a5502de02a938054844ad4.zip
Update line op
Diffstat (limited to 'src/parse/parse.c')
-rwxr-xr-xsrc/parse/parse.c90
1 files changed, 60 insertions, 30 deletions
diff --git a/src/parse/parse.c b/src/parse/parse.c
index 1fc24be..b9bb156 100755
--- a/src/parse/parse.c
+++ b/src/parse/parse.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* parse.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/06/17 18:09:04 by nahaddac #+# #+# */
+/* Updated: 2020/06/17 18:36:54 by nahaddac ### ########.fr */
+/* */
+/* ************************************************************************** */
+
/*
** \file parse.c
** \brief Parser
@@ -11,11 +23,43 @@
+t_ast *cmd_push_ast(t_ftlst *rest)
+{
+ enum e_token_tag tag;
+ t_ast *ast;
+
+ ast = NULL;
+ while (rest != NULL)
+ {
+ tag = ((t_token *)rest->data)->tag;
+ if (parse_cmd_str_true_false(tag))
+ {
+ ast = push_cmd(ast, rest);
+ }
+ else if (parse_redir_true_false(tag))
+ {
+ while(rest != NULL)
+ {
+ ast = push_redir(ast, rest);
+ if (tag & TAG_IS_STR && tag & TAG_STICK)
+ rest = rest->next;
+ else if (tag & TAG_IS_REDIR)
+ rest = rest->next;
+ else
+ break;
+ tag = ((t_token *)rest->data)->tag;
+ }
+ }
+ rest = rest->next;
+ }
+ return ast;
+}
+
t_ret *parse(t_ftlst *input)
{
t_ret *ret;
t_ret *first;
- enum e_token_tag tag;
+ t_ast *new_ast;
if(!(ret = malloc(sizeof(t_ret) * 1)))
return(NULL);
@@ -24,38 +68,24 @@ t_ret *parse(t_ftlst *input)
ret->unexpected = NULL;
first = ret;
- while (ret->rest != NULL)
+ if(!(new_ast = malloc(sizeof(t_ast) * 1)))
+ return(0);
+ new_ast = cmd_push_ast(ret->rest);
+ printf("%s\n",((t_token *)ret->rest->data)->content);
+ if (ret->ast)
{
- tag = ((t_token *)ret->rest->data)->tag;
- if (parse_cmd_str_true_false(tag))
- ret->ast = push_cmd(ret->ast, ret->rest);
- else if (parse_redir_true_false(tag))
+ while(ret->ast->cmd_argv != NULL)
+ {
+ printf("[%s]\n", ((t_token *)ret->ast->cmd_argv->data)->content);
+ ret->ast->cmd_argv = ret->ast->cmd_argv->next;
+ }
+ while(ret->ast->redirs != NULL)
{
- while(ret->rest != NULL)
- {
- ret->ast = push_redir(ret->ast, ret->rest);
- if (tag & TAG_IS_STR && tag & TAG_STICK)
- ret->rest = ret->rest->next;
- else if (tag & TAG_IS_REDIR)
- ret->rest = ret->rest->next;
- else
- break;
- tag = ((t_token *)ret->rest->data)->tag;
- }
+ printf("[%s]\n", ((t_token *)ret->ast->redirs->data)->content);
+ ret->ast->redirs = ret->ast->redirs->next;
}
- ret->rest = ret->rest->next;
}
- /* while(ret->ast->cmd_argv != NULL) */
- /* { */
- /* printf("[%s]\n", ((t_token *)ret->ast->cmd_argv->data)->content); */
- /* ret->ast->cmd_argv = ret->ast->cmd_argv->next; */
- /* } */
- /* while(ret->ast->redirs != NULL) */
- /* { */
- /* printf("[%s]\n", ((t_token *)ret->ast->redirs->data)->content); */
- /* ret->ast->redirs = ret->ast->redirs->next; */
- /* } */
- /* 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 first;
}