yacc(1)
NAME
yacc − yet another compiler-compiler
SYNOPSIS
yacc [-vdlt] [-N <secondary><n> ...] [-p sym_prefix] [-b file_prefix] grammar
DESCRIPTION
yacc converts a context-free grammar into a set of tables for a simple automaton which executes an LALR(1) parsing algorithm as described in popular compiler-construction literature. Ambiguous grammar is allowed; specified precedence rules are used to break ambiguities.
The output file, y.tab.c, must be compiled by the C compiler to produce a program yyparse. This program must be loaded with the lexical analyzer program, yylex, as well as main and yyerror, an error handling routine. These routines must be supplied by the user; lex is useful for creating lexical analyzers usable by yacc (see lex(1)).
Options
yacc recognizes the following options:
-v Prepare file y.output containing a description of the parsing tables and a report on conflicts generated by ambiguities in the grammar.
-d Generate file y.tab.h with the #define statements that associate the yacc-assigned “token codes” with the user-declared “token names”. This allows source files other than y.tab.c to access the token codes.
-l Do not place any #line constructs in code produced in y.tab.c. Generally, this option should only be used after y.tab.c has compiled successfully, since the #line directives allow the C compiler to give error messages that refer to the yacc source file rather than the y.tab.c file. This option is useful, however, for symbolic debugging, since some symbolic debuggers may be confused by line numbers that are not in order.
-t Compile runtime debugging code (see Debugging below for details).
-N<secondary><n>
Allow the sizes of certain internal yacc tables to be reset. secondary is one of the letters from the set {B a m s p n e c l w} and specifies the table; n is the new size. Tables that can be reset by using secondary letters are as follows:
a a-array size; default is 12000.
m mem array size; default is 12000.
s number of states; default is 1000.
p number of productions; default is 800.
n number of non-terminals; default is 600.
e temp-space size; default is 1250.
c name-space size; default is 5000.
l look-ahead set table size; default is 650.
w working set table size; default is 650.
-p sym_prefix Use sym_prefix instead of yy as the prefix for externally scoped variable and function names produced by yacc. Names affected are: yyparse, yylex, yyerror, yylval, yychar, yydebug, and yynerrs.
-b file_prefix Use file_prefix instead of y as the prefix for output filenames. Names affected are: y.tab.c, y.tab.h, and y.output.
If an array overflows, yacc issues a fatal error message including a suggestion of which table to reset. For example:
too many states, try -Ns option
Debugging
Runtime debugging code is always generated in y.tab.c under conditional compilation control. By default, this code is not included when y.tab.c is compiled. However, when yacc’s -t option is used, this debugging code is compiled by default. Independent of whether the -t option was used, the runtime debugging code is under the control of YYDEBUG, a pre-processor symbol. If YYDEBUG has a non-zero value, the debugging code is included. If its value is zero, the code is not included. The size and execution time of a program produced without the runtime debugging code is smaller and slightly faster.
EXTERNAL INFLUENCES
Environment Variables
LC_CTYPE determines the classification of characters as letters and digits for name fields. If LC_CTYPE indicates a multi-byte character set is in use, intermixed ASCII and 16-bit characters can be used in non-reserved token names, terminal symbols, non-terminal symbols, strings and comments.
LC_MESSAGES determines the language in which messages are displayed.
LANG is used as a default if LC_CTYPE or LC_MESSAGES is not set.
International Code Set Support
Single- and multi-byte character code sets are supported.
ERRORS
The number of reduce-reduce and shift-reduce conflicts is reported on the standard error output; a more detailed report is found in the y.output file. Similarly, if some rules are not reachable from the start symbol, this is also reported.
FILES
y.output
y.tab.c
y.tab.h defines for token names
yacc.tmp,
yacc.acts, yacc.debug temporary files
/usr/lib/yaccpar parser prototype for C programs
WARNINGS
File names are fixed. Therefore, only one yacc process can be active in a given directory at any given time.
The maximum number of terminal symbols is fixed at 2000 and cannot be reset using the -N option.
Even though yacc is able to accept and process 16-bit characters, C compilers that are used to compile the generated y.tab.c and y.tab.h files may not. Using the -d option to generate a y.tab.h file with %token definitions may result in an un-compilable file if multi-byte characters are used in token names.
SEE ALSO
lex(1), setlocale(3C), malloc(3C).
YACC − Yet Another Compiler Compiler tutorial in C Programming Tools manual.
Compilers − Principles, Techniques, and Tools by Aho, Sethi, and Ullman; Addison-Wesley ISBN 0-201-10088-6.
STANDARDS CONFORMANCE
yacc: SVID2, XPG2, XPG3, POSIX.2
Hewlett-Packard Company — HP-UX Release 9.0: August 1992