No subject


Sat Oct 25 20:44:27 CEST 2014


There are a number of special directives which can be included
within an action:

`ECHO'
     copies yytext to the scanner's output.

`BEGIN'
     followed by the name of a start condition places the scanner in the
     corresponding start condition (see below).

`REJECT'
     directs the scanner to proceed on to the "second best" rule which
     matched the input (or a prefix of the input).  The rule is chosen
     as described above in *Note Matching::, and `yytext' and `yyleng'
     set up appropriately.  It may either be one which matched as much
     text as the originally chosen rule but came later in the `flex'
     input file, or one which matched less text.  For example, the
     following will both count the words in the input and call the
     routine `special()' whenever `frob' is seen:

                      int word_count = 0;
              %%

              frob        special(); REJECT;
              [^ \t\n]+   ++word_count;

     Without the `REJECT', any occurrences of `frob' in the input would
     not be counted as words, since the scanner normally executes only
     one action per token.  Multiple uses of `REJECT' are allowed, each
     one finding the next best choice to the currently active rule.  For
     example, when the following scanner scans the token `abcd', it will
     write `abcdabcaba' to the output:
....

`flex' scans your rule actions to determine whether you use the
`REJECT' or `yymore()' features.  The `REJECT' and `yymore' options are
available to override its decision as to whether you use the options,
either by setting them (e.g., `%option reject)' to indicate the feature
is indeed used, or unsetting them to indicate it actually is not used
(e.g., `%option noyymore)'.

Another indication is:
 flex  -s -Cf -B -8 -ocf-lex.c -Pcf_ cf-lex.l
 flex: REJECT cannot be used with -f or -F
 make: *** [cf-lex.c] Error 1

You can't use -Cf because flex think you are using REJECT in your
scanner.

>
> Sure, it is not elegant and it might cause bugs in the future (currently, I do
> not see any real bug), but your rename is not elegant either.

No, but it is the equivalent of renaming a variable from an ideal name
to a less ideal name, not a big deal.




More information about the Bird-users mailing list