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