Skip to content
GRAMMAR 1.5 KiB
Newer Older
Seblu's avatar
Seblu committed
input:	  	list '\n'
		list EOF
Seblu's avatar
Seblu committed
list:		and_or ((';'|'&') and_or)* ['&'|';']
Seblu's avatar
Seblu committed
and_or:		pipeline (('&&'|'||') ('\n')* pipeline)*
Seblu's avatar
Seblu committed
pipeline:	['!'] command ('|' ('\n')* command)*

command:	  simple_command
		| shell_command  (redirection)*
Seblu's avatar
Seblu committed
		| funcdec
Seblu's avatar
Seblu committed
simple_command:	(cmp_prefix)* (element)+

shell_command:	'{' compound_list '}'
                | '(' compound_list ')'
                | rule_for
                | rule_while
                | rule_until
                | rule_case
                | rule_if

Seblu's avatar
Seblu committed
funcdec:	['function'] WORD '(' ')' ('\n')* shell_command (redirection)*
Seblu's avatar
Seblu committed
redirection:  [NUMBER] '>' WORD
		| [NUMBER] '<' WORD
		| [NUMBER] '>>' WORD
		| [NUMBER] '<<' WORD
		| [NUMBER] '<<-' WORD
		| [NUMBER] '>&' WORD
		| [NUMBER] '<&' WORD
		| [NUMBER] '>|' WORD
		| [NUMBER] '<>' WORD

cmd_prefix:	  ASSIGMENT_WORD
		| redirection

element:	  WORD
		| redirection

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

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

Seblu's avatar
Seblu committed
rule_case:	'case' WORD ('\n')* 'in' ('\n')* [case_clause] 'esac'
Seblu's avatar
Seblu committed
rule_if:  'if' compound_list 'then' compound_list [else_clause] 'fi'

else_clause:  'else' compound_list
		| 'elif' compound_list 'then' compound_list [else_clause]
Seblu's avatar
Seblu committed
do_group:	'do' compound_list 'done'
Seblu's avatar
Seblu committed
case_clause:	case_item (';;' (\n)* case_item)* [;;]
Seblu's avatar
Seblu committed
case_item:	['('] WORD ('|' WORD)* ')' ( ('\n')* | compound_list )