Open System Services Shell and Utilities Reference Manual (G06.27+, H06.04+)

User Commands (v - z) yacc(1)
The general format of the yacc input le is:
[ denitions ]
%%
[ rules ]
[ %%
[ user functions ]]
where
definitions Is the section where you dene the variables to be used later in the grammar,
such as in the rules section. It is also the le where les are included (#include)
and processing conditions are dened. This section is optional.
rules Is the section that contains grammar rules for the parser. A yacc input le 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 denitions can be:
%{
%} When placed on lines by themselves, these enclose C code to be passed into the
global denitions of the output le. 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 le. This line
is needed for tokens that do not appear in other % denitions.
%left token [ token ... ]
Indicates that each token is an operator, that all tokens in this denition have
equal precedence, and that a succession of the operators listed in this denition
are evaluated left to right.
%right token [ token ... ]
Indicates that each token is an operator, that all tokens in this denition have
equal precedence, and that a succession of the operators listed in this denition
are evaluated right to left.
%nonassoc token [ token ... ]
Indicates that each token is an operator, and that the operators listed in this
denition 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 denition is
not included, the parser uses the rst production rule. symbol must be non-
terminal (not a token).
%type < type > symbol [ symbol ... ]
Denes each symbol as data type type, to resolve ambiguities.
%union union-def
Denes the yylval global variable as a union, where union-def is a standard C
denition in the format:
{ type member ;[type member ; ... ] }
527188-004 Hewlett-Packard Company 1037