news parsing if and case
This commit is contained in:
parent
30645abeb0
commit
1c1c75934a
14 changed files with 47 additions and 111 deletions
|
|
@ -283,7 +283,6 @@ parser/add_loop.c\
|
|||
parser/add_math.c\
|
||||
parser/add_number.c\
|
||||
parser/add_redir.c\
|
||||
parser/add_redir_condition.c\
|
||||
parser/add_sep.c\
|
||||
parser/add_subshell.c\
|
||||
parser/add_var.c\
|
||||
|
|
|
|||
0
42sh/file
Normal file
0
42sh/file
Normal file
16
42sh/file1
Normal file
16
42sh/file1
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
42sh
|
||||
Makefile
|
||||
STDBUG
|
||||
TESTSHELL
|
||||
condition_file
|
||||
donovan_segaults_06-02
|
||||
file
|
||||
file1
|
||||
includes
|
||||
libft
|
||||
objs
|
||||
pdf
|
||||
sample
|
||||
src
|
||||
test_framework.sh
|
||||
update_makefile.sh
|
||||
|
|
@ -110,7 +110,6 @@ int add_condition_sep(t_btree **ast, t_list **lst);
|
|||
int add_branch(t_btree **ast, t_list **lst);
|
||||
int add_redir_word(t_btree **ast, t_list **lst);
|
||||
int add_redir_type(t_btree **ast, t_list **lst);
|
||||
int add_redir_condition(t_btree **ast, t_list **lst);
|
||||
int redir_init(t_type type, t_redir *redir);
|
||||
int add_case_cmd(t_btree **ast, t_list **lst);
|
||||
int add_case_sep(t_btree **ast, t_list **lst);
|
||||
|
|
@ -141,7 +140,6 @@ int isfunc_name(t_btree **ast, t_list **lst);
|
|||
int isdir(t_btree **ast);
|
||||
int iscondition(t_btree **ast, t_list **list);
|
||||
int isdir_sep(t_btree **ast, t_list **list);
|
||||
int isdir_condition(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);
|
||||
|
|
@ -155,8 +153,6 @@ 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);
|
||||
|
||||
int ft_show_heredoc_data(t_astnode *node);
|
||||
|
||||
struct s_distrostree
|
||||
{
|
||||
int (*test)(t_btree **ast, t_list **lst);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/13 17:51:05 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/13 21:36:40 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/10 14:57:45 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/13 19:32:08 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/13 20:36:01 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/04 20:42:13 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/13 17:32:22 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/13 22:38:44 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ int iscase(t_btree **ast, t_list **lst)
|
|||
|| node->type == TK_AMP || node->type == TK_PIPE)
|
||||
&& iscase(&(*ast)->right, lst) == 1)
|
||||
return (1);
|
||||
if (node->type == TK_CASE || node->type == TK_PAREN_OPEN)
|
||||
if (node->type == TK_CASE)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
|
|
@ -91,18 +91,12 @@ int add_pattern(t_btree **ast, t_list **lst)
|
|||
{
|
||||
t_astnode *node;
|
||||
t_token *token;
|
||||
char **my_tab;
|
||||
|
||||
token = (*lst)->content;
|
||||
node = (*ast)->item;
|
||||
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.wordlist, my_tab);
|
||||
DG("node type is %s", read_state(node->type));
|
||||
ft_ld_pushback(&node->data.cmd.wordlist,
|
||||
gen_tab(token->data, token->esc, token->esc2, 1));
|
||||
node->pattern = 1;
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/13 17:37:50 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/13 22:45:29 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,7 +15,6 @@
|
|||
t_distrostree g_distrostree[] =
|
||||
{
|
||||
{&superflous_token, &add_null},
|
||||
{&isdir_condition, &add_redir_condition},
|
||||
{&isdir_sep, &add_redir_type},
|
||||
{&isdir_word, &add_redir_word},
|
||||
{&isvar, &add_var},
|
||||
|
|
@ -24,8 +23,8 @@ t_distrostree g_distrostree[] =
|
|||
{&iscondition_branch, &add_branch},
|
||||
{&iscondition, &add_condition_cmd},
|
||||
{&iscase_pattern, &add_pattern},
|
||||
{&iscase_branch, &add_branch},
|
||||
{&iscase, &add_case_cmd},
|
||||
{&iscase_branch, &add_branch},
|
||||
{&ismath, &add_null},
|
||||
{&ismath_expr, &add_pattern},
|
||||
{&issubshell, &add_subshell_cmd},
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/10 17:06:16 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/13 16:10:30 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/13 20:46:40 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ int iscondition_branch(t_btree **ast, t_list **lst)
|
|||
if (*ast)
|
||||
{
|
||||
node = (*ast)->item;
|
||||
if ((node->type == TK_IF || node->type == TK_ELIF)
|
||||
if ((node->type == TK_ELIF)
|
||||
&& (token->type == TK_ELIF || token->type == TK_ELSE)
|
||||
&& node->nest == 0)
|
||||
return (1);
|
||||
|
|
@ -93,6 +93,6 @@ int add_if(t_btree **ast, t_list **lst)
|
|||
node = (*ast)->item;
|
||||
node->type = TK_IF;
|
||||
token->type = TK_ELIF;
|
||||
add_cmd(ast, lst);
|
||||
add_cmd(&(*ast)->right, lst);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,69 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* add_redir_condition.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/11 14:54:18 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/13 14:08:09 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
static int isdir_sep_condition(t_btree **ast)//, t_list **lst)
|
||||
{
|
||||
// t_token *token;
|
||||
t_astnode *node;
|
||||
|
||||
// token = (*lst)->content;
|
||||
if (*ast)
|
||||
{
|
||||
node = (*ast)->item;
|
||||
if (node->type == TK_IF || node->type == TK_CASE)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int isdir_word_condition(t_btree **ast)//, t_list **lst)
|
||||
{
|
||||
// t_token *token;
|
||||
t_astnode *node;
|
||||
|
||||
// token = (*lst)->content;
|
||||
if (*ast)
|
||||
{
|
||||
node = (*ast)->item;
|
||||
if (node->type == REDIR)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int isdir_condition(t_btree **ast, t_list **lst)
|
||||
{
|
||||
t_token *token;
|
||||
// t_astnode *node;
|
||||
|
||||
token = (*lst)->content;
|
||||
if (*ast)
|
||||
{
|
||||
// node = (*ast)->item;
|
||||
if ((token->type == TK_LESS || token->type == TK_GREAT
|
||||
|| token->type == TK_GREATAND || token->type == TK_LESSAND
|
||||
|| token->type == TK_DLESS || token->type == TK_DGREAT)
|
||||
&& isdir_sep_condition(&(*ast)->left) == 1)
|
||||
return (1);
|
||||
if (token->type == TK_WORD
|
||||
&& isdir_word_condition(&(*ast)->left) == 1)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int add_redir_condition(t_btree **ast, t_list **lst)
|
||||
{
|
||||
return (add_cmd(&(*ast)->left, lst));
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/11 15:58:38 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/13 19:40:56 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/13 20:36:45 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -57,13 +57,14 @@ t_aggrematch g_aggrematch[] =
|
|||
{TK_RBRACE, CMD_SUPERIOR, BRACE_CLAUSE, TK_LBRACE},
|
||||
{TK_RBRACE, PIPE_SEMI_SEQUENCE, BRACE_CLAUSE, TK_LBRACE},
|
||||
{TK_RBRACE, PIPE_CLOSE_SEQUENCE, BRACE_CLAUSE, TK_LBRACE},
|
||||
|
||||
{TK_RBRACE, COMPOUND_LIST, BRACE_CLAUSE, TK_LBRACE},
|
||||
{TK_RBRACE, CMD_SUPERIOR, BRACE_CLAUSE, TK_LBRACE},
|
||||
{TK_AND_IF, CMD_SUPERIOR, AND_OR_MINOR, CMD_SUPERIOR},
|
||||
{TK_OR_IF, CMD_SUPERIOR, AND_OR_MINOR, CMD_SUPERIOR},
|
||||
{TK_AND_IF, PIPE_CLOSE_SEQUENCE, AND_OR_MINOR, PIPE_CLOSE_SEQUENCE},
|
||||
{TK_AND_IF, PIPE_SEMI_SEQUENCE, AND_OR_MINOR, PIPE_SEMI_SEQUENCE},
|
||||
{TK_OR_IF, PIPE_SEMI_SEQUENCE, AND_OR_MINOR, PIPE_SEMI_SEQUENCE},
|
||||
{TK_OR_IF, CMD_SUPERIOR, AND_OR_MINOR, CMD_SUPERIOR},
|
||||
{TK_OR_IF, PIPE_CLOSE_SEQUENCE, AND_OR_MINOR, PIPE_CLOSE_SEQUENCE},
|
||||
{SEPARATOR_OP, MATH_SUP, CMD_SUPERIOR, MATH_SUP},
|
||||
{SEPARATOR_OP, CMD_SUPERIOR, SEPARATOR, 0},
|
||||
{SEPARATOR_OP, COMPOUND_LIST, SEPARATOR, 0},
|
||||
|
|
@ -390,20 +391,20 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state)
|
|||
return (1);
|
||||
i = 0;
|
||||
head = (*stack)->content;
|
||||
DG("aggregate head %s && sym %s",
|
||||
read_state(*head), read_state(*new_sym));
|
||||
// DG("aggregate head %s && sym %s",
|
||||
// read_state(*head), read_state(*new_sym));
|
||||
while (g_aggrematch[i].top)
|
||||
{
|
||||
if (*new_sym == g_aggrematch[i].top
|
||||
&& MATCH_STACK(*head, 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);
|
||||
head = (*stack)->content;
|
||||
DG("stack after pop: %s", read_state(*head));
|
||||
// DG("stack after pop: %s", read_state(*head));
|
||||
}
|
||||
if (eval_sym(stack, *new_sym))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/11 16:11:21 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/13 19:39:30 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/13 20:36:26 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -57,10 +57,12 @@ t_stackmatch g_stackmatch[] =
|
|||
{TK_AND_IF, AND_OR},
|
||||
{TK_AND_IF, CMD_SUPERIOR},
|
||||
{TK_AND_IF, PIPE_SEMI_SEQUENCE},
|
||||
{TK_AND_IF, PIPE_CLOSE_SEQUENCE},
|
||||
{TK_AND_IF, COMPOUND_LIST},
|
||||
{TK_OR_IF, AND_OR},
|
||||
{TK_OR_IF, CMD_SUPERIOR},
|
||||
{TK_OR_IF, PIPE_SEMI_SEQUENCE},
|
||||
{TK_OR_IF, PIPE_CLOSE_SEQUENCE},
|
||||
{TK_OR_IF, COMPOUND_LIST},
|
||||
{TK_DSEMI, LINEBREAK},
|
||||
{TK_DSEMI, TK_BANG},
|
||||
|
|
@ -542,8 +544,6 @@ t_stackmatch g_stackmatch[] =
|
|||
{TK_PAREN_CLOSE, SEPARATOR_OP},
|
||||
{TK_PAREN_CLOSE, WORD},
|
||||
{TK_PAREN_CLOSE, IN},
|
||||
{TK_PAREN_CLOSE, TK_AND_IF},
|
||||
{TK_PAREN_CLOSE, TK_OR_IF},
|
||||
{TK_PAREN_CLOSE, TK_PIPE},
|
||||
{TK_PAREN_CLOSE, COMPLETE_COMMANDS},
|
||||
{TK_PAREN_CLOSE, CMD_SUPERIOR},
|
||||
|
|
@ -564,8 +564,6 @@ t_stackmatch g_stackmatch[] =
|
|||
{TK_RBRACE, SEPARATOR_OP},
|
||||
{TK_RBRACE, WORD},
|
||||
{TK_RBRACE, IN},
|
||||
{TK_RBRACE, TK_AND_IF},
|
||||
{TK_RBRACE, TK_OR_IF},
|
||||
{TK_RBRACE, TK_PIPE},
|
||||
{TK_RBRACE, TK_RBRACE},
|
||||
{TK_RBRACE, COMPLETE_COMMANDS},
|
||||
|
|
@ -1266,7 +1264,7 @@ int eval_sym(t_list **stack, t_sym new_sym)
|
|||
if (!*stack)
|
||||
return (1);
|
||||
head = (*stack)->content;
|
||||
DG("eval head %s && sym %s", read_state(*head), read_state(new_sym));
|
||||
// DG("eval head %s && sym %s", read_state(*head), read_state(new_sym));
|
||||
i = 0;
|
||||
while (g_stackmatch[i].top)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/13 17:30:53 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/13 20:37:27 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -134,8 +134,8 @@ int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst)
|
|||
return (1);
|
||||
token = (*lst)->content;
|
||||
head = (*stack)->content;
|
||||
DG("produce stack : %s && token : %s", read_state(*head),
|
||||
read_state(token->type));
|
||||
// DG("produce stack : %s && token : %s", read_state(*head),
|
||||
// read_state(token->type));
|
||||
i = 0;
|
||||
*new_sym = 0;
|
||||
while (g_prodmatch[i].new_sym)
|
||||
|
|
@ -143,7 +143,7 @@ int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst)
|
|||
if (token->type == g_prodmatch[i].token
|
||||
&& *head == 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++;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 15:32:10 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/13 14:13:05 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/13 19:52:30 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
char *read_state(t_sym current)
|
||||
{
|
||||
if (current == PIPE_CLOSE_SEQUENCE)
|
||||
return ("PIPE_CLOSE_SEQUENCE");
|
||||
if (current == TK_BANG)
|
||||
return ("TK_BANG");
|
||||
if (current == OPEN_FUNC)
|
||||
|
|
|
|||
Loading…
Reference in a new issue