SOURCES := main.c \
vars.c \
input_handling.c \
- tree.c \
+ tokenization.c \
parsing.c \
+ expansion.c \
execution.c \
+ helpers.c \
SOURCES := $(addprefix $(SRCDIR)/, $(SOURCES))
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* parsing.h :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2024/05/03 15:24:31 by ljiriste #+# #+# */
-/* Updated: 2024/06/14 10:30:40 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:
+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
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;
- char *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
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 13:22:57 by ljiriste #+# #+# */
-/* Updated: 2024/05/03 13:01:59 by ljiriste ### ########.fr */
+/* Updated: 2024/06/21 16:35:59 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
t_vec other;
} t_vars;
+typedef t_parse_tree_node t_tree;
+
int init_vars(t_vars *vars, char **envp);
int add_var_line(t_vec *vec, const char *line);
int add_var(t_vec *vec, const char *key, const char *value);
void handle_input(const char *line, t_vars *vars);
+int tokenize(const char *line, t_vec *tokens);
+int parse(t_vec *tokens, t_tree *parse_tree);
+int expand(t_tree *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);
+void free_token(void *token);
+
#endif // MINISHELL_H
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/03 15:59:58 by ljiriste #+# #+# */
-/* Updated: 2024/05/03 16:21:02 by ljiriste ### ########.fr */
+/* Updated: 2024/06/21 17:00:46 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
-#include "parsing.h"
+#include "minishell.h"
int execute(__attribute__((unused))t_tree *parse_tree, __attribute__((unused))t_vars *vars)
{
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* tree.c :+: :+: :+: */
+/* expansion.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
-/* Created: 2024/05/03 15:56:55 by ljiriste #+# #+# */
-/* Updated: 2024/05/03 16:03:37 by ljiriste ### ########.fr */
+/* Created: 2024/06/21 16:29:48 by ljiriste #+# #+# */
+/* Updated: 2024/06/21 16:31:57 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
-#include "parsing.h"
+#include "minishell.h"
-int init_tree(__attribute__((unused))t_tree *tree)
+int expand(__attribute__((unused))t_tree *parse_tree, __attribute__((unused))t_vars *vars)
{
- ft_printf("Function init_tree has to be implemented.\n");
+ ft_printf("Variable expansion has yet to be implemented.\n");
return (0);
}
-
-void free_tree(__attribute__((unused))t_tree *tree)
-{
- ft_printf("Function free_tree has to by implemented.\n");
- return ;
-}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* helpers.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/06/21 16:35:16 by ljiriste #+# #+# */
+/* Updated: 2024/06/21 16:40:21 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "minishell.h"
+#include <stdlib.h>
+
+void free_token(void *token)
+{
+ free(((t_token *)token)->str);
+ return ;
+}
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/03 09:00:00 by ljiriste #+# #+# */
-/* Updated: 2024/06/14 11:00:16 by ljiriste ### ########.fr */
+/* Updated: 2024/06/21 16:39:27 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
-#include "parsing.h"
#include "minishell.h"
#include "libft.h"
#include <stdlib.h>
-static void free_token(void *token)
-{
- free(((t_token *)token)->str);
- 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);
-}
-
-// This function turns the input char string into a string of tokens
-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;
+ t_tree *parse_tree;
ft_vec_init(&tokens, sizeof(t_token));
- init_tree(&parse_tree);
+ parse_tree = NULL;
res = tokenize(input, &tokens);
- res = res || parse(&tokens, &parse_tree, vars);
- res = res || execute(&parse_tree, vars);
+ res = res || parse(&tokens, parse_tree);
+ res = res || expand(parse_tree, vars);
+ res = res || execute(parse_tree, vars);
ft_vec_free(&tokens, free_token);
- free_tree(&parse_tree);
+ ft_parse_tree_free(parse_tree);
if (res != 0)
ft_printf("An error has occured.\n");
return ;
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/03 15:58:55 by ljiriste #+# #+# */
-/* Updated: 2024/05/03 16:20:45 by ljiriste ### ########.fr */
+/* Updated: 2024/06/21 16:32:50 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
-#include "parsing.h"
+#include "minishell.h"
+#include "libft.h"
-int parse(__attribute__((unused))t_vec *tokens, __attribute__((unused))t_tree_node *parse_tree, __attribute__((unused))t_vars *vars)
+// table should be static or loaded at start and passed in as argument
+int parse(t_vec *tokens, t_tree *parse_tree)
{
- ft_printf("Function parse has to be implemented.\n");
+ t_parsing_table table;
+
+ ft_parsing_table_init(&table);
+ ft_parsing_table_load(&table, "shell_parsing_table", "shell_rules");
+ parse_tree = ft_parse(tokens, &table);
+ ft_parse_tree_print(parse_tree);
+ ft_parsing_table_free(&table);
return (0);
}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* tokenize.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/06/21 16:34:43 by ljiriste #+# #+# */
+/* Updated: 2024/06/21 16:35:59 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "minishell.h"
+
+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);
+}
+
+// This function turns the input char string into a string of tokens
+int tokenize(const char *line, t_vec *tokens)
+{
+ if (delimit(line, tokens))
+ return (1);
+ if (identify(tokens))
+ return (1);
+ return (0);
+}