-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.y
More file actions
78 lines (65 loc) · 1.15 KB
/
Copy pathshell.y
File metadata and controls
78 lines (65 loc) · 1.15 KB
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
%{
#include "parsetypes.h"
#include "error.h"
extern int yylex();
root_t cmds_root;
int parse_error;
%}
%token <str> STR
%type <cmd> cmd
%type <cmds> cmds
%type <root> root
%union {
char* str;
cmd_t cmd;
cmds_t cmds;
root_t root;
}
%left '<' '>' '|'
%nonassoc '&'
%%
root : cmds '&' {
$$ = (root_t) {$1, 1};
cmds_root = $$;
}
| cmds {
$$ = (root_t) {$1, 0};
cmds_root = $$;
}
| {
$$ = (root_t) { {NULL, NULL}, 0};
cmds_root = $$;
}
;
cmds : cmd {
$$ = (cmds_t) {NULL, NULL};
add_cmd(&$$, &$1);
}
| cmds '|' cmd {
add_cmd(&$1, &$3);
$$ = $1;
}
;
cmd : STR {
$$ = (cmd_t) {$1, NULL, NULL, NULL, NULL, 0};
}
| cmd '<' STR {
$1.infile = $3;
$$ = $1;
}
| cmd '>' STR {
$1.outfile = $3;
$$ = $1;
}
| cmd STR {
add_arg(&$1, $2);
$$ = $1;
}
;
%%
void yyerror(const char* msg) {
error("parse error");
// FIXME Allocated memory won't be freed.
// Support better error handling.
parse_error = 1;
}