From 78a2dafe50afc0a2e85eeb4bc1037ed6750f73a3 Mon Sep 17 00:00:00 2001 From: "ariard@student.42.fr" Date: Wed, 15 Feb 2017 18:31:37 +0100 Subject: [PATCH 1/2] before merge with clean dir --- 42sh/includes/parser.h | 2 +- 42sh/src/parser/aggregate_sym.c | 2 +- 42sh/src/parser/eval_sym.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index b6a50c7e..cc55c791 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/14 19:07:15 by ariard ### ########.fr */ +/* Updated: 2017/02/14 19:09:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index a845f0ad..59441c34 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/14 19:08:33 by ariard ### ########.fr */ +/* Updated: 2017/02/14 19:09:44 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 510970b5..75d9dc3b 100644 --- a/42sh/src/parser/eval_sym.c +++ b/42sh/src/parser/eval_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 16:26:30 by ariard #+# #+# */ -/* Updated: 2017/02/13 22:59:09 by ariard ### ########.fr */ +/* Updated: 2017/02/14 19:09:40 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ From 185ed2ebd3f83faa43e94e74959f105bf3379463 Mon Sep 17 00:00:00 2001 From: "ariard@student.42.fr" Date: Wed, 15 Feb 2017 20:58:41 +0100 Subject: [PATCH 2/2] gen ast en cours --- 42sh/Makefile | 4 ++ 42sh/file1 | 0 42sh/file2 | 0 42sh/file3 | 0 42sh/file4 | 0 42sh/includes/lexer.h | 2 +- 42sh/includes/minishell.h | 2 +- 42sh/includes/parser.h | 84 ++++++++++--------------------- 42sh/sample/stack.sh | 2 +- 42sh/src/main/shell_script.c | 10 ++-- 42sh/src/parser/add_cmd.c | 33 ++++++++++++ 42sh/src/parser/add_sep.c | 28 +++++++++++ 42sh/src/parser/aggregate_sym.c | 10 ++-- 42sh/src/parser/build_tree.c | 38 ++++++++++++++ 42sh/src/parser/eval_sym.c | 4 +- 42sh/src/parser/ft_parse.c | 6 +-- 42sh/src/parser/old_parse.c | 2 +- 42sh/src/parser/parse_do.c | 2 +- 42sh/src/parser/parse_great.c | 2 +- 42sh/src/parser/parse_separator.c | 2 +- 42sh/src/parser/parse_word.c | 2 +- 42sh/src/parser/pop_stack.c | 4 +- 42sh/src/parser/produce_sym.c | 6 +-- 42sh/src/parser/tree_wrapper.c | 32 ++++++++++++ 24 files changed, 189 insertions(+), 86 deletions(-) delete mode 100644 42sh/file1 delete mode 100644 42sh/file2 delete mode 100644 42sh/file3 delete mode 100644 42sh/file4 create mode 100644 42sh/src/parser/add_cmd.c create mode 100644 42sh/src/parser/add_sep.c create mode 100644 42sh/src/parser/build_tree.c create mode 100644 42sh/src/parser/tree_wrapper.c diff --git a/42sh/Makefile b/42sh/Makefile index 2aad4347..91ab3226 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -176,6 +176,10 @@ parser/aggregate_sym.c\ parser/pop_stack.c\ parser/push_stack.c\ parser/error_syntax.c\ +parser/build_tree.c\ +parser/tree_wrapper.c\ +parser/add_sep.c\ +parser/add_cmd.c\ parser/get_instruction.c\ parser/get_sub_instruction.c\ parser/parse_dgreat.c\ diff --git a/42sh/file1 b/42sh/file1 deleted file mode 100644 index e69de29b..00000000 diff --git a/42sh/file2 b/42sh/file2 deleted file mode 100644 index e69de29b..00000000 diff --git a/42sh/file3 b/42sh/file3 deleted file mode 100644 index e69de29b..00000000 diff --git a/42sh/file4 b/42sh/file4 deleted file mode 100644 index e69de29b..00000000 diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index c52567d4..b8891c65 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/02/13 19:41:57 by ariard ### ########.fr */ +/* Updated: 2017/02/15 19:46:49 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 8fe62ce6..f1870080 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/02/09 22:31:21 by ariard ### ########.fr */ +/* Updated: 2017/02/15 19:22:59 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 7d5f20f7..90ccbcb3 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/14 19:09:38 by ariard ### ########.fr */ +/* Updated: 2017/02/15 20:50:55 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -121,63 +121,6 @@ enum e_sym typedef int t_sym; -/* -typedef unsigned long long int t_sym; - -#define PROGRAM (1UL << 0) -#define COMPLETE_COMMANDS (1UL << 1) -#define COMPLETE_COMMAND (1UL << 2) -#define LIST (1UL << 3) -#define AND_OR (1UL << 4) -#define PIPELINE (1UL << 5) -#define PIPE_SEQUENCE (1UL << 6) -#define COMMAND (1UL << 7) -#define COMPOUND_COMMAND (1UL << 8) -#define SUBSHELL (1UL << 9) -#define COMPOUND_LIST (1UL << 10) -#define TERM (1UL << 11) -#define FOR_CLAUSE (1UL << 12) -#define NAME (1UL << 13) -#define IN (1UL << 14) -#define WORDLIST (1UL << 15) -#define CASE_CLAUSE (1UL << 16) -#define CASE_LIST_NS (1UL << 17) -#define CASE_LIST (1UL << 18) -#define CASE_ITEM_NS (1UL << 19) -#define PATTERN (1UL << 20) -#define IF_CLAUSE (1UL << 21) -#define ELSE_PART (1UL << 22) -#define WHILE_CLAUSE (1UL << 23) -#define UNTIL_CLAUSE (1UL << 24) -#define FUNCTION_DEFINITION (1UL << 25) -#define FUNCTION_BODY (1UL << 26) -#define FNAME (1UL << 27) -#define BRACE_GROUP (1UL << 28) -#define DO_GROUP (1UL << 29) -#define SIMPLE_COMMAND (1UL << 30) -#define CMD_NAME (1UL << 31) -#define CMD_WORD (1UL << 32) -#define CMD_PREFIX (1UL << 33) -#define CMD_SUFFIX (1UL << 34) -#define REDIRECT_LIST (1UL << 35) -#define IO_REDIRECT (1UL << 36) -#define IO_FILE (1UL << 37) -#define FILENAME (1UL << 38) -#define IO_HERE (1UL << 39) -#define HERE_END (1UL << 40) -#define NEWLINE_LIST (1UL << 41) -#define LINEBREAK (1UL << 42) -#define SEPARATOR_OP (1UL << 43) -#define SEPARATOR (1UL << 44) -#define SEQUENTIAL_SEP (1UL << 45) - -#define SYM_LESS (1UL << 49) -#define SYM_GREAT (1UL << 50) - -#define ALL_SYM !0 -//#define ALL_SYM -1UL -*/ - # define MATCH_STACK(x, y) (x == y || y == ALL) typedef int t_parstate; @@ -232,6 +175,31 @@ char *read_state(t_sym current); #define ERROR (1 << 1) #define SUCCESS (1 << 2) +/* + * Build AST - rewriting + * +*/ + +struct s_treematch +{ + t_type type; + int (*add)(t_btree **ast, t_list **lst); +}; + +typedef struct s_treematch t_treematch; + +extern t_treematch g_treematch[]; + +int build_tree(t_btree **ast, t_list **lst); + +int add_sep(t_btree **ast, t_list **lst); +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 1c1823ad..b3bc3407 100644 --- a/42sh/sample/stack.sh +++ b/42sh/sample/stack.sh @@ -1 +1 @@ -ls | cat | cat > file1 +ls | cat diff --git a/42sh/src/main/shell_script.c b/42sh/src/main/shell_script.c index 1e953693..994a89b9 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/14 18:29:49 by ariard ### ########.fr */ +/* Updated: 2017/02/15 20:58:03 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/add_cmd.c b/42sh/src/parser/add_cmd.c new file mode 100644 index 00000000..b299c780 --- /dev/null +++ b/42sh/src/parser/add_cmd.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* add_cmd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ +/* Updated: 2017/02/15 20:57:47 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "parser.h" + +int add_cmd(t_btree **ast, t_list **lst) +{ + t_token *token; + t_astnode *node; + char **my_tab; + + if (!*ast) + gen_node(ast); + else + return (add_cmd(&(*ast)->right, lst)); + my_tab = NULL; + token = (*lst)->content; + node = (*ast)->item; + node->type = TK_COMMAND; + my_tab = ft_sstradd(my_tab, token->data); + my_tab = ft_sstradd(my_tab, (char *)token->esc); + ft_ld_pushback(&node->data.token, my_tab); + return (0); +} diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c new file mode 100644 index 00000000..01dd18a6 --- /dev/null +++ b/42sh/src/parser/add_sep.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* add_sep.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/02/15 19:12:07 by ariard #+# #+# */ +/* Updated: 2017/02/15 20:48:17 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "parser.h" + +int add_sep(t_btree **ast, t_list **lst) +{ + t_token *token; + t_astnode *node; + t_btree *new_node; + + new_node = NULL; + gen_node(&new_node); + join_ast(ast, &new_node); + token = (*lst)->content; + node = (new_node)->item; + node->type = token->type; + return (0); +} diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 0b81a7f2..7d3434e5 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/14 19:09:44 by ariard ### ########.fr */ +/* Updated: 2017/02/15 19:52:56 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -149,20 +149,20 @@ int aggregate_sym(t_sym **stack, t_sym *new_sym, t_parstate *state) int i; i = 0; - DG("aggregate head %s && sym %s", - read_state(**stack), read_state(*new_sym)); +// DG("aggregate head %s && sym %s", +// read_state(**stack), read_state(*new_sym)); while (g_aggrematch[i].top) { if (*new_sym == g_aggrematch[i].top && MATCH_STACK(**stack, 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); - DG("stack after pop: %s", read_state(**stack)); +// DG("stack after pop: %s", read_state(**stack)); } if (eval_sym(**stack, *new_sym)) return ((*state = ERROR)); diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c new file mode 100644 index 00000000..2441360a --- /dev/null +++ b/42sh/src/parser/build_tree.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* build_tree.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/02/15 18:32:59 by ariard #+# #+# */ +/* Updated: 2017/02/15 20:51:50 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "parser.h" + +t_treematch g_treematch[] = +{ + {TK_N_WORD, &add_cmd}, + {TK_PIPE, &add_sep}, + {0, NULL}, +}; + +int build_tree(t_btree **ast, t_list **lst) +{ + int i; + t_token *token; + + i = 0; + token = (*lst)->content; + while (g_treematch[i].type) + { + DG("func TK : '%s' TK : '%s'", + read_state(g_treematch[i].type) ,read_state(token->type)); + if (g_treematch[i].type == token->type) + return (g_treematch[i].add(ast, lst)); + i++; + } + return (0); +} diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 38e9361c..49f4acf3 100644 --- a/42sh/src/parser/eval_sym.c +++ b/42sh/src/parser/eval_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 16:26:30 by ariard #+# #+# */ -/* Updated: 2017/02/14 19:09:40 by ariard ### ########.fr */ +/* Updated: 2017/02/15 19:52:12 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -427,7 +427,7 @@ int eval_sym(t_sym stack, t_sym new_sym) { int i; - DG("eval head %s && sym %s", read_state(stack), read_state(new_sym)); +// DG("eval head %s && sym %s", read_state(stack), read_state(new_sym)); i = 0; while (g_stackmatch[i].top) { diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index 2ee26cc2..b8a0f105 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 14:30:22 by ariard #+# #+# */ -/* Updated: 2017/02/13 22:59:00 by ariard ### ########.fr */ +/* Updated: 2017/02/15 20:40:28 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ int ft_parse(t_btree **ast, t_list **token) while (*token) { produce_sym(*stack, new_sym, token); - DG("new sym %s", read_state(*new_sym)); +// DG("new sym %s", read_state(*new_sym)); if (eval_sym(*stack, *new_sym)) state = ERROR; else @@ -43,7 +43,7 @@ int ft_parse(t_btree **ast, t_list **token) return (error_syntax(token)); if (state == SUCCESS) ft_putstr("success"); -// build_tree(token, ast); + build_tree(ast, token); ft_lst_delif(token, (*token)->content, &ft_addrcmp, &token_free); } return (0); diff --git a/42sh/src/parser/old_parse.c b/42sh/src/parser/old_parse.c index 8814ece1..b5310530 100644 --- a/42sh/src/parser/old_parse.c +++ b/42sh/src/parser/old_parse.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */ -/* Updated: 2017/02/09 22:06:41 by ariard ### ########.fr */ +/* Updated: 2017/02/15 19:56:09 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/parse_do.c b/42sh/src/parser/parse_do.c index e4d8ba80..1c0051c1 100644 --- a/42sh/src/parser/parse_do.c +++ b/42sh/src/parser/parse_do.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/30 16:28:41 by ariard #+# #+# */ -/* Updated: 2017/02/03 16:46:45 by ariard ### ########.fr */ +/* Updated: 2017/02/15 19:08:49 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/parse_great.c b/42sh/src/parser/parse_great.c index fd15c29d..91420222 100644 --- a/42sh/src/parser/parse_great.c +++ b/42sh/src/parser/parse_great.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */ -/* Updated: 2017/02/04 23:44:59 by ariard ### ########.fr */ +/* Updated: 2017/02/15 19:30:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/parse_separator.c b/42sh/src/parser/parse_separator.c index aa644e27..ca1e0387 100644 --- a/42sh/src/parser/parse_separator.c +++ b/42sh/src/parser/parse_separator.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 16:21:51 by jhalford #+# #+# */ -/* Updated: 2017/02/09 19:27:22 by ariard ### ########.fr */ +/* Updated: 2017/02/15 19:34:57 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/parse_word.c b/42sh/src/parser/parse_word.c index 7fa5fa7c..eba9cfdf 100644 --- a/42sh/src/parser/parse_word.c +++ b/42sh/src/parser/parse_word.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */ -/* Updated: 2017/02/09 15:24:49 by ariard ### ########.fr */ +/* Updated: 2017/02/15 19:54:27 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/pop_stack.c b/42sh/src/parser/pop_stack.c index 597d3867..4d2b8fe5 100644 --- a/42sh/src/parser/pop_stack.c +++ b/42sh/src/parser/pop_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 19:12:44 by ariard #+# #+# */ -/* Updated: 2017/02/13 22:51:52 by ariard ### ########.fr */ +/* Updated: 2017/02/15 19:52:42 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ int pop_stack(t_sym **stack, t_sym erase_sym) { t_sym *temp; - DG("pop until :%s", read_state(erase_sym)); +// DG("pop until :%s", read_state(erase_sym)); temp = *stack; while (*temp != erase_sym) *temp-- = 0; diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index bb95c364..c5f415b6 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/14 18:26:07 by ariard ### ########.fr */ +/* Updated: 2017/02/15 19:50:59 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,8 +64,8 @@ int produce_sym(t_sym stack, t_sym *new_sym, t_list **lst) int i; token = (*lst)->content; - DG("produce stack : %s && token : %s", read_state(stack), - read_state(token->type)); +// DG("produce stack : %s && token : %s", read_state(stack), +// read_state(token->type)); i = 0; *new_sym = 0; while (g_prodmatch[i].new_sym) diff --git a/42sh/src/parser/tree_wrapper.c b/42sh/src/parser/tree_wrapper.c new file mode 100644 index 00000000..31258f7e --- /dev/null +++ b/42sh/src/parser/tree_wrapper.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* tree_wrapper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/02/15 18:57:44 by ariard #+# #+# */ +/* Updated: 2017/02/15 20:56:38 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "parser.h" + +int join_ast(t_btree **ast, t_btree **new_node) +{ + (*new_node)->left = *ast; + *ast = *new_node; + return (0); +} + +int gen_node(t_btree **ast) +{ + t_astnode item; + + if (!*ast) + { + *ast = btree_create_node(&item, sizeof(item)); + ((t_astnode *)(*ast)->item)->data.token = NULL; + } + return (0); +}