This commit is contained in:
Nathan Lebrun
2025-01-29 11:40:30 +01:00
parent 9bce0bf9cb
commit 64100fe0f4
19 changed files with 29 additions and 91 deletions

View File

@@ -36,7 +36,7 @@ $(NAME): $(LIBFT) $(OBJS)
# test part # test part
TEST_SRCDIR = tests TEST_SRCDIR = test
TEST_OBJDIR = .TEST_objs TEST_OBJDIR = .TEST_objs
TEST_SRCS = $(shell find $(TEST_SRCDIR) -name "*.c") TEST_SRCS = $(shell find $(TEST_SRCDIR) -name "*.c")
TEST_OBJS = $(patsubst $(TEST_SRCDIR)/%.c, $(TEST_OBJDIR)/%.o, $(TEST_SRCS)) TEST_OBJS = $(patsubst $(TEST_SRCDIR)/%.c, $(TEST_OBJDIR)/%.o, $(TEST_SRCS))
@@ -46,8 +46,8 @@ $(TEST_OBJDIR)/%.o: $(TEST_SRCDIR)/%.c
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
@$(CC) $(WFLAGS) -MMD -MP -I$(INCDIR) -c $< -g3 -ggdb -o $@ $(LINK) @$(CC) $(WFLAGS) -MMD -MP -I$(INCDIR) -c $< -g3 -ggdb -o $@ $(LINK)
tests: $(LIBFT) $(TEST_OBJS) parser: $(LIBFT) $(TEST_OBJS)
@$(CC) $(WFLAGS) $(TEST_OBJS) $(LIBFT) -o test $(LINK) @$(CC) $(WFLAGS) $(TEST_OBJS) $(LIBFT) -o parser $(LINK)
@echo "$(CYAN)Test build completed: test$(RESET)" @echo "$(CYAN)Test build completed: test$(RESET)"
# test part end # test part end

BIN
parser Executable file

Binary file not shown.

View File

@@ -47,10 +47,11 @@ void setup_cmd(t_ast_n *node, char *cmd, char *args)
node->args = ft_split(args, " "); node->args = ft_split(args, " ");
} }
t_ast_n *return_hardcode_ast(char **envp) t_ast_n *get_ast(char **envp, t_node *lst)
{ {
t_ast_n *head; t_ast_n *head;
(void)lst;
// head // head
head = created_ast_n(_AND, NULL, NULL); head = created_ast_n(_AND, NULL, NULL);
head->env = init_env(envp); head->env = init_env(envp);

View File

@@ -15,6 +15,7 @@
/*# include "../../includes/env.h"*/ /*# include "../../includes/env.h"*/
# include "../../lib/libft/libft.h" # include "../../lib/libft/libft.h"
# include "../tokenizer/tokenizer.h"
typedef enum e_state typedef enum e_state
{ {
@@ -54,7 +55,7 @@ typedef struct s_ast_n
char **env; char **env;
} t_ast_n; } t_ast_n;
t_ast_n *return_hardcode_ast(char **envp); t_ast_n *get_ast(char **envp, t_node *lst);
// env TMP // env TMP
char **init_env(char **envp); char **init_env(char **envp);

View File

@@ -13,11 +13,13 @@
#ifndef PARSING_H #ifndef PARSING_H
# define PARSING_H # define PARSING_H
# define DEBUG 1
# include "tokenizer/tokenizer.h" # include "tokenizer/tokenizer.h"
# include "ast/ast.h" # include "ast/ast.h"
# include "drawio/drawio.h"
// drawio // drawio
# include "drawio/drawio.h"
// tmp_env // tmp_env
char **init_env(char **envp); char **init_env(char **envp);

View File

@@ -11,7 +11,6 @@
/* ************************************************************************** */ /* ************************************************************************** */
#include "parsing.h" #include "parsing.h"
/*#include "../includes/env.h"*/
void truncate_comment(char *str) void truncate_comment(char *str)
{ {
@@ -37,37 +36,34 @@ void truncate_comment(char *str)
} }
} }
/*static t_data *init_data(char **envp)*/
/*{*/
/* t_data *data;*/
/**/
/* data = malloc (sizeof(t_data));*/
/* data->env = init_env(envp);*/
/* return (data);*/
/*}*/
int main(int ac, char **av, char **envp) int main(int ac, char **av, char **envp)
{ {
t_node *lst; t_node *lst;
t_ast_n *ast; t_ast_n *ast;
int dio; int dio;
/*t_data data;*/
if (ac != 3) if (ac != 3)
{ {
ft_error("./test drawio_file command_str\n"); ft_error("./test drawio_file command_str\n");
return (1); return (1);
} }
/*data = init_data(envp);*/
truncate_comment(av[1]); truncate_comment(av[1]);
lst = tokenize(av[2]); lst = tokenize(av[2]);
if (!lst) if (!lst)
return (1); return (1);
if (DEBUG)
{
dio = drawio_init(av[1]); dio = drawio_init(av[1]);
gen_dio_linked_list(lst, dio); gen_dio_linked_list(lst, dio);
/*debug_linked_list(lst, "ff");*/ }
ast = return_hardcode_ast(envp); ast = get_ast(envp, lst);
if (!ast)
return (1);
if (DEBUG)
{
gen_dio_ast(ast, dio); gen_dio_ast(ast, dio);
drawio_end_file(dio); drawio_end_file(dio);
ft_debug(" draw.io file generated !\n");
}
free_linked_list(lst); free_linked_list(lst);
} }

