Add new udafs and RMR support to gsprintconsole_ves
[com/gs-lite.git] / src / ftacmp / res.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 -PResParser -oreslexer.cc res.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 "res.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 ResParserwrap(){return(1);}
53
54 extern int ResParserdebug;
55
56
57 /*
58                 These variables are used for error reporting:
59                 flex_res_lineno : the line currently being parsed when the error occurs.
60                 flex_res_ch : the character on the line where the error occurs
61                 flex_res_linebuf : store the line for reporting.
62
63                 NOTE : 1) the fixed size flex_res_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_res_lineno = 1;
70 int flex_res_ch = 0;
71 char flex_res_linebuf[20000];
72
73 char *flex_res_stringinput = NULL;
74 int flex_res_stringinput_ptr = 0;
75 FILE *flex_res_fileinput = NULL;
76 int my_ResParser_yyinput(char *buf, int max_size);
77
78
79
80 void ResParsererror(char *s){
81         int i;
82         fprintf(stderr,"On line %d, char %d: %s (token %s):\n%s\n",
83                                 flex_res_lineno, flex_res_ch, s, ResParsertext, flex_res_linebuf );
84     for(i=0;i<flex_res_ch;i++){
85                 if(flex_res_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_res_ch,"^");
93 }
94
95 #undef YY_INPUT
96 #define YY_INPUT(b, r, ms) (r = my_ResParser_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
122
123
124 [<>=/]  { flex_res_ch+=ResParserleng; return yytext[0]; }
125
126         /* names */
127
128 [A-Za-z_][A-Za-z0-9_]*  { flex_res_ch+=ResParserleng; ResParserlval.strval = strdup(yytext); return NAME; }
129
130
131         /* strings */
132
133 '[^'\n]*'       {
134                 
135                 int c;
136                 
137                 ResParserlval.strval = strdup(ResParsertext+1); 
138
139                 c = yyinput();
140
141                 unput(c);       /* just peeking */
142                 if(c != '\'') {
143                         flex_res_ch+=ResParserleng; 
144                         ResParserlval.strval[ResParserleng-2] = '\0';
145                         return STRING_TOKEN;
146                 } else
147                         yymore();
148         }
149                 
150 '[^'\n]*$       { flex_res_ch+=ResParserleng; ResParsererror("Unterminated string"); }
151
152  /*                                                                                                                     */
153  /*             Newline : advance the error reporting line number       */
154  /*             and grab the next line into flex_res_linebuf                    */
155  /*                                                                                                                     */
156
157 \n.*            {flex_res_ch=0; flex_res_lineno++;
158                            strcpy(flex_res_linebuf,ResParsertext+1);
159                            yyless(1);
160                            }
161
162 [ \t\r]+        {flex_res_ch+=ResParserleng; }  /* white space */
163
164 "--".*$         {flex_res_ch+=ResParserleng; }; /* comment */
165 "//".*$         {flex_res_ch+=ResParserleng; }; /* comment */
166 "<?xml".*$      {flex_res_ch+=ResParserleng; }; /* comment */
167
168 .|\n            {flex_res_ch+=ResParserleng; fprintf(stderr,"Warning: unknown token (ignored)\n");  ResParsererror(yytext);}
169
170 %%
171
172 int my_ResParser_yyinput(char *buf, int max_size){
173         int c = 0;
174         int inchar = 0;
175         
176         if(flex_res_stringinput != NULL){
177                 while(c<max_size){
178                         if(flex_res_stringinput[flex_res_stringinput_ptr] != '\0'){
179                                 buf[c++] = flex_res_stringinput[flex_res_stringinput_ptr++];
180                         }else{
181                                 break;
182                         }
183                 }
184                 return(c);
185         }
186         
187         if(flex_res_fileinput != NULL){
188                 while(c < max_size){
189                         inchar = getc(flex_res_fileinput);
190                         if(inchar != EOF){
191                                 buf[c++] = inchar;
192                         }else{
193                                 break;
194                         }
195                 }
196                 return(c);
197         }
198         
199         return(0);
200 }
201
202 void ResParser_setfileinput(FILE *f){
203         ResParserrestart(NULL);
204
205         flex_res_fileinput = f;
206         flex_res_stringinput = NULL;
207         flex_res_lineno = 1;
208         flex_res_ch = 0;
209 }
210
211 void ResParser_setstringinput(char *s){
212         ResParserrestart(NULL);
213
214         flex_res_fileinput = NULL;
215         flex_res_stringinput = s;
216         flex_res_stringinput_ptr = 0;
217         flex_res_lineno = 1;
218         flex_res_ch = 0;
219 }
220         
221                 
222
223