-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsphinxselect.y
87 lines (75 loc) · 2.36 KB
/
sphinxselect.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
%{
#if USE_WINDOWS
#pragma warning(push,1)
#pragma warning(disable:4702) // unreachable code
#endif
%}
%lex-param { SelectParser_t * pParser }
%parse-param { SelectParser_t * pParser }
%pure-parser
%error-verbose
%token SEL_TOKEN
%token SEL_AS
%token SEL_AVG
%token SEL_MAX
%token SEL_MIN
%token SEL_SUM
%token TOK_NEG
%token TOK_LTE
%token TOK_GTE
%token TOK_EQ
%token TOK_NE
%left TOK_AND TOK_OR
%left TOK_EQ TOK_NE
%left '<' '>' TOK_LTE TOK_GTE
%left '+' '-'
%left '*' '/'
%nonassoc TOK_NEG
%nonassoc TOK_NOT
%%
select_list:
select_item
| select_list ',' select_item
;
select_item:
expr { pParser->AddItem ( &$1, NULL ); }
| expr SEL_AS SEL_TOKEN { pParser->AddItem ( &$1, &$3 ); }
| '*' { pParser->AddItem ( &$1, NULL ); }
| SEL_AVG '(' expr ')' SEL_AS SEL_TOKEN { pParser->AddItem ( &$3, &$6, SPH_AGGR_AVG ); }
| SEL_MAX '(' expr ')' SEL_AS SEL_TOKEN { pParser->AddItem ( &$3, &$6, SPH_AGGR_MAX ); }
| SEL_MIN '(' expr ')' SEL_AS SEL_TOKEN { pParser->AddItem ( &$3, &$6, SPH_AGGR_MIN ); }
| SEL_SUM '(' expr ')' SEL_AS SEL_TOKEN { pParser->AddItem ( &$3, &$6, SPH_AGGR_SUM ); }
;
expr:
SEL_TOKEN
| '-' expr %prec TOK_NEG { $$ = $1; $$.m_iEnd = $2.m_iEnd; }
| TOK_NOT expr { $$ = $1; $$.m_iEnd = $2.m_iEnd; }
| expr '+' expr { $$ = $1; $$.m_iEnd = $3.m_iEnd; }
| expr '-' expr { $$ = $1; $$.m_iEnd = $3.m_iEnd; }
| expr '*' expr { $$ = $1; $$.m_iEnd = $3.m_iEnd; }
| expr '/' expr { $$ = $1; $$.m_iEnd = $3.m_iEnd; }
| expr '<' expr { $$ = $1; $$.m_iEnd = $3.m_iEnd; }
| expr '>' expr { $$ = $1; $$.m_iEnd = $3.m_iEnd; }
| expr TOK_LTE expr { $$ = $1; $$.m_iEnd = $3.m_iEnd; }
| expr TOK_GTE expr { $$ = $1; $$.m_iEnd = $3.m_iEnd; }
| expr TOK_EQ expr { $$ = $1; $$.m_iEnd = $3.m_iEnd; }
| expr TOK_NE expr { $$ = $1; $$.m_iEnd = $3.m_iEnd; }
| expr TOK_AND expr { $$ = $1; $$.m_iEnd = $3.m_iEnd; }
| expr TOK_OR expr { $$ = $1; $$.m_iEnd = $3.m_iEnd; }
| '(' expr ')' { $$ = $1; $$.m_iEnd = $3.m_iEnd; }
| function
;
function:
SEL_TOKEN '(' arglist ')' { $$ = $1; $$.m_iEnd = $4.m_iEnd; }
| SEL_TOKEN '(' ')' { $$ = $1; $$.m_iEnd = $3.m_iEnd }
| SEL_MIN '(' expr ',' expr ')' { $$ = $1; $$.m_iEnd = $6.m_iEnd } // handle clash with aggregate functions
| SEL_MAX '(' expr ',' expr ')' { $$ = $1; $$.m_iEnd = $6.m_iEnd }
;
arglist:
expr
| arglist ',' expr
;
%%
#if USE_WINDOWS
#pragma warning(pop)
#endif