Open System Services Shell and Utilities Reference Manual (G06.28+, H06.05+)
User Commands (v - z) yacc(1)
The general format of the yacc input file is:
[ definitions ]
%%
[ rules ]
[ %%
[ user functions ]]
where
definitions Is the section where you define the variables to be used later in the grammar,
such as in the rules section. It is also the file where files are included (#include)
and processing conditions are defined. This section is optional.
rules Is the section that contains grammar rules for the parser. A yacc input file must
have a rules section.
user functions Is the section that contains user-supplied functions that can be used by the
actions in the rules section. This section is optional.
Each line in the definitions can be:
%{
%} When placed on lines by themselves, these enclose C code to be passed into the
global definitions of the output file. Such lines commonly include preprocessor
directives and declarations of external variables and functions.
%token token [ token ... ]
Lists tokens or terminal symbols to be used in the rest of the input file. This line
is needed for tokens that do not appear in other % definitions.
%left token [ token ... ]
Indicates that each token is an operator, that all tokens in this definition have
equal precedence, and that a succession of the operators listed in this definition
are evaluated left to right.
%right token [ token ... ]
Indicates that each token is an operator, that all tokens in this definition have
equal precedence, and that a succession of the operators listed in this definition
are evaluated right to left.
%nonassoc token [ token ... ]
Indicates that each token is an operator, and that the operators listed in this
definition cannot appear in succession.
%start symbol Indicates the highest-level production rule to be reduced; in other words, the rule
where the parser can consider its work done and terminate. If this definition is
not included, the parser uses the first production rule. symbol must be non-
terminal (not a token).
%type < type > symbol [ symbol ... ]
Defines each symbol as data type type, to resolve ambiguities.
%union union-def
Defines the yylval global variable as a union, where union-def is a standard C
definition in the format:
{ type member ;[type member ; ... ] }
527188-007 Hewlett-Packard Company 10−37