xref: /onnv-gate/usr/src/cmd/filebench/common/parser_lex.l (revision 9356:2ff1c33b24c1)
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 2009 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 nousestats		{ return FSC_NOUSESTATS; }
80 run                     { return FSC_RUN; }
81 set                     { return FSC_SET; }
82 shutdown                { return FSC_SHUTDOWN; }
83 sleep                   { return FSC_SLEEP; }
84 stats                   { return FSC_STATS; }
85 system                  { return FSC_SYSTEM; }
86 usage                   { return FSC_USAGE; }
87 vars                    { return FSC_VARS; }
88 version                 { return FSC_VERSION; }
89 warmup                  { return FSC_WARMUP; }
90 quit		        { return FSC_QUIT; }
91 
92 file[s]*       	        { return FSE_FILE; }
93 fileset[s]*             { return FSE_FILESET; }
94 directory               { return FSE_DIRECTORY; }
95 command                 { return FSE_COMMAND; }
96 process[es]*	        { return FSE_PROC; }
97 thread		        { return FSE_THREAD; }
98 randvar		        { return FSE_RAND; }
99 clear                   { return FSE_CLEAR; }
100 snap                    { return FSE_SNAP; }
101 dump                    { return FSE_DUMP; }
102 xmldump                 { return FSE_XMLDUMP; }
103 multidump               { return FSE_MULTIDUMP; }
104 all                     { return FSE_ALL; }
105 mode                    { return FSE_MODE; }
106 multi			{ return FSE_MULTI; }
107 
108 alldone                 { return FSA_ALLDONE; }
109 blocking                { return FSA_BLOCKING; }
110 cached                  { return FSA_CACHED; }
111 client			{ return FSA_CLIENT; }
112 dirwidth                { return FSA_DIRWIDTH; }
113 dirdepthrv              { return FSA_DIRDEPTHRV; }
114 directio                { return FSA_DIRECTIO; }
115 dirgamma                { return FSA_DIRGAMMA; }
116 dsync                   { return FSA_DSYNC;  }
117 entries                 { return FSA_ENTRIES;}
118 fd                      { return FSA_FD; }
119 filename                { return FSA_FILE; }
120 filesetname             { return FSA_FILE; }
121 filesize                { return FSA_SIZE; }
122 filesizegamma           { return FSA_FILESIZEGAMMA; }
123 firstdone               { return FSA_FIRSTDONE; }
124 gamma                   { return FSA_RANDGAMMA; }
125 highwater               { return FSA_HIGHWATER; }
126 indexed                 { return FSA_INDEXED; }
127 instances               { return FSA_INSTANCES;}
128 iosize                  { return FSA_IOSIZE; }
129 iters                   { return FSA_ITERS;}
130 leafdirs                { return FSA_LEAFDIRS;}
131 master			{ return FSA_MASTER; }
132 mean                    { return FSA_RANDMEAN; }
133 memsize                 { return FSA_MEMSIZE; }
134 min                     { return FSA_RANDMIN; }
135 name                    { return FSA_NAME;}
136 namelength              { return FSA_NAMELENGTH; }
137 nice                    { return FSA_NICE;}
138 opennext                { return FSA_ROTATEFD; }
139 paralloc                { return FSA_PARALLOC; }
140 path                    { return FSA_PATH; }
141 prealloc                { return FSA_PREALLOC; }
142 procname                { return FSA_PROCESS; }
143 random                  { return FSA_RANDOM;}
144 randsrc			{ return FSA_RANDSRC; }
145 randtable		{ return FSA_RANDTABLE; }
146 rate                    { return FSA_RATE;}
147 readonly		{ return FSA_READONLY; }
148 reuse                   { return FSA_REUSE; }
149 round			{ return FSA_RANDROUND; }
150 seed			{ return FSA_RANDSEED; }
151 size                    { return FSA_SIZE; }
152 srcfd                   { return FSA_SRCFD; }
153 target                  { return FSA_TARGET;}
154 timeout                 { return FSA_TIMEOUT; }
155 trusttree		{ return FSA_TRUSTTREE; }
156 type			{ return FSA_TYPE; }
157 useism                  { return FSA_USEISM;}
158 value                   { return FSA_VALUE;}
159 workingset              { return FSA_WSS; }
160 
161 uniform                 { return FSV_RANDUNI; }
162 tabular			{ return FSV_RANDTAB; }
163 "."type			{ return FSS_TYPE; }
164 "."seed			{ return FSS_SEED; }
165 "."gamma		{ return FSS_GAMMA; }
166 "."mean			{ return FSS_MEAN; }
167 "."min			{ return FSS_MIN; }
168 "."round		{ return FSS_ROUND; }
169 "."randsrc		{ return FSS_SRC; }
170 urandom			{ return FSV_URAND; }
171 rand48			{ return FSV_RAND48; }
172 
173 
174 <INITIAL>\"			{
175                                 BEGIN WHITESTRINGSTATE;
176                                 return FSK_QUOTE;
177                         }
178 
179 <WHITESTRINGSTATE>\"    {
180                                 BEGIN INITIAL;
181                                 return FSK_QUOTE;
182                         }
183 
184 <WHITESTRINGSTATE>[^$^\\^"][^$^"]*[^\\^$^"] {
185 				if ((yylval.sval = strdup(yytext)) == NULL) {
186 					yyerror("Out of memory");
187 					filebench_shutdown(E_ERROR);
188 				}
189  				return FSV_WHITESTRING;
190 	       	}
191 
192 <WHITESTRINGSTATE>\\n	{
193 				yylval.sval = "\n";
194  				return FSV_WHITESTRING;
195 	       	}
196 
197 
198 <WHITESTRINGSTATE>\\$[^"^$^\\]+	{
199 				if ((yylval.sval = strdup(yytext + 1)) == NULL) {
200 					yyerror("Out of memory");
201 					filebench_shutdown(E_ERROR);
202 				}
203  				return FSV_WHITESTRING;
204 	       	}
205 
206 <WHITESTRINGSTATE>[^$^\\^"] {
207 				if ((yylval.sval = strdup(yytext)) == NULL) {
208 					yyerror("Out of memory");
209 					filebench_shutdown(E_ERROR);
210 				}
211  				return FSV_WHITESTRING;
212 	       	}
213 
214 
215 <INITIAL>\{			{ return FSK_OPENLST; }
216 <INITIAL>\}			{ return FSK_CLOSELST; }
217 <INITIAL>=			{ return FSK_ASSIGN; }
218 <INITIAL>\,			{ return FSK_SEPLST; }
219 <INITIAL>in                     { return FSK_IN; }
220 
221 <INITIAL>[0-9]+	{
222                                 errno = 0;
223 				yylval.ival = strtoll(yytext, NULL, 10);
224 				if (errno == EINVAL || errno == ERANGE) {
225                                         (void) filebench_log(LOG_ERROR,
226 						"Invalid I value '%s':%s", yytext,
227 						strerror(errno));
228 				}
229                                 return FSV_VAL_INT;
230 }
231 
232 <INITIAL>[0-9]+k	{
233                                 errno = 0;
234 				yylval.ival = KB * strtoll(yytext, NULL, 10);
235 				if (errno == EINVAL || errno == ERANGE) {
236                                         (void) filebench_log(LOG_ERROR,
237 						"Invalid I value '%s':%s", yytext,
238 						strerror(errno));
239 				}
240                                 return FSV_VAL_INT;
241 }
242 
243 <INITIAL>[0-9]+m	{
244                                 errno = 0;
245 				yylval.ival = MB * strtoll(yytext, NULL, 10);
246 				if (errno == EINVAL || errno == ERANGE) {
247                                         (void) filebench_log(LOG_ERROR,
248 						"Invalid I value '%s':%s", yytext,
249 						strerror(errno));
250 				}
251                                 return FSV_VAL_INT;
252 }
253 
254 <INITIAL>[0-9]+g	{
255                                 errno = 0;
256 				yylval.ival = GB * strtoll(yytext, NULL, 10);
257 				if (errno == EINVAL || errno == ERANGE) {
258                                         (void) filebench_log(LOG_ERROR,
259 						"Invalid I value '%s':%s", yytext,
260 						strerror(errno));
261 				}
262                                 return FSV_VAL_INT;
263 }
264 
265 <INITIAL>true	{
266 				yylval.bval = TRUE;
267 				return FSV_VAL_BOOLEAN;
268 		}
269 
270 <INITIAL>false	{
271 				yylval.bval = FALSE;
272 				return FSV_VAL_BOOLEAN;
273 		}
274 
275 $[({A-Za-z][A-Za-z0-9_]*[A-Za-z0-9][)}]*	{
276 				if ((yylval.sval = strdup(yytext)) == NULL) {
277 					yyerror("Out of memory");
278 					filebench_shutdown(E_ERROR);
279 				}
280 
281  				return FSV_VARIABLE;
282 			}
283 
284 
285 $[({A-Za-z][A-Za-z0-9_]*"."[A-Za-z0-9][)}]*	{
286 				int backtrack;
287 
288 				if ((backtrack =
289 				    var_is_set4_randvar(yytext)) != 0)
290 					yyless(yyleng - backtrack);
291 
292 				if ((yylval.sval = strdup(yytext)) == NULL) {
293 					yyerror("Out of memory");
294 					filebench_shutdown(E_ERROR);
295 				}
296 
297  				return FSV_RANDVAR;
298 			}
299 
300 
301 <INITIAL>[/A-Za-z-][/A-Za-z0-9._-]*	{
302 				if ((yylval.sval = strdup(yytext)) == NULL) {
303 					yyerror("Out of memory");
304 					filebench_shutdown(E_ERROR);
305 				}
306  				return FSV_STRING;
307 			}
308 
309 
310 .			{
311 				yyerror("Illegal character");
312 			}
313 
314 %%
315 
316 void
317 yyerror(char *s)
318 {
319 	if (dofile == FS_TRUE) {
320 		if (yytext[0] == '\0') {
321 			filebench_log(LOG_ERROR,
322 				      "%s, token expected",
323 				      s);
324 			return;
325 		}
326 		(void) filebench_log(LOG_ERROR,
327 				     "%s at '%s'",
328 				     s,
329 				     yytext);
330 	} else {
331 		if (yytext[0] == '\0') {
332 			(void) filebench_log(LOG_ERROR,
333 					     "%s, token expected", s);
334 			return;
335 		}
336 		(void) filebench_log(LOG_ERROR, "%s at '%s'", s, yytext);
337 	}
338 }
339 
340 struct yy_buffer_state *parent;
341 struct yy_buffer_state *script;
342 
343 int
344 yy_switchfileparent(FILE *file)
345 {
346 	script = YY_CURRENT_BUFFER;
347 	parent = (struct yy_buffer_state *)yy_create_buffer(yyin, 128);
348 	yy_switch_to_buffer(parent);
349 	return (0);
350 }
351 
352 int
353 yy_switchfilescript(FILE *file)
354 {
355 	yy_switch_to_buffer(script);
356 	return (0);
357 }
358 
359