archi ok, test struct de grammaire
This commit is contained in:
parent
e7a7fc04df
commit
87b7d65d71
17 changed files with 102 additions and 63 deletions
|
|
@ -170,10 +170,13 @@ main/shell_script.c\
|
|||
main/sig_handler.c\
|
||||
parser/parse.c\
|
||||
parser/ft_parse.c\
|
||||
parser/produce_prim_sym.c\
|
||||
parser/produce_sym.c\
|
||||
parser/eval_sym.c\
|
||||
parser/aggregate_sym.c\
|
||||
parser/pop_stack.c\
|
||||
parser/push_stack.c\
|
||||
parser/superflous_sym.c\
|
||||
parser/error_syntax.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 17:06:08 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/09 20:20:23 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 18:04:35 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/09 20:28:03 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -75,27 +75,27 @@ typedef unsigned long long int t_sym;
|
|||
#define SYM_GREAT (1UL << 49)
|
||||
#define SYM_LESSAND (1UL << 50)
|
||||
#define SYM_LESS (1UL << 51)
|
||||
|
||||
#define SYM_SEMI (1UL << 52)
|
||||
|
||||
int ft_parse(t_btree **ast, t_list **token);
|
||||
int produce_sym(t_sym *new_sym, t_list **lst);
|
||||
int produce_sym(t_sym stack, 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 aggregate_sym(t_sym **stack, t_sym *new_sym);
|
||||
int superflous_sym(t_sym stack, t_sym new_sym);
|
||||
|
||||
int push_stack(t_sym *stack, t_sym *new_sym);
|
||||
int push_stack(t_sym *stack, t_sym new_sym);
|
||||
int pop_stack(t_sym **stack, int k);
|
||||
|
||||
int error_syntax(t_list **token);
|
||||
|
||||
int ft_read_stack(t_sym *stack);
|
||||
char *read_state(t_sym current);
|
||||
|
||||
enum e_parstate
|
||||
{
|
||||
UNDEFINED,
|
||||
ERROR,
|
||||
SUCCESS,
|
||||
};
|
||||
#define UNDEFINED (1 << 0)
|
||||
#define ERROR (1 << 1)
|
||||
#define SUCCESS (1 << 2)
|
||||
|
||||
typedef enum e_parstate t_parstate;
|
||||
typedef int t_parstate;
|
||||
|
||||
/*
|
||||
* Build AST
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
ls > file1
|
||||
ls ;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/09 15:37:13 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/09 19:54:13 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/03 19:53:49 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/09 19:26:55 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/22 23:06:34 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/09 16:45:16 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/09 20:30:31 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* 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 */
|
||||
/* Updated: 2017/02/09 20:19:29 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,20 +14,15 @@
|
|||
|
||||
//descente recursive pour multi aggregation
|
||||
|
||||
int aggregate_sym(t_sym stack, t_sym *new_sym)
|
||||
int aggregate_sym(t_sym **stack, t_sym *new_sym)
|
||||
{
|
||||
int k;
|
||||
|
||||
if (stack == 0 && *new_sym == CMD_NAME)
|
||||
DG("aggregate head %s && sym %s", read_state(**stack), read_state(*new_sym));
|
||||
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
|
||||
*new_sym = SIMPLE_COMMAND;
|
||||
aggregate_sym(stack, new_sym);
|
||||
}
|
||||
if (**stack == 0 && *new_sym == SIMPLE_COMMAND)
|
||||
*new_sym = PROGRAM;
|
||||
return (0);
|
||||
|
||||
}
|
||||
|
|
|
|||
20
42sh/src/parser/error_syntax.c
Normal file
20
42sh/src/parser/error_syntax.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* error_syntax.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 20:15:35 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/09 20:31:48 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
int error_syntax(t_list **lst)
|
||||
{
|
||||
(void)lst;
|
||||
ft_putstr_fd("syntax error near unexepected token ';'", 2);
|
||||
return (1);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* 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 */
|
||||
/* Updated: 2017/02/09 20:14:46 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
int eval_sym(t_sym stack, t_sym new_sym)
|
||||
{
|
||||
// DG("eval head %s && eval sym %s", read_state(stack), read_state(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)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 14:30:22 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/09 18:03:53 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/09 20:32:25 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,40 +17,32 @@ 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));
|
||||
stack = ft_memalloc(sizeof(t_sym) * 1000);
|
||||
*stack = 0;
|
||||
k = 0;
|
||||
push_stack(stack, 0);
|
||||
while (*token)
|
||||
{
|
||||
produce_sym(new_sym, token);
|
||||
produce_sym(*stack, new_sym, token);
|
||||
if (eval_sym(*stack, *new_sym))
|
||||
state = ERROR;
|
||||
DG("head state : %s", read_state(*stack));
|
||||
else
|
||||
{
|
||||
k = aggregate_sym(*stack, new_sym)
|
||||
if (k)
|
||||
{
|
||||
while (k--)
|
||||
pop_stack(stack--);
|
||||
push_stack(++stack, new_sym);
|
||||
aggregate_sym(&stack, new_sym);
|
||||
//superflous sym
|
||||
push_stack(++stack, *new_sym);
|
||||
}
|
||||
else if (!superflous_sym(new_sym, stack))
|
||||
push_stack(++stack, new_sym);
|
||||
}
|
||||
/* if (head_stack == PROGRAM)
|
||||
if (*stack == PROGRAM)
|
||||
state = PROGRAM;
|
||||
if (state == ERROR)
|
||||
return (error_syntax(token));
|
||||
if (state == PROGRAM)
|
||||
return (0);
|
||||
build_tree(token, ast);
|
||||
*/ }
|
||||
ft_putstr("success");
|
||||
// build_tree(token, ast);
|
||||
ft_lst_delif(token, (*token)->content, &ft_addrcmp, &token_free);
|
||||
}
|
||||
ft_read_stack(stack);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 16:21:51 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/06 17:52:31 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/09 19:27:22 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
20
42sh/src/parser/pop_stack.c
Normal file
20
42sh/src/parser/pop_stack.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pop_stack.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 19:12:44 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/09 20:02:05 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
int pop_stack(t_sym **stack, int k)
|
||||
{
|
||||
while (k--)
|
||||
*stack-- = 0;
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,16 +6,17 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/09 17:58:45 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/09 20:28:25 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
int produce_sym(t_sym *new_sym, t_list **lst)
|
||||
int produce_sym(t_sym stack, t_sym *new_sym, t_list **lst)
|
||||
{
|
||||
t_token *token;
|
||||
|
||||
(void)stack;
|
||||
token = (*lst)->content;
|
||||
if (token->type == TK_N_WORD)
|
||||
*new_sym = CMD_NAME;
|
||||
|
|
@ -33,5 +34,7 @@ int produce_sym(t_sym *new_sym, t_list **lst)
|
|||
*new_sym = SYM_LESSAND;
|
||||
else if (token->type == TK_LESS)
|
||||
*new_sym = SYM_LESS;
|
||||
else if (token->type == TK_SEMI)
|
||||
*new_sym = SYM_SEMI;
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@
|
|||
/* 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 */
|
||||
/* Updated: 2017/02/09 20:00:35 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
int push_stack(t_sym *stack, t_sym *new_sym)
|
||||
int push_stack(t_sym *stack, t_sym new_sym)
|
||||
{
|
||||
*stack = *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 17:33:30 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/09 19:41:44 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -30,6 +30,12 @@ char *read_state(t_sym current)
|
|||
return ("LESSAND");
|
||||
if (current == SYM_LESS)
|
||||
return ("LESS");
|
||||
if (current == SIMPLE_COMMAND)
|
||||
return ("SIMPLE_COMMAND");
|
||||
if (current == PROGRAM)
|
||||
return ("PROGRAM");
|
||||
if (current != 0)
|
||||
return ("NON-DEFINED");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* 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 */
|
||||
/* Updated: 2017/02/09 19:25:30 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
int superflous_sym(t_sym stack, t_sym new_sym)
|
||||
{
|
||||
if (stack == new_sym);
|
||||
if (stack == new_sym)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue