commit from un cluster qui marche aka new redir

This commit is contained in:
ariard@student.42.fr 2017-02-25 19:31:02 +01:00
parent 7b1d505a5b
commit eeb0887081
14 changed files with 173 additions and 135 deletions

View file

@ -26,114 +26,6 @@ enum e_parstate
SUCCESS,
};
enum e_sym
{
LINEBREAK = 1,
TK_COMMAND,
TK_LESS,
TK_GREAT,
TK_DLESS,
TK_DGREAT,
TK_LESSAND,
TK_GREATAND,
TK_SEMI,
TK_PIPE,
TK_AND_IF,
TK_OR_IF,
TK_AMP,
TK_PAREN_OPEN,
TK_PAREN_CLOSE,
TK_BQUOTE,
TK_NEWLINE,
TK_WHILE,
TK_DO,
TK_DONE,
TK_IF,
TK_THEN,
TK_FI,
TK_ELIF,
TK_ELSE,
TK_UNTIL,
TK_WORD,
TK_ASSIGNEMENT_WORD = 50,
TK_BANG,
TK_NAME,
TK_FOR,
TK_IO_NUMBER,
TK_DLESSDASH,
TK_LESSGREAT,
TK_SUBSHELL,
TK_CASE,
TK_IN,
TK_ESAC,
TK_CLOBBER,
TK_LBRACE,
TK_RBRACE,
TK_DSEMI,
PROGRAM = 100,
COMPLETE_COMMAND,
COMPLETE_COMMANDS,
LIST,
AND_OR,
PIPELINE,
PIPE_SEQUENCE,
COMMAND,
COMPOUND_COMMAND,
SUBSHELL,
COMPOUND_LIST,
TERM,
FOR_CLAUSE,
NAME,
IN,
WORDLIST,
CASE_CLAUSE,
CASE_LIST,
CASE_LIST_NS,
CASE_ITEM,
CASE_ITEM_NS,
PATTERN,
IF_CLAUSE,
BRACE_CLAUSE,
ELSE_PART,
WHILE_CLAUSE,
UNTIL_CLAUSE,
FUNCTION_DEFINITION,
FUNCTION_BODY,
FNAME,
BRACE_GROUP,
DO_GROUP,
SIMPLE_COMMAND,
CMD_NAME,
CMD_WORD,
CMD_PREFIX,
CMD_SUFFIX,
REDIRECT_LIST,
IO_REDIRECT,
IO_FILE,
FILENAME,
IO_HERE,
HERE_END,
NEWLINE_LIST,
SEPARATOR_OP,
SEPARATOR,
SEQUENTIAL_SEP,
BRACE,
LOOP,
FUNC,
PIPE_SEMI_SEQUENCE,
CMD_SUPERIOR,
AND_OR_MAJOR,
AND_OR_MINOR,
END_COMMAND,
CONDITION,
COMPLETE_CONDITION,
FOR_WORDLIST,
PATTERN_CASE,
FUNC_NAME,
CLOSE_LIST,
ALL = 200,
};
# define TK_REDIR(x) (TK_LESS <= x && x <= TK_GREATAND)
# define MATCH_STACK(x, y) (x == y || y == ALL)
@ -215,6 +107,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_redir(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 add_loop_condition(t_btree **ast, t_list **lst);
@ -229,7 +122,7 @@ int add_subshell_sep(t_btree **ast, t_list **lst);
int add_func_cmd(t_btree **ast, t_list **lst);
int add_func_sep(t_btree **ast, t_list **lst);
int isloop(t_btree **ast, t_list **lst);
int isdir(t_btree **ast);
int isdir(t_btree **ast, t_list **lst);
int iscase(t_btree **ast, t_list **lst);
int iscondition(t_btree **ast, t_list **lst);
int issubshell(t_btree **ast, t_list **lst);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
/* Updated: 2017/02/21 16:15:41 by ariard ### ########.fr */
/* Updated: 2017/02/25 18:47:20 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -51,4 +51,112 @@ typedef struct s_treematch t_treematch;
t_data *data_singleton();
enum e_sym
{
LINEBREAK = 1,
TK_COMMAND,
TK_LESS,
TK_GREAT,
TK_DLESS,
TK_DGREAT,
TK_LESSAND,
TK_GREATAND,
TK_SEMI,
TK_PIPE,
TK_AND_IF,
TK_OR_IF,
TK_AMP,
TK_PAREN_OPEN,
TK_PAREN_CLOSE,
TK_BQUOTE,
TK_NEWLINE,
TK_WHILE,
TK_DO,
TK_DONE,
TK_IF,
TK_THEN,
TK_FI,
TK_ELIF,
TK_ELSE,
TK_UNTIL,
TK_WORD,
TK_ASSIGNEMENT_WORD = 50,
TK_BANG,
TK_NAME,
TK_FOR,
TK_IO_NUMBER,
TK_DLESSDASH,
TK_LESSGREAT,
TK_SUBSHELL,
TK_CASE,
TK_IN,
TK_ESAC,
TK_CLOBBER,
TK_LBRACE,
TK_RBRACE,
TK_DSEMI,
PROGRAM = 100,
COMPLETE_COMMAND,
COMPLETE_COMMANDS,
LIST,
AND_OR,
PIPELINE,
PIPE_SEQUENCE,
COMMAND,
COMPOUND_COMMAND,
SUBSHELL,
COMPOUND_LIST,
TERM,
FOR_CLAUSE,
NAME,
IN,
WORDLIST,
CASE_CLAUSE,
CASE_LIST,
CASE_LIST_NS,
CASE_ITEM,
CASE_ITEM_NS,
PATTERN,
IF_CLAUSE,
BRACE_CLAUSE,
ELSE_PART,
WHILE_CLAUSE,
UNTIL_CLAUSE,
FUNCTION_DEFINITION,
FUNCTION_BODY,
FNAME,
BRACE_GROUP,
DO_GROUP,
SIMPLE_COMMAND,
CMD_NAME,
CMD_WORD,
CMD_PREFIX,
CMD_SUFFIX,
REDIRECT_LIST,
IO_REDIRECT,
IO_FILE,
FILENAME,
IO_HERE,
HERE_END,
NEWLINE_LIST,
SEPARATOR_OP,
SEPARATOR,
SEQUENTIAL_SEP,
BRACE,
LOOP,
FUNC,
PIPE_SEMI_SEQUENCE,
CMD_SUPERIOR,
AND_OR_MAJOR,
AND_OR_MINOR,
END_COMMAND,
CONDITION,
COMPLETE_CONDITION,
FOR_WORDLIST,
PATTERN_CASE,
FUNC_NAME,
CLOSE_LIST,
ALL = 200,
};
#endif

View file

@ -0,0 +1 @@
ls >> 1 >> 2 >> 3 < 4 < 5 ; pwd > 1 > 2

View file

@ -1 +1,2 @@
(ls | cat && pwd)
(ls | cat
pwd ; ls)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/02/25 00:00:16 by ariard ### ########.fr */
/* Updated: 2017/02/25 18:25:11 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
/* Updated: 2017/02/25 00:11:05 by ariard ### ########.fr */
/* Updated: 2017/02/25 18:50:30 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,7 +23,7 @@ int add_cmd(t_btree **ast, t_list **lst)
return (0);
else if (!*ast)
gen_node(ast);
else if (isdir(ast))
else if (isdir(ast, lst))
return (add_file(ast, lst));
else if (isloop(ast, lst) == 3)
return (add_loop_condition(ast, lst));

View file

@ -6,24 +6,35 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
/* Updated: 2017/02/18 16:43:28 by ariard ### ########.fr */
/* Updated: 2017/02/25 19:29:53 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int isdir(t_btree **ast)
int isdir(t_btree **ast, t_list **list)
{
t_astnode *node;
t_token *token;
node = (*ast)->item;
if (node->data.redir.word.word)
return (0);
if (node->type == TK_LESS || node->type == TK_GREAT
|| node->type == TK_LESSAND || node->type == TK_GREATAND
|| node->type == TK_DGREAT || node->type == TK_LESSGREAT
|| node->type == TK_CLOBBER)
return (1);
token = (*list)->content;
if (ast)
{
DG("isdir");
node = (*ast)->item;
if ((node->type == TK_LESS || node->type == TK_GREAT
|| node->type == TK_LESSAND || node->type == TK_GREATAND
|| node->type == TK_DGREAT)
&& token->type == TK_WORD)
return (1);
if ((node->type == TK_LESS || node->type == TK_GREAT
|| node->type == TK_LESSAND || node->type == TK_GREATAND
|| node->type == TK_DGREAT)
&& (token->type == TK_LESS || token->type == TK_GREAT
|| token->type == TK_LESSAND || token->type == TK_GREATAND
|| token->type == TK_DGREAT))
return (2);
}
return (0);
}
@ -31,10 +42,30 @@ int add_file(t_btree **ast, t_list **lst)
{
t_astnode *node;
t_token *token;
t_redir *redir;
token = (*lst)->content;
node = (*ast)->item;
node->data.redir.n = ft_atoi(token->data);
node->data.redir.word.word = ft_strdup(token->data);
if (node->data.wordlist)
{
DG("add file");
redir = (ft_lstlast(node->data.wordlist))->content;
redir->word.word = token->data;
}
return (0);
}
int add_redir(t_btree **ast, t_list **lst)
{
t_astnode *node;
t_token *token;
t_redir *redir;
DG("add_redir");
token = (*lst)->content;
node = (*ast)->item;
redir = ft_memalloc(sizeof(redir));
redir->type = token->type;
ft_lsteadd(&node->data.wordlist, ft_lstnew(redir, sizeof(redir)));
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 23:43:07 by ariard #+# #+# */
/* Updated: 2017/02/25 00:28:35 by ariard ### ########.fr */
/* Updated: 2017/02/25 00:32:00 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 22:17:14 by ariard #+# #+# */
/* Updated: 2017/02/24 18:47:29 by ariard ### ########.fr */
/* Updated: 2017/02/25 19:18:01 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/02/25 00:13:07 by ariard ### ########.fr */
/* Updated: 2017/02/25 19:28:47 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,6 +27,8 @@ int add_sep(t_btree **ast, t_list **lst)
return (add_case_sep(ast, lst));
else if (issubshell(ast, lst))
return (add_subshell_sep(ast, lst));
else if (isdir(ast, lst) == 2)
return (add_redir(ast, lst));
else if (isfunc(ast, lst))
return (add_func_sep(ast, lst));
if (!*ast)

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:39:18 by ariard #+# #+# */
/* Updated: 2017/02/24 23:16:29 by ariard ### ########.fr */
/* Updated: 2017/02/25 13:53:57 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:32:59 by ariard #+# #+# */
/* Updated: 2017/02/24 23:58:10 by ariard ### ########.fr */
/* Updated: 2017/02/25 19:21:05 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,6 +19,8 @@ t_treematch g_treematch[] =
{TK_SEMI, &add_sep},
{TK_GREAT, &add_sep},
{TK_LESS, &add_sep},
{TK_DGREAT, &add_sep},
{TK_DLESS, &add_sep},
{TK_OR_IF, &add_sep},
{TK_AND_IF, &add_sep},
{TK_WHILE, &add_cmd},

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
/* Updated: 2017/02/24 23:10:35 by ariard ### ########.fr */
/* Updated: 2017/02/25 13:54:08 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:57:44 by ariard #+# #+# */
/* Updated: 2017/02/24 16:00:40 by ariard ### ########.fr */
/* Updated: 2017/02/25 19:10:34 by ariard ### ########.fr */
/* */
/* ************************************************************************** */