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

User Commands (v - z) yacc(1)
unrecognized input.
The parser always executes action after encountering the symbol that precedes it. Thus, an
action can appear in the middle of a symbol-sequence, after each symbol-sequenc e, or after multi-
ple instances of symbol-sequence . In the last case, action is executed when the parser matches
any of the sequences.
The action consists of standard C code within braces and can also take the following values,
variables, and keywords.
yylval If the token returned by the yylex function is associated with a significant value,
yylex should place the value in this global variable. By default, yylval is of type
int. The definitions section can include a %union definition to associate with
other data types, including structures. If you run yacc with the -d option, the full
yylval definition is passed into the y.tab.h file for access by lex.
yyerrok Causes the parser to start parsing tokens immediately after an erroneous
sequence, instead of performing the default action of reading and discarding
tokens up to a synchronization token. The yyerrok action should appear
immediately after the error token.
$[<type>]n Refers to symbol n, a token index in the production, counting from the beginning
of the production rule, where the first symbol after the colon is $1. The type
variable is the name of one of the union lines listed in the %union directive in
the declaration section. The <type> syntax (non-standard) allows the value to be
set to a specific data type. Note that you will rarely need to use the type syntax.
$[<type> ] $ Refers to the value returned by the matched symbol-sequence and used for the
matched symbol when reducing other rules. The symbol-sequence generally
assigns a value to $$. The type variable is the name of one of the union lines
listed in the %union directive in the declaration section. The <type> syntax
(non-standard) allows the value to be set to a specific data type. Note that you
will rarely need to use the type syntax.
The user functions section contains user-supplied programs. If you supply a lexical analyzer
(yylex
) to the parser, it must be contained in the user functions section.
The
following functions, which are contained in the user functions section, are invoked within
the yyparse function generated by yacc.
yylex() The lexical analyzer called by yyparse to recognize each token of input. Usu-
ally this function is created by lex. yylex reads input, recognizes expressions
within the input, and returns tokens. The function returns an int value. A return
value of 0 (zero) means the end of input.
yyerror(string)
The function that the parser calls upon encountering an input error. The default
function, defined in liby.a, simply prints string to the standard error. The user
can redefine the function. The function’s type is void.
The liby.a library contains default main() and yyerror() functions. These look like the follow-
ing, respectively:
main()
{
setlocale(LC_ALL, "");
(void) yyparse();
return(0);
527188-021 Hewlett-Packard Company 1039