forked from XinShuoWang/FilterTree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter.y
174 lines (148 loc) · 3.56 KB
/
filter.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
%{
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "ast.h"
#include "debug.h"
int yydebug=0;
extern int yylex();
extern struct Value* val;
void yyerror(const char* s) {
fprintf(stderr, "Parse error: %s\n", s);
exit(1);
}
%}
%token<ival> T_INT
%token<fval> T_FLOAT
%token<sval> T_PARAMETER
%token T_LEFT_BRACKET T_RIGHT_BRACKET T_COMMA T_COLON
%token T_AND T_OR
%token T_LESS T_LESS_OR_EQUAL T_EQUAL T_NOT_EQUAL T_GREATER T_GREATER_OR_EQUAL
%token T_TO_YEAR
%type<val> filter hyper logic judge func param
%start filter
%union {
int ival;
float fval;
char* sval;
struct Value* val;
}
%%
filter : logic
{
val = $1;
}
;
logic : T_AND T_LEFT_BRACKET hyper T_RIGHT_BRACKET
{
struct Value* p = new_value(AND);
append_child(p, $3);
$$ = p;
INFO("and filter \n");
}
| T_OR T_LEFT_BRACKET hyper T_RIGHT_BRACKET
{
struct Value* p = new_value(OR);
append_child(p, $3);
$$ = p;
INFO("or filter \n");
}
;
hyper : judge T_COMMA hyper
{
append_child($$, $3);
}
| logic T_COMMA hyper
{
append_child($$, $3);
}
| judge
{
$$ = $1;
}
| logic
{
$$ = $1;
}
judge : T_LESS T_LEFT_BRACKET func T_COMMA func T_RIGHT_BRACKET
{
struct Value* p = new_value(LESS);
append_child(p, $3);
append_child(p, $5);
$$ = p;
INFO("less \n");
}
| T_LESS_OR_EQUAL T_LEFT_BRACKET func T_COMMA func T_RIGHT_BRACKET
{
struct Value* p = new_value(LESS_OR_EQUAL);
append_child(p, $3);
append_child(p, $5);
$$ = p;
INFO("less or equal \n");
}
| T_EQUAL T_LEFT_BRACKET func T_COMMA func T_RIGHT_BRACKET
{
struct Value* p = new_value(EQUAL);
append_child(p, $3);
append_child(p, $5);
$$ = p;
INFO("equal \n");
}
| T_NOT_EQUAL T_LEFT_BRACKET func T_COMMA func T_RIGHT_BRACKET
{
struct Value* p = new_value(NOT_EQUAL);
append_child(p, $3);
append_child(p, $5);
$$ = p;
INFO("not equal \n");
}
| T_GREATER T_LEFT_BRACKET func T_COMMA func T_RIGHT_BRACKET
{
struct Value* p = new_value(GREATER);
append_child(p, $3);
append_child(p, $5);
$$ = p;
INFO("greater \n");
}
| T_GREATER_OR_EQUAL T_LEFT_BRACKET func T_COMMA func T_RIGHT_BRACKET
{
struct Value* p = new_value(GREATER_OR_EQUAL);
append_child(p, $3);
append_child(p, $5);
$$ = p;
INFO("greater or equal \n");
}
;
func : T_TO_YEAR T_LEFT_BRACKET param T_RIGHT_BRACKET
{
struct Value* p = new_value(TO_YEAR);
append_child(p, $3);
$$ = p;
INFO("toyear \n");
}
| param
{
$$ = $1;
INFO("param \n");
}
;
param : T_INT
{
struct Value* p = new_int_value($1);
$$ = p;
INFO("int %d \n", $1);
}
| T_FLOAT
{
struct Value* p = new_float_value($1);
$$ = p;
INFO("float %f \n", $1);
}
| T_PARAMETER
{
struct Value* p = new_string_value($1, strlen($1));
$$ = p;
INFO("col name %s \n", $1);
}
;
%%