1 | .TH FLEX 1 "26 May 1990" "Version 2.3"
|
---|
2 | .SH NAME
|
---|
3 | flex, lex - fast lexical analyzer generator
|
---|
4 | .SH SYNOPSIS
|
---|
5 | .B flex
|
---|
6 | .B [-bcdfinpstvFILT8 -C[efmF] -Sskeleton]
|
---|
7 | .I [filename ...]
|
---|
8 | .SH DESCRIPTION
|
---|
9 | .I flex
|
---|
10 | is a tool for generating
|
---|
11 | .I scanners:
|
---|
12 | programs which recognized lexical patterns in text.
|
---|
13 | .I flex
|
---|
14 | reads
|
---|
15 | the given input files, or its standard input if no file names are given,
|
---|
16 | for a description of a scanner to generate. The description is in
|
---|
17 | the form of pairs
|
---|
18 | of regular expressions and C code, called
|
---|
19 | .I rules. flex
|
---|
20 | generates as output a C source file,
|
---|
21 | .B lex.yy.c,
|
---|
22 | which defines a routine
|
---|
23 | .B yylex().
|
---|
24 | This file is compiled and linked with the
|
---|
25 | .B -lfl
|
---|
26 | library to produce an executable. When the executable is run,
|
---|
27 | it analyzes its input for occurrences
|
---|
28 | of the regular expressions. Whenever it finds one, it executes
|
---|
29 | the corresponding C code.
|
---|
30 | .LP
|
---|
31 | For full documentation, see
|
---|
32 | .B flexdoc(1).
|
---|
33 | This manual entry is intended for use as a quick reference.
|
---|
34 | .SH OPTIONS
|
---|
35 | .I flex
|
---|
36 | has the following options:
|
---|
37 | .TP
|
---|
38 | .B -b
|
---|
39 | Generate backtracking information to
|
---|
40 | .I lex.backtrack.
|
---|
41 | This is a list of scanner states which require backtracking
|
---|
42 | and the input characters on which they do so. By adding rules one
|
---|
43 | can remove backtracking states. If all backtracking states
|
---|
44 | are eliminated and
|
---|
45 | .B -f
|
---|
46 | or
|
---|
47 | .B -F
|
---|
48 | is used, the generated scanner will run faster.
|
---|
49 | .TP
|
---|
50 | .B -c
|
---|
51 | is a do-nothing, deprecated option included for POSIX compliance.
|
---|
52 | .IP
|
---|
53 | .B NOTE:
|
---|
54 | in previous releases of
|
---|
55 | .I flex
|
---|
56 | .B -c
|
---|
57 | specified table-compression options. This functionality is
|
---|
58 | now given by the
|
---|
59 | .B -C
|
---|
60 | flag. To ease the the impact of this change, when
|
---|
61 | .I flex
|
---|
62 | encounters
|
---|
63 | .B -c,
|
---|
64 | it currently issues a warning message and assumes that
|
---|
65 | .B -C
|
---|
66 | was desired instead. In the future this "promotion" of
|
---|
67 | .B -c
|
---|
68 | to
|
---|
69 | .B -C
|
---|
70 | will go away in the name of full POSIX compliance (unless
|
---|
71 | the POSIX meaning is removed first).
|
---|
72 | .TP
|
---|
73 | .B -d
|
---|
74 | makes the generated scanner run in
|
---|
75 | .I debug
|
---|
76 | mode. Whenever a pattern is recognized and the global
|
---|
77 | .B yy_flex_debug
|
---|
78 | is non-zero (which is the default), the scanner will
|
---|
79 | write to
|
---|
80 | .I stderr
|
---|
81 | a line of the form:
|
---|
82 | .nf
|
---|
83 |
|
---|
84 | --accepting rule at line 53 ("the matched text")
|
---|
85 |
|
---|
86 | .fi
|
---|
87 | The line number refers to the location of the rule in the file
|
---|
88 | defining the scanner (i.e., the file that was fed to flex). Messages
|
---|
89 | are also generated when the scanner backtracks, accepts the
|
---|
90 | default rule, reaches the end of its input buffer (or encounters
|
---|
91 | a NUL; the two look the same as far as the scanner's concerned),
|
---|
92 | or reaches an end-of-file.
|
---|
93 | .TP
|
---|
94 | .B -f
|
---|
95 | specifies (take your pick)
|
---|
96 | .I full table
|
---|
97 | or
|
---|
98 | .I fast scanner.
|
---|
99 | No table compression is done. The result is large but fast.
|
---|
100 | This option is equivalent to
|
---|
101 | .B -Cf
|
---|
102 | (see below).
|
---|
103 | .TP
|
---|
104 | .B -i
|
---|
105 | instructs
|
---|
106 | .I flex
|
---|
107 | to generate a
|
---|
108 | .I case-insensitive
|
---|
109 | scanner. The case of letters given in the
|
---|
110 | .I flex
|
---|
111 | input patterns will
|
---|
112 | be ignored, and tokens in the input will be matched regardless of case. The
|
---|
113 | matched text given in
|
---|
114 | .I yytext
|
---|
115 | will have the preserved case (i.e., it will not be folded).
|
---|
116 | .TP
|
---|
117 | .B -n
|
---|
118 | is another do-nothing, deprecated option included only for
|
---|
119 | POSIX compliance.
|
---|
120 | .TP
|
---|
121 | .B -p
|
---|
122 | generates a performance report to stderr. The report
|
---|
123 | consists of comments regarding features of the
|
---|
124 | .I flex
|
---|
125 | input file which will cause a loss of performance in the resulting scanner.
|
---|
126 | .TP
|
---|
127 | .B -s
|
---|
128 | causes the
|
---|
129 | .I default rule
|
---|
130 | (that unmatched scanner input is echoed to
|
---|
131 | .I stdout)
|
---|
132 | to be suppressed. If the scanner encounters input that does not
|
---|
133 | match any of its rules, it aborts with an error.
|
---|
134 | .TP
|
---|
135 | .B -t
|
---|
136 | instructs
|
---|
137 | .I flex
|
---|
138 | to write the scanner it generates to standard output instead
|
---|
139 | of
|
---|
140 | .B lex.yy.c.
|
---|
141 | .TP
|
---|
142 | .B -v
|
---|
143 | specifies that
|
---|
144 | .I flex
|
---|
145 | should write to
|
---|
146 | .I stderr
|
---|
147 | a summary of statistics regarding the scanner it generates.
|
---|
148 | .TP
|
---|
149 | .B -F
|
---|
150 | specifies that the
|
---|
151 | .I fast
|
---|
152 | scanner table representation should be used. This representation is
|
---|
153 | about as fast as the full table representation
|
---|
154 | .RB ( \-f ),
|
---|
155 | and for some sets of patterns will be considerably smaller (and for
|
---|
156 | others, larger). See
|
---|
157 | .B flexdoc(1)
|
---|
158 | for details.
|
---|
159 | .IP
|
---|
160 | This option is equivalent to
|
---|
161 | .B -CF
|
---|
162 | (see below).
|
---|
163 | .TP
|
---|
164 | .B -I
|
---|
165 | instructs
|
---|
166 | .I flex
|
---|
167 | to generate an
|
---|
168 | .I interactive
|
---|
169 | scanner, that is, a scanner which stops immediately rather than
|
---|
170 | looking ahead if it knows
|
---|
171 | that the currently scanned text cannot be part of a longer rule's match.
|
---|
172 | Again, see
|
---|
173 | .B flexdoc(1)
|
---|
174 | for details.
|
---|
175 | .IP
|
---|
176 | Note,
|
---|
177 | .B -I
|
---|
178 | cannot be used in conjunction with
|
---|
179 | .I full
|
---|
180 | or
|
---|
181 | .I fast tables,
|
---|
182 | i.e., the
|
---|
183 | .B -f, -F, -Cf,
|
---|
184 | or
|
---|
185 | .B -CF
|
---|
186 | flags.
|
---|
187 | .TP
|
---|
188 | .B -L
|
---|
189 | instructs
|
---|
190 | .I flex
|
---|
191 | not to generate
|
---|
192 | .B #line
|
---|
193 | directives in
|
---|
194 | .B lex.yy.c.
|
---|
195 | The default is to generate such directives so error
|
---|
196 | messages in the actions will be correctly
|
---|
197 | located with respect to the original
|
---|
198 | .I flex
|
---|
199 | input file, and not to
|
---|
200 | the fairly meaningless line numbers of
|
---|
201 | .B lex.yy.c.
|
---|
202 | .TP
|
---|
203 | .B -T
|
---|
204 | makes
|
---|
205 | .I flex
|
---|
206 | run in
|
---|
207 | .I trace
|
---|
208 | mode. It will generate a lot of messages to
|
---|
209 | .I stdout
|
---|
210 | concerning
|
---|
211 | the form of the input and the resultant non-deterministic and deterministic
|
---|
212 | finite automata. This option is mostly for use in maintaining
|
---|
213 | .I flex.
|
---|
214 | .TP
|
---|
215 | .B -8
|
---|
216 | instructs
|
---|
217 | .I flex
|
---|
218 | to generate an 8-bit scanner.
|
---|
219 | On some sites, this is the default. On others, the default
|
---|
220 | is 7-bit characters. To see which is the case, check the verbose
|
---|
221 | .B (-v)
|
---|
222 | output for "equivalence classes created". If the denominator of
|
---|
223 | the number shown is 128, then by default
|
---|
224 | .I flex
|
---|
225 | is generating 7-bit characters. If it is 256, then the default is
|
---|
226 | 8-bit characters.
|
---|
227 | .TP
|
---|
228 | .B -C[efmF]
|
---|
229 | controls the degree of table compression.
|
---|
230 | .IP
|
---|
231 | .B -Ce
|
---|
232 | directs
|
---|
233 | .I flex
|
---|
234 | to construct
|
---|
235 | .I equivalence classes,
|
---|
236 | i.e., sets of characters
|
---|
237 | which have identical lexical properties.
|
---|
238 | Equivalence classes usually give
|
---|
239 | dramatic reductions in the final table/object file sizes (typically
|
---|
240 | a factor of 2-5) and are pretty cheap performance-wise (one array
|
---|
241 | look-up per character scanned).
|
---|
242 | .IP
|
---|
243 | .B -Cf
|
---|
244 | specifies that the
|
---|
245 | .I full
|
---|
246 | scanner tables should be generated -
|
---|
247 | .I flex
|
---|
248 | should not compress the
|
---|
249 | tables by taking advantages of similar transition functions for
|
---|
250 | different states.
|
---|
251 | .IP
|
---|
252 | .B -CF
|
---|
253 | specifies that the alternate fast scanner representation (described in
|
---|
254 | .B flexdoc(1))
|
---|
255 | should be used.
|
---|
256 | .IP
|
---|
257 | .B -Cm
|
---|
258 | directs
|
---|
259 | .I flex
|
---|
260 | to construct
|
---|
261 | .I meta-equivalence classes,
|
---|
262 | which are sets of equivalence classes (or characters, if equivalence
|
---|
263 | classes are not being used) that are commonly used together. Meta-equivalence
|
---|
264 | classes are often a big win when using compressed tables, but they
|
---|
265 | have a moderate performance impact (one or two "if" tests and one
|
---|
266 | array look-up per character scanned).
|
---|
267 | .IP
|
---|
268 | A lone
|
---|
269 | .B -C
|
---|
270 | specifies that the scanner tables should be compressed but neither
|
---|
271 | equivalence classes nor meta-equivalence classes should be used.
|
---|
272 | .IP
|
---|
273 | The options
|
---|
274 | .B -Cf
|
---|
275 | or
|
---|
276 | .B -CF
|
---|
277 | and
|
---|
278 | .B -Cm
|
---|
279 | do not make sense together - there is no opportunity for meta-equivalence
|
---|
280 | classes if the table is not being compressed. Otherwise the options
|
---|
281 | may be freely mixed.
|
---|
282 | .IP
|
---|
283 | The default setting is
|
---|
284 | .B -Cem,
|
---|
285 | which specifies that
|
---|
286 | .I flex
|
---|
287 | should generate equivalence classes
|
---|
288 | and meta-equivalence classes. This setting provides the highest
|
---|
289 | degree of table compression. You can trade off
|
---|
290 | faster-executing scanners at the cost of larger tables with
|
---|
291 | the following generally being true:
|
---|
292 | .nf
|
---|
293 |
|
---|
294 | slowest & smallest
|
---|
295 | -Cem
|
---|
296 | -Cm
|
---|
297 | -Ce
|
---|
298 | -C
|
---|
299 | -C{f,F}e
|
---|
300 | -C{f,F}
|
---|
301 | fastest & largest
|
---|
302 |
|
---|
303 | .fi
|
---|
304 | .IP
|
---|
305 | .B -C
|
---|
306 | options are not cumulative; whenever the flag is encountered, the
|
---|
307 | previous -C settings are forgotten.
|
---|
308 | .TP
|
---|
309 | .B -Sskeleton_file
|
---|
310 | overrides the default skeleton file from which
|
---|
311 | .I flex
|
---|
312 | constructs its scanners. You'll never need this option unless you are doing
|
---|
313 | .I flex
|
---|
314 | maintenance or development.
|
---|
315 | .SH SUMMARY OF FLEX REGULAR EXPRESSIONS
|
---|
316 | The patterns in the input are written using an extended set of regular
|
---|
317 | expressions. These are:
|
---|
318 | .nf
|
---|
319 |
|
---|
320 | x match the character 'x'
|
---|
321 | . any character except newline
|
---|
322 | [xyz] a "character class"; in this case, the pattern
|
---|
323 | matches either an 'x', a 'y', or a 'z'
|
---|
324 | [abj-oZ] a "character class" with a range in it; matches
|
---|
325 | an 'a', a 'b', any letter from 'j' through 'o',
|
---|
326 | or a 'Z'
|
---|
327 | [^A-Z] a "negated character class", i.e., any character
|
---|
328 | but those in the class. In this case, any
|
---|
329 | character EXCEPT an uppercase letter.
|
---|
330 | [^A-Z\\n] any character EXCEPT an uppercase letter or
|
---|
331 | a newline
|
---|
332 | r* zero or more r's, where r is any regular expression
|
---|
333 | r+ one or more r's
|
---|
334 | r? zero or one r's (that is, "an optional r")
|
---|
335 | r{2,5} anywhere from two to five r's
|
---|
336 | r{2,} two or more r's
|
---|
337 | r{4} exactly 4 r's
|
---|
338 | {name} the expansion of the "name" definition
|
---|
339 | (see above)
|
---|
340 | "[xyz]\\"foo"
|
---|
341 | the literal string: [xyz]"foo
|
---|
342 | \\X if X is an 'a', 'b', 'f', 'n', 'r', 't', or 'v',
|
---|
343 | then the ANSI-C interpretation of \\x.
|
---|
344 | Otherwise, a literal 'X' (used to escape
|
---|
345 | operators such as '*')
|
---|
346 | \\123 the character with octal value 123
|
---|
347 | \\x2a the character with hexadecimal value 2a
|
---|
348 | (r) match an r; parentheses are used to override
|
---|
349 | precedence (see below)
|
---|
350 |
|
---|
351 |
|
---|
352 | rs the regular expression r followed by the
|
---|
353 | regular expression s; called "concatenation"
|
---|
354 |
|
---|
355 |
|
---|
356 | r|s either an r or an s
|
---|
357 |
|
---|
358 |
|
---|
359 | r/s an r but only if it is followed by an s. The
|
---|
360 | s is not part of the matched text. This type
|
---|
361 | of pattern is called as "trailing context".
|
---|
362 | ^r an r, but only at the beginning of a line
|
---|
363 | r$ an r, but only at the end of a line. Equivalent
|
---|
364 | to "r/\\n".
|
---|
365 |
|
---|
366 |
|
---|
367 | <s>r an r, but only in start condition s (see
|
---|
368 | below for discussion of start conditions)
|
---|
369 | <s1,s2,s3>r
|
---|
370 | same, but in any of start conditions s1,
|
---|
371 | s2, or s3
|
---|
372 |
|
---|
373 |
|
---|
374 | <<EOF>> an end-of-file
|
---|
375 | <s1,s2><<EOF>>
|
---|
376 | an end-of-file when in start condition s1 or s2
|
---|
377 |
|
---|
378 | .fi
|
---|
379 | The regular expressions listed above are grouped according to
|
---|
380 | precedence, from highest precedence at the top to lowest at the bottom.
|
---|
381 | Those grouped together have equal precedence.
|
---|
382 | .LP
|
---|
383 | Some notes on patterns:
|
---|
384 | .IP -
|
---|
385 | Negated character classes
|
---|
386 | .I match newlines
|
---|
387 | unless "\\n" (or an equivalent escape sequence) is one of the
|
---|
388 | characters explicitly present in the negated character class
|
---|
389 | (e.g., "[^A-Z\\n]").
|
---|
390 | .IP -
|
---|
391 | A rule can have at most one instance of trailing context (the '/' operator
|
---|
392 | or the '$' operator). The start condition, '^', and "<<EOF>>" patterns
|
---|
393 | can only occur at the beginning of a pattern, and, as well as with '/' and '$',
|
---|
394 | cannot be grouped inside parentheses. The following are all illegal:
|
---|
395 | .nf
|
---|
396 |
|
---|
397 | foo/bar$
|
---|
398 | foo|(bar$)
|
---|
399 | foo|^bar
|
---|
400 | <sc1>foo<sc2>bar
|
---|
401 |
|
---|
402 | .fi
|
---|
403 | .SH SUMMARY OF SPECIAL ACTIONS
|
---|
404 | In addition to arbitrary C code, the following can appear in actions:
|
---|
405 | .IP -
|
---|
406 | .B ECHO
|
---|
407 | copies yytext to the scanner's output.
|
---|
408 | .IP -
|
---|
409 | .B BEGIN
|
---|
410 | followed by the name of a start condition places the scanner in the
|
---|
411 | corresponding start condition.
|
---|
412 | .IP -
|
---|
413 | .B REJECT
|
---|
414 | directs the scanner to proceed on to the "second best" rule which matched the
|
---|
415 | input (or a prefix of the input).
|
---|
416 | .B yytext
|
---|
417 | and
|
---|
418 | .B yyleng
|
---|
419 | are set up appropriately. Note that
|
---|
420 | .B REJECT
|
---|
421 | is a particularly expensive feature in terms scanner performance;
|
---|
422 | if it is used in
|
---|
423 | .I any
|
---|
424 | of the scanner's actions it will slow down
|
---|
425 | .I all
|
---|
426 | of the scanner's matching. Furthermore,
|
---|
427 | .B REJECT
|
---|
428 | cannot be used with the
|
---|
429 | .I -f
|
---|
430 | or
|
---|
431 | .I -F
|
---|
432 | options.
|
---|
433 | .IP
|
---|
434 | Note also that unlike the other special actions,
|
---|
435 | .B REJECT
|
---|
436 | is a
|
---|
437 | .I branch;
|
---|
438 | code immediately following it in the action will
|
---|
439 | .I not
|
---|
440 | be executed.
|
---|
441 | .IP -
|
---|
442 | .B yymore()
|
---|
443 | tells the scanner that the next time it matches a rule, the corresponding
|
---|
444 | token should be
|
---|
445 | .I appended
|
---|
446 | onto the current value of
|
---|
447 | .B yytext
|
---|
448 | rather than replacing it.
|
---|
449 | .IP -
|
---|
450 | .B yyless(n)
|
---|
451 | returns all but the first
|
---|
452 | .I n
|
---|
453 | characters of the current token back to the input stream, where they
|
---|
454 | will be rescanned when the scanner looks for the next match.
|
---|
455 | .B yytext
|
---|
456 | and
|
---|
457 | .B yyleng
|
---|
458 | are adjusted appropriately (e.g.,
|
---|
459 | .B yyleng
|
---|
460 | will now be equal to
|
---|
461 | .I n
|
---|
462 | ).
|
---|
463 | .IP -
|
---|
464 | .B unput(c)
|
---|
465 | puts the character
|
---|
466 | .I c
|
---|
467 | back onto the input stream. It will be the next character scanned.
|
---|
468 | .IP -
|
---|
469 | .B input()
|
---|
470 | reads the next character from the input stream (this routine is called
|
---|
471 | .B yyinput()
|
---|
472 | if the scanner is compiled using
|
---|
473 | .B C++).
|
---|
474 | .IP -
|
---|
475 | .B yyterminate()
|
---|
476 | can be used in lieu of a return statement in an action. It terminates
|
---|
477 | the scanner and returns a 0 to the scanner's caller, indicating "all done".
|
---|
478 | .IP
|
---|
479 | By default,
|
---|
480 | .B yyterminate()
|
---|
481 | is also called when an end-of-file is encountered. It is a macro and
|
---|
482 | may be redefined.
|
---|
483 | .IP -
|
---|
484 | .B YY_NEW_FILE
|
---|
485 | is an action available only in <<EOF>> rules. It means "Okay, I've
|
---|
486 | set up a new input file, continue scanning".
|
---|
487 | .IP -
|
---|
488 | .B yy_create_buffer( file, size )
|
---|
489 | takes a
|
---|
490 | .I FILE
|
---|
491 | pointer and an integer
|
---|
492 | .I size.
|
---|
493 | It returns a YY_BUFFER_STATE
|
---|
494 | handle to a new input buffer large enough to accomodate
|
---|
495 | .I size
|
---|
496 | characters and associated with the given file. When in doubt, use
|
---|
497 | .B YY_BUF_SIZE
|
---|
498 | for the size.
|
---|
499 | .IP -
|
---|
500 | .B yy_switch_to_buffer( new_buffer )
|
---|
501 | switches the scanner's processing to scan for tokens from
|
---|
502 | the given buffer, which must be a YY_BUFFER_STATE.
|
---|
503 | .IP -
|
---|
504 | .B yy_delete_buffer( buffer )
|
---|
505 | deletes the given buffer.
|
---|
506 | .SH VALUES AVAILABLE TO THE USER
|
---|
507 | .IP -
|
---|
508 | .B char *yytext
|
---|
509 | holds the text of the current token. It may not be modified.
|
---|
510 | .IP -
|
---|
511 | .B int yyleng
|
---|
512 | holds the length of the current token. It may not be modified.
|
---|
513 | .IP -
|
---|
514 | .B FILE *yyin
|
---|
515 | is the file which by default
|
---|
516 | .I flex
|
---|
517 | reads from. It may be redefined but doing so only makes sense before
|
---|
518 | scanning begins. Changing it in the middle of scanning will have
|
---|
519 | unexpected results since
|
---|
520 | .I flex
|
---|
521 | buffers its input. Once scanning terminates because an end-of-file
|
---|
522 | has been seen,
|
---|
523 | .B
|
---|
524 | void yyrestart( FILE *new_file )
|
---|
525 | may be called to point
|
---|
526 | .I yyin
|
---|
527 | at the new input file.
|
---|
528 | .IP -
|
---|
529 | .B FILE *yyout
|
---|
530 | is the file to which
|
---|
531 | .B ECHO
|
---|
532 | actions are done. It can be reassigned by the user.
|
---|
533 | .IP -
|
---|
534 | .B YY_CURRENT_BUFFER
|
---|
535 | returns a
|
---|
536 | .B YY_BUFFER_STATE
|
---|
537 | handle to the current buffer.
|
---|
538 | .SH MACROS THE USER CAN REDEFINE
|
---|
539 | .IP -
|
---|
540 | .B YY_DECL
|
---|
541 | controls how the scanning routine is declared.
|
---|
542 | By default, it is "int yylex()", or, if prototypes are being
|
---|
543 | used, "int yylex(void)". This definition may be changed by redefining
|
---|
544 | the "YY_DECL" macro. Note that
|
---|
545 | if you give arguments to the scanning routine using a
|
---|
546 | K&R-style/non-prototyped function declaration, you must terminate
|
---|
547 | the definition with a semi-colon (;).
|
---|
548 | .IP -
|
---|
549 | The nature of how the scanner
|
---|
550 | gets its input can be controlled by redefining the
|
---|
551 | .B YY_INPUT
|
---|
552 | macro.
|
---|
553 | YY_INPUT's calling sequence is "YY_INPUT(buf,result,max_size)". Its
|
---|
554 | action is to place up to
|
---|
555 | .I max_size
|
---|
556 | characters in the character array
|
---|
557 | .I buf
|
---|
558 | and return in the integer variable
|
---|
559 | .I result
|
---|
560 | either the
|
---|
561 | number of characters read or the constant YY_NULL (0 on Unix systems)
|
---|
562 | to indicate EOF. The default YY_INPUT reads from the
|
---|
563 | global file-pointer "yyin".
|
---|
564 | A sample redefinition of YY_INPUT (in the definitions
|
---|
565 | section of the input file):
|
---|
566 | .nf
|
---|
567 |
|
---|
568 | %{
|
---|
569 | #undef YY_INPUT
|
---|
570 | #define YY_INPUT(buf,result,max_size) \\
|
---|
571 | { \\
|
---|
572 | int c = getchar(); \\
|
---|
573 | result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \\
|
---|
574 | }
|
---|
575 | %}
|
---|
576 |
|
---|
577 | .fi
|
---|
578 | .IP -
|
---|
579 | When the scanner receives an end-of-file indication from YY_INPUT,
|
---|
580 | it then checks the
|
---|
581 | .B yywrap()
|
---|
582 | function. If
|
---|
583 | .B yywrap()
|
---|
584 | returns false (zero), then it is assumed that the
|
---|
585 | function has gone ahead and set up
|
---|
586 | .I yyin
|
---|
587 | to point to another input file, and scanning continues. If it returns
|
---|
588 | true (non-zero), then the scanner terminates, returning 0 to its
|
---|
589 | caller.
|
---|
590 | .IP
|
---|
591 | The default
|
---|
592 | .B yywrap()
|
---|
593 | always returns 1. Presently, to redefine it you must first
|
---|
594 | "#undef yywrap", as it is currently implemented as a macro. It is
|
---|
595 | likely that
|
---|
596 | .B yywrap()
|
---|
597 | will soon be defined to be a function rather than a macro.
|
---|
598 | .IP -
|
---|
599 | YY_USER_ACTION
|
---|
600 | can be redefined to provide an action
|
---|
601 | which is always executed prior to the matched rule's action.
|
---|
602 | .IP -
|
---|
603 | The macro
|
---|
604 | .B YY_USER_INIT
|
---|
605 | may be redefined to provide an action which is always executed before
|
---|
606 | the first scan.
|
---|
607 | .IP -
|
---|
608 | In the generated scanner, the actions are all gathered in one large
|
---|
609 | switch statement and separated using
|
---|
610 | .B YY_BREAK,
|
---|
611 | which may be redefined. By default, it is simply a "break", to separate
|
---|
612 | each rule's action from the following rule's.
|
---|
613 | .SH FILES
|
---|
614 | .TP
|
---|
615 | .I flex.skel
|
---|
616 | skeleton scanner.
|
---|
617 | .TP
|
---|
618 | .I lex.yy.c
|
---|
619 | generated scanner (called
|
---|
620 | .I lexyy.c
|
---|
621 | on some systems).
|
---|
622 | .TP
|
---|
623 | .I lex.backtrack
|
---|
624 | backtracking information for
|
---|
625 | .B -b
|
---|
626 | flag (called
|
---|
627 | .I lex.bck
|
---|
628 | on some systems).
|
---|
629 | .TP
|
---|
630 | .B -lfl
|
---|
631 | library with which to link the scanners.
|
---|
632 | .SH "SEE ALSO"
|
---|
633 | .LP
|
---|
634 | flexdoc(1), lex(1), yacc(1), sed(1), awk(9).
|
---|
635 | .LP
|
---|
636 | M. E. Lesk and E. Schmidt,
|
---|
637 | .I LEX - Lexical Analyzer Generator
|
---|
638 | .SH DIAGNOSTICS
|
---|
639 | .I reject_used_but_not_detected undefined
|
---|
640 | or
|
---|
641 | .LP
|
---|
642 | .I yymore_used_but_not_detected undefined -
|
---|
643 | These errors can occur at compile time. They indicate that the
|
---|
644 | scanner uses
|
---|
645 | .B REJECT
|
---|
646 | or
|
---|
647 | .B yymore()
|
---|
648 | but that
|
---|
649 | .I flex
|
---|
650 | failed to notice the fact, meaning that
|
---|
651 | .I flex
|
---|
652 | scanned the first two sections looking for occurrences of these actions
|
---|
653 | and failed to find any, but somehow you snuck some in (via a #include
|
---|
654 | file, for example). Make an explicit reference to the action in your
|
---|
655 | .I flex
|
---|
656 | input file. (Note that previously
|
---|
657 | .I flex
|
---|
658 | supported a
|
---|
659 | .B %used/%unused
|
---|
660 | mechanism for dealing with this problem; this feature is still supported
|
---|
661 | but now deprecated, and will go away soon unless the author hears from
|
---|
662 | people who can argue compellingly that they need it.)
|
---|
663 | .LP
|
---|
664 | .I flex scanner jammed -
|
---|
665 | a scanner compiled with
|
---|
666 | .B -s
|
---|
667 | has encountered an input string which wasn't matched by
|
---|
668 | any of its rules.
|
---|
669 | .LP
|
---|
670 | .I flex input buffer overflowed -
|
---|
671 | a scanner rule matched a string long enough to overflow the
|
---|
672 | scanner's internal input buffer (16K bytes - controlled by
|
---|
673 | .B YY_BUF_MAX
|
---|
674 | in "flex.skel").
|
---|
675 | .LP
|
---|
676 | .I scanner requires -8 flag -
|
---|
677 | Your scanner specification includes recognizing 8-bit characters and
|
---|
678 | you did not specify the -8 flag (and your site has not installed flex
|
---|
679 | with -8 as the default).
|
---|
680 | .LP
|
---|
681 | .I
|
---|
682 | fatal flex scanner internal error--end of buffer missed -
|
---|
683 | This can occur in an scanner which is reentered after a long-jump
|
---|
684 | has jumped out (or over) the scanner's activation frame. Before
|
---|
685 | reentering the scanner, use:
|
---|
686 | .nf
|
---|
687 |
|
---|
688 | yyrestart( yyin );
|
---|
689 |
|
---|
690 | .fi
|
---|
691 | .LP
|
---|
692 | .I too many %t classes! -
|
---|
693 | You managed to put every single character into its own %t class.
|
---|
694 | .I flex
|
---|
695 | requires that at least one of the classes share characters.
|
---|
696 | .SH AUTHOR
|
---|
697 | Vern Paxson, with the help of many ideas and much inspiration from
|
---|
698 | Van Jacobson. Original version by Jef Poskanzer.
|
---|
699 | .LP
|
---|
700 | See flexdoc(1) for additional credits and the address to send comments to.
|
---|
701 | .SH DEFICIENCIES / BUGS
|
---|
702 | .LP
|
---|
703 | Some trailing context
|
---|
704 | patterns cannot be properly matched and generate
|
---|
705 | warning messages ("Dangerous trailing context"). These are
|
---|
706 | patterns where the ending of the
|
---|
707 | first part of the rule matches the beginning of the second
|
---|
708 | part, such as "zx*/xy*", where the 'x*' matches the 'x' at
|
---|
709 | the beginning of the trailing context. (Note that the POSIX draft
|
---|
710 | states that the text matched by such patterns is undefined.)
|
---|
711 | .LP
|
---|
712 | For some trailing context rules, parts which are actually fixed-length are
|
---|
713 | not recognized as such, leading to the abovementioned performance loss.
|
---|
714 | In particular, parts using '|' or {n} (such as "foo{3}") are always
|
---|
715 | considered variable-length.
|
---|
716 | .LP
|
---|
717 | Combining trailing context with the special '|' action can result in
|
---|
718 | .I fixed
|
---|
719 | trailing context being turned into the more expensive
|
---|
720 | .I variable
|
---|
721 | trailing context. For example, this happens in the following example:
|
---|
722 | .nf
|
---|
723 |
|
---|
724 | %%
|
---|
725 | abc |
|
---|
726 | xyz/def
|
---|
727 |
|
---|
728 | .fi
|
---|
729 | .LP
|
---|
730 | Use of unput() invalidates yytext and yyleng.
|
---|
731 | .LP
|
---|
732 | Use of unput() to push back more text than was matched can
|
---|
733 | result in the pushed-back text matching a beginning-of-line ('^')
|
---|
734 | rule even though it didn't come at the beginning of the line
|
---|
735 | (though this is rare!).
|
---|
736 | .LP
|
---|
737 | Pattern-matching of NUL's is substantially slower than matching other
|
---|
738 | characters.
|
---|
739 | .LP
|
---|
740 | .I flex
|
---|
741 | does not generate correct #line directives for code internal
|
---|
742 | to the scanner; thus, bugs in
|
---|
743 | .I flex.skel
|
---|
744 | yield bogus line numbers.
|
---|
745 | .LP
|
---|
746 | Due to both buffering of input and read-ahead, you cannot intermix
|
---|
747 | calls to <stdio.h> routines, such as, for example,
|
---|
748 | .B getchar(),
|
---|
749 | with
|
---|
750 | .I flex
|
---|
751 | rules and expect it to work. Call
|
---|
752 | .B input()
|
---|
753 | instead.
|
---|
754 | .LP
|
---|
755 | The total table entries listed by the
|
---|
756 | .B -v
|
---|
757 | flag excludes the number of table entries needed to determine
|
---|
758 | what rule has been matched. The number of entries is equal
|
---|
759 | to the number of DFA states if the scanner does not use
|
---|
760 | .B REJECT,
|
---|
761 | and somewhat greater than the number of states if it does.
|
---|
762 | .LP
|
---|
763 | .B REJECT
|
---|
764 | cannot be used with the
|
---|
765 | .I -f
|
---|
766 | or
|
---|
767 | .I -F
|
---|
768 | options.
|
---|
769 | .LP
|
---|
770 | Some of the macros, such as
|
---|
771 | .B yywrap(),
|
---|
772 | may in the future become functions which live in the
|
---|
773 | .B -lfl
|
---|
774 | library. This will doubtless break a lot of code, but may be
|
---|
775 | required for POSIX-compliance.
|
---|
776 | .LP
|
---|
777 | The
|
---|
778 | .I flex
|
---|
779 | internal algorithms need documentation.
|
---|
780 | .\" ref. to awk(9) man page corrected -- ASW 2005-01-15
|
---|