@@ -354,49 +354,15 @@ Here's another simple example:
354
354
355
355
@cindex counting characters and lines; reentrant
356
356
@example
357
- @verbatim
358
- %{
359
- int num_lines = 0, num_chars = 0;
360
- %}
361
- %option reentrant
362
- %%
363
- \n ++num_lines; ++num_chars;
364
- . ++num_chars;
365
-
366
- %%
367
-
368
- int main() {
369
- yyscan_t scanner;
370
-
371
- yylex_init ( &scanner );
372
- yylex ( scanner );
373
- yylex_destroy ( scanner );
374
-
375
- printf( "# of lines = %d, # of chars = %d\n",
376
- num_lines, num_chars );
377
- }
378
- @end verbatim
357
+ @verbatiminclude ../examples/manual/example_r.lex
379
358
@end example
380
359
381
360
If you have looked at older versions of the Flex nanual, you might
382
361
have seen a version of the above example that looked more like this:
383
362
384
363
@cindex counting characters and lines; non-reentrant
385
364
@example
386
- @verbatim
387
- int num_lines = 0, num_chars = 0;
388
- %%
389
- \n ++num_lines; ++num_chars;
390
- . ++num_chars;
391
-
392
- %%
393
-
394
- int main() {
395
- yylex();
396
- printf( "# of lines = %d, # of chars = %d\n",
397
- num_lines, num_chars );
398
- }
399
- @end verbatim
365
+ @verbatiminclude ../examples/manual/example_nr.lex
400
366
@end example
401
367
402
368
Both versions count the number of characters and the number of lines in
@@ -422,13 +388,24 @@ language other than the original C/C++ non-reentrancy is not even an
422
388
option.
423
389
424
390
This, it's a good idea to get used to using the reentrant interface
425
- from the beginning of your Flex prgramming . This is so even though the
391
+ from the beginning of your Flex programming . This is so even though the
426
392
reentrant example above is a rather poor one; it avoids exposing the
427
393
scanner state in globals but creates globals of its own. There is a
428
394
mechanism for including user-defined fields in the scanner structure
429
395
which will be explained in detail at @xref {Extra Data }. For now,
430
396
consider this:
431
397
398
+ @example
399
+ @verbatiminclude ../examples/manual/example_er.lex
400
+ @end example
401
+
402
+ While it requires a bit more ceremony, several instances of this
403
+ scanner can be run concurrently without stepping on each others'
404
+ storage.
405
+
406
+ (The @code {%option noyywrap } in these examples is helpful in
407
+ making them run standalone, but does not change the behavior of the scsnner.)
408
+
432
409
A somewhat more complicated example:
433
410
434
411
@cindex Pascal-like language
@@ -596,7 +573,8 @@ themselves.
596
573
597
574
A @code {%top } block is similar to a @samp {% @{ } ... @samp {% @} } block, except
598
575
that the code in a @code {%top } block is relocated to the @emph {top } of the
599
- generated file, before any flex definitions @footnote {Actually ,
576
+ generated file, before any flex definitions @footnote {Actually , in the
577
+ C/C++ back end ,
600
578
@code {yyIN_HEADER } is defined before the @samp {%top } block. }.
601
579
The @code {%top } block is useful when you want definitions to be
602
580
evaluated or certain files to be included before the generated code.
@@ -1642,7 +1620,7 @@ condition remains unchanged; it does @emph{not} revert to
1642
1620
1643
1621
@cindex yywrap , default for
1644
1622
@cindex noyywrap , %option
1645
- @cindex %option noyywrapp
1623
+ @cindex %option noyywrap
1646
1624
If you do not supply your own version of @code {yywrap() }, then you must
1647
1625
either use @code {%option noyywrap } (in which case the scanner behaves as
1648
1626
though @code {yywrap() } returned 1), or you must link with @samp {-lfl } to
0 commit comments