blob: 624801b60c0c1d28a4e8107bf23ffb1e72e97d32 (
plain)
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
|
#include <iostream>
#include <wchar.h>
#include "Expressions.hpp"
using namespace std;
COMPILER Query
private:
Expression *expressions;
public:
Expression *getExpressions( ) {
return expressions;
}
CHARACTERS
letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".
digit = "0123456789".
cr = '\r'.
lf = '\n'.
tab = '\t'.
TOKENS
ident = letter { letter | digit }.
COMMENTS FROM "/*" TO "*/" NESTED
IGNORE cr + lf + tab
PRODUCTIONS
Query (. expressions = 0; .)
=
[ BinaryExpr<expressions> ]
EOF
.
BinaryExpr<Expression *&expr> (. expr = 0; Expression *right = 0; .)
=
NotExpr<expr> { (. bool is_and; .)
(
"OR" (. is_and = false; .)
| "AND" (. is_and = true; .)
)
NotExpr<right> (.
if( is_and ) {
expr = new AndExpression( expr, right );
} else {
expr = new OrExpression( expr, right );
}
.)
}
.
NotExpr<Expression *&expr> (. expr = 0; int nots = 0; .)
=
{
"NOT" (. nots++; .)
}
(
"(" BinaryExpr<expr> ")"
|
ident (.
char *ident = coco_string_create_char( t->val );
expr = new Predicate( ident );
coco_string_delete( ident ); .)
) (.
for( int i = 0; i < nots; ++i ) {
expr = new NotExpression( expr );
}
.)
.
END Query.
|