-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathriba.y
87 lines (61 loc) · 1.78 KB
/
riba.y
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
79
80
81
82
83
84
85
86
87
%{
#include <stdio.h>
#include <string.h>
#include "riba.h"
#define YYSTYPE char*
// External Declarations
extern int yylex(void);
// Parser error handler
void yyerror(const char* error)
{
fprintf(stderr, "%s\n", error);
}
extern "C" {
int yywrap()
{
return 1;
}
}
%}
%token R_NEWLINE R_NUMBER R_BYTES R_QWORD R_COMMA R_SQUOTE R_EQ
R_CMD_OPEN R_CMD_CLOSE R_CMD_GET R_CMD_PUT R_CMD_DELETE
R_CMD_BATCH R_CMD_COMMIT R_CMD_SNAP R_CMD_UNSNAP R_CMD_PRINT
R_CMD_COMPACT R_CMD_COUNT R_CMD_HELP R_CMD_ABOUT R_CMD_EXIT
%%
commands:
| commands command R_NEWLINE
;
command:
| open_command
| close_command
| get_command
| put_command
| delete_command
| batch_command
| commit_command
| snap_command
| unsnap_command
| print_command
| compact_command
| count_command
| help_command
| about_command
| exit_command
;
open_command: R_CMD_OPEN R_QWORD { leveldb_open($2); free($2); }
close_command: R_CMD_CLOSE { leveldb_close(); }
get_command: R_CMD_GET ptype { leveldb_get($2); free($2); }
put_command: R_CMD_PUT ptype ptype { leveldb_put($2, $3); free($2); free($3); }
delete_command: R_CMD_DELETE ptype { leveldb_delete($2); free($2); }
batch_command: R_CMD_BATCH { leveldb_start_batch(); }
commit_command: R_CMD_COMMIT { leveldb_commit_batch(); }
snap_command: R_CMD_SNAP { leveldb_snap(); }
unsnap_command: R_CMD_UNSNAP { leveldb_unsnap(); }
print_command: R_CMD_PRINT { leveldb_print(); }
compact_command: R_CMD_COMPACT { leveldb_compact(); }
count_command: R_CMD_COUNT { leveldb_count(); }
help_command: R_CMD_HELP { leveldb_help(); }
about_command: R_CMD_ABOUT { leveldb_about(); }
exit_command: R_CMD_EXIT { leveldb_exit(); }
ptype: R_NUMBER | R_BYTES | R_QWORD
%%