Open System Services Shell and Utilities Reference Manual (G06.29+, H06.08+, J06.03+)
lex(1) OSS Shell and Utilities Reference Manual
2. The scanner program converts uppercase to lowercase letters, removes spaces at the end
of a line, and replaces multiple spaces with single spaces. The lexcommands file con-
tains:
%%
[A-Z] putchar(tolower(yytext[0]));
[ ]+$
[ ]+ putchar(’ ’);
FILES
flex.skel Is the skeleton scanner.
lex.yy.c Is the generated scanner C source.
lex.backtrack Contains backtracking information generated from the -b flag.
NOTES
• Some trailing context patterns cannot be properly matched and generate warning mes-
sages:
Dangerous trailing context
These are patterns where the ending of the first part of the rule matches the beginning of
the second part, such as zx*/xy*, where the x* matches the x at the beginning of the trail-
ing context.
• For some trailing context rules, parts that are actually fixed length are not recognized as
such, leading to the previously mentioned performance loss. In particular, patterns using
{n} (such as test{3}) are always considered variable length.
Combining trailing context with the special | (vertical bar) action can result in fixed trail-
ing context being turned into the more expensive variable trailing context. This happens
in the following example:
%%
abc|
xyz/def
• Use of the unput() macro invalidates the contents of the yytext and yyleng variables
within the current lex action.
• Use of the unput() macro to push back more text than was matched can result in the
pushed-back text matching a beginning-of-line (ˆ) rule even though it did not come at the
beginning of the line.
• Pattern matching of NULLs is substantially slower than matching other characters.
• The lex command does not generate correct #line directives for code internal to the
scanner; thus, bugs in flex.skel yield invalid line numbers.
• Due to both buffering of input and read-ahead, you cannot intermix calls to <stdio.h>
routines, such as getchar( ), with lex rules and expect it to work. Call input() instead.
• The total table entries listed by the -v flag excludes the number of table entries needed to
determine what rule was matched. The number of entries is equal to the number of deter-
ministic finite-state automaton (DFA) states if the scanner does not use REJECT, and is
somewhat greater than the number of states if it does.
5−58 Hewlett-Packard Company 527188-021