From 2f97574a370aa594c6b9cae715e52feab7d42164 Mon Sep 17 00:00:00 2001 From: Nathan Lebrun Date: Mon, 20 Jan 2025 16:09:48 +0100 Subject: [PATCH] tokenizer but the pressisons --- tests/parse.c | 23 +++++++++++++++++------ tests/tokenizer/linked_list.c | 26 ++++++++++++++++++++++---- tests/tokenizer/tokenizer.h | 10 ++++++++++ 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/tests/parse.c b/tests/parse.c index 5447e74..3986e0d 100644 --- a/tests/parse.c +++ b/tests/parse.c @@ -11,6 +11,7 @@ /* ************************************************************************** */ #include "tokenizer/tokenizer.h" +/*#include "../includes/env.h"*/ void truncate_comment(char *str) { @@ -30,18 +31,28 @@ void truncate_comment(char *str) } } -int main(int ac, char **av) +/*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) { t_node *lst; - char *expanded; (void)ac; + (void)envp; + /*t_data data;*/ + + /*data = init_data(envp);*/ truncate_comment(av[1]); - expanded = expander(av[1]); - lst = tokenize(expanded); + lst = tokenize(av[1]); if (!lst) - return (free(expanded), 1); - ft_free(expanded); + return (1); debug_linked_list(lst, "Tokenized"); free_linked_list(lst); } diff --git a/tests/tokenizer/linked_list.c b/tests/tokenizer/linked_list.c index 62e0875..27ee38a 100644 --- a/tests/tokenizer/linked_list.c +++ b/tests/tokenizer/linked_list.c @@ -23,6 +23,7 @@ t_node *create_node(char *val, t_token token) return (NULL); node->val = ft_strdup(val); node->token = token; + node->pressision = 0; node->next = NULL; return (node); } @@ -86,21 +87,38 @@ 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 "); + token = ft_strdup(" WORD"); else if (current->token == UNSET) - token = ft_strdup("UNSET "); + token = ft_strdup(" UNSET"); else - token = ft_strdup("??? "); - printf("| Node - TOKEN: %s -> val: |%s|\n", token, current->val); + token = ft_strdup(" ???"); + + // set vals for pressision token + if (current->pressision == AND) + pres = ft_strdup("AND "); + if (current->pressision == OR) + pres = ft_strdup("OR "); + if (current->pressision == PIPE) + pres = ft_strdup("PIPE "); + if (current->pressision == SUBSH_S) + pres = ft_strdup("SUBSH_S"); + if (current->pressision == SUBSH_E) + pres = ft_strdup("SUBSH_E"); + else + pres = ft_strdup("??? "); + + printf("| Node - TOKEN: %s.%s -> val: |%s|\n", token, pres, current->val); free(token); current = current->next; } diff --git a/tests/tokenizer/tokenizer.h b/tests/tokenizer/tokenizer.h index 72b7389..de9f988 100644 --- a/tests/tokenizer/tokenizer.h +++ b/tests/tokenizer/tokenizer.h @@ -22,11 +22,21 @@ typedef enum e_token WORD } t_token; +typedef enum e_pres +{ + AND, + OR, + PIPE, + SUBSH_S, + SUBSH_E +} t_pres; + typedef struct s_node { struct s_node *next; char *val; enum e_token token; + enum e_pres pressision; } t_node; t_node *tokenize(char *str);