-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparser_reduce_3.c
More file actions
97 lines (88 loc) · 3.16 KB
/
parser_reduce_3.c
File metadata and controls
97 lines (88 loc) · 3.16 KB
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
90
91
92
93
94
95
96
97
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser_reduce_3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkong <jkong@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/08 01:52:04 by jkong #+# #+# */
/* Updated: 2022/06/14 17:00:51 by jkong ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "libft.h"
//list -> pipeline
t_token_kind parser_reduce_15(t_parser *pst)
{
(void)&pst;
return (TK_NT_LIST);
}
//list -> list '||' pipeline
t_token_kind parser_reduce_16(t_parser *pst)
{
t_parser_stack val;
t_command command_lhs;
t_command command_rhs;
ft_memset(&val, 0, sizeof(val));
ft_memset(&command_lhs, 0, sizeof(command_lhs));
swap_command(&command_lhs, &pst->now[-2].command);
ft_memset(&command_rhs, 0, sizeof(command_rhs));
swap_command(&command_rhs, &pst->now[0].command);
val.command.type = CMD_CONNECTION;
val.command.value.connection = connect_command(&command_lhs, &command_rhs,
TK_OR_OR);
clear_parser_stack_item(&pst->now[-2]);
clear_parser_stack_item(&pst->now[-1]);
clear_parser_stack_item(&pst->now[0]);
pst->now -= 3;
*++pst->now = val;
return (TK_NT_LIST);
}
//list -> list '&&' pipeline
t_token_kind parser_reduce_17(t_parser *pst)
{
t_parser_stack val;
t_command command_lhs;
t_command command_rhs;
ft_memset(&val, 0, sizeof(val));
ft_memset(&command_lhs, 0, sizeof(command_lhs));
swap_command(&command_lhs, &pst->now[-2].command);
ft_memset(&command_rhs, 0, sizeof(command_rhs));
swap_command(&command_rhs, &pst->now[0].command);
val.command.type = CMD_CONNECTION;
val.command.value.connection = connect_command(&command_lhs, &command_rhs,
TK_AND_AND);
clear_parser_stack_item(&pst->now[-2]);
clear_parser_stack_item(&pst->now[-1]);
clear_parser_stack_item(&pst->now[0]);
pst->now -= 3;
*++pst->now = val;
return (TK_NT_LIST);
}
//pipeline -> command
t_token_kind parser_reduce_18(t_parser *pst)
{
(void)&pst;
return (TK_NT_PIPELINE);
}
//pipeline -> command '|' pipeline
t_token_kind parser_reduce_19(t_parser *pst)
{
t_parser_stack val;
t_command command_lhs;
t_command command_rhs;
ft_memset(&val, 0, sizeof(val));
ft_memset(&command_lhs, 0, sizeof(command_lhs));
swap_command(&command_lhs, &pst->now[-2].command);
ft_memset(&command_rhs, 0, sizeof(command_rhs));
swap_command(&command_rhs, &pst->now[0].command);
val.command.type = CMD_CONNECTION;
val.command.value.connection = connect_command(&command_lhs, &command_rhs,
TK_OR);
clear_parser_stack_item(&pst->now[-2]);
clear_parser_stack_item(&pst->now[-1]);
clear_parser_stack_item(&pst->now[0]);
pst->now -= 3;
*++pst->now = val;
return (TK_NT_PIPELINE);
}