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
7 http://www.apache.org/licenses/LICENSE-2.0
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 ------------------------------------------- */
19 flex -PExt_fcnsParser -oext_fcnslexer.cc ext_fcns.l
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.
29 #include "parse_ext_fcns.h"
34 #include "ext_fcns.tab.cc.h"
37 Some includes that flex doesn't include as standard,
45 // Prevent flex from defining yywrap as extern "C"
47 #define YY_SKIP_YYWRAP
49 /* No lex lib, supply the yywrap fcn. that normally resides there
52 int Ext_fcnsParserwrap(){return(1);}
54 extern int Ext_fcnsParserdebug;
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.
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
69 int flex_ext_fcns_lineno = 1;
70 int flex_ext_fcns_ch = 0;
71 char flex_ext_fcns_linebuf[20000];
73 //void Ext_fcnsParsererror(char *s);
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,"^");
83 /* MKS needs the next line to increase the NFA table */
89 /* literal keyword tokens */
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
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
100 This parser is somewhat of a work in progress.
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;}
114 [(),\[\]] { flex_ext_fcns_ch+=Ext_fcnsParserleng; return yytext[0]; }
119 [A-Za-z][A-Za-z0-9_]* { flex_ext_fcns_ch+=Ext_fcnsParserleng; Ext_fcnsParserlval.strval = strdup(yytext); return NAME; }
124 [0-9]+UL { flex_ext_fcns_ch+=Ext_fcnsParserleng; Ext_fcnsParserlval.strval = strdup(yytext); return INTNUM; }
132 Ext_fcnsParserlval.strval = strdup(Ext_fcnsParsertext+1);
136 unput(c); /* just peeking */
138 flex_ext_fcns_ch+=Ext_fcnsParserleng;
139 Ext_fcnsParserlval.strval[Ext_fcnsParserleng-2] = '\0';
145 '[^'\n]*$ { flex_ext_fcns_ch+=Ext_fcnsParserleng; Ext_fcnsParsererror("Unterminated string"); }
150 /* Newline : advance the error reporting line number */
151 /* and grab the next line into flex_linebuf */
154 \n.* {flex_ext_fcns_ch=0; flex_ext_fcns_lineno++;
155 strcpy(flex_ext_fcns_linebuf,Ext_fcnsParsertext+1);
159 [ \t\r]+ {flex_ext_fcns_ch+=Ext_fcnsParserleng; } /* white space */
161 "--".*$ {flex_ext_fcns_ch+=Ext_fcnsParserleng; }; /* comment */
162 "//".*$ {flex_ext_fcns_ch+=Ext_fcnsParserleng; }; /* comment */
164 /* Parse error on anything else. */
165 .|\n {fprintf(stderr,"Warning: unknown token (ignored)\n"); Ext_fcnsParsererror(yytext);}