-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrees2.c
89 lines (78 loc) · 2.49 KB
/
trees2.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
81
82
83
84
85
86
87
88
89
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* trees2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: btaha <btaha@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/02 17:19:37 by btaha #+# #+# */
/* Updated: 2023/01/14 21:31:05 by btaha ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/minishell.h"
t_tree *pipe_tree(t_lexer *lexer, t_tree *ast)
{
t_tree *root_ast;
if (!ast)
{
return (ft_printf(2, "minishell: parse error near '||'\n"),
g_shell.error = 1, NULL);
}
root_ast = ft_init_tree(NULL);
lexer_advance(lexer);
root_ast->left = ast;
root_ast->type = PIPE;
root_ast->right = construct_tree(lexer, root_ast->right);
return (root_ast);
}
t_tree *gt_tree(t_lexer *lexer, t_tree *ast)
{
t_tree *root_ast;
if (!ast)
ast = ft_init_tree(NULL);
root_ast = ft_init_tree(NULL);
lexer_advance(lexer);
root_ast->left = ast;
root_ast->type = GREATER_THAN;
root_ast->right = construct_tree(lexer, root_ast->right);
return (root_ast);
}
t_tree *dgt_tree(t_lexer *lexer, t_tree *ast)
{
t_tree *root_ast;
if (!ast)
ast = ft_init_tree(NULL);
root_ast = ft_init_tree(NULL);
lexer_advance(lexer);
lexer_advance(lexer);
root_ast->left = ast;
root_ast->type = DGREATER_THAN;
root_ast->right = construct_tree(lexer, root_ast->right);
return (root_ast);
}
t_tree *lt_tree(t_lexer *lexer, t_tree *ast)
{
t_tree *root_ast;
if (!ast)
ast = ft_init_tree(NULL);
root_ast = ft_init_tree(NULL);
lexer_advance(lexer);
lexer_advance(lexer);
root_ast->left = ast;
root_ast->type = LOWER_THAN;
root_ast->right = construct_tree(lexer, root_ast->right);
return (root_ast);
}
t_tree *dlt_tree(t_lexer *lexer, t_tree *ast)
{
t_tree *root_ast;
if (!ast)
ast = ft_init_tree(NULL);
root_ast = ft_init_tree(NULL);
lexer_advance(lexer);
lexer_advance(lexer);
root_ast->left = ast;
root_ast->type = DLOWER_THAN;
root_ast->right = construct_tree(lexer, root_ast->right);
return (root_ast);
}