1 /* ------------------------------------------------
2 Copyright 2020 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 WATCHLIST_JOIN|Watchlist_Join|watchlist_join { flex_fta_ch+=FtaParserleng; return WATCHLIST_JOIN; }
138 FILTER_JOIN|Filter_Join|filter_join { flex_fta_ch+=FtaParserleng; return FILTER_JOIN; }
139 GROUP|Group|group { flex_fta_ch+=FtaParserleng; return GROUP; }
140 ROLLUP|Rollup|rollup { flex_fta_ch+=FtaParserleng; return ROLLUP; }
141 CUBE|Cube|cube { flex_fta_ch+=FtaParserleng; return CUBE; }
142 GROUPING_SETS|Grouping_Sets|grouping_sets { flex_fta_ch+=FtaParserleng; return GROUPING_SETS; }
143 SUPERGROUP|Supergroup|supergroup { flex_fta_ch+=FtaParserleng; return SUPERGROUP; }
144 CLEANING_WHEN|Cleaning_When|cleaning_when { flex_fta_ch+=FtaParserleng; return CLEANING_WHEN; }
145 CLEANING_BY|Cleaning_By|cleaning_by { flex_fta_ch+=FtaParserleng; return CLEANING_BY; }
146 CLOSING_WHEN|Closing_When|closing_when { flex_fta_ch+=FtaParserleng; return CLOSING_WHEN; }
147 HAVING|Having|having { flex_fta_ch+=FtaParserleng; return HAVING; }
148 AS|As|as { flex_fta_ch+=FtaParserleng; return AS; }
149 IN|In|in { flex_fta_ch+=FtaParserleng; return IN; }
150 NOT|Not|not { flex_fta_ch+=FtaParserleng; return NOT; }
151 OR|Or|or { flex_fta_ch+=FtaParserleng; return OR; }
153 SELECT|Select|select { flex_fta_ch+=FtaParserleng; return SELECT; }
154 WHERE|Where|where { flex_fta_ch+=FtaParserleng; return WHERE; }
155 SUCH|Such|such { flex_fta_ch+=FtaParserleng; return SUCH;}
156 THAT|That|that { flex_fta_ch+=FtaParserleng; return THAT;}
157 MERGE|Merge|merge {flex_fta_ch+=FtaParserleng; return MERGE;}
158 SLACK {flex_fta_ch+=FtaParserleng; return SLACK;}
159 WATCHLIST|Watchlist|watchlist {flex_fta_ch+=FtaParserleng; return WATCHLIST;}
161 TRUE { flex_fta_ch+=FtaParserleng; return TRUE_V;}
162 FALSE { flex_fta_ch+=FtaParserleng; return FALSE_V;}
163 TIMEVAL { flex_fta_ch+=FtaParserleng; return TIMEVAL_L;}
164 HEX { flex_fta_ch+=FtaParserleng; return HEX_L;}
165 LHEX { flex_fta_ch+=FtaParserleng; return LHEX_L;}
166 IP_VAL { flex_fta_ch+=FtaParserleng; return IP_L;}
167 IPV6_VAL|IPv6_VAL { flex_fta_ch+=FtaParserleng; return IPV6_L;}
169 DEFINE { flex_fta_ch+=FtaParserleng; return DEFINE_SEC;}
170 PARAM { flex_fta_ch+=FtaParserleng; return PARAM_SEC;}
172 [\{] {flex_fta_ch+=FtaParserleng; return LEFTBRACE;}
173 [\}] {flex_fta_ch+=FtaParserleng; return RIGHTBRACE;}
176 Table definition keywords
178 TABLE { flex_fta_ch+=FtaParserleng; return TABLE; }
179 PROTOCOL { flex_fta_ch+=FtaParserleng; return PROTOCOL; }
180 STREAM { flex_fta_ch+=FtaParserleng; return STREAM; }
181 FTA { flex_fta_ch+=FtaParserleng; return FTA; }
182 UNPACK_FCNS { flex_fta_ch+=FtaParserleng; return UNPACK_FCNS; }
184 OPERATOR { flex_fta_ch+=FtaParserleng; return OPERATOR; }
185 OPERATOR_VIEW { flex_fta_ch+=FtaParserleng; return OPERATOR_VIEW; }
186 FIELDS { flex_fta_ch+=FtaParserleng; return FIELDS; }
187 SUBQUERIES { flex_fta_ch+=FtaParserleng; return SUBQUERIES; }
188 SELECTION_PUSHDOWN { flex_fta_ch+=FtaParserleng; return SELECTION_PUSHDOWN; }
189 ; {flex_fta_ch+=FtaParserleng; return SEMICOLON;}
194 ">>" { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return SHIFT_OP; }
201 ">=" { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return COMPARISON; }
203 [%&|!+*/:(),.\[\]$@#] { flex_fta_ch+=FtaParserleng; return yytext[0]; }
204 "-" { flex_fta_ch+=FtaParserleng; return yytext[0]; }
205 "~" { flex_fta_ch+=FtaParserleng; return yytext[0]; }
209 [A-Za-z_][A-Za-z0-9_]* { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return NAME; }
214 [0-9]+UL { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return INTNUM; }
216 [0-9]+ULL { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return LONGINTNUM; }
220 [0-9]+[eE][+-]?[0-9]+ |
221 [0-9]+"."[0-9]*[eE][+-]?[0-9]+ |
222 "."[0-9]+[eE][+-]?[0-9]+ { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return APPROXNUM; }
230 FtaParserlval.strval = strdup(FtaParsertext+1);
234 unput(c); /* just peeking */
236 flex_fta_ch+=FtaParserleng;
237 FtaParserlval.strval[FtaParserleng-2] = '\0';
243 '[^'\n]*$ { flex_fta_ch+=FtaParserleng; FtaParsererror("Unterminated string"); }
246 /* Newline : advance the error reporting line number */
247 /* and grab the next line into flex_fta_linebuf */
250 \n.* {flex_fta_ch=0; flex_fta_lineno++;
251 strcpy(flex_fta_linebuf,FtaParsertext+1);
255 [ \t\r]+ {flex_fta_ch+=FtaParserleng; } /* white space */
257 "--".*$ {flex_fta_ch+=FtaParserleng; }; /* comment */
258 "//".*$ {flex_fta_ch+=FtaParserleng; }; /* comment */
260 .|\n {flex_fta_ch+=FtaParserleng; fprintf(stderr,"Warning: unknown token (ignored)\n"); FtaParsererror(yytext);}
264 int my_FtaParser_yyinput(char *buf, int max_size){
268 if(flex_fta_stringinput != NULL){
270 if(flex_fta_stringinput[flex_fta_stringinput_ptr] != '\0'){
271 buf[c++] = flex_fta_stringinput[flex_fta_stringinput_ptr++];
279 if(flex_fta_fileinput != NULL){
281 inchar = getc(flex_fta_fileinput);
294 void FtaParser_setfileinput(FILE *f){
295 FtaParserrestart(NULL);
297 flex_fta_fileinput = f;
298 flex_fta_stringinput = NULL;
303 void FtaParser_setstringinput(char *s){
304 FtaParserrestart(NULL);
306 flex_fta_fileinput = NULL;
307 flex_fta_stringinput = s;
308 flex_fta_stringinput_ptr = 0;