Added quantiling UDAFs
[com/gs-lite.git] / src / ftacmp / ifq.l
1 /* ------------------------------------------------\r
2 Copyright 2014 AT&T Intellectual Property\r
3    Licensed under the Apache License, Version 2.0 (the "License");\r
4    you may not use this file except in compliance with the License.\r
5    You may obtain a copy of the License at\r
6 \r
7      http://www.apache.org/licenses/LICENSE-2.0\r
8 \r
9    Unless required by applicable law or agreed to in writing, software\r
10    distributed under the License is distributed on an "AS IS" BASIS,\r
11    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12    See the License for the specific language governing permissions and\r
13    limitations under the License.\r
14  ------------------------------------------- */\r
15 \r
16 \r
17 /*\r
18         MUST COMPILE WITH\r
19                 flex -PIfqParser -oifqlexer.cc ifq.l\r
20         (or equivalent).\r
21 */      \r
22 \r
23 %{\r
24 /*\r
25  * AT&T lex can't handle this lexer due to lex bugs.  It works with flex\r
26  * 2.3.7, pclex 2.0.5, and MKS lex 3.1a.\r
27  */\r
28 \r
29  #include "parse_fta.h"\r
30  #include <string.h>\r
31 \r
32 \r
33 \r
34 #include "ifq.tab.cc.h"\r
35 \r
36 /*\r
37         Some includes that flex doesn't include as standard,\r
38         but which are needed.\r
39 */\r
40 \r
41 #include <stdlib.h>\r
42 #include <string.h>\r
43 \r
44 \r
45 //              Prevent flex from defining yywrap as extern "C" \r
46 \r
47 #define YY_SKIP_YYWRAP\r
48 \r
49 /*              No lex lib, supply the yywrap fcn. that normally resides there\r
50 */\r
51 \r
52 int IfqParserwrap(){return(1);}\r
53 \r
54 extern int IfqParserdebug;\r
55 \r
56 \r
57 /*\r
58                 These variables are used for error reporting:\r
59                 flex_ifq_lineno : the line currently being parsed when the error occurs.\r
60                 flex_ifq_ch : the character on the line where the error occurs\r
61                 flex_ifq_linebuf : store the line for reporting.\r
62 \r
63                 NOTE : 1) the fixed size flex_ifq_linebuf buffer is dangerous.\r
64                            2) You might get pointed to a place shortly after\r
65                                   where the syntax error occurs.  It is close enough\r
66                                   for now.\r
67 */\r
68 \r
69 int flex_ifq_lineno = 1;\r
70 int flex_ifq_ch = 0;\r
71 char flex_ifq_linebuf[20000];\r
72 \r
73 char *flex_ifq_stringinput = NULL;\r
74 int flex_ifq_stringinput_ptr = 0;\r
75 FILE *flex_ifq_fileinput = NULL;\r
76 int my_IfqParser_yyinput(char *buf, int max_size);\r
77 \r
78 \r
79 \r
80 void IfqParsererror(char *s){\r
81         int i;\r
82         fprintf(stderr,"On line %d, char %d: %s (token %s):\n%s\n",\r
83                                 flex_ifq_lineno, flex_ifq_ch, s, IfqParsertext, flex_ifq_linebuf );\r
84     for(i=0;i<flex_ifq_ch;i++){\r
85                 if(flex_ifq_linebuf[i] == '\t'){\r
86                         fprintf(stderr,"\t");\r
87                 }else{\r
88                         fprintf(stderr," ");\r
89                 }\r
90         }\r
91         fprintf(stderr,"^\n");\r
92         //      fprintf(stderr,"%*s\n",1+flex_ifq_ch,"^");\r
93 }\r
94 \r
95 #undef YY_INPUT\r
96 #define YY_INPUT(b, r, ms) (r = my_IfqParser_yyinput(b,ms))\r
97 \r
98 %}\r
99         /* MKS needs the next line to increase the NFA table */\r
100 %e 1200\r
101 %option noyywrap\r
102 \r
103 %%\r
104 \r
105         /* literal keyword tokens */\r
106 \r
107  /*\r
108                         The actions associated with each text token are to\r
109                         keep track of the current location (for syntax error reporting)\r
110                         and to report any necessary info to the emf.y parse tree builder\r
111 \r
112                         Its likely that there are a number of omissions, inconsistencies\r
113                         (some keywords do not need to be in caps), and relics\r
114                         (keywords such as BETWEEN, INDICATOR, etc., are not used\r
115                          in emf.y)\r
116                         This parser is somewhat of a work in progress.\r
117  */\r
118 \r
119  /*             Query keywords          */\r
120 \r
121 AND|And|and             { flex_ifq_ch+=IfqParserleng; return AND; }\r
122 NOT|Not|not             { flex_ifq_ch+=IfqParserleng; return NOT; }\r
123 OR|Or|or        { flex_ifq_ch+=IfqParserleng; return OR; }\r
124 \r
125 TRUE    { flex_ifq_ch+=IfqParserleng; return TRUE_V;}\r
126 FALSE   { flex_ifq_ch+=IfqParserleng; return FALSE_V;}\r
127 \r
128 Contains|Equals|Exists  {flex_ifq_ch+=IfqParserleng; IfqParserlval.strval = strdup(yytext); return PRED; }\r
129 \r
130 ;               {flex_ifq_ch+=IfqParserleng; return SEMICOLON;}\r
131 \r
132 \r
133 \r
134 [&|!+*/:(),.\[\]$]      { flex_ifq_ch+=IfqParserleng; return yytext[0]; }\r
135 "-"     { flex_ifq_ch+=IfqParserleng; return yytext[0]; }\r
136 "~"     { flex_ifq_ch+=IfqParserleng; return yytext[0]; }\r
137 \r
138         /* names */\r
139 \r
140 [A-Za-z_][A-Za-z0-9_]*  { flex_ifq_ch+=IfqParserleng; IfqParserlval.strval = strdup(yytext); return NAME; }\r
141 \r
142         /* numbers */\r
143 \r
144 [0-9]+  |\r
145 [0-9]+UL        { flex_ifq_ch+=IfqParserleng; IfqParserlval.strval = strdup(yytext);  return INTNUM; }\r
146 \r
147 [0-9]+ULL       { flex_ifq_ch+=IfqParserleng; IfqParserlval.strval = strdup(yytext);  return LONGINTNUM; }\r
148 \r
149 [0-9]+"."[0-9]* |\r
150 "."[0-9]*       |\r
151 [0-9]+[eE][+-]?[0-9]+   |\r
152 [0-9]+"."[0-9]*[eE][+-]?[0-9]+ |\r
153 "."[0-9]*[eE][+-]?[0-9]+        { flex_ifq_ch+=IfqParserleng; IfqParserlval.strval = strdup(yytext); return APPROXNUM; }\r
154 \r
155         /* strings */\r
156 \r
157 '[^'\n]*'       {\r
158                 \r
159                 int c;\r
160                 \r
161                 IfqParserlval.strval = strdup(IfqParsertext+1); \r
162 \r
163                 c = yyinput();\r
164 \r
165                 unput(c);       /* just peeking */\r
166                 if(c != '\'') {\r
167                         flex_ifq_ch+=IfqParserleng; \r
168                         IfqParserlval.strval[IfqParserleng-2] = '\0';\r
169                         return STRING_TOKEN;\r
170                 } else\r
171                         yymore();\r
172         }\r
173                 \r
174 '[^'\n]*$       { flex_ifq_ch+=IfqParserleng; IfqParsererror("Unterminated string"); }\r
175 \r
176  /*                                                                                                                     */\r
177  /*             Newline : advance the error reporting line number       */\r
178  /*             and grab the next line into flex_ifq_linebuf                    */\r
179  /*                                                                                                                     */\r
180 \r
181 \n.*            {flex_ifq_ch=0; flex_ifq_lineno++;\r
182                            strcpy(flex_ifq_linebuf,IfqParsertext+1);\r
183                            yyless(1);\r
184                            }\r
185 \r
186 [ \t\r]+        {flex_ifq_ch+=IfqParserleng; }  /* white space */\r
187 \r
188 "--".*$         {flex_ifq_ch+=IfqParserleng; }; /* comment */\r
189 "//".*$         {flex_ifq_ch+=IfqParserleng; }; /* comment */\r
190 \r
191 .|\n            {flex_ifq_ch+=IfqParserleng; fprintf(stderr,"Warning: unknown token (ignored)\n");  IfqParsererror(yytext);}\r
192 \r
193 %%\r
194 \r
195 int my_IfqParser_yyinput(char *buf, int max_size){\r
196         int c = 0;\r
197         int inchar = 0;\r
198         \r
199         if(flex_ifq_stringinput != NULL){\r
200                 while(c<max_size){\r
201                         if(flex_ifq_stringinput[flex_ifq_stringinput_ptr] != '\0'){\r
202                                 buf[c++] = flex_ifq_stringinput[flex_ifq_stringinput_ptr++];\r
203                         }else{\r
204                                 break;\r
205                         }\r
206                 }\r
207                 return(c);\r
208         }\r
209         \r
210         if(flex_ifq_fileinput != NULL){\r
211                 while(c < max_size){\r
212                         inchar = getc(flex_ifq_fileinput);\r
213                         if(inchar != EOF){\r
214                                 buf[c++] = inchar;\r
215                         }else{\r
216                                 break;\r
217                         }\r
218                 }\r
219                 return(c);\r
220         }\r
221         \r
222         return(0);\r
223 }\r
224 \r
225 void IfqParser_setfileinput(FILE *f){\r
226         IfqParserrestart(NULL);\r
227 \r
228         flex_ifq_fileinput = f;\r
229         flex_ifq_stringinput = NULL;\r
230         flex_ifq_lineno = 1;\r
231         flex_ifq_ch = 0;\r
232 }\r
233 \r
234 void IfqParser_setstringinput(char *s){\r
235         IfqParserrestart(NULL);\r
236 \r
237         flex_ifq_fileinput = NULL;\r
238         flex_ifq_stringinput = s;\r
239         flex_ifq_stringinput_ptr = 0;\r
240         flex_ifq_lineno = 1;\r
241         flex_ifq_ch = 0;\r
242 }\r
243         \r
244                 \r
245 \r
246 \r