Newer
Older
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
good_input: simple_list '\n'
| '\n'
| EOF
redirection: [NUMBER] '>' WORD
| [NUMBER] '<' WORD
| [NUMBER] '>>' WORD
| [NUMBER] '<<' WORD
| [NUMBER] '<<-' WORD
| [NUMBER] '>&' WORD
| [NUMBER] '<&' WORD
| [NUMBER] '>|' WORD
| [NUMBER] '<>' WORD
element: WORD
| redirection
cmd_prefix: ASSIGMENT_WORD
| redirection
simple_command: (cmp_prefix)* (element)+
command: simple_command
| shell_command (redirection)*
| function_def
simple_list: and_or ((';'|'&') and_or)* ['&'|';']
and_or: pipeline (('&&'|'||') ('\n')* pipeline)*
pipeline: ['!'] command ('|' ('\n')* command)*
shell_command: '{' compound_list '}'
| '(' compound_list ')'
| rule_for
| rule_while
| rule_until
| rule_case
| rule_if
rule_if: 'if' compound_list 'then' compound_list [else_clause] 'fi'
else_clause: 'else' compound_list
| 'elif' compound_list 'then' compound_list [else_clause]
rule_for: 'for' WORD ('\n')* ['in' (WORD)+ (';'|'\n') ('\n')*] do_group
rule_while: 'while' compound_list do_group
rule_until: 'until' compound_list do_group
do_group: 'do' compound_list 'done'
compound_list: ('\n')* and_or ((';'|'&'|'\n') ('\n')* and_or)* [(('&'|';'|'\n') ('\n')*)]
case: 'case' WORD ('\n')* 'in' ('\n')* [case_clause] 'esac'
case_clause: pattern (';;' (\n)* pattern)* [;;]
pattern: ['('] WORD ('|' WORD)* ')' ( ('\n')* | compound_list )
function: ['function'] WORD '(' ')' ('\n')* shell_command (redirection)*