-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer4.c
80 lines (72 loc) · 2.17 KB
/
lexer4.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer4.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rng <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/13 21:49:14 by ethanlim #+# #+# */
/* Updated: 2024/09/18 09:32:23 by rng ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_tokens *get_last_node(t_tokens *tokens)
{
t_tokens *list;
list = tokens;
while (list->next)
{
list = list->next;
}
return (list);
}
int check_operator(int n)
{
if (n == PIPE || n == REDIR_INPUT
|| n == REDIR_OUT_APPEND || n == REDIR_OUT_OVERWRITE
|| n == HEREDOC)
return (1);
return (0);
}
int check_valid_list_helper_cuz_norminette(t_tokens *first_node,
t_tokens *last_node)
{
if (first_node->type == PIPE || check_operator(last_node->type) == 1)
{
if (check_operator(last_node->type) == 1)
printf("syntax error near unexpected token '%s'\n",
last_node->token);
else
printf("syntax error near unexpected token '|'\n");
return (1);
}
return (0);
}
int check_valid_list(t_tokens *list)
{
t_tokens *last_node;
t_tokens *first_node;
t_tokens *temp;
first_node = list;
last_node = get_last_node(list);
temp = list;
if (check_valid_list_helper_cuz_norminette(first_node, last_node) == 1)
return (1);
while (temp->next)
{
if (check_operator(temp->type) == 1
&& check_operator(temp->next->type) == 1)
{
ft_printf("syntax error near unexpected token '%s'\n",
temp->token);
return (1);
}
temp = temp->next;
}
return (0);
}
void cleanup_failed_lexer_helper3(t_lexing *lexer)
{
lexer->res[lexer->j] = NULL;
free_2d_array(lexer->res);
}