--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* parsing.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/05/03 15:24:31 by ljiriste #+# #+# */
+/* Updated: 2024/05/03 16:20:14 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef PARSING_H
+# define PARSING_H
+
+# include "minishell.h"
+# include "libft.h"
+
+/*
+// As this is a minishell I used the
+// The Open Group Base Specifications Issue 7, 2018 edition
+// chapter 2. Shell Command Language as a main source.
+// which can be found at the address
+// https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
+// Because minishell is mini, I trim the grammar quite a bit,
+// so I think it appropriate to include the grammar here:
+
+Grammar Rules:
+ 2. Redirection to or from file
+ Variable expansion and quote removal
+ 3. Redirection from here-document
+ Quote removal
+ 7. Assignment preceding command name
+ a. First word
+ If the TOKEN contains the character '=', a WORD is returned
+ otherwise use rule 7b.
+ b. Not the first word
+ If TOKEN contaion unqouted '=' character:
+ - if characters before '=' form valid name*
+ an ASSIGNMENT_WORD is returned
+ - otherwise a WORD is returned
+
+* A valid name consists solely of underscores, digits and alphabetics
+ from the porable character set. The first character of a valid name
+ is not a digit.
+
+
+Grammar symbols:
+
+ WORD
+ ASSIGNMENT_WORD
+ IO_NUMBER
+
+ AND_IF '&&'
+ OR_IF '||'
+
+ LESS '<'
+ GREAT '>'
+ DLESS '<<'
+ DGREAT '>>'
+
+ PIPE '|'
+
+ LPARA '('
+ RPARA ')'
+
+The grammar:
+
+filename : WORD // Rule 2
+ ;
+io_file : LESS filename
+ | GREAT filename
+ | DGREAT filename
+ ;
+here_end : WORD // Rule 3
+ ;
+io_here : DLESS here_end
+ ;
+io_redirect : io_file
+ | IO_NUMBER io_file
+ | io_here
+ | IO_NUMBER io_here
+ ;
+cmd_name : WORD // Rule 7a
+ ;
+cmd_word : WORD // Rule 7b
+ ;
+cmd_prefix : io_redirect
+ | cmd_prefix io_redirect
+ | ASSIGNMENT_WORD
+ | cmd_prefix ASSIGNMENT_WORD
+ ;
+cmd_suffix : io_redirect
+ | cmd_suffix io_redirect
+ | WORD
+ | cmd_suffix WORD
+ ;
+simple_command : cmd_prefix cmd_word cmd_suffix
+ | cmd_prefix cmd_word
+ | cmd_prefix
+ | cmd_name cmd_suffix
+ | cmd_name
+ ;
+comp_command : LPARA program RPARA
+ ;
+command : simple_command
+ | comp_command
+ ;
+pipeline : command
+ | pipeline PIPE command
+ ;
+program : pipeline
+ | program AND_IF pipeline
+ | program OR_IF pipeline
+ ;
+
+
+Form for parse table generator:
+
+program -> program && pipeline
+program -> program || pipeline
+program -> pipeline
+pipeline -> command
+pipeline -> pipeline | command
+command -> simple_command
+command -> comp_command
+comp_command -> ( program )
+simple_command -> cmd_prefix cmd_word cmd_suffix
+simple_command -> cmd_prefix cmd_word
+simple_command -> cmd_prefix
+simple_command -> cmd_name cmd_suffix
+simple_command -> cmd_name
+cmd_suffix -> io_redirect
+cmd_suffix -> cmd_suffix io_redirect
+cmd_suffix -> WORD
+cmd_suffix -> cmd_suffix WORD
+cmd_prefix -> io_redirect
+cmd_prefix -> cmd_prefix io_redirect
+cmd_prefix -> ASSIGNMENT_WORD
+cmd_prefix -> cmd_prefix ASSIGNMENT_WORD
+cmd_word -> WORD
+cmd_name -> WORD
+io_redirect -> io_file
+io_redirect -> IO_NUMBER io_file
+io_redirect -> io_here
+io_redirect -> IO_NUMBER io_here
+io_here -> << here_end
+here_end -> WORD
+io_file -> < filename
+io_file -> > filename
+io_file -> >> filename
+filename -> WORD
+
+*/
+
+// Common type for WORD, ASSIGNMENT_WORD and IO_NUMBER is TOKEN.
+// The TOKEN type is identifies as WORD, ASSIGNMENT_WORD or IO_NUMBER
+// after tokenization itself
+typedef enum e_token_type
+{
+ TOKEN,
+ WORD,
+ ASSIGNMENT_WORD,
+ IO_NUMBER,
+ AND_IF,
+ OR_IF,
+ LESS,
+ GREAT,
+ DLESS,
+ DGREAT,
+ PIPE,
+ LPARA,
+ RPARA,
+} t_token_type;
+
+// Only TOKEN (WORD, ASSIGNMENT_WORD, IO_NUMBER) type tokens
+// have the str member non-empty
+typedef struct s_token
+{
+ t_token_type type;
+ t_vec str;
+} t_token;
+
+typedef struct s_tree_node
+{
+ t_token token;
+ struct s_tree_node *children[3];
+} t_tree_node;
+
+typedef t_tree_node t_tree;
+
+void handle_input(const char *input, t_vars *vars);
+int parse(t_vec *tokens, t_tree_node *parse_tree, t_vars *vars);
+int execute(t_tree *parse_tree, t_vars *vars);
+
+int init_tree(t_tree *tree);
+void free_tree(t_tree *tree);
+
+#endif // PARSING_H
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* input_handling.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/05/03 09:00:00 by ljiriste #+# #+# */
+/* Updated: 2024/05/03 16:06:16 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "parsing.h"
+#include "minishell.h"
+#include "libft.h"
+
+static void free_token(void *token)
+{
+ ft_vec_free(&((t_token *)token)->str, NULL);
+ return ;
+}
+
+static int delimit(__attribute__((unused))const char *line, __attribute__((unused))t_vec *tokens)
+{
+ ft_printf("Function delimit has to be implemented.\n");
+ return (0);
+}
+
+static int identify(__attribute__((unused))t_vec *tokens)
+{
+ ft_printf("Function identify has to be implemented.\n");
+ return (0);
+}
+
+static int tokenize(const char *line, t_vec *tokens)
+{
+ if (delimit(line, tokens))
+ return (1);
+ if (identify(tokens))
+ return (1);
+ return (0);
+}
+
+void handle_input(const char *input, t_vars *vars)
+{
+ int res;
+ t_vec tokens;
+ t_tree parse_tree;
+
+ ft_vec_init(&tokens, sizeof(t_token));
+ init_tree(&parse_tree);
+ res = tokenize(input, &tokens);
+ res = res || parse(&tokens, &parse_tree, vars);
+ res = res || execute(&parse_tree, vars);
+ ft_vec_free(&tokens, free_token);
+ free_tree(&parse_tree);
+ if (res != 0)
+ ft_printf("An error has occured.\n");
+ return ;
+}