forked from jbrinksma/codam-42sh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar
51 lines (33 loc) · 1.48 KB
/
grammar
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
/*----------------------------------*/
/* TOKENS */
/*----------------------------------*/
%token WORD
%token ASSIGNMENT_WORD
%token IO_NUMBER
%token SEMICOLON BG
/* ';' '&' */
%token AND_IF OR_IF
/* '&&' '||' */
%token PIPE
/* '|' */
%token SLESS SGREAT DLESS DGREAT LESSAND GREATAND
/* '<' '>' '<<' '>>' '<&' '>&' */
/*----------------------------------*/
/* GRAMMAR */
/*----------------------------------*/
%start complete_command
%%
complete_command ::= list
list ::= and_or [separator_op and_or]* separator_op?
and_or ::= pipe_sequence [[AND_IF | OR_IF] pipe_sequence]*
pipe_sequence ::= command [PIPE command]*
command ::= [cmd_prefix [cmd_word [cmd_suffix]?]?] | [cmd_word cmd_suffix?]
cmd_prefix ::= [io_redirect | ASSIGNMENT_WORD]*
io_redirect ::= IO_NUMBER? [io_file | io_here]
io_file ::= [SLESS | SGREAT | LESSAND | GREATAND | DGREAT] filename
filename ::= WORD
io_here ::= DLESS here_end
here_end ::= WORD
cmd_word ::= WORD
cmd_suffix ::= [io_redirect | WORD]*
separator_op ::= BG | SEMICOLON