pipe fix grammar + assignement word parsing

This commit is contained in:
Antoine Riard 2017-03-03 17:19:39 +01:00
parent b90a17f2fa
commit d0b821c483
12 changed files with 74 additions and 19 deletions

View file

@ -6,7 +6,7 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
# Updated: 2017/03/03 14:36:32 by ariard ### ########.fr #
# Updated: 2017/03/03 16:05:17 by ariard ### ########.fr #
# #
# **************************************************************************** #
@ -237,6 +237,7 @@ parser/add_loop.c\
parser/add_redir.c\
parser/add_sep.c\
parser/add_subshell.c\
parser/add_var.c\
parser/aggregate_sym.c\
parser/build_tree.c\
parser/error_syntax.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
/* Updated: 2017/03/03 14:16:02 by ariard ### ########.fr */
/* Updated: 2017/03/03 16:07:33 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -125,17 +125,21 @@ int add_func_cmd(t_btree **ast, t_list **lst);
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 isloop(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);
int isfunc(t_btree **ast, t_list **lst);
int join_ast(t_btree **ast, t_btree **new_node);
int gen_node(t_btree **ast);
int isdir(t_btree **ast);
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 join_ast(t_btree **ast, t_btree **new_node);
int gen_node(t_btree **ast);
/*
* Build AST

1
42sh/src/addls Normal file
View file

@ -0,0 +1 @@

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */
/* Updated: 2017/03/03 14:34:25 by ariard ### ########.fr */
/* Updated: 2017/03/03 14:56: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/03/03 14:33:19 by ariard ### ########.fr */
/* Updated: 2017/03/03 15:34:38 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,6 +26,8 @@ int add_cmd(t_btree **ast, t_list **lst)
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))

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 14:27:40 by ariard ### ########.fr */
/* Updated: 2017/03/03 16:05:24 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

45
42sh/src/parser/add_var.c Normal file
View file

@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* add_var.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/03 15:08:16 by ariard #+# #+# */
/* Updated: 2017/03/03 16:17:27 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int isvar(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_ASSIGNEMENT_WORD && token->type == TK_ASSIGNEMENT_WORD)
return (1);
}
return (0);
}
int add_var(t_btree **ast, t_list **lst)
{
t_astnode *node;
t_btree *new_node;
if (!*ast)
return (0);
new_node = NULL;
gen_node(&new_node);
join_ast(ast, &new_node);
node = (new_node)->item;
node->type = TK_SEMI;
add_cmd(&new_node, lst);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:39:18 by ariard #+# #+# */
/* Updated: 2017/03/03 14:27:46 by ariard ### ########.fr */
/* Updated: 2017/03/03 16:35:04 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -25,6 +25,7 @@ t_aggrematch g_aggrematch[] =
{TK_PAREN_OPEN, CMD_SUPERIOR, FUNC_NAME, CMD_SUPERIOR},
{TK_ASSIGNEMENT_WORD, CMD_PREFIX,CMD_PREFIX, 0},
{TK_PIPE, CMD_SUPERIOR, SIMPLE_COMMAND, CMD_SUPERIOR},
{TK_PIPE, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE},
{TK_FI, ELSE_PART, IF_CLAUSE, TK_IF},
{TK_FI, COMPOUND_LIST, IF_CLAUSE, COMPLETE_CONDITION},
{TK_FI, COMPLETE_CONDITION, IF_CLAUSE, COMPLETE_CONDITION},
@ -306,20 +307,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));

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 14:35:40 by ariard ### ########.fr */
/* Updated: 2017/03/03 15:08:55 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -393,6 +393,7 @@ t_stackmatch g_stackmatch[] =
{TK_AMP, TERM},
{TK_PIPE, PATTERN},
{TK_PIPE, CMD_SUPERIOR},
{TK_PIPE, PIPE_SEMI_SEQUENCE},
{PATTERN_CASE, TK_IN},
{PATTERN_CASE, CASE_LIST_NS},
{TK_PAREN_OPEN, COMPLETE_COMMANDS},
@ -1009,7 +1010,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)
{

View file

@ -32,7 +32,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
while (*token)
{
produce_sym(*parser->stack, parser->new_sym, token);
//DG("new sym %s", read_state(*parser->new_sym));
DG("new sym %s", read_state(*parser->new_sym));
if (eval_sym(*parser->stack, *parser->new_sym))
return ((parser->state = ERROR));

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
/* Updated: 2017/03/03 14:28:05 by ariard ### ########.fr */
/* Updated: 2017/03/03 16:22:31 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -105,8 +105,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)
@ -114,7 +114,7 @@ int produce_sym(t_sym stack, t_sym *new_sym, t_list **lst)
if (token->type == g_prodmatch[i].token
&& stack == g_prodmatch[i].stack)
{
// DG("MATCH : %s", read_state(g_prodmatch[i].new_sym));
DG("MATCH : %s", read_state(g_prodmatch[i].new_sym));
*new_sym = g_prodmatch[i].new_sym;
}
i++;