tokenizer but the pressisons

This commit is contained in:
Nathan Lebrun
2025-01-20 16:09:48 +01:00
parent 9ee0c5bf2d
commit 2f97574a37
3 changed files with 49 additions and 10 deletions

View File

@@ -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);
}

View File

@@ -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,12 +87,14 @@ 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)
@@ -100,7 +103,22 @@ void debug_linked_list(t_node *head, char *msg)
token = ft_strdup(" UNSET");
else
token = ft_strdup(" ???");
printf("| Node - TOKEN: %s -> val: |%s|\n", token, current->val);
// 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;
}

View File

@@ -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);