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
7 http://www.apache.org/licenses/LICENSE-2.0
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 ------------------------------------------- */
19 flex -PFtaParser -oftalexer.cc fta.l
25 * AT&T lex can't handle this lexer due to lex bugs. It works with flex
26 * 2.3.7, pclex 2.0.5, and MKS lex 3.1a.
29 #include "parse_fta.h"
30 #include "parse_schema.h"
35 #include "fta.tab.cc.h"
38 Some includes that flex doesn't include as standard,
46 // Prevent flex from defining yywrap as extern "C"
48 #define YY_SKIP_YYWRAP
50 /* No lex lib, supply the yywrap fcn. that normally resides there
53 int FtaParserwrap(){return(1);}
55 extern int FtaParserdebug;
59 These variables are used for error reporting:
60 flex_fta_lineno : the line currently being parsed when the error occurs.
61 flex_fta_ch : the character on the line where the error occurs
62 flex_fta_linebuf : store the line for reporting.
64 NOTE : 1) the fixed size flex_fta_linebuf buffer is dangerous.
65 2) You might get pointed to a place shortly after
66 where the syntax error occurs. It is close enough
70 int flex_fta_lineno = 1;
72 char flex_fta_linebuf[200000];
74 char *flex_fta_stringinput = NULL;
75 int flex_fta_stringinput_ptr = 0;
76 FILE *flex_fta_fileinput = NULL;
77 int my_FtaParser_yyinput(char *buf, int max_size);
81 void FtaParsererror(char *s){
83 fprintf(stderr,"On line %d, char %d: %s (token %s):\n%s\n",
84 flex_fta_lineno, flex_fta_ch, s, FtaParsertext, flex_fta_linebuf );
85 for(i=0;i<flex_fta_ch;i++){
86 if(flex_fta_linebuf[i] == '\t'){
92 fprintf(stderr,"^\n");
93 // fprintf(stderr,"%*s\n",1+flex_fta_ch,"^");
97 #define YY_INPUT(b, r, ms) (r = my_FtaParser_yyinput(b,ms))
100 /* MKS needs the next line to increase the NFA table */
106 /* literal keyword tokens */
109 The actions associated with each text token are to
110 keep track of the current location (for syntax error reporting)
111 and to report any necessary info to the emf.y parse tree builder
113 Its likely that there are a number of omissions, inconsistencies
114 (some keywords do not need to be in caps), and relics
115 (keywords such as BETWEEN, INDICATOR, etc., are not used
117 This parser is somewhat of a work in progress.
122 AND|And|and { flex_fta_ch+=FtaParserleng; return AND; }
123 AND_AGGR|And_Aggr|and_aggr { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup("AND_AGGR"); return AGGR; }
124 OR_AGGR|Or_Aggr|or_aggr { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup("OR_AGGR"); return AGGR; }
125 XOR_AGGR|Xor_Aggr|xor_aggr { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup("XOR_AGGR"); return AGGR; }
126 AVG|Avg|avg { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup("AVG"); return AGGR; }
127 MIN|Min|min { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup("MIN"); return AGGR; }
128 MAX|Max|max { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup("MAX"); return AGGR; }
129 SUM|Sum|sum { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup("SUM"); return AGGR; }
130 COUNT|Count|count { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup("COUNT"); return AGGR; }
131 BY|By|by { flex_fta_ch+=FtaParserleng; return BY; }
132 FROM|From|from { flex_fta_ch+=FtaParserleng; return FROM; }
133 INNER_JOIN|Inner_Join|inner_join { flex_fta_ch+=FtaParserleng; return INNER_JOIN; }
134 OUTER_JOIN|Outer_Join|outer_join { flex_fta_ch+=FtaParserleng; return OUTER_JOIN; }
135 RIGHT_OUTER_JOIN|Right_Outer_Join|right_outer_join { flex_fta_ch+=FtaParserleng; return RIGHT_OUTER_JOIN; }
136 LEFT_OUTER_JOIN|Left_Outer_Join|left_outer_join { flex_fta_ch+=FtaParserleng; return LEFT_OUTER_JOIN; }
137 FILTER_JOIN|Filter_Join|filter_join { flex_fta_ch+=FtaParserleng; return FILTER_JOIN; }
138 GROUP|Group|group { flex_fta_ch+=FtaParserleng; return GROUP; }
139 ROLLUP|Rollup|rollup { flex_fta_ch+=FtaParserleng; return ROLLUP; }
140 CUBE|Cube|cube { flex_fta_ch+=FtaParserleng; return CUBE; }
141 GROUPING_SETS|Grouping_Sets|grouping_sets { flex_fta_ch+=FtaParserleng; return GROUPING_SETS; }
142 SUPERGROUP|Supergroup|supergroup { flex_fta_ch+=FtaParserleng; return SUPERGROUP; }
143 CLEANING_WHEN|Cleaning_When|cleaning_when { flex_fta_ch+=FtaParserleng; return CLEANING_WHEN; }
144 CLEANING_BY|Cleaning_By|cleaning_by { flex_fta_ch+=FtaParserleng; return CLEANING_BY; }
145 CLOSING_WHEN|Closing_When|closing_when { flex_fta_ch+=FtaParserleng; return CLOSING_WHEN; }
146 HAVING|Having|having { flex_fta_ch+=FtaParserleng; return HAVING; }
147 AS|As|as { flex_fta_ch+=FtaParserleng; return AS; }
148 IN|In|in { flex_fta_ch+=FtaParserleng; return IN; }
149 NOT|Not|not { flex_fta_ch+=FtaParserleng; return NOT; }
150 OR|Or|or { flex_fta_ch+=FtaParserleng; return OR; }
152 SELECT|Select|select { flex_fta_ch+=FtaParserleng; return SELECT; }
153 WHERE|Where|where { flex_fta_ch+=FtaParserleng; return WHERE; }
154 SUCH|Such|such { flex_fta_ch+=FtaParserleng; return SUCH;}
155 THAT|That|that { flex_fta_ch+=FtaParserleng; return THAT;}
156 MERGE|Merge|merge {flex_fta_ch+=FtaParserleng; return MERGE;}
157 SLACK {flex_fta_ch+=FtaParserleng; return SLACK;}
159 TRUE { flex_fta_ch+=FtaParserleng; return TRUE_V;}
160 FALSE { flex_fta_ch+=FtaParserleng; return FALSE_V;}
161 TIMEVAL { flex_fta_ch+=FtaParserleng; return TIMEVAL_L;}
162 HEX { flex_fta_ch+=FtaParserleng; return HEX_L;}
163 LHEX { flex_fta_ch+=FtaParserleng; return LHEX_L;}
164 IP_VAL { flex_fta_ch+=FtaParserleng; return IP_L;}
165 IPV6_VAL|IPv6_VAL { flex_fta_ch+=FtaParserleng; return IPV6_L;}
167 DEFINE { flex_fta_ch+=FtaParserleng; return DEFINE_SEC;}
168 PARAM { flex_fta_ch+=FtaParserleng; return PARAM_SEC;}
170 [\{] {flex_fta_ch+=FtaParserleng; return LEFTBRACE;}
171 [\}] {flex_fta_ch+=FtaParserleng; return RIGHTBRACE;}
174 Table definition keywords
176 TABLE { flex_fta_ch+=FtaParserleng; return TABLE; }
177 PROTOCOL { flex_fta_ch+=FtaParserleng; return PROTOCOL; }
178 STREAM { flex_fta_ch+=FtaParserleng; return STREAM; }
179 FTA { flex_fta_ch+=FtaParserleng; return FTA; }
180 UNPACK_FCNS { flex_fta_ch+=FtaParserleng; return UNPACK_FCNS; }
182 OPERATOR { flex_fta_ch+=FtaParserleng; return OPERATOR; }
183 OPERATOR_VIEW { flex_fta_ch+=FtaParserleng; return OPERATOR_VIEW; }
184 FIELDS { flex_fta_ch+=FtaParserleng; return FIELDS; }
185 SUBQUERIES { flex_fta_ch+=FtaParserleng; return SUBQUERIES; }
186 SELECTION_PUSHDOWN { flex_fta_ch+=FtaParserleng; return SELECTION_PUSHDOWN; }
187 ; {flex_fta_ch+=FtaParserleng; return SEMICOLON;}
192 ">>" { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return SHIFT_OP; }
199 ">=" { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return COMPARISON; }
201 [%&|!+*/:(),.\[\]$@#] { flex_fta_ch+=FtaParserleng; return yytext[0]; }
202 "-" { flex_fta_ch+=FtaParserleng; return yytext[0]; }
203 "~" { flex_fta_ch+=FtaParserleng; return yytext[0]; }
207 [A-Za-z_][A-Za-z0-9_]* { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return NAME; }
212 [0-9]+UL { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return INTNUM; }
214 [0-9]+ULL { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return LONGINTNUM; }
218 [0-9]+[eE][+-]?[0-9]+ |
219 [0-9]+"."[0-9]*[eE][+-]?[0-9]+ |
220 "."[0-9]*[eE][+-]?[0-9]+ { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return APPROXNUM; }
228 FtaParserlval.strval = strdup(FtaParsertext+1);
232 unput(c); /* just peeking */
234 flex_fta_ch+=FtaParserleng;
235 FtaParserlval.strval[FtaParserleng-2] = '\0';
241 '[^'\n]*$ { flex_fta_ch+=FtaParserleng; FtaParsererror("Unterminated string"); }
244 /* Newline : advance the error reporting line number */
245 /* and grab the next line into flex_fta_linebuf */
248 \n.* {flex_fta_ch=0; flex_fta_lineno++;
249 strcpy(flex_fta_linebuf,FtaParsertext+1);
253 [ \t\r]+ {flex_fta_ch+=FtaParserleng; } /* white space */
255 "--".*$ {flex_fta_ch+=FtaParserleng; }; /* comment */
256 "//".*$ {flex_fta_ch+=FtaParserleng; }; /* comment */
258 .|\n {flex_fta_ch+=FtaParserleng; fprintf(stderr,"Warning: unknown token (ignored)\n"); FtaParsererror(yytext);}
262 int my_FtaParser_yyinput(char *buf, int max_size){
266 if(flex_fta_stringinput != NULL){
268 if(flex_fta_stringinput[flex_fta_stringinput_ptr] != '\0'){
269 buf[c++] = flex_fta_stringinput[flex_fta_stringinput_ptr++];
277 if(flex_fta_fileinput != NULL){
279 inchar = getc(flex_fta_fileinput);
292 void FtaParser_setfileinput(FILE *f){
293 FtaParserrestart(NULL);
295 flex_fta_fileinput = f;
296 flex_fta_stringinput = NULL;
301 void FtaParser_setstringinput(char *s){
302 FtaParserrestart(NULL);
304 flex_fta_fileinput = NULL;
305 flex_fta_stringinput = s;
306 flex_fta_stringinput_ptr = 0;