Added quantiling UDAFs
[com/gs-lite.git] / src / ftacmp / ext_fcns.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 -PExt_fcnsParser -oext_fcnslexer.cc ext_fcns.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_ext_fcns.h"\r
30  #include <string.h>\r
31 \r
32 \r
33 \r
34 #include "ext_fcns.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 Ext_fcnsParserwrap(){return(1);}\r
53 \r
54 extern int Ext_fcnsParserdebug;\r
55 \r
56 \r
57 /*\r
58                 These variables are used for error reporting:\r
59                 flex_lineno : the line currently being parsed when the error occurs.\r
60                 flexch : the character on the line where the error occurs\r
61                 flex_linebuf : store the line for reporting.\r
62 \r
63                 NOTE : 1) the fixed size flex_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_ext_fcns_lineno = 1;\r
70 int flex_ext_fcns_ch = 0;\r
71 char flex_ext_fcns_linebuf[20000];\r
72 \r
73 //void Ext_fcnsParsererror(char *s);\r
74 \r
75 void Ext_fcnsParsererror(char *s){\r
76         fprintf(stderr,"On line %d, char %d: %s (token %s):\n%s\n",\r
77                                 flex_ext_fcns_lineno, flex_ext_fcns_ch, s, Ext_fcnsParsertext, flex_ext_fcns_linebuf );\r
78         fprintf(stderr,"%*s\n",1+flex_ext_fcns_ch,"^");\r
79 }\r
80 \r
81 \r
82 %}\r
83         /* MKS needs the next line to increase the NFA table */\r
84 %e 1200\r
85 %option noyywrap\r
86 \r
87 %%\r
88 \r
89         /* literal keyword tokens */\r
90 \r
91  /*\r
92                         The actions associated with each text token are to\r
93                         keep track of the current location (for syntax error reporting)\r
94                         and to report any necessary info to the emf.y parse tree builder\r
95 \r
96                         Its likely that there are a number of omissions, inconsistencies\r
97                         (some keywords do not need to be in caps), and relics\r
98                         (keywords such as BETWEEN, INDICATOR, etc., are not used\r
99                          in emf.y)\r
100                         This parser is somewhat of a work in progress.\r
101  */\r
102 \r
103 FUN             { flex_ext_fcns_ch+=Ext_fcnsParserleng; return FUN; }\r
104 PRED    { flex_ext_fcns_ch+=Ext_fcnsParserleng; return PRED; }\r
105 UDAF    { flex_ext_fcns_ch+=Ext_fcnsParserleng; return UDAF; }\r
106 EXTR    { flex_ext_fcns_ch+=Ext_fcnsParserleng; return EXTR; }\r
107 STATE   { flex_ext_fcns_ch+=Ext_fcnsParserleng; return STATE; }\r
108 SFUN    { flex_ext_fcns_ch+=Ext_fcnsParserleng; return SFUN; }\r
109 HANDLE          { flex_ext_fcns_ch+=Ext_fcnsParserleng; return HANDLE; }\r
110 CONST           { flex_ext_fcns_ch+=Ext_fcnsParserleng; return CONST; }\r
111 CLASS           { flex_ext_fcns_ch+=Ext_fcnsParserleng; return CLASS; }\r
112 ;       {flex_ext_fcns_ch+=Ext_fcnsParserleng; return SEMICOLON;}\r
113 \r
114 [(),\[\]]    { flex_ext_fcns_ch+=Ext_fcnsParserleng; return yytext[0]; }\r
115 \r
116 \r
117         /* names */\r
118 \r
119 [A-Za-z][A-Za-z0-9_]*   { flex_ext_fcns_ch+=Ext_fcnsParserleng; Ext_fcnsParserlval.strval = strdup(yytext); return NAME; }\r
120 \r
121         /* numbers */\r
122 \r
123 [0-9]+  |\r
124 [0-9]+UL        { flex_ext_fcns_ch+=Ext_fcnsParserleng; Ext_fcnsParserlval.strval = strdup(yytext);  return INTNUM; }\r
125 \r
126         /* strings */\r
127 \r
128 '[^'\n]*'       {\r
129                 \r
130                 int c;\r
131                 \r
132                 Ext_fcnsParserlval.strval = strdup(Ext_fcnsParsertext+1); \r
133 \r
134                 c = yyinput();\r
135 \r
136                 unput(c);       /* just peeking */\r
137                 if(c != '\'') {\r
138                         flex_ext_fcns_ch+=Ext_fcnsParserleng; \r
139                         Ext_fcnsParserlval.strval[Ext_fcnsParserleng-2] = '\0';\r
140                         return STRING_TOKEN;\r
141                 } else\r
142                         yymore();\r
143         }\r
144                 \r
145 '[^'\n]*$       { flex_ext_fcns_ch+=Ext_fcnsParserleng; Ext_fcnsParsererror("Unterminated string"); }\r
146 \r
147 \r
148 \r
149  /*                                                                                                                     */\r
150  /*             Newline : advance the error reporting line number       */\r
151  /*             and grab the next line into flex_linebuf                        */\r
152  /*                                                                                                                     */\r
153 \r
154 \n.*            {flex_ext_fcns_ch=0; flex_ext_fcns_lineno++;\r
155                            strcpy(flex_ext_fcns_linebuf,Ext_fcnsParsertext+1);\r
156                            yyless(1);\r
157                            }\r
158 \r
159 [ \t\r]+        {flex_ext_fcns_ch+=Ext_fcnsParserleng; }        /* white space */\r
160 \r
161 "--".*$         {flex_ext_fcns_ch+=Ext_fcnsParserleng; };       /* comment */\r
162 "//".*$         {flex_ext_fcns_ch+=Ext_fcnsParserleng; };       /* comment */\r
163 \r
164  /*             Parse error on anything else.           */                              \r
165 .|\n                    {fprintf(stderr,"Warning: unknown token (ignored)\n");  Ext_fcnsParsererror(yytext);}\r
166  \r
167 \r
168 %%\r
169 \r
170 \r