Open System Services Shell and Utilities Reference Manual (G06.25+, H06.03+)

User Commands (d - f)
ex(1)
YY_BREAK
Is used in the scanner to separate different actions. By default, it is
simply a break, but it can be redened if necessary.
The user_functions section consists of complete C functions, which are passed directly into the
lex.y.cc output le (the effect is similar to dening the functions in separate .c les and linking
them with lex.y.cc). This section is separated from the rules section by the %% delimiter.
Comments, in C syntax, can appear anywhere in the user_functions or denitions sections. In the
rules section, comments can be embedded within actions. Empty lines or lines consisting of white
space are ignored.
The following macros are not normally called explicitly within an action, but they are used inter-
nally by the ex command to handle the input and output streams.
input( ) Reads the next character from the input stream. You cannot redene input().
output() Writes the next character to the output stream.
unput(c) Puts the character c back into the input stream. It will be the next character
scanned. You cannot redene unput().
libl.a contains default functions to support testing or quick use of a ex program without the yacc
command; these functions can be linked in through -ll. They can also be provided by the user.
main() A simple wrapper that simply calls setlocale() and then calls the yylex() function.
yywrap() The function called when the scanner reaches the end of an input stream. The
default denition simply returns 1, which causes the scanner in turn to return 0
(zero).
EXAMPLES
1. The following command processes the le lexcommands to produce the scanner le
lex.yy.c:
ex lexcommands
This is then compiled and linked by the command:
cc -oscanner lex.yy.c -ll
to produce a program scanner.
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 le 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 ag.
527188-003 Hewlett-Packard Company 3151