DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

yacc(CP)


yacc -- yet another compiler-compiler--a parser generator

Syntax

yacc [-vdltwV -Q[y|n] ] filename

Description

The yacc command is used to generate C code that implements a parser. The program that yacc generates is based on an input file consisting of a grammar and possibly some C code fragments and internal declarations. yacc converts a context-free grammar into a set of tables for a simple automaton which executes a parsing algorithm. Code that is executed whenever a grammar production is recognized may be supplied. The grammar may be ambiguous; precedence rules are used to resolve ambiguities.

The output file containing the parser code is called y.tab.c. This program must be compiled by the C compiler; the parsing routine is called yyparse. This program must be linked with a lexical analyzer routine with the name yylex, as well as main and yyerror, an error-handling routine. lex(CP) will generate a lexical analyzer routine called yylex; if the program is linked with the yacc library, main and yyerror will be supplied.

yacc produces C code which may be compiled with C++. All functions produced and used by yacc-produced code explicitly have "C" linkage. In particular, user-supplied version of yylex() and yyerror() may be written in C++, but must have "C" linkage, and the function yyparse, must be declared extern "C" if called by C++ code.

Because file names are fixed, only one yacc process can be active in a given directory.

Options


-d
A file called y.tab.h will be generated. This file contains #define statements associating yacc-assigned token codes with the user-declared token names. This file may be included in other programs which need to access the token codes.

-l
The code produced in y.tab.c will not contain any #line constructs. This option should only be used after the grammar and the associated actions are fully debugged.

-S
Obsolete. Silently ignored for backwards compatibility.

-t
Runtime debugging code is always generated in y.tab.c. By default, this code is not compiled. However, when yacc's -t option is used, this debugging code will be compiled. Independent of whether the -t option is used, the runtime debugging code is under the control of YYDEBUG, a preprocessor symbol. If YYDEBUG has a non-zero value, then the debugging code is compiled. If its value is zero, then the code will not be compiled. A program compiled without the runtime debugging code will be smaller and slightly faster.

-v
A file called y.output will be generated. This file contains a description of the parsing tables and a report on conflicts generated by ambiguities in the grammar.

-V
Print out version information on standard error.

-Q(y|n)
Print out version information to output file lex.yy.c by using -Qy. The -Qn option does not print out version information and is the default.

Diagnostics

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. If some rules are not reachable from the start symbol, this is reported.

Files


y.output

y.tab.c

y.tab.h
Defines for token names.

yacc.tmp
yacc.debug
yacc.acts
Temporary files.

/usr/ccs/lib/yaccpar
Parser prototype for C programs.

See also

lex(CP)

Standards conformance

yacc is conformant with:

X/Open Portability Guide, Issue 3, 1989


© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003