Fixed newline characters throughout the code
[com/gs-lite.git] / src / ftacmp / ifq.y
1 /* ------------------------------------------------
2 Copyright 2014 AT&T Intellectual Property
3    Licensed under the Apache License, Version 2.0 (the "License");
4    you may not use this file except in compliance with the License.
5    You may obtain a copy of the License at
6
7      http://www.apache.org/licenses/LICENSE-2.0
8
9    Unless required by applicable law or agreed to in writing, software
10    distributed under the License is distributed on an "AS IS" BASIS,
11    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12    See the License for the specific language governing permissions and
13    limitations under the License.
14  ------------------------------------------- */
15
16 /*
17         MUST COMPILE WITH
18                 bison --verbose --defines=ifq.tab.cc.h -p IfqParser  -o ifq.tab.cc ifq.y
19
20          (or equivalent).
21 */
22
23 %{
24
25
26 #include <stdio.h>
27
28 /*              Some addn'l includes, necessary but not included by the
29                 bison generated code.
30 */
31
32 #include <stdlib.h>
33
34 /*              prototypes for the parser callbacks.
35 */
36
37 #include "parse_fta.h"
38
39
40 extern fta_parse_t *ifq_parse_result;
41
42
43 #define YYDEBUG 1
44
45 %}
46
47
48         /* symbolic tokens */
49
50 %union {
51         int intval;
52         double floatval;
53         char *strval;
54         int subtok;
55
56 /*                      for FTA definition.     */
57         literal_t *litval;
58         scalarexp_t *scalarval;
59         se_list_t *se_listval;
60         select_list_t *select_listval;
61         table_exp_t *tblp;
62         predicate_t *predp;
63         literal_list_t *lit_l;
64         tablevar_t *table;
65         tablevar_list_t *tbl_list;
66         colref_t *colref;
67         colref_list_t *clist;
68         var_defs_t *var_defs;
69         var_pair_t *var_pair;
70         gb_t *gb_val;
71         gb_list_t *gb_list;
72
73         query_list_t *q_list;
74
75
76 }
77
78 %token <strval> NAME
79 %token <strval> PRED
80 %token <strval> STRING_TOKEN
81 %token <strval> INTNUM
82 %token <strval> LONGINTNUM
83 %token <strval> APPROXNUM
84
85 /*                      for FTA definition.     */
86 %type <q_list> query_list
87 %type <tblp> gsql
88 %type <tblp> select_statement
89 %type <tblp> table_exp
90 %type <predp> where_clause
91 %type <predp> search_condition
92 %type <predp> predicate
93 %type <litval> literal
94 %type <scalarval> scalar_exp
95 %type <se_listval> scalar_exp_commalist
96
97
98
99
100
101         /* operators */
102
103 %left OR
104 %left AND
105 %left NOT
106
107         /* literal keyword tokens */
108 %token  SEMICOLON LEFTBRACE RIGHTBRACE
109 /*              For query definition    */
110 %token BY AS
111 %token <strval> AGGR
112 %token FROM INNER_JOIN OUTER_JOIN LEFT_OUTER_JOIN RIGHT_OUTER_JOIN
113 %token GROUP HAVING IN
114 %token SELECT
115 %token WHERE
116 %token SUCH THAT
117
118 %token TRUE_V FALSE_V
119 %token TIMEVAL_L HEX_L LHEX_L IP_L
120 %token  MERGE SLACK
121
122 %token DEFINE_SEC PARAM_SEC
123
124 /*              For table definition    */
125 %token RIGHTBRACE PROTOCOL TABLE STREAM FTA
126 %token OPERATOR OPERATOR_VIEW FIELDS SUBQUERIES SELECTION_PUSHDOWN
127
128
129 %%
130
131 /*                      Union of possible results       */
132 parse_result:   query_list      {
133                 ifq_parse_result->parse_tree_list = $1;
134                 ifq_parse_result->tables = NULL;
135                 ifq_parse_result->parse_type = QUERY_PARSE;
136         }
137         ;
138
139
140
141 /*              Query definition.
142                 WARNING: there might be some relics.
143 */
144
145 gsql:   NAME ':' select_statement {
146                                 $$ = $3; $$->nmap["name"] = $1;
147                         }
148         ;
149
150 query_list:     gsql    {$$ = new query_list_t($1);}
151         |       query_list SEMICOLON gsql       {$$ = $1->append($3);}
152         ;
153
154
155 select_statement:
156                 table_exp       {$$ = $1;}
157         ;
158
159
160         /* query expressions */
161
162
163
164 table_exp:
165                 where_clause {$$=new table_exp_t(NULL,$1,NULL,NULL,NULL,NULL,NULL,NULL);}
166         ;
167
168
169
170 where_clause:
171                 search_condition        {$$ = $1;}
172         ;
173
174
175
176         /* search conditions */
177
178 search_condition:
179                 search_condition OR search_condition  {$$=new predicate_t("OR",$1,$3);}
180         |       search_condition AND search_condition {$$=new predicate_t("AND",$1,$3);}
181         |       NOT search_condition    {$$ = new predicate_t("NOT", $2 );}
182         |       '(' search_condition ')' {$$ = $2;}
183         |       predicate {$$ = $1;}
184         ;
185
186 predicate:
187                 PRED '[' scalar_exp_commalist ']' {$$ = new predicate_t($1, $3->get_se_list()); }
188         ;
189
190
191         /* scalar expressions */
192
193 scalar_exp:
194                 literal { $$= scalarexp_t::make_param_reference($1->to_string().c_str());}
195         |       NAME {$$ = scalarexp_t::make_param_reference($1);}
196         ;
197
198
199 scalar_exp_commalist:
200                 scalar_exp      {       $$= new se_list_t($1); }
201         |       scalar_exp_commalist ',' scalar_exp     { $$=$1->append($3); }
202         ;
203
204 literal:
205                 STRING_TOKEN    {$$ = new literal_t($1,LITERAL_STRING);}
206         |       INTNUM          {$$ = new literal_t($1,LITERAL_INT);}
207         |       LONGINTNUM              {$$ = new literal_t($1,LITERAL_LONGINT);}
208         |       APPROXNUM       {$$ = new literal_t($1,LITERAL_FLOAT);}
209         |       TRUE_V          {$$ = new literal_t("TRUE",LITERAL_BOOL);}
210         |       FALSE_V         {$$ = new literal_t("FALSE",LITERAL_BOOL);}
211         |       TIMEVAL_L STRING_TOKEN  {$$ = new literal_t($2,LITERAL_TIMEVAL);}
212         |       HEX_L  STRING_TOKEN     {$$ = new literal_t($2,LITERAL_HEX);}
213         |       LHEX_L  STRING_TOKEN    {$$ = new literal_t($2,LITERAL_LONGHEX);}
214         |       IP_L  STRING_TOKEN      {$$ = new literal_t($2,LITERAL_IP);}
215         ;
216
217
218
219 %%
220