proto parser en cours
This commit is contained in:
parent
ebc57c0da8
commit
e7a7fc04df
11 changed files with 143 additions and 26 deletions
|
|
@ -171,6 +171,9 @@ main/sig_handler.c\
|
|||
parser/parse.c\
|
||||
parser/ft_parse.c\
|
||||
parser/produce_prim_sym.c\
|
||||
parser/eval_sym.c\
|
||||
parser/push_stack.c\
|
||||
parser/superflous_sym.c\
|
||||
parser/get_instruction.c\
|
||||
parser/get_sub_instruction.c\
|
||||
parser/parse_dgreat.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/09 15:26:01 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/09 17:06:08 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/09 15:58:13 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/09 18:04:35 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -78,9 +78,14 @@ typedef unsigned long long int t_sym;
|
|||
|
||||
|
||||
int ft_parse(t_btree **ast, t_list **token);
|
||||
int produce_prim_sym(t_sym *new_sym, t_list **lst);
|
||||
int produce_sym(t_sym *new_sym, t_list **lst);
|
||||
int eval_sym(t_sym stack, t_sym new_sym);
|
||||
int aggregate_sym(t_sym stack, t_sym *new_sym);
|
||||
int superflous_sym(t_sym stack, t_sym new_sym);
|
||||
|
||||
int ft_read_stack(t_sym stack[], int size);
|
||||
int push_stack(t_sym *stack, t_sym *new_sym);
|
||||
|
||||
int ft_read_stack(t_sym *stack);
|
||||
char *read_state(t_sym current);
|
||||
|
||||
enum e_parstate
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/22 23:06:34 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/09 15:26:55 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/09 16:45:16 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
33
42sh/src/parser/aggregate_sym.c
Normal file
33
42sh/src/parser/aggregate_sym.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* aggregate_sym.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 17:39:18 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/09 18:10:13 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
//descente recursive pour multi aggregation
|
||||
|
||||
int aggregate_sym(t_sym stack, t_sym *new_sym)
|
||||
{
|
||||
int k;
|
||||
|
||||
if (stack == 0 && *new_sym == CMD_NAME)
|
||||
{
|
||||
new_sym = SIMPLE_COMMAND;
|
||||
k = aggregate_sym(stack, new_sym);
|
||||
return (k);
|
||||
}
|
||||
if (stack == SIMPLE_COMMAND && *new_sym == PROGRAM)
|
||||
{
|
||||
new_sym = PROGRAM
|
||||
}
|
||||
return (0);
|
||||
|
||||
}
|
||||
25
42sh/src/parser/eval_sym.c
Normal file
25
42sh/src/parser/eval_sym.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* eval_sym.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 16:26:30 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/09 17:50:23 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
int eval_sym(t_sym stack, t_sym new_sym)
|
||||
{
|
||||
// DG("eval head %s && eval sym %s", read_state(stack), read_state(new_sym));
|
||||
if (stack == 0 && new_sym == CMD_NAME)
|
||||
return (0);
|
||||
if (stack == SYM_GREAT && new_sym == CMD_NAME)
|
||||
return (0);
|
||||
if (stack == CMD_NAME && new_sym == SYM_GREAT)
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 14:30:22 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/09 16:02:49 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/09 18:03:53 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,32 +15,42 @@
|
|||
int ft_parse(t_btree **ast, t_list **token)
|
||||
{
|
||||
t_sym *new_sym;
|
||||
t_sym *stack;
|
||||
t_parstate state;
|
||||
int k;
|
||||
|
||||
(void)ast;
|
||||
state = UNDEFINED;
|
||||
new_sym = ft_memalloc(sizeof(t_sym));
|
||||
new_sym = ft_memalloc(sizeof(t_sym));
|
||||
stack = ft_memalloc(sizeof(t_sym) * 1000);
|
||||
*stack = 0;
|
||||
k = 0;
|
||||
while (*token)
|
||||
{
|
||||
produce_prim_sym(new_sym, token);
|
||||
DG("new sym : %s", read_state(*new_sym));
|
||||
/* if (eval_sym(head_stack, new_sym))
|
||||
produce_sym(new_sym, token);
|
||||
if (eval_sym(*stack, *new_sym))
|
||||
state = ERROR;
|
||||
DG("head state : %s", read_state(*stack));
|
||||
else
|
||||
{
|
||||
aggregate_sym(head_stack, new_sym, struct_sym);
|
||||
if (struct_sym)
|
||||
pop(struct_sym.sym);
|
||||
else if (!same_sym(new_sym, head_stack))
|
||||
push(new_sym);
|
||||
k = aggregate_sym(*stack, new_sym)
|
||||
if (k)
|
||||
{
|
||||
while (k--)
|
||||
pop_stack(stack--);
|
||||
push_stack(++stack, new_sym);
|
||||
}
|
||||
else if (!superflous_sym(new_sym, stack))
|
||||
push_stack(++stack, new_sym);
|
||||
}
|
||||
build_tree(token, ast);
|
||||
if (head_stack == PROGRAM)
|
||||
/* if (head_stack == PROGRAM)
|
||||
state = PROGRAM;
|
||||
if (state == ERROR)
|
||||
return (error_syntax(token));
|
||||
if (state == PROGRAM)
|
||||
return (0);
|
||||
build_tree(token, ast);
|
||||
*/ }
|
||||
ft_read_stack(stack);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* produce_prim_sym.c :+: :+: :+: */
|
||||
/* produce_sym.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 14:55:10 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/09 16:05:27 by ariard ### ########.fr */
|
||||
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/09 17:58:45 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
int produce_prim_sym(t_sym *new_sym, t_list **lst)
|
||||
int produce_sym(t_sym *new_sym, t_list **lst)
|
||||
{
|
||||
t_token *token;
|
||||
|
||||
|
|
@ -33,6 +33,5 @@ int produce_prim_sym(t_sym *new_sym, t_list **lst)
|
|||
*new_sym = SYM_LESSAND;
|
||||
else if (token->type == TK_LESS)
|
||||
*new_sym = SYM_LESS;
|
||||
ft_lst_delif(lst, (*lst)->content, &ft_addrcmp, &token_free);
|
||||
return (0);
|
||||
}
|
||||
19
42sh/src/parser/push_stack.c
Normal file
19
42sh/src/parser/push_stack.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* push_stack.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 16:48:30 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/09 17:55:44 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
int push_stack(t_sym *stack, t_sym *new_sym)
|
||||
{
|
||||
*stack = *new_sym;
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 15:32:10 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/09 16:02:30 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/09 17:33:30 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -33,9 +33,12 @@ char *read_state(t_sym current)
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
int ft_read_stack(t_sym stack[], int size)
|
||||
int ft_read_stack(t_sym *stack)
|
||||
{
|
||||
while (stack[size])
|
||||
ft_putstr(read_state(stack[size--]));
|
||||
while (*stack)
|
||||
{
|
||||
ft_putstr(read_state(*stack--));
|
||||
ft_putchar(10);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
20
42sh/src/parser/superflous_sym.c
Normal file
20
42sh/src/parser/superflous_sym.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* superflous_sym.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 17:47:33 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/09 17:56:25 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
int superflous_sym(t_sym stack, t_sym new_sym)
|
||||
{
|
||||
if (stack == new_sym);
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
Loading…
Reference in a new issue