GRAMMAR 1.56 KB
Newer Older
1 2
input:	  	  list '\n'
		  list EOF
3 4 5
		| '\n'
		| EOF

Seblu's avatar
Seblu committed
6
list:		and_or ((';'|'&') and_or)* ['&'|';']
7

Seblu's avatar
Seblu committed
8
and_or:		pipeline (('&&'|'||') ('\n')* pipeline)*
9

Seblu's avatar
Seblu committed
10
pipeline:	['!'] command ('|' ('\n')* command)*
11 12 13

command:	  simple_command
		| shell_command  (redirection)*
Seblu's avatar
----  
Seblu committed
14
		| funcdec (redirection)*
15

16 17
simple_command:   (prefix)+
		| (prefix)* (element)+
18

19
shell_command:	  '{' compound_list '}'
20 21 22 23 24 25 26
                | '(' compound_list ')'
                | rule_for
                | rule_while
                | rule_until
                | rule_case
                | rule_if

Seblu's avatar
----  
Seblu committed
27
funcdec:	['function'] WORD '(' ')' ('\n')* shell_command
28

29 30 31 32 33 34 35 36 37
redirection:  	  [IONUMBER] '>' WORD
		| [IONUMBER] '<' WORD
		| [IONUMBER] '>>' WORD
		| [IONUMBER] '<<' HEREDOC
		| [IONUMBER] '<<-' HEREDOC
		| [IONUMBER] '>&' WORD
		| [IONUMBER] '<&' WORD
		| [IONUMBER] '>|' WORD
		| [IONUMBER] '<>' WORD
Seblu's avatar
Seblu committed
38

39
prefix:		  ASSIGMENT_WORD
Seblu's avatar
Seblu committed
40 41 42 43 44 45
		| redirection

element:	  WORD
		| redirection

compound_list:  ('\n')* and_or ((';'|'&'|'\n') ('\n')* and_or)* [(('&'|';'|'\n') ('\n')*)]
46

47
rule_for: 	'for' WORD ('\n')* ['in' (WORD)* (';'|'\n') ('\n')*] do_group
48 49 50 51 52

rule_while:	'while' compound_list do_group

rule_until:	'until' compound_list do_group

Seblu's avatar
Seblu committed
53
rule_case:	'case' WORD ('\n')* 'in' ('\n')* [case_clause] 'esac'
54

55
rule_if:  	'if' compound_list 'then' compound_list [else_clause] 'fi'
Seblu's avatar
Seblu committed
56

57
else_clause:  	  'else' compound_list
Seblu's avatar
Seblu committed
58
		| 'elif' compound_list 'then' compound_list [else_clause]
59

Seblu's avatar
Seblu committed
60
do_group:	'do' compound_list 'done'
61

62
case_clause: 	case_item (';;' ('\n')* case_item)* [;;] ('\n')*
63

64
case_item:	['('] WORD ('|' WORD)* ')' ( ('\n')* | compound_list )