parsing while simple ok
This commit is contained in:
parent
4ef7af6e20
commit
96e439b652
22 changed files with 158 additions and 29 deletions
|
|
@ -199,7 +199,8 @@ parser/build_tree.c\
|
|||
parser/tree_wrapper.c\
|
||||
parser/add_sep.c\
|
||||
parser/add_cmd.c\
|
||||
parser/add_file.c
|
||||
parser/add_file.c\
|
||||
parser/add_loop.c
|
||||
|
||||
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
||||
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
42sh
|
||||
Makefile
|
||||
blind.text
|
||||
debug
|
||||
|
|
@ -5,6 +6,7 @@ file1
|
|||
grammar
|
||||
includes
|
||||
libft
|
||||
objs
|
||||
pdf
|
||||
sample
|
||||
script.sh
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/17 18:49:28 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/17 23:18:23 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -120,6 +120,7 @@ enum e_sym
|
|||
CMD_SUPERIOR,
|
||||
AND_OR_MAJOR,
|
||||
AND_OR_MINOR,
|
||||
END_COMMAND,
|
||||
ALL = 200,
|
||||
};
|
||||
|
||||
|
|
@ -201,6 +202,9 @@ 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);
|
||||
int isloop(t_btree **ast);
|
||||
int isdir(t_btree **ast);
|
||||
|
||||
int join_ast(t_btree **ast, t_btree **new_node);
|
||||
|
|
@ -245,6 +249,7 @@ union u_astdata
|
|||
t_ld *token;
|
||||
char **sstr;
|
||||
char *str;
|
||||
int loop;
|
||||
};
|
||||
|
||||
struct s_astnode
|
||||
|
|
|
|||
1
42sh/sample/dir.sh
Normal file
1
42sh/sample/dir.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
file1 <file1 ls
|
||||
|
|
@ -1 +1,4 @@
|
|||
ls | cat | cat | cat | cat | cat
|
||||
while ls | cat ;
|
||||
do
|
||||
pwd | cat ;
|
||||
done
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/16 16:23:26 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/05 14:16:53 by wescande ### ########.fr */
|
||||
/* Updated: 2017/02/17 23:31:05 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/16 15:59:38 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/05 14:17:40 by wescande ### ########.fr */
|
||||
/* Updated: 2017/02/17 23:33:37 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/06 20:37:16 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/17 23:41:26 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,6 +20,8 @@ char *ft_putast(void *nodein)
|
|||
t_type type;
|
||||
};
|
||||
node = nodein;
|
||||
if (node->type == TK_DO)
|
||||
return ("TK_DO");
|
||||
if (node->type == TK_AMP)
|
||||
return (" & ");
|
||||
else if (node->type == TK_N_WORD)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/22 23:06:34 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/17 17:22:03 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/17 23:27:06 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ int shell_script()
|
|||
token_print(token);
|
||||
if (ft_parse2(&ast, &token))
|
||||
return (1);
|
||||
btree_print(STDBUG, ast, &ft_putast);
|
||||
// btree_print(STDBUG, ast, &ft_putast);
|
||||
// if (ft_exec(&ast))
|
||||
// return (1);
|
||||
ast = NULL;
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/17 17:46:18 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/17 23:40:13 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,18 +18,26 @@ int add_cmd(t_btree **ast, t_list **lst)
|
|||
t_astnode *node;
|
||||
char **my_tab;
|
||||
|
||||
DG("add cmd");
|
||||
if (!*ast)
|
||||
gen_node(ast);
|
||||
else if (isdir(ast))
|
||||
return (add_file(ast, lst));
|
||||
return (add_file(ast, lst));
|
||||
else if (isloop(ast))
|
||||
return (add_loop_cmd(ast, lst));
|
||||
else
|
||||
return (add_cmd(&(*ast)->right, lst));
|
||||
DG("insert data cmd");
|
||||
my_tab = NULL;
|
||||
token = (*lst)->content;
|
||||
node = (*ast)->item;
|
||||
node->type = token->type;
|
||||
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);
|
||||
if (token->type == TK_N_WORD)
|
||||
{
|
||||
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);
|
||||
DG("still alive");
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/17 17:19:35 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/17 23:24:01 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
59
42sh/src/parser/add_loop.c
Normal file
59
42sh/src/parser/add_loop.c
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* add_loop.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/17 22:17:14 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/17 23:38:25 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
int isloop(t_btree **ast)
|
||||
{
|
||||
t_astnode *node;
|
||||
|
||||
node = NULL;
|
||||
if (*ast)
|
||||
{
|
||||
DG("end isloop");
|
||||
node = (*ast)->item;
|
||||
if (node->data.loop == 1)
|
||||
return (2);
|
||||
if (node->type == TK_WHILE)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int add_loop_cmd(t_btree **ast, t_list **lst)
|
||||
{
|
||||
t_token *token;
|
||||
t_astnode *node;
|
||||
|
||||
DG("add loop cmd");
|
||||
token = (*lst)->content;
|
||||
node = (*ast)->item;
|
||||
if (token->type == TK_DONE)
|
||||
return ((node->data.loop = 1));
|
||||
else if (token->type == TK_DO)
|
||||
return (add_cmd(&(*ast)->right, lst));
|
||||
else if (!(*ast)->right && isloop(&(*ast)->left) != 2)
|
||||
return (add_cmd(&(*ast)->left, lst));
|
||||
else
|
||||
return (add_cmd(&(*ast)->right, lst));
|
||||
return (0);
|
||||
}
|
||||
|
||||
int add_loop_sep(t_btree **ast, t_list **lst)
|
||||
{
|
||||
DG("add loop sep");
|
||||
if (!(*ast)->right)
|
||||
return (add_sep(&(*ast)->left, lst));
|
||||
else
|
||||
return (add_sep(&(*ast)->right, lst));
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/15 19:12:07 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/17 17:09:31 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/17 23:34:43 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,6 +18,9 @@ int add_sep(t_btree **ast, t_list **lst)
|
|||
t_astnode *node;
|
||||
t_btree *new_node;
|
||||
|
||||
DG("add sep");
|
||||
if (isloop(&(*ast)->right) == 1 || isloop(ast))
|
||||
return (add_loop_sep(ast, lst));
|
||||
new_node = NULL;
|
||||
gen_node(&new_node);
|
||||
join_ast(ast, &new_node);
|
||||
|
|
@ -25,4 +28,4 @@ int add_sep(t_btree **ast, t_list **lst)
|
|||
node = (new_node)->item;
|
||||
node->type = token->type;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 17:39:18 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/17 19:48:12 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/17 21:35:09 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ t_aggrematch g_aggrematch[] =
|
|||
//watch this
|
||||
{SEPARATOR_OP, CMD_SUPERIOR, SEPARATOR, 0},
|
||||
{SEPARATOR_OP, COMPOUND_LIST, SEPARATOR, 0},
|
||||
{SEPARATOR, CMD_SUPERIOR, SIMPLE_COMMAND, CMD_SUPERIOR},
|
||||
{SEPARATOR, CMD_SUPERIOR, END_COMMAND, CMD_SUPERIOR},
|
||||
{SEPARATOR, COMPOUND_LIST, COMPOUND_LIST, COMPOUND_LIST},
|
||||
{LINEBREAK, SEPARATOR_OP, SEPARATOR, SEPARATOR_OP},
|
||||
{LINEBREAK, TK_SEMI, SEQUENTIAL_SEP, TK_SEMI},
|
||||
|
|
@ -47,7 +47,7 @@ t_aggrematch g_aggrematch[] =
|
|||
{LINEBREAK, COMPLETE_COMMANDS, PROGRAM, LINEBREAK},
|
||||
{LINEBREAK, TK_PIPE, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE},
|
||||
{LINEBREAK, COMPLETE_COMMANDS, PROGRAM, LINEBREAK},
|
||||
{LINEBREAK, CMD_SUPERIOR, SIMPLE_COMMAND, CMD_SUPERIOR},
|
||||
{LINEBREAK, CMD_SUPERIOR, SEPARATOR_OP, 0},
|
||||
{LINEBREAK, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE, PIPE_SEMI_SEQUENCE},
|
||||
{LINEBREAK, COMPOUND_LIST, COMPOUND_LIST, COMPOUND_LIST},
|
||||
{NEWLINE_LIST, CMD_NAME, CMD_SUPERIOR, CMD_NAME},
|
||||
|
|
@ -102,6 +102,8 @@ t_aggrematch g_aggrematch[] =
|
|||
{CMD_NAME, SEPARATOR_OP, CMD_SUPERIOR, 0},
|
||||
{CMD_NAME, NEWLINE_LIST, CMD_SUPERIOR, 0},
|
||||
{CMD_NAME, TK_WHILE, CMD_SUPERIOR, 0},
|
||||
{CMD_NAME, TK_DO, CMD_SUPERIOR, 0},
|
||||
{CMD_NAME, COMPOUND_LIST, CMD_SUPERIOR, 0},
|
||||
{CMD_NAME, TK_PIPE, CMD_SUPERIOR, 0},
|
||||
{CMD_NAME, PIPE_SEMI_SEQUENCE, CMD_SUPERIOR, 0},
|
||||
{CMD_NAME, AND_OR_MAJOR, CMD_SUPERIOR, 0},
|
||||
|
|
@ -130,31 +132,44 @@ t_aggrematch g_aggrematch[] =
|
|||
{TERM, LINEBREAK, COMPOUND_LIST, LINEBREAK},
|
||||
{COMPOUND_LIST, TK_ELSE, ELSE_PART, TK_ELSE},
|
||||
{COMPOUND_LIST, TK_THEN, ELSE_PART, TK_ELIF},
|
||||
{COMPOUND_LIST, COMPOUND_LIST, COMPOUND_LIST, COMPOUND_LIST},
|
||||
{SUBSHELL, ALL, COMPOUND_COMMAND, 0},
|
||||
{COMPOUND_COMMAND, ALL, COMMAND, 0},
|
||||
{AND_OR_MINOR, PIPE_SEMI_SEQUENCE, AND_OR_MAJOR, PIPE_SEMI_SEQUENCE},
|
||||
{AND_OR_MINOR, LINEBREAK, AND_OR_MAJOR, 0},
|
||||
{AND_OR_MINOR, AND_OR_MAJOR, AND_OR_MAJOR, 0},
|
||||
{COMMAND, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE},
|
||||
{COMMAND, COMPOUND_LIST, PIPE_SEMI_SEQUENCE, 0},
|
||||
{COMMAND, TK_WHILE, PIPE_SEMI_SEQUENCE, 0},
|
||||
{COMMAND, TK_DO, PIPE_SEMI_SEQUENCE, 0},
|
||||
{COMMAND, TK_BANG, PIPE_SEMI_SEQUENCE, 0},
|
||||
{COMMAND, SEPARATOR_OP, PIPE_SEMI_SEQUENCE, 0},
|
||||
{COMMAND, NEWLINE_LIST, PIPE_SEMI_SEQUENCE, 0},
|
||||
{COMMAND, LINEBREAK, PIPE_SEMI_SEQUENCE, 0},
|
||||
{COMMAND, AND_OR_MAJOR, PIPE_SEMI_SEQUENCE, 0},
|
||||
{END_COMMAND, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE, PIPE_SEMI_SEQUENCE},
|
||||
{END_COMMAND, TK_WHILE, PIPE_SEQUENCE, 0},
|
||||
{END_COMMAND, LINEBREAK, PIPE_SEQUENCE, 0},
|
||||
{END_COMMAND, TK_DO, PIPE_SEQUENCE, 0},
|
||||
{PIPE_SEQUENCE, TK_WHILE, PIPELINE, 0},
|
||||
{PIPE_SEQUENCE, TK_BANG, PIPELINE, TK_BANG},
|
||||
{PIPE_SEQUENCE, SEPARATOR_OP, PIPELINE, 0},
|
||||
{PIPE_SEQUENCE, NEWLINE_LIST, PIPELINE, 0},
|
||||
{PIPE_SEQUENCE, LINEBREAK, PIPELINE, 0},
|
||||
{PIPE_SEQUENCE, AND_OR_MAJOR, PIPELINE, 0},
|
||||
{PIPE_SEQUENCE, TK_DO, PIPELINE, 0},
|
||||
{PIPE_SEQUENCE, COMPOUND_LIST, PIPELINE, 0},
|
||||
{PIPELINE, TK_WHILE, AND_OR, 0},
|
||||
{PIPELINE, TK_DO, AND_OR, 0},
|
||||
{PIPELINE, COMPOUND_LIST, AND_OR, 0},
|
||||
{PIPELINE, LINEBREAK, AND_OR, 0},
|
||||
// {PIPELINE, LINEBREAK, AND_OR, AND_OR},
|
||||
{PIPELINE, SEPARATOR_OP, AND_OR, 0},
|
||||
{PIPELINE, AND_OR_MAJOR, AND_OR, AND_OR_MAJOR},
|
||||
{AND_OR_MAJOR, AND_OR_MAJOR, AND_OR_MAJOR, AND_OR_MAJOR},
|
||||
{AND_OR, TK_DO, COMPOUND_LIST, 0},
|
||||
{AND_OR, TK_WHILE, COMPOUND_LIST, 0},
|
||||
{AND_OR, COMPOUND_LIST, COMPOUND_LIST, 0},
|
||||
{AND_OR, SEPARATOR_OP, LIST, LIST},
|
||||
{AND_OR, NEWLINE_LIST, LIST, 0},
|
||||
{AND_OR, LINEBREAK, LIST, 0},
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/15 18:32:59 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/17 18:48:56 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/17 23:34:15 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,6 +21,9 @@ t_treematch g_treematch[] =
|
|||
{TK_LESS, &add_sep},
|
||||
{TK_OR_IF, &add_sep},
|
||||
{TK_AND_IF, &add_sep},
|
||||
{TK_WHILE, &add_cmd},
|
||||
{TK_DO, &add_cmd},
|
||||
{TK_DONE, &add_cmd},
|
||||
{0, NULL},
|
||||
};
|
||||
|
||||
|
|
@ -36,8 +39,8 @@ int build_tree(t_btree **ast, t_list **lst)
|
|||
if (g_treematch[i].type == token->type)
|
||||
{
|
||||
|
||||
// DG("func TK : '%s' TK : '%s'",
|
||||
// read_state(g_treematch[i].type) ,read_state(token->type));
|
||||
DG("func TK : '%s' TK : '%s'",
|
||||
read_state(g_treematch[i].type) ,read_state(token->type));
|
||||
return (g_treematch[i].add(ast, lst));
|
||||
}
|
||||
i++;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 16:26:30 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/17 19:43:28 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/17 21:35:11 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -181,6 +181,7 @@ t_stackmatch g_stackmatch[] =
|
|||
{TK_DO, SEQUENTIAL_SEP},
|
||||
{TK_DONE, CMD_SUPERIOR},
|
||||
{TK_DONE, COMPOUND_LIST},
|
||||
{TK_DONE, END_COMMAND},
|
||||
{TK_CASE, LINEBREAK},
|
||||
{TK_CASE, TK_BANG},
|
||||
{TK_CASE, NEWLINE_LIST},
|
||||
|
|
@ -238,6 +239,10 @@ t_stackmatch g_stackmatch[] =
|
|||
{SEQUENTIAL_SEP, NAME},
|
||||
{SEQUENTIAL_SEP, IN},
|
||||
{SEQUENTIAL_SEP, WORDLIST},
|
||||
{END_COMMAND, PIPE_SEMI_SEQUENCE},
|
||||
{END_COMMAND, TK_WHILE},
|
||||
{END_COMMAND, TK_DO},
|
||||
{END_COMMAND, LINEBREAK},
|
||||
{SEPARATOR, CMD_SUPERIOR},
|
||||
{SEPARATOR, TERM},
|
||||
{SEPARATOR, COMPOUND_LIST},
|
||||
|
|
@ -328,9 +333,11 @@ t_stackmatch g_stackmatch[] =
|
|||
{CMD_NAME, AND_OR_MAJOR},
|
||||
{CMD_NAME, TK_WHILE},
|
||||
{CMD_NAME, TK_DO},
|
||||
{CMD_NAME, COMPOUND_LIST},
|
||||
|
||||
{CMD_SUPERIOR, TK_WHILE},
|
||||
{CMD_SUPERIOR, TK_DO},
|
||||
{CMD_SUPERIOR, COMPOUND_LIST},
|
||||
{CMD_SUPERIOR, LINEBREAK,},
|
||||
{CMD_SUPERIOR, TK_BANG},
|
||||
{CMD_SUPERIOR, SEPARATOR_OP},
|
||||
|
|
@ -340,6 +347,8 @@ t_stackmatch g_stackmatch[] =
|
|||
{CMD_SUPERIOR, AND_OR_MAJOR},
|
||||
|
||||
{SIMPLE_COMMAND, TK_WHILE},
|
||||
{SIMPLE_COMMAND, TK_DO},
|
||||
{SIMPLE_COMMAND, COMPOUND_LIST},
|
||||
{SIMPLE_COMMAND, LINEBREAK},
|
||||
{SIMPLE_COMMAND, TK_BANG},
|
||||
{SIMPLE_COMMAND, SEPARATOR_OP},
|
||||
|
|
@ -414,6 +423,7 @@ t_stackmatch g_stackmatch[] =
|
|||
{COMPOUND_LIST, TK_ELIF},
|
||||
{COMPOUND_LIST, TK_ELSE},
|
||||
{COMPOUND_LIST, TK_IF},
|
||||
{COMPOUND_LIST, COMPOUND_LIST},
|
||||
{SUBSHELL, LINEBREAK},
|
||||
{SUBSHELL, TK_BANG},
|
||||
{SUBSHELL, SEPARATOR_OP},
|
||||
|
|
@ -427,6 +437,8 @@ t_stackmatch g_stackmatch[] =
|
|||
{COMPOUND_COMMAND, FUNC},
|
||||
{COMMAND, TK_WHILE},
|
||||
{COMMAND, LINEBREAK},
|
||||
{COMMAND, TK_DO},
|
||||
{COMMAND, COMPOUND_LIST},
|
||||
{COMMAND, TK_BANG},
|
||||
{COMMAND, SEPARATOR_OP},
|
||||
{COMMAND, NEWLINE_LIST},
|
||||
|
|
@ -436,25 +448,33 @@ t_stackmatch g_stackmatch[] =
|
|||
{AND_OR_MINOR, LINEBREAK},
|
||||
{AND_OR_MINOR, AND_OR_MAJOR},
|
||||
{PIPE_SEQUENCE, TK_WHILE},
|
||||
{PIPE_SEQUENCE, TK_DO},
|
||||
{PIPE_SEQUENCE, COMPOUND_LIST},
|
||||
{PIPE_SEQUENCE, LINEBREAK},
|
||||
{PIPE_SEQUENCE, TK_BANG},
|
||||
{PIPE_SEQUENCE, SEPARATOR_OP},
|
||||
{PIPE_SEQUENCE, NEWLINE_LIST},
|
||||
{PIPE_SEQUENCE, AND_OR_MAJOR},
|
||||
{PIPE_SEMI_SEQUENCE, TK_WHILE},
|
||||
{PIPE_SEMI_SEQUENCE, TK_DO},
|
||||
{PIPE_SEMI_SEQUENCE, COMPOUND_LIST},
|
||||
{PIPE_SEMI_SEQUENCE, LINEBREAK},
|
||||
{PIPE_SEMI_SEQUENCE, TK_BANG},
|
||||
{PIPE_SEMI_SEQUENCE, SEPARATOR_OP},
|
||||
{PIPE_SEMI_SEQUENCE, NEWLINE_LIST},
|
||||
{PIPE_SEMI_SEQUENCE, AND_OR_MAJOR},
|
||||
{PIPELINE, TK_WHILE},
|
||||
{PIPELINE, TK_DO},
|
||||
{PIPELINE, COMPOUND_LIST},
|
||||
{PIPELINE, LINEBREAK},
|
||||
{PIPELINE, SEPARATOR_OP},
|
||||
{PIPELINE, NEWLINE_LIST},
|
||||
{PIPELINE, AND_OR_MAJOR},
|
||||
{AND_OR_MAJOR, LINEBREAK},
|
||||
{AND_OR_MAJOR, AND_OR_MAJOR},
|
||||
{AND_OR, TK_DO},
|
||||
{AND_OR, TK_WHILE},
|
||||
{AND_OR, COMPOUND_LIST},
|
||||
{AND_OR, LINEBREAK},
|
||||
{AND_OR, SEPARATOR_OP},
|
||||
{AND_OR, NEWLINE_LIST},
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 14:30:22 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/17 19:48:01 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/17 23:39:18 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -57,6 +57,7 @@ int ft_parse2(t_btree **ast, t_list **token)
|
|||
if (state == SUCCESS)
|
||||
ft_putstr("success");
|
||||
build_tree(ast, token);
|
||||
btree_print(STDBUG, *ast, &ft_putast);
|
||||
if (end_instruction(*stack) && !(*token)->next)
|
||||
insert_linebreak(token);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/17 19:48:06 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/17 21:29:20 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -31,6 +31,7 @@ t_prodmatch g_prodmatch[] =
|
|||
{TK_N_WORD, AND_OR_MAJOR, CMD_NAME},
|
||||
{TK_N_WORD, TK_WHILE, CMD_NAME},
|
||||
{TK_N_WORD, TK_DO, CMD_NAME},
|
||||
{TK_N_WORD, COMPOUND_LIST, CMD_NAME},
|
||||
|
||||
{TK_N_WORD, NEWLINE_LIST, CMD_NAME},
|
||||
{TK_N_WORD, TK_BANG, CMD_NAME},
|
||||
|
|
@ -58,11 +59,9 @@ t_prodmatch g_prodmatch[] =
|
|||
{TK_SEMI, CMD_SUPERIOR, SEPARATOR_OP},
|
||||
{TK_SEMI, TERM, SEPARATOR_OP},
|
||||
{TK_SEMI, LIST, SEPARATOR_OP},
|
||||
{TK_SEMI, COMPOUND_LIST, SEPARATOR_OP},
|
||||
{TK_AMP, CMD_SUPERIOR, SEPARATOR_OP},
|
||||
{TK_AMP, TERM, SEPARATOR_OP},
|
||||
{TK_AMP, LIST, SEPARATOR_OP},
|
||||
{TK_AMP, COMPOUND_LIST, SEPARATOR_OP},
|
||||
|
||||
{0, 0, 0},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 15:32:10 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/17 19:40:45 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/17 23:40:50 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,6 +14,12 @@
|
|||
|
||||
char *read_state(t_sym current)
|
||||
{
|
||||
if (current == TK_DONE)
|
||||
return ("DONE");
|
||||
if (current == TK_DO)
|
||||
return ("TK_DO");
|
||||
if (current == END_COMMAND)
|
||||
return ("END_COMMAND");
|
||||
if (current == SEQUENTIAL_SEP)
|
||||
return ("SEQUENTIAL_SEP");
|
||||
if (current == SEPARATOR)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/15 18:57:44 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/17 17:19:41 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/17 23:38:47 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -28,6 +28,7 @@ int gen_node(t_btree **ast)
|
|||
*ast = btree_create_node(&item, sizeof(item));
|
||||
((t_astnode *)(*ast)->item)->data.token = NULL;
|
||||
((t_astnode *)(*ast)->item)->data.redir.word.word = NULL;
|
||||
((t_astnode *)(*ast)->item)->data.loop = 0;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue