builtin, lexer et parser .h a la nomre
This commit is contained in:
parent
b4fc0b6bff
commit
e83a22b16b
9 changed files with 39 additions and 29 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/14 22:59:57 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/20 23:22:19 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/22 17:28:02 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
# define BT_ENV_LI (1 << 0)
|
||||
# define BT_ENV_LU (1 << 1)
|
||||
|
||||
struct s_env_data
|
||||
struct s_env_data
|
||||
{
|
||||
t_flag flag;
|
||||
char **av_data;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/20 16:44:48 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/22 17:25:58 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
# include "libft.h"
|
||||
# include "types.h"
|
||||
|
||||
enum e_lexstate
|
||||
enum e_lexstate
|
||||
{
|
||||
DEFAULT,
|
||||
PAREN,
|
||||
|
|
@ -37,7 +37,7 @@ enum e_lexstate
|
|||
END,
|
||||
};
|
||||
|
||||
struct s_token
|
||||
struct s_token
|
||||
{
|
||||
t_type type;
|
||||
char *data;
|
||||
|
|
@ -46,7 +46,7 @@ struct s_token
|
|||
int size;
|
||||
};
|
||||
|
||||
struct s_lexer
|
||||
struct s_lexer
|
||||
{
|
||||
char *str;
|
||||
int pos;
|
||||
|
|
@ -55,7 +55,7 @@ struct s_lexer
|
|||
t_list *heredoc_stack;
|
||||
};
|
||||
|
||||
struct s_rvwords
|
||||
struct s_rvwords
|
||||
{
|
||||
char *word;
|
||||
int type;
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/21 18:09:39 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/22 17:26:34 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MINISHELL_H
|
||||
# define MINISHELL_H
|
||||
|
||||
# define SHELL_NAME "minishell"
|
||||
|
||||
# include <dirent.h>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parser.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/03 18:18:14 by ariard ### ########.fr */
|
||||
/* Created: 2017/03/22 17:22:51 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/22 17:25:11 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -35,10 +36,10 @@ struct s_parser
|
|||
|
||||
struct s_aggrematch
|
||||
{
|
||||
t_sym top;
|
||||
t_sym under;
|
||||
t_sym new_sym;
|
||||
int erase_sym;
|
||||
t_sym top;
|
||||
t_sym under;
|
||||
t_sym new_sym;
|
||||
int erase_sym;
|
||||
};
|
||||
|
||||
struct s_prodmatch
|
||||
|
|
@ -64,7 +65,7 @@ int do_parser_routine(t_list **token, t_btree **ast);
|
|||
void parser_init(t_parser *parser);
|
||||
void parser_destroy(t_parser *parser);
|
||||
int stack_init(t_parser *parser);
|
||||
int redir_init(t_type type, t_redir *redir);
|
||||
int redir_init(t_type type, t_redir *redir);
|
||||
int ft_parse(t_btree **ast, t_list **token, t_parser *parser);
|
||||
|
||||
int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst);
|
||||
|
|
@ -82,15 +83,10 @@ int error_eof(void);
|
|||
int ft_read_stack(t_sym *stack);
|
||||
char *read_state(t_sym current);
|
||||
|
||||
/*
|
||||
* Build AST - rewriting
|
||||
*
|
||||
*/
|
||||
|
||||
struct s_treematch
|
||||
{
|
||||
t_type type;
|
||||
int (*add)(t_btree **ast, t_list **lst);
|
||||
int (*add)(t_btree **ast, t_list **lst);
|
||||
};
|
||||
|
||||
int build_tree(t_btree **ast, t_list **lst);
|
||||
|
|
@ -145,7 +141,7 @@ int superflous_token(t_btree **ast, t_list **list);
|
|||
void sym_free(void *data, size_t size);
|
||||
void tree_func_free(void *data, size_t content_size);
|
||||
|
||||
struct s_distrostree
|
||||
struct s_distrostree
|
||||
{
|
||||
int (*test)(t_btree **ast, t_list **lst);
|
||||
int (*add)(t_btree **ast, t_list **lst);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/20 10:38:12 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/22 16:53:22 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -198,6 +198,8 @@ enum e_sym
|
|||
OPEN_FUNC,
|
||||
CLOSE_FUNC,
|
||||
CLOSE_LIST,
|
||||
SEMI_SUBSHELL,
|
||||
SEMI_BRACE,
|
||||
REDIR,
|
||||
CMD,
|
||||
HEREDOCDATA,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/22 15:22:59 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/22 17:00:12 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ static int handle_instruction(t_list **token, t_btree **ast)
|
|||
return (ret);
|
||||
if (do_lexer_routine(token, stream) > 0)
|
||||
continue ;
|
||||
/* token_print(*token); */
|
||||
token_print(*token);
|
||||
if ((ret = do_parser_routine(token, ast)) == 1
|
||||
&& SH_NO_INTERACTIVE(data->opts))
|
||||
return (ret);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/11 15:58:38 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/18 19:18:21 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/22 16:54:58 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -38,6 +38,7 @@ t_aggrematch g_aggrematch[] =
|
|||
{TK_DONE, COMPOUND_LIST, DO_GROUP, TK_DO},
|
||||
{TK_ESAC, TK_IN, CASE_CLAUSE, TK_CASE},
|
||||
{TK_ESAC, CASE_LIST_NS, CASE_CLAUSE, TK_CASE},
|
||||
{TK_PAREN_CLOSE, SEMI_SUBSHELL, SUBSHELL, TK_PAREN_OPEN},
|
||||
{TK_PAREN_CLOSE, COMPOUND_LIST, SUBSHELL, TK_PAREN_OPEN},
|
||||
{TK_PAREN_CLOSE, CMD_SUPERIOR, SUBSHELL, TK_PAREN_OPEN},
|
||||
{TK_PAREN_CLOSE, PIPE_SEMI_SEQUENCE, SUBSHELL, TK_PAREN_OPEN},
|
||||
|
|
@ -220,7 +221,9 @@ t_aggrematch g_aggrematch[] =
|
|||
{COMPOUND_LIST, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS},
|
||||
{CLOSE_LIST, PATTERN, CASE_LIST_NS, PATTERN_CASE},
|
||||
{CLOSE_LIST, FUNC_NAME, FUNCTION_DEFINITION, FUNC_NAME},
|
||||
{SUBSHELL, TK_PAREN_OPEN, SEMI_SUBSHELL, 0},
|
||||
{SUBSHELL, ALL, COMPOUND_COMMAND, 0},
|
||||
{BRACE_CLAUSE, TK_LBRACE, SEMI_BRACE, 0},
|
||||
{BRACE_CLAUSE, ALL, COMPOUND_COMMAND, 0},
|
||||
{COMPOUND_COMMAND, FUNC_NAME, COMMAND, FUNC_NAME},
|
||||
{AND_OR_MINOR, PIPE_SEMI_SEQUENCE, AND_OR_MAJOR, PIPE_SEMI_SEQUENCE},
|
||||
|
|
@ -379,15 +382,20 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state)
|
|||
return (1);
|
||||
i = -1;
|
||||
head = (*stack)->content;
|
||||
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));
|
||||
*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));
|
||||
}
|
||||
if (eval_sym(stack, *new_sym) && !(*state = ERROR))
|
||||
return (1);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/11 16:11:21 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/22 16:11:11 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/22 16:56:05 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -578,6 +578,7 @@ t_stackmatch g_stackmatch[] =
|
|||
{TK_PAREN_CLOSE, COMPOUND_LIST},
|
||||
{TK_PAREN_CLOSE, FUNC_NAME},
|
||||
{TK_PAREN_CLOSE, OPEN_FUNC},
|
||||
{TK_PAREN_CLOSE, SEMI_SUBSHELL},
|
||||
{TK_RBRACE, TK_SEMI},
|
||||
{TK_RBRACE, END_COMMAND},
|
||||
{TK_RBRACE, SEPARATOR_OP},
|
||||
|
|
@ -1047,6 +1048,7 @@ t_stackmatch g_stackmatch[] =
|
|||
{SUBSHELL, COMPLETE_CONDITION},
|
||||
{SUBSHELL, CONDITION},
|
||||
{SUBSHELL, AND_OR_MAJOR},
|
||||
{SEMI_SUBSHELL, TK_PAREN_OPEN},
|
||||
{COMPOUND_COMMAND, LINEBREAK},
|
||||
{COMPOUND_COMMAND, TK_PAREN_OPEN},
|
||||
{COMPOUND_COMMAND, TK_LBRACE},
|
||||
|
|
@ -1271,6 +1273,7 @@ int eval_sym(t_list **stack, t_sym new_sym)
|
|||
return (1);
|
||||
head = (*stack)->content;
|
||||
i = 0;
|
||||
DG("eval head %s && sym %s", read_state(*head), read_state(new_sym));
|
||||
while (g_stackmatch[i].top)
|
||||
{
|
||||
if (new_sym == g_stackmatch[i].top && *head == g_stackmatch[i].under)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/22 16:10:09 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/22 16:34:24 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue