xref: /onnv-gate/usr/src/cmd/filebench/common/parser_lex.l (revision 7946:36d7e7afa9fa)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Portions Copyright 2008 Denis Cheng
27  */
28 
29 %{
30 
31 #include <stdlib.h>
32 #include <sys/types.h>
33 #include <assert.h>
34 #include <string.h>
35 #include <errno.h>
36 #ifdef HAVE_STDINT_H
37 #include <stdint.h>
38 #endif
39 
40 #include "filebench.h"
41 #include "parsertypes.h"
42 #include "utils.h"
43 #include "parser_gram.h"
44 
45 int lex_lineno = 1;		/* line-number for error reporting */
46 extern void yyerror(char *s);
47 extern int dofile;			/* are we processing a file? */
48 %}
49 
50 %s WHITESTRINGSTATE
51 
52 %a 50000
53 %p 50000
54 %o 50000
55 %n 5000
56 
57 %%
58 
59 \n			{ lex_lineno++; }
60 
61 <INITIAL>[ \t]+			;
62 
63 <INITIAL>#.*			;
64 
65 eventgen                { return FSC_EVENTGEN; }
66 create                  { return FSC_CREATE; }
67 define			{ return FSC_DEFINE; }
68 debug                   { return FSC_DEBUG; }
69 domultisync		{ return FSC_DOMULTISYNC; }
70 echo                    { return FSC_ECHO; }
71 enable			{ return FSC_ENABLE; }
72 exit		        { return FSC_QUIT; }
73 foreach                 { return FSC_FOREACH; }
74 flowop		        { return FSC_FLOWOP; }
75 help		        { return FSC_HELP; }
76 list		        { return FSC_LIST; }
77 load                    { return FSC_LOAD; }
78 log		        { return FSC_LOG; }
79 run                     { return FSC_RUN; }
80 set                     { return FSC_SET; }
81 shutdown                { return FSC_SHUTDOWN; }
82 sleep                   { return FSC_SLEEP; }
83 stats                   { return FSC_STATS; }
84 system                  { return FSC_SYSTEM; }
85 usage                   { return FSC_USAGE; }
86 vars                    { return FSC_VARS; }
87 version                 { return FSC_VERSION; }
88 quit		        { return FSC_QUIT; }
89 
90 file[s]*       	        { return FSE_FILE; }
91 fileset[s]*             { return FSE_FILESET; }
92 directory               { return FSE_DIRECTORY; }
93 command                 { return FSE_COMMAND; }
94 process[es]*	        { return FSE_PROC; }
95 thread		        { return FSE_THREAD; }
96 randvar		        { return FSE_RAND; }
97 clear                   { return FSE_CLEAR; }
98 snap                    { return FSE_SNAP; }
99 dump                    { return FSE_DUMP; }
100 xmldump                 { return FSE_XMLDUMP; }
101 multidump               { return FSE_MULTIDUMP; }
102 all                     { return FSE_ALL; }
103 mode                    { return FSE_MODE; }
104 multi			{ return FSE_MULTI; }
105 
106 cached                  { return FSA_CACHED; }
107 dirwidth                { return FSA_DIRWIDTH; }
108 dirdepthrv              { return FSA_DIRDEPTHRV; }
109 dirgamma                { return FSA_DIRGAMMA; }
110 filesize                { return FSA_SIZE; }
111 filesizegamma           { return FSA_FILESIZEGAMMA; }
112 directio                { return FSA_DIRECTIO; }
113 dsync                   { return FSA_DSYNC;  }
114 fd                      { return FSA_FD; }
115 srcfd                   { return FSA_SRCFD; }
116 opennext                { return FSA_ROTATEFD; }
117 filename                { return FSA_FILE; }
118 filesetname             { return FSA_FILE; }
119 instances               { return FSA_INSTANCES;}
120 iosize                  { return FSA_IOSIZE; }
121 iters                   { return FSA_ITERS;}
122 master			{ return FSA_MASTER; }
123 client			{ return FSA_CLIENT; }
124 memsize                 { return FSA_MEMSIZE; }
125 name                    { return FSA_NAME;}
126 namelength              { return FSA_NAMELENGTH; }
127 nice                    { return FSA_NICE;}
128 entries                 { return FSA_ENTRIES;}
129 leafdirs                { return FSA_LEAFDIRS;}
130 prealloc                { return FSA_PREALLOC; }
131 paralloc                { return FSA_PARALLOC; }
132 reuse                   { return FSA_REUSE; }
133 path                    { return FSA_PATH; }
134 procname                { return FSA_PROCESS; }
135 random                  { return FSA_RANDOM;}
136 rate                    { return FSA_RATE;}
137 size                    { return FSA_SIZE; }
138 target                  { return FSA_TARGET;}
139 useism                  { return FSA_USEISM;}
140 value                   { return FSA_VALUE;}
141 workingset              { return FSA_WSS; }
142 blocking                { return FSA_BLOCKING; }
143 highwater               { return FSA_HIGHWATER; }
144 alldone                 { return FSA_ALLDONE; }
145 firstdone               { return FSA_FIRSTDONE; }
146 timeout                 { return FSA_TIMEOUT; }
147 type			{ return FSA_TYPE; }
148 seed			{ return FSA_RANDSEED; }
149 gamma                   { return FSA_RANDGAMMA; }
150 mean                    { return FSA_RANDMEAN; }
151 min                     { return FSA_RANDMIN; }
152 round			{ return FSA_RANDROUND; }
153 randsrc			{ return FSA_RANDSRC; }
154 randtable		{ return FSA_RANDTABLE; }
155 uniform                 { return FSV_RANDUNI; }
156 tabular			{ return FSV_RANDTAB; }
157 "."type			{ return FSS_TYPE; }
158 "."seed			{ return FSS_SEED; }
159 "."gamma		{ return FSS_GAMMA; }
160 "."mean			{ return FSS_MEAN; }
161 "."min			{ return FSS_MIN; }
162 "."round		{ return FSS_ROUND; }
163 "."randsrc		{ return FSS_SRC; }
164 urandom			{ return FSV_URAND; }
165 rand48			{ return FSV_RAND48; }
166 
167 
168 <INITIAL>\"			{
169                                 BEGIN WHITESTRINGSTATE;
170                                 return FSK_QUOTE;
171                         }
172 
173 <WHITESTRINGSTATE>\"    {
174                                 BEGIN INITIAL;
175                                 return FSK_QUOTE;
176                         }
177 
178 <WHITESTRINGSTATE>[^$^\\^"][^$^"]*[^\\^$^"] {
179 				if ((yylval.sval = strdup(yytext)) == NULL) {
180 					yyerror("Out of memory");
181 					filebench_shutdown(E_ERROR);
182 				}
183  				return FSV_WHITESTRING;
184 	       	}
185 
186 <WHITESTRINGSTATE>\\n	{
187 				yylval.sval = "\n";
188  				return FSV_WHITESTRING;
189 	       	}
190 
191 
192 <WHITESTRINGSTATE>\\$[^"^$^\\]+	{
193 				if ((yylval.sval = strdup(yytext + 1)) == NULL) {
194 					yyerror("Out of memory");
195 					filebench_shutdown(E_ERROR);
196 				}
197  				return FSV_WHITESTRING;
198 	       	}
199 
200 <WHITESTRINGSTATE>[^$^\\^"] {
201 				if ((yylval.sval = strdup(yytext)) == NULL) {
202 					yyerror("Out of memory");
203 					filebench_shutdown(E_ERROR);
204 				}
205  				return FSV_WHITESTRING;
206 	       	}
207 
208 
209 <INITIAL>\{			{ return FSK_OPENLST; }
210 <INITIAL>\}			{ return FSK_CLOSELST; }
211 <INITIAL>=			{ return FSK_ASSIGN; }
212 <INITIAL>\,			{ return FSK_SEPLST; }
213 <INITIAL>in                     { return FSK_IN; }
214 
215 <INITIAL>[0-9]+	{
216                                 errno = 0;
217 				yylval.ival = strtoll(yytext, NULL, 10);
218 				if (errno == EINVAL || errno == ERANGE) {
219                                         (void) filebench_log(LOG_ERROR,
220 						"Invalid I value '%s':%s", yytext,
221 						strerror(errno));
222 				}
223                                 return FSV_VAL_INT;
224 }
225 
226 <INITIAL>[0-9]+k	{
227                                 errno = 0;
228 				yylval.ival = KB * strtoll(yytext, NULL, 10);
229 				if (errno == EINVAL || errno == ERANGE) {
230                                         (void) filebench_log(LOG_ERROR,
231 						"Invalid I value '%s':%s", yytext,
232 						strerror(errno));
233 				}
234                                 return FSV_VAL_INT;
235 }
236 
237 <INITIAL>[0-9]+m	{
238                                 errno = 0;
239 				yylval.ival = MB * strtoll(yytext, NULL, 10);
240 				if (errno == EINVAL || errno == ERANGE) {
241                                         (void) filebench_log(LOG_ERROR,
242 						"Invalid I value '%s':%s", yytext,
243 						strerror(errno));
244 				}
245                                 return FSV_VAL_INT;
246 }
247 
248 <INITIAL>[0-9]+g	{
249                                 errno = 0;
250 				yylval.ival = GB * strtoll(yytext, NULL, 10);
251 				if (errno == EINVAL || errno == ERANGE) {
252                                         (void) filebench_log(LOG_ERROR,
253 						"Invalid I value '%s':%s", yytext,
254 						strerror(errno));
255 				}
256                                 return FSV_VAL_INT;
257 }
258 
259 <INITIAL>true	{
260 				yylval.bval = TRUE;
261 				return FSV_VAL_BOOLEAN;
262 		}
263 
264 <INITIAL>false	{
265 				yylval.bval = FALSE;
266 				return FSV_VAL_BOOLEAN;
267 		}
268 
269 $[({A-Za-z][A-Za-z0-9_]*[A-Za-z0-9][)}]*	{
270 				if ((yylval.sval = strdup(yytext)) == NULL) {
271 					yyerror("Out of memory");
272 					filebench_shutdown(E_ERROR);
273 				}
274 
275  				return FSV_VARIABLE;
276 			}
277 
278 
279 $[({A-Za-z][A-Za-z0-9_]*"."[A-Za-z0-9][)}]*	{
280 				int backtrack;
281 
282 				if ((backtrack =
283 				    var_is_set4_randvar(yytext)) != 0)
284 					yyless(yyleng - backtrack);
285 
286 				if ((yylval.sval = strdup(yytext)) == NULL) {
287 					yyerror("Out of memory");
288 					filebench_shutdown(E_ERROR);
289 				}
290 
291  				return FSV_RANDVAR;
292 			}
293 
294 
295 <INITIAL>[/A-Za-z-][/A-Za-z0-9._-]*	{
296 				if ((yylval.sval = strdup(yytext)) == NULL) {
297 					yyerror("Out of memory");
298 					filebench_shutdown(E_ERROR);
299 				}
300  				return FSV_STRING;
301 			}
302 
303 
304 .			{
305 				yyerror("Illegal character");
306 			}
307 
308 %%
309 
310 void
311 yyerror(char *s)
312 {
313 	if (dofile == FS_TRUE) {
314 		if (yytext[0] == '\0') {
315 			filebench_log(LOG_ERROR,
316 				      "%s, token expected",
317 				      s);
318 			return;
319 		}
320 		(void) filebench_log(LOG_ERROR,
321 				     "%s at '%s'",
322 				     s,
323 				     yytext);
324 	} else {
325 		if (yytext[0] == '\0') {
326 			(void) filebench_log(LOG_ERROR,
327 					     "%s, token expected", s);
328 			return;
329 		}
330 		(void) filebench_log(LOG_ERROR, "%s at '%s'", s, yytext);
331 	}
332 }
333 
334 struct yy_buffer_state *parent;
335 struct yy_buffer_state *script;
336 
337 int
338 yy_switchfileparent(FILE *file)
339 {
340 	script = YY_CURRENT_BUFFER;
341 	parent = (struct yy_buffer_state *)yy_create_buffer(yyin, 128);
342 	yy_switch_to_buffer(parent);
343 	return (0);
344 }
345 
346 int
347 yy_switchfilescript(FILE *file)
348 {
349 	yy_switch_to_buffer(script);
350 	return (0);
351 }
352 
353