-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparser.y
More file actions
60 lines (50 loc) · 1.15 KB
/
parser.y
File metadata and controls
60 lines (50 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
%{
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "interpreter.h"
#include "util.h"
%}
%union {
char* str;
int d;
CMD* cmd;
CMD** cmds;
}
%token <str> WORD
%token PIPE
%token EOL
%type <cmd> command
%type <cmds> sequence
%%
seqlist:
| seqlist sequence EOL {
CMD** seq = $2;
pipe_commands(seq);
char* current_dir = get_current_dir();
printf("(%s (EGG> ", current_dir);
}
;
sequence: sequence PIPE command { CMD** pointer = $1;
while(*pointer != NULL) {
pointer++;
}
*pointer = $3;
$$ = $1;
}
| command { CMD** out = calloc(256, sizeof(CMD*)); out[0] = $1; $$ = out; }
;
command: command WORD { cmd_append($1, $2); $$ = $1; free($2); }
| WORD { CMD* out = cmd_init($1); $$ = out; free($1); }
;
%%
int main(int argc, char** argv) {
system("clear");
char* current_dir = get_current_dir();
printf("(%s (EGG> ", current_dir);
yyparse();
return 0;
}
void yyerror(char *s) {
fprintf(stderr, "error: %s\n", s);
}