Files
42_INT_07_minishell/srcs/parsing/parsing.c
2021-11-07 04:41:17 +01:00

105 lines
3.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/24 10:52:40 by lperrey #+# #+# */
/* Updated: 2021/11/07 04:37:30 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
// HUGO WIP
void handle_argv(t_token *token, t_cmd **cmd, size_t cmd_nbr);
void handle_path(t_cmd **cmd_arr, char **envp);
void handle_fd(t_token *token, t_cmd **cmd_arr);
void fd_heredoc(t_token *token, t_cmd *cmd);
void fd_redirection(t_token *token, t_cmd *cmd);
void find_path(char **argv, char **envp);
int handle_builtin(t_cmd *cmd);
int fill_builtin(t_cmd *cmd, int (*builtin)(int, char **, t_all *));
int next_cmd(t_token *token);
int is_redirection(enum e_token_id id);
// HUGO WIP
t_cmd **parsing(t_token *token_list)
{
t_cmd **cmd_arr;
if (!valid_syntax(token_list))
return (NULL);
// Struct CMD alloc
cmd_arr = alloc_cmd_array(count_pipes(token_list) + 1);
if (!cmd_arr)
return (NULL);
// 2.9.1 - 2) Expansion
words_expansions(token_list);
// 2.9.1 - 3) Redirection
// Struct CMD fill
// HUGO WIP
// cmd_expansion(cmd_arr, envp);
// handle_argv(token_list, cmd_arr, cmd_nbr);
// handle_path(cmd_arr, envp);
// handle_fd(token_list, cmd_arr);
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
| pipeline '|' 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
;
*/