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