View File

@@ -81,65 +81,3 @@ int merge_with_next_node(t_node *node)
node->next = tmp_next; node->next = tmp_next;
return (1); return (1);
} }
// have to be deleted after
void debug_linked_list(t_node *head, char *msg)
{
t_node *current;
char *token;
char *pres;
current = head;
printf("----------------------------------------------------------{%s} \n",
msg);
while (current != NULL)
{
// set val for base token
if (current->token == OPERATOR)
token = ft_strdup("OPERATOR");
else if (current->token == WORD)
token = ft_strdup(" WORD");
else if (current->token == UNSET)
token = ft_strdup(" UNSET");
else
token = ft_strdup(" ???");
// set vals for pressision token
if (current->pressision == COMMAND)
pres = ft_strdup("COMMAND ");
else if (current->pressision == UNDEFINED)
pres = ft_strdup("UNDEF ");
else if (current->pressision == AND)
pres = ft_strdup("AND ");
else if (current->pressision == OR)
pres = ft_strdup("OR ");
else if (current->pressision == PIPE)
pres = ft_strdup("PIPE ");
else if (current->pressision == SUBSH_S)
pres = ft_strdup("SUBSH_S ");
else if (current->pressision == SUBSH_E)
pres = ft_strdup("SUBSH_E ");
else if (current->pressision == RED_L)
pres = ft_strdup("RED_L ");
else if (current->pressision == RED_R)
pres = ft_strdup("RED_R ");
else if (current->pressision == HEREDOC)
pres = ft_strdup("HEREDOC ");
else if (current->pressision == D_RED_R)
pres = ft_strdup("D_RED_R ");
else if (current->pressision == PARAMETER)
pres = ft_strdup("PARAMETER");
else if (current->pressision == RED_FILE)
pres = ft_strdup("RED_FILE ");
else if (current->pressision == LIM)
pres = ft_strdup("LIM ");
else
pres = ft_strdup("??? ");
printf("| Node - TOKEN: %s.%s -> val: |%s|\n", token, pres, current->val);
free(token);
free(pres);
current = current->next;
}
printf("----------------------------------------------------------\n\n");
}

View File

@@ -13,7 +13,7 @@
#ifndef TOKENIZER_H #ifndef TOKENIZER_H
# define TOKENIZER_H # define TOKENIZER_H
# include "../includes/minishell.h" # include "../../lib/libft/libft.h"
typedef enum e_token typedef enum e_token
{ {