-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.y
109 lines (106 loc) · 3.29 KB
/
grammar.y
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
98
99
100
101
102
103
104
105
106
107
108
109
/* -------------------------------------------------------
The grammar symbols
------------------------------------------------------- */
%token WORD
%token ASSIGNMENT_WORD
%token NAME
%token IO_NUMBER
/* The following are the operators (see XBD Operator)
containing more than one character. */
%token DLESS DGREAT LESSAND GREATAND LESSGREAT DLESSDASH
/* '<<' '>>' '<&' '>&' '<>' '<<-' */
/* -------------------------------------------------------
The Grammar
------------------------------------------------------- */
complete_command : list separator
| list
;
/*
list : list separator and_or
| and_or
;
*/
list : and_or list_next
;
list_next : separator and_or list_next
| EMPTY
;
/*
and_or : pipeline
| and_or AND_IF pipeline
| and_or OR_IF pipeline
*/
and_or : pipeline and_or_list
;
and_or_list : AND_IF pipeline and_or_list
| OR_IF pipeline and_or_list
| EMPTY
;
/*
pipeline : command
| pipeline '|' command
;
*/
pipeline : command pipe_list
;
pipe_list : '|' command pipe_list
| EMPTY
;
command : cmd_prefix cmd_word cmd_suffix
| cmd_prefix cmd_word
| cmd_prefix
| cmd_name cmd_suffix
| cmd_name
;
cmd_name : WORD /* Apply rule 7a */
;
cmd_word : WORD /* Apply rule 7b */
;
/*cmd_prefix : io_redirect
| cmd_prefix io_redirect
| ASSIGNMENT_WORD
| cmd_prefix ASSIGNMENT_WORD
;
*/
cmd_prefix : io_redirect cmd_prefix_list
| ASSIGNMENT_WORD cmd_prefix_list
;
cmd_prefix_list : io_redirect cmd_prefix_list
| ASSIGNMENT_WORD cmd_prefix_list
| EMPTY
;
/*
cmd_suffix : io_redirect
| cmd_suffix io_redirect
| WORD
| cmd_suffix WORD
;
*/
cmd_suffix : io_redirect cmd_suffix_list
| WORD cmd_suffix_list
;
cmd_suffix_list | io_redirect cmd_suffix_list
| WORD cmd_suffix_list
| EMPTY;
io_redirect : io_file
| IO_NUMBER io_file
| io_here
| IO_NUMBER io_here
;
io_file : '<' filename
| LESSAND filename
| '>' filename
| GREATAND filename
| DGREAT filename
| LESSGREAT filename
;
filename : WORD /* Apply rule 2 */
;
io_here : DLESS here_end
| DLESSDASH here_end
;
here_end : WORD /* Apply rule 3 */
;
separator : '&'
| ';'
;