gen ast cleand

This commit is contained in:
Antoine Riard 2017-03-04 22:08:31 +01:00
parent 7d660fec7c
commit 56b106ee0f
29 changed files with 311 additions and 102 deletions

View file

@ -1,5 +1,5 @@
/* ************************************************************************** */
/* */ /* ::: :::::::: */
/* */
/* parser.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
@ -82,13 +82,6 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state);
int push_stack(t_list **stack, t_sym new_sym);
int pop_stack(t_list **stack, t_sym erase_sym);
/*int produce_sym(t_sym stack, t_sym *new_sym, t_list **lst);
int eval_sym(t_sym stack, t_sym new_sym);
int aggregate_sym(t_sym **stack, t_sym *new_sym, t_parstate *state);
int push_stack(t_sym *stack, t_sym new_sym);
int pop_stack(t_sym **stack, t_sym erase_sym);
*/
int error_syntax(t_list **token, t_parser *parser, t_btree **ast);
int error_EOF(t_list **token, t_parser *parser, t_btree **ast);
@ -113,6 +106,7 @@ 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 add_file(t_btree **ast, t_list **lst);
int add_loop_cmd(t_btree **ast, t_list **lst);
int add_loop_sep(t_btree **ast, t_list **lst);
@ -132,10 +126,15 @@ int add_func_sep(t_btree **ast, t_list **lst);
int add_one_func(t_btree **ast, t_list **lst);
int add_pipe(t_btree **ast, t_list **lst);
int add_var(t_btree **ast, t_list **lst);
int add_null(t_btree **ast, t_list **lst);
int isloop(t_btree **ast, t_list **lst);
int isloop_condition(t_btree **ast, t_list **lst);
int iscase(t_btree **ast, t_list **lst);
int iscase_pattern(t_btree **ast, t_list **lst);
int iscase_branch(t_btree **ast, t_list **lst);
int iscondition(t_btree **ast, t_list **lst);
int iscondition_branch(t_btree **ast, t_list **lst);
int issubshell(t_btree **ast, t_list **lst);
int isfunc(t_btree **ast, t_list **lst);
int isdir(t_btree **ast);
@ -143,9 +142,19 @@ int iscondition(t_btree **ast, t_list **list);
int isdir_sep(t_btree **ast, t_list **list);
int isdir_word(t_btree **ast, t_list **list);
int isvar(t_btree **ast, t_list **list);
int isnull(t_btree **ast, t_list **list);
int join_ast(t_btree **ast, t_btree **new_node);
int gen_node(t_btree **ast);
int superflous_token(t_btree **ast, t_list **list);
struct s_distrostree
{
int (*test)(t_btree **ast, t_list **lst);
int (*add)(t_btree **ast, t_list **lst);
};
extern t_distrostree g_distrostree[];
union u_word
{

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
/* Updated: 2017/03/03 20:07:30 by ariard ### ########.fr */
/* Updated: 2017/03/04 19:50:36 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -50,6 +50,7 @@ typedef struct s_prodmatch t_prodmatch;
typedef struct s_stackmatch t_stackmatch;
typedef struct s_errormatch t_errormatch;
typedef struct s_treematch t_treematch;
typedef struct s_distrostree t_distrostree;
t_data *data_singleton();

View file

@ -1,6 +1,4 @@
case $rental in
("bus") case $rental in
("yolo") echo bonjour
esac ;;
("van") echo yolo ;;
( "bus" ) echo Hello world ;;
( "van" ) echo Comment va ? ;;
esac

View file

@ -1,11 +1,21 @@
if ls
then
ls ; cat
pwd ; echo "Salut"
while ls
do
until ls
until pwd
do
pwd
echo KO SI JE M AFFICHE
done
if cat faux
then
echo BONJOUR MAKEFILE
elif [ -f Makefile ]
then
echo BONJOUR MAKEFILE
else
echo KO SI JE M M AFFICHE
fi
echo "Encore une"
done
fi

View file

@ -1,11 +1,11 @@
until ls
until cat wefwef
do
until ls
do
pwd | cat
done
until ls
do
pwd ; ls
done
until cat eqwfewf
do
ls | cat
done
done

View file

@ -1,4 +1,4 @@
while pwd
while ls
do
while cat rwgwghe
do

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 18:07:31 by ariard #+# #+# */
/* Updated: 2017/03/03 16:29:52 by jhalford ### ########.fr */
/* Updated: 2017/03/04 18:18:29 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,6 +18,7 @@ int exec_case(t_btree **ast)
/* char **av; */
t_exec *exec;
return (0);
exec = &data_singleton()->exec;
/* data_singleton()->exec.process.case_branch = 0; */
exec->attrs |= EXEC_CASE_BRANCH;

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 18:07:31 by ariard #+# #+# */
/* Updated: 2017/03/03 16:28:15 by jhalford ### ########.fr */
/* Updated: 2017/03/04 18:23:29 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,6 +18,7 @@ int exec_case_branch(t_btree **ast)
/* char **av; */
t_exec *exec;
return (0);
exec = &data_singleton()->exec;
/* if (data_singleton()->exec.process.case_branch == 1) */
if (EXEC_IS_CASE_BRANCH(exec->attrs))

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 18:55:07 by ariard #+# #+# */
/* Updated: 2017/03/04 18:00:47 by ariard ### ########.fr */
/* Updated: 2017/03/04 18:06:55 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 20:42:20 by ariard #+# #+# */
/* Updated: 2017/03/03 16:26:40 by jhalford ### ########.fr */
/* Updated: 2017/03/04 18:17:05 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,7 +19,6 @@ int exec_for(t_btree **ast)
// char **av = NULL;
char *var;
node = (*ast)->item;
temp = node->data.wordlist;
var = temp->content;

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 20:42:20 by ariard #+# #+# */
/* Updated: 2017/03/03 16:30:13 by jhalford ### ########.fr */
/* Updated: 2017/03/04 18:16:38 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,9 +15,11 @@
int exec_until(t_btree **ast)
{
ft_exec(&(*ast)->left);
while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)
while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "1") == 0)
{
DG("before right");
ft_exec(&(*ast)->right);
DG("before left");
ft_exec(&(*ast)->left);
}
return (0);

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/18 11:20:11 by gwojda #+# #+# */
/* Updated: 2017/02/18 14:38:21 by gwojda ### ########.fr */
/* Updated: 2017/03/04 18:51:01 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/18 11:06:19 by gwojda #+# #+# */
/* Updated: 2017/02/21 20:57:19 by ariard ### ########.fr */
/* Updated: 2017/03/04 18:50:56 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/18 11:32:18 by gwojda #+# #+# */
/* Updated: 2017/02/21 20:57:42 by ariard ### ########.fr */
/* Updated: 2017/03/04 18:51:14 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
/* Updated: 2017/03/03 17:55:55 by jhalford ### ########.fr */
/* Updated: 2017/03/04 20:51:21 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/20 18:20:23 by gwojda #+# #+# */
/* Updated: 2017/02/03 17:50:48 by gwojda ### ########.fr */
/* Updated: 2017/03/04 18:51:45 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/16 17:06:30 by gwojda #+# #+# */
/* Updated: 2017/02/04 18:16:34 by gwojda ### ########.fr */
/* Updated: 2017/03/04 18:52:22 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/08 12:35:11 by gwojda #+# #+# */
/* Updated: 2017/02/14 11:13:10 by gwojda ### ########.fr */
/* Updated: 2017/03/04 18:51:59 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/03/04 17:35:55 by ariard ### ########.fr */
/* Updated: 2017/03/04 19:29:28 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -62,7 +62,7 @@ int handle_instruction(int fd)
error_syntax(&token, &parser, &ast);
}
DG("Before execution:");
btree_print(STDBUG, ast, &ft_putast);
// btree_print(STDBUG, ast, &ft_putast);
if (ft_exec(&ast))
return (1);
instruction_free(&token, &parser, &ast);

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* add_case.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/04 20:42:13 by ariard #+# #+# */
/* Updated: 2017/03/04 21:54:21 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int iscase(t_btree **ast, t_list **lst)
@ -5,6 +17,22 @@ int iscase(t_btree **ast, t_list **lst)
t_astnode *node;
t_token *token;
node = NULL;
token = (*lst)->content;
if (*ast)
{
node = (*ast)->item;
if (node->type == TK_CASE || node->type == TK_PAREN_OPEN)
return (1);
}
return (0);
}
int iscase_pattern(t_btree **ast, t_list **lst)
{
t_astnode *node;
t_token *token;
node = NULL;
token = (*lst)->content;
if (*ast)
@ -13,11 +41,23 @@ int iscase(t_btree **ast, t_list **lst)
if ((node->type == TK_CASE || node->type == TK_PAREN_OPEN)
&& token->type == TK_WORD && node->pattern == 0)
return (1);
}
return (0);
}
int iscase_branch(t_btree **ast, t_list **lst)
{
t_astnode *node;
t_token *token;
node = NULL;
token = (*lst)->content;
if (*ast)
{
node = (*ast)->item;
if ((node->type == TK_PAREN_OPEN || node->type == TK_CASE)
&& node->nest == 0 && token->type == TK_PAREN_OPEN)
return (3);
if (node->type == TK_CASE || node->type == TK_PAREN_OPEN)
return (2);
return (1);
}
return (0);
}
@ -43,11 +83,6 @@ int add_case_cmd(t_btree **ast, t_list **lst)
return (add_cmd(&(*ast)->right, lst));
}
int add_case_sep(t_btree **ast, t_list **lst)
{
return (add_sep(&(*ast)->right, lst));
}
int add_pattern(t_btree **ast, t_list **lst)
{
t_astnode *node;

View file

@ -6,50 +6,86 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
/* Updated: 2017/03/04 17:08:04 by ariard ### ########.fr */
/* Updated: 2017/03/04 22:05:47 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
t_distrostree g_distrostree[] =
{
{&superflous_token, &add_null},
{&isdir_sep, &add_redir_type},
{&isdir_word, &add_redir_word},
{&isvar, &add_var},
{&isloop_condition, &add_loop_condition},
{&isloop, &add_loop_cmd},
{&iscondition_branch, &add_branch},
{&iscondition, &add_condition_cmd},
{&iscase_pattern, &add_pattern},
{&iscase_branch, &add_branch},
{&iscase, &add_case_cmd},
{&issubshell, &add_subshell_cmd},
{&isfunc, &add_func_cmd},
{&isnull, &add_null},
};
int superflous_token(t_btree **ast, t_list **lst)
{
t_token *token;
(void)ast;
DG("superflous token");
if (*lst)
{
token = (*lst)->content;
if (token->type == TK_IN || token->type == TK_PAREN_OPEN)
return (1);
}
return (0);
}
static int no_del_token(t_btree **ast, t_list **lst)
{
t_astnode *node;
(void)lst;
node = NULL;
if (*ast)
{
node = (*ast)->item;
if (node->type != TK_DO && node->type != TK_THEN && node->type != TK_PAREN_CLOSE
&& node->type != CMD && node->type != REDIR)
return (1);
}
return (0);
}
int add_cmd(t_btree **ast, t_list **lst)
{
t_token *token;
t_astnode *node;
char **my_tab;
int i;
if ((token = (*lst)->content)->type == TK_IN || token->type == TK_PAREN_OPEN)
return (0);
else if (isdir_sep(ast, lst))
return (add_redir_type(ast, lst));
else if (!*ast)
i = 0;
DG("add cmd");
while (i < 14)
{
DG("test");
if (g_distrostree[i].test(ast, lst) == 1)
{
DG("add : %d", i);
return (g_distrostree[i].add(ast, lst));
}
i++;
}
if (!*ast)
gen_node(ast);
else if (isdir_word(ast, lst))
return (add_redir_word(ast, lst));
else if (isvar(ast, lst))
return (add_var(ast, lst));
else if (isloop(ast, lst) == 3)
return (add_loop_condition(ast, lst));
else if (isloop(ast, lst))
return (add_loop_cmd(ast, lst));
else if (iscondition(ast, lst) == 1)
return (add_condition_cmd(ast, lst));
else if (iscondition(ast, lst) == 2)
return (add_branch(ast, lst));
else if (iscase(ast, lst) == 1)
return (add_pattern(ast, lst));
else if (iscase(ast, lst) == 2)
return (add_case_cmd(ast, lst));
else if (iscase(ast, lst) == 3)
return (add_branch(ast, lst));
else if (issubshell(ast, lst))
return (add_subshell_cmd(ast, lst));
else if (isfunc(ast, lst))
return (add_func_cmd(ast, lst));
else if ((node = (*ast)->item)->type != TK_DO && node->type != TK_THEN
&& node->type != TK_PAREN_CLOSE && node->type != CMD
&& node->type != REDIR)
else if (no_del_token(ast, lst))
return (add_cmd(&(*ast)->right, lst));
token = (*lst)->content;
node = (*ast)->item;
if (token->type != TK_WORD)
node->type = token->type;
@ -57,7 +93,6 @@ int add_cmd(t_btree **ast, t_list **lst)
node->type = CMD;
if (token->type == TK_WORD || token->type == TK_ASSIGNEMENT_WORD)
{
DG("add data");
if ((my_tab = (char **)malloc(sizeof(char *) * 4)))
{
my_tab[0] = ft_strdup(token->data);

View file

@ -0,0 +1,71 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* add_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
/* Updated: 2017/03/04 21:31:18 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 ((token = (*lst)->content)->type == TK_IN || token->type == TK_PAREN_OPEN)
return (0);
else if (isdir_sep(ast, lst))
return (add_redir_type(ast, lst));
else if (!*ast)
gen_node(ast);
else if (isdir_word(ast, lst))
return (add_redir_word(ast, lst));
else if (isvar(ast, lst))
return (add_var(ast, lst));
else if (isloop(ast, lst) == 3)
return (add_loop_condition(ast, lst));
else if (isloop(ast, lst))
return (add_loop_cmd(ast, lst));
else if (iscondition(ast, lst) == 1)
return (add_condition_cmd(ast, lst));
else if (iscondition(ast, lst) == 2)
return (add_branch(ast, lst));
else if (iscase(ast, lst) == 1)
return (add_pattern(ast, lst));
else if (iscase(ast, lst) == 2)
return (add_case_cmd(ast, lst));
else if (iscase(ast, lst) == 3)
return (add_branch(ast, lst));
else if (issubshell(ast, lst))
return (add_subshell_cmd(ast, lst));
else if (isfunc(ast, lst))
return (add_func_cmd(ast, lst));
else if ((node = (*ast)->item)->type != TK_DO && node->type != TK_THEN
&& node->type != TK_PAREN_CLOSE && node->type != CMD
&& node->type != REDIR)
return (add_cmd(&(*ast)->right, lst));
node = (*ast)->item;
if (token->type != TK_WORD)
node->type = token->type;
else
node->type = CMD;
if (token->type == TK_WORD || token->type == TK_ASSIGNEMENT_WORD)
{
DG("add data");
if ((my_tab = (char **)malloc(sizeof(char *) * 4)))
{
my_tab[0] = ft_strdup(token->data);
my_tab[1] = (char *)dup_char_esc(token->esc, token->size >> 3);
my_tab[2] = (char *)dup_char_esc(token->esc2, token->size >> 3);
my_tab[3] = NULL;
}
ft_ld_pushback(&node->data.cmd.token, my_tab);
}
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/19 18:12:52 by ariard #+# #+# */
/* Updated: 2017/03/03 14:27:21 by ariard ### ########.fr */
/* Updated: 2017/03/04 21:51:34 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,6 +17,27 @@ int iscondition(t_btree **ast, t_list **lst)
t_astnode *node;
t_token *token;
node = NULL;
token = (*lst)->content;
DG("iscondition");
if (*ast)
{
node = (*ast)->item;
if ((node->type == TK_IF || node->type == TK_ELIF || node->type == TK_ELSE)
&& node->full == 0)
return (1);
if ((node->type == TK_NEWLINE || node->type == TK_SEMI
|| node->type == TK_AMP) && iscondition(&(*ast)->right, lst))
return (1);
}
return (0);
}
int iscondition_branch(t_btree **ast, t_list **lst)
{
t_astnode *node;
t_token *token;
node = NULL;
token = (*lst)->content;
if (*ast)
@ -25,12 +46,6 @@ int iscondition(t_btree **ast, t_list **lst)
if ((node->type == TK_IF || iscondition(&(*ast)->right, lst))
&& (token->type == TK_ELIF || token->type == TK_ELSE)
&& node->nest == 0)
return (2);
if ((node->type == TK_IF || node->type == TK_ELIF || node->type == TK_ELSE)
&& node->full == 0)
return (1);
if ((node->type == TK_NEWLINE || node->type == TK_SEMI
|| node->type == TK_AMP) && iscondition(&(*ast)->right, lst) == 1)
return (1);
}
return (0);
@ -41,6 +56,7 @@ int add_condition_cmd(t_btree **ast, t_list **lst)
t_token *token;
t_astnode *node;
DG("add condition");
token = (*lst)->content;
node = (*ast)->item;
if (token->type == TK_IF && (node->type == TK_IF || node->type == TK_ELIF

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 22:17:14 by ariard #+# #+# */
/* Updated: 2017/03/03 18:01:55 by ariard ### ########.fr */
/* Updated: 2017/03/04 22:05:26 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,17 +19,13 @@ int isloop(t_btree **ast, t_list **lst)
node = NULL;
token = (*lst)->content;
DG("isloop");
if (*ast)
{
node = (*ast)->item;
if (node->type == TK_FOR && token->type == TK_WORD && node->pattern == 0)
return (3);
if ((node->type == TK_NEWLINE || node->type == TK_SEMI
|| node->type == TK_AMP) && isloop(&(*ast)->right, lst) == 1)
return (1);
if ((node->type == TK_WHILE || node->type == TK_UNTIL
|| node->type == TK_FOR) && node->full == 1)
return (2);
if ((node->type == TK_WHILE || node->type == TK_UNTIL
|| node->type == TK_FOR) && node->full == 0)
return (1);
@ -37,6 +33,23 @@ int isloop(t_btree **ast, t_list **lst)
return (0);
}
int isloop_condition(t_btree **ast, t_list **lst)
{
t_astnode *node;
t_token *token;
node = NULL;
token = (*lst)->content;
if (*ast)
{
node = (*ast)->item;
if (node->type == TK_FOR && token->type == TK_WORD
&& node->pattern == 0)
return (1);
}
return (0);
}
int add_loop_cmd(t_btree **ast, t_list **lst)
{
t_token *token;

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
/* Updated: 2017/03/03 20:02:22 by ariard ### ########.fr */
/* Updated: 2017/03/04 20:00:46 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 19:12:07 by ariard #+# #+# */
/* Updated: 2017/03/03 16:05:24 by ariard ### ########.fr */
/* Updated: 2017/03/04 21:43:00 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,12 +19,12 @@ int add_sep(t_btree **ast, t_list **lst)
t_btree *new_node;
DG("add sep");
if (isloop(ast, lst) == 1)
if (isloop(ast, lst))
return (add_loop_sep(ast, lst));
else if (iscondition(ast, lst) == 1)
else if (iscondition(ast, lst))
return (add_condition_sep(ast, lst));
else if (iscase(ast, lst) == 2)
return (add_case_sep(ast, lst));
else if (iscase(ast, lst))
return (add_sep(&(*ast)->right, lst));
else if (issubshell(ast, lst))
return (add_subshell_sep(ast, lst));
else if (isfunc(ast, lst))

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:32:59 by ariard #+# #+# */
/* Updated: 2017/03/03 15:08:55 by ariard ### ########.fr */
/* Updated: 2017/03/04 20:56:42 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -39,7 +39,10 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
produce_sym(&parser->stack, parser->new_sym, token);
DG("new sym %s", read_state(*parser->new_sym));
if (eval_sym(&parser->stack, *parser->new_sym))
{
DG("ERRROR");
return ((parser->state = ERROR));
}
else
{
aggregate_sym(&parser->stack, parser->new_sym, &parser->state);
@ -52,7 +55,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
else
parser->state = UNDEFINED;
build_tree(ast, token);
btree_print(STDBUG, *ast, &ft_putast);
// btree_print(STDBUG, *ast, &ft_putast);
if ((end_instruction(&parser->stack) && !(*token)->next))
insert_linebreak(token);
else

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:57:44 by ariard #+# #+# */
/* Updated: 2017/03/03 14:28:14 by ariard ### ########.fr */
/* Updated: 2017/03/04 21:20:16 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -34,3 +34,18 @@ int gen_node(t_btree **ast)
}
return (0);
}
int isnull(t_btree **ast, t_list **lst)
{
(void)ast;
(void)lst;
return (-1);
}
int add_null(t_btree **ast, t_list **lst)
{
(void)ast;
(void)lst;
return (-1);
}