modifs gestion d'erreur

This commit is contained in:
ariard@student.42.fr 2017-02-19 16:55:06 +01:00
parent 6609e3b8d9
commit fbce14ef34
18 changed files with 89 additions and 31 deletions

0
42sh/eewfew Normal file
View file

Binary file not shown.

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
/* Updated: 2017/02/18 20:06:02 by ariard ### ########.fr */
/* Updated: 2017/02/19 16:29:14 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -163,6 +163,16 @@ typedef struct s_stackmatch t_stackmatch;
extern t_stackmatch g_stackmatch[];
struct s_errormatch
{
t_type token;
char *error;
};
typedef struct s_errormatch t_errormatch;
extern t_errormatch g_errormatch[];
int ft_parse2(t_btree **ast, t_list **token);
int ft_parse(t_btree **ast, t_list **token);

1
42sh/sample/error.sh Normal file
View file

@ -0,0 +1 @@
ls ; pwd | |

View file

@ -4,5 +4,8 @@ do
do
pwd
done
pwd ; ls
while ls
do
pwd
done
done

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/22 23:06:34 by ariard #+# #+# */
/* Updated: 2017/02/17 23:27:06 by ariard ### ########.fr */
/* Updated: 2017/02/19 16:02:17 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

Binary file not shown.

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
/* Updated: 2017/02/18 18:56:15 by ariard ### ########.fr */
/* Updated: 2017/02/18 20:12:23 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/18 20:10:08 by ariard ### ########.fr */
/* Updated: 2017/02/18 20:12:26 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/18 20:06:47 by ariard ### ########.fr */
/* Updated: 2017/02/19 16:48:44 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,6 +21,8 @@ int add_sep(t_btree **ast, t_list **lst)
DG("add sep");
if (isloop(ast) == 1)
return (add_loop_sep(ast, lst));
if (!*ast)
gen_node(ast);
node = (*ast)->item;
token = (*lst)->content;
// if (node->type != TK_DO)

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:39:18 by ariard #+# #+# */
/* Updated: 2017/02/18 16:58:05 by ariard ### ########.fr */
/* Updated: 2017/02/19 16:48:12 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -179,7 +179,6 @@ t_aggrematch g_aggrematch[] =
{COMPLETE_COMMAND, NEWLINE_LIST, COMPLETE_COMMANDS, COMPLETE_COMMANDS},
{COMPLETE_COMMAND, LINEBREAK, COMPLETE_COMMANDS, 0},
{COMPLETE_COMMANDS, LINEBREAK, PROGRAM, LINEBREAK},
// voir decoupe separateur au lexer
{0, 0, 0, 0},
};
@ -188,8 +187,8 @@ 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
@ -201,7 +200,7 @@ int aggregate_sym(t_sym **stack, t_sym *new_sym, t_parstate *state)
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/02/18 18:43:50 by ariard ### ########.fr */
/* Updated: 2017/02/19 16:35:25 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,28 +6,67 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 20:15:35 by ariard #+# #+# */
/* Updated: 2017/02/13 22:09:03 by ariard ### ########.fr */
/* Updated: 2017/02/19 16:35:56 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int error_syntax(t_list **lst)
t_errormatch g_errormatch[] =
{
{TK_NEWLINE, "newline"},
{TK_SEMI, ";"},
{TK_PIPE, "|"},
{TK_AMP, "&"},
{TK_LESS, "<"},
{TK_GREAT, ">"},
{TK_DGREAT, ">>"},
{TK_LESSAND, "<&"},
{TK_GREATAND, ">&"},
{TK_LESSGREAT, "<>"},
{TK_CLOBBER, ">|"},
{TK_DLESS, "<<"},
{TK_DLESSDASH, "<<-"},
{TK_AND_IF, "&&"},
{TK_OR_IF, "||"},
{TK_DSEMI, ";;"},
{TK_IF, "if"},
{TK_THEN, "then"},
{TK_ELSE, "else"},
{TK_ELIF, "elif"},
{TK_FI, "fi"},
{TK_DO, "do"},
{TK_DONE, "done"},
{TK_CASE, "case"},
{TK_ESAC, "esac"},
{TK_WHILE, "while"},
{TK_UNTIL, "until"},
{TK_FOR, "for"},
{TK_LBRACE, "{"},
{TK_RBRACE, "}"},
{TK_BANG, "!"},
{TK_IN, "in"},
{0, NULL},
};
int error_syntax(t_list **lst)
{
t_token *token;
int i;
token = (*lst)->content;
if (token->type == TK_SEMI)
ft_putstr_fd("syntax error near unexepected token ';'", 2);
else if (token->type == TK_WORD)
ft_putstr_fd("syntax error near unexepected token 'word'", 2);
else if (token->type == TK_GREAT)
ft_putstr_fd("syntax error near unexepected token '>'", 2);
else if (token->type == TK_NEWLINE)
ft_putstr_fd("syntax error near unexepected token 'newline'", 2);
else if (token->type == TK_LESS)
ft_putstr_fd("syntax error near unexepected token '<'", 2);
else
ft_putstr_fd("grammar error, notify ariard", 2);
i = 0;
while (g_errormatch[i].token)
{
if (g_errormatch[i].token == token->type)
{
ft_putstr_fd("syntax error near unexpetcted token `", 2);
ft_putstr_fd(g_errormatch[i].error, 2);
ft_putstr_fd("'", 2);
return (1);
}
i++;
}
ft_putstr_fd("grammar error, notify ariard", 2);
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 16:26:30 by ariard #+# #+# */
/* Updated: 2017/02/18 18:50:18 by ariard ### ########.fr */
/* Updated: 2017/02/19 16:53:14 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -196,6 +196,7 @@ t_stackmatch g_stackmatch[] =
{TK_WHILE, NEWLINE_LIST},
{TK_WHILE, PIPE_SEMI_SEQUENCE},
{TK_WHILE, TK_DO},
{TK_WHILE, COMPOUND_LIST},
{TK_UNTIL, LINEBREAK},
{TK_UNTIL, TK_BANG},
{TK_UNTIL, SEPARATOR_OP},
@ -265,6 +266,7 @@ t_stackmatch g_stackmatch[] =
{LINEBREAK, CMD_SUPERIOR},
{LINEBREAK, PIPE_SEMI_SEQUENCE},
{LINEBREAK, COMPOUND_LIST},
{LINEBREAK, PROGRAM},
{NEWLINE_LIST, TK_DO},
{NEWLINE_LIST, CMD_NAME},
{NEWLINE_LIST, NEWLINE_LIST},
@ -390,6 +392,7 @@ t_stackmatch g_stackmatch[] =
{WHILE_CLAUSE, NEWLINE_LIST},
{WHILE_CLAUSE, PIPE_SEMI_SEQUENCE},
{WHILE_CLAUSE, TK_DO},
{WHILE_CLAUSE, COMPOUND_LIST},
{ELSE_PART, COMPOUND_LIST},
{IF_CLAUSE, LINEBREAK},
{IF_CLAUSE, TK_BANG},
@ -439,6 +442,7 @@ t_stackmatch g_stackmatch[] =
{COMPOUND_COMMAND, PIPE_SEMI_SEQUENCE},
{COMPOUND_COMMAND, FUNC},
{COMPOUND_COMMAND, TK_DO},
{COMPOUND_COMMAND, COMPOUND_LIST},
{COMMAND, TK_WHILE},
{COMMAND, LINEBREAK},
{COMMAND, TK_DO},

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 14:30:22 by ariard #+# #+# */
/* Updated: 2017/02/18 18:06:45 by ariard ### ########.fr */
/* Updated: 2017/02/19 16:54:31 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -58,7 +58,7 @@ int ft_parse2(t_btree **ast, t_list **token)
ft_putstr("success");
build_tree(ast, token);
btree_print(STDBUG, *ast, &ft_putast);
if (end_instruction(*stack) && !(*token)->next)
if ((end_instruction(*stack) && !(*token)->next) || *stack == PROGRAM)
insert_linebreak(token);
else
ft_lst_delif(token, (*token)->content, &ft_addrcmp, &token_free);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:57:44 by ariard #+# #+# */
/* Updated: 2017/02/18 20:06:49 by ariard ### ########.fr */
/* Updated: 2017/02/19 16:34:17 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -25,7 +25,6 @@ int gen_node(t_btree **ast)
if (!*ast)
{
DG("node create");
*ast = btree_create_node(&item, sizeof(item));
((t_astnode *)(*ast)->item)->data.token = NULL;
((t_astnode *)(*ast)->item)->data.redir.word.word = NULL;

1
42sh/wefwe Normal file
View file

@ -0,0 +1 @@
/Users/ariard/Projects/42sh

0
42sh/wfewef Normal file
View file