88 lines
2.2 KiB
C
88 lines
2.2 KiB
C
|
|
#include "minishell.h"
|
|
|
|
// A quoi bon un arbre binaire ? Je ne vois plus l'utilité.
|
|
|
|
/* typedef struct s_binary_tree
|
|
{
|
|
char *content;
|
|
struct s_binary_tree *sub;
|
|
struct s_binary_tree *sibling;
|
|
enum e_token_id id;
|
|
} t_binary_tree; */
|
|
|
|
t_cmd **parsing(t_token *token_list, char **envp)
|
|
{
|
|
t_cmd **cmd_arr;
|
|
|
|
/* t_binary_tree *syntax_tree;
|
|
|
|
syntax_tree = ft_calloc(1, sizeof *syntax_tree);
|
|
if (!syntax_tree)
|
|
return (0); //WIP ERROR */
|
|
|
|
if (!valid_syntax(token_list))
|
|
return (NULL);
|
|
// Pipes count (determine cmd_nbr)
|
|
|
|
// Struct CMD alloc/fill
|
|
cmd_arr = fill_cmd(token_list, envp);
|
|
|
|
// 2.9.1 - 2) Expansion
|
|
|
|
// 2.9.1 - 3) Redirection
|
|
|
|
return (cmd_arr);
|
|
}
|
|
|
|
/* -------------------------------------------------------
|
|
The grammar symbols
|
|
------------------------------------------------------- */
|
|
/*
|
|
%token WORD
|
|
%token LESS // '<'
|
|
%token GREAT // '>'
|
|
%token DLESS // '<<'
|
|
%token DGREAT // '>>'
|
|
%token PIPE // '|'
|
|
*/
|
|
|
|
/* -------------------------------------------------------
|
|
The Simplified Grammar
|
|
------------------------------------------------------- */
|
|
/*
|
|
%start program
|
|
%%
|
|
pipeline : command
|
|
| pipe_sequence '|' command
|
|
;
|
|
command : cmd_prefix cmd_name cmd_suffix
|
|
| cmd_prefix cmd_name
|
|
| cmd_name cmd_suffix
|
|
| cmd_name
|
|
;
|
|
cmd_name : WORD // Apply rule 7a
|
|
;
|
|
cmd_prefix : io_redirect
|
|
| cmd_prefix io_redirect
|
|
;
|
|
cmd_suffix : io_redirect
|
|
| cmd_suffix io_redirect
|
|
| WORD
|
|
| cmd_suffix WORD
|
|
;
|
|
io_redirect : io_file
|
|
| io_here
|
|
;
|
|
io_file : '<' filename
|
|
| '>' filename
|
|
| DGREAT filename
|
|
;
|
|
filename : WORD // Apply rule 2
|
|
;
|
|
io_here : DLESS here_end
|
|
;
|
|
here_end : WORD // Apply rule 3
|
|
;
|
|
*/
|