2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document. The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
25 .\" This notice shall appear on any product containing this material.
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
43 .\" Copyright 1989 AT&T
44 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
45 .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved.
47 .TH YACC 1 "Aug 24, 2009"
49 yacc \- yet another compiler-compiler
53 \fByacc\fR [\fB-dltVv\fR] [\fB-b\fR \fIfile_prefix\fR] [\fB-Q\fR [y | n]]
54 [\fB-P\fR \fIparser\fR] [\fB-p\fR \fIsym_prefix\fR] \fIfile\fR
60 The \fByacc\fR command converts a context-free grammar into a set of tables for
61 a simple automaton that executes an LALR(1) parsing algorithm. The grammar can
62 be ambiguous. Specified precedence rules are used to break ambiguities.
65 The output file, \fBy.tab.c\fR, must be compiled by the C compiler to produce a
66 function \fByyparse()\fR. This program must be loaded with the lexical analyzer
67 program, \fByylex()\fR, as well as \fBmain()\fR and \fByyerror()\fR, an error
68 handling routine. These routines must be supplied by the user. The \fBlex\fR(1)
69 command is useful for creating lexical analyzers usable by \fByacc\fR.
73 The following options are supported:
77 \fB\fB-b\fR \fIfile_prefix\fR\fR
80 Uses \fIfile_prefix\fR instead of \fBy\fR as the prefix for all output files.
81 The code file \fBy.tab.c\fR, the header file \fBy.tab.h\fR (created when
82 \fB-d\fR is specified), and the description file \fBy.output\fR (created when
83 \fB-v\fR is specified), is changed to \fIfile_prefix\fR\fB\&.tab.c\fR,
84 \fIfile_prefix\fR\fB\&.tab.h\fR, and \fIfile_prefix\fR\fB\&.output\fR,
94 Generates the file \fBy.tab.h\fR with the \fB#define\fR statements that
95 associate the \fByacc\fR user-assigned "token codes" with the user-declared
96 "token names". This association allows source files other than \fBy.tab.c\fR to
97 access the token codes.
106 Specifies that the code produced in \fBy.tab.c\fR does not contain any
107 \fB#line\fR constructs. This option should only be used after the grammar and
108 the associated actions are fully debugged.
114 \fB\fB-p\fR \fIsym_prefix\fR\fR
117 Uses \fIsym_prefix\fR instead of \fByy\fR as the prefix for all external names
118 produced by \fByacc\fR. The names affected include the functions
119 \fByyparse()\fR, \fByylex()\fR and \fByyerror()\fR, and the variables
120 \fIyylval\fR, \fIyychar\fR and \fIyydebug\fR. (In the remainder of this
121 section, the six symbols cited are referenced using their default names only as
122 a notational convenience.) Local names can also be affected by the \fB-p\fR
123 option. However, the \fB-p\fR option does not affect \fB#define\fR symbols
124 generated by \fByacc\fR.
130 \fB\fB-P\fR \fIparser\fR\fR
133 Allows you to specify the parser of your choice instead of
134 \fB/usr/share/lib/ccs/yaccpar\fR. For example, you can specify:
138 example% \fByacc -P ~/myparser parser.y\fR
148 \fB\fB-Q\fR[\fBy\fR|\fBn\fR]\fR
151 The \fB-Qy\fR option puts the version stamping information in \fBy.tab.c\fR.
152 This allows you to know what version of \fByacc\fR built the file. The
153 \fB-Qn\fR option (the default) writes no version information.
162 Compiles runtime debugging code by default. Runtime debugging code is always
163 generated in \fBy.tab.c\fR under conditional compilation control. By default,
164 this code is not included when \fBy.tab.c\fR is compiled. Whether or not the
165 \fB-t\fR option is used, the runtime debugging code is under the control of
166 \fBYYDEBUG\fR , a preprocessor symbol. If \fBYYDEBUG\fR has a non-zero value,
167 then the debugging code is included. If its value is \fB0\fR, then the code is
168 not included. The size and execution time of a program produced without the
169 runtime debugging code is smaller and slightly faster.
178 Prepares the file \fBy.output\fR, which contains a description of the parsing
179 tables and a report on conflicts generated by ambiguities in the grammar.
188 Prints on the standard error output the version information for \fByacc\fR.
194 The following operand is required:
201 A path name of a file containing instructions for which a parser is to be
207 \fBExample 1 \fRAccessing the yacc Library
210 Access to the \fByacc\fR library is obtained with library search operands to
211 \fBcc\fR. To use the \fByacc\fR library \fBmain\fR:
216 example% \fBcc y.tab.c -ly\fR
223 Both the \fBlex\fR library and the \fByacc\fR library contain \fBmain\fR. To
224 access the \fByacc\fR \fBmain\fR:
229 example% \fBcc y.tab.c lex.yy.c -ly -ll\fR
236 This ensures that the \fByacc\fR library is searched first, so that its
241 The historical \fByacc\fR libraries have contained two simple functions that
242 are normally coded by the application programmer. These library functions are
243 similar to the following code:
251 extern int yyparse();
253 setlocale(LC_ALL, "");
255 /* If the following parser is one created by lex, the
256 application must be careful to ensure that LC_CTYPE
257 and LC_COLLATE are set to the POSIX locale. */
264 int yyerror(const char *msg)
266 (void) fprintf(stderr, "%s\en", msg);
272 .SH ENVIRONMENT VARIABLES
275 See \fBenviron\fR(5) for descriptions of the following environment variables
276 that affect the execution of \fByacc\fR: \fBLANG\fR, \fBLC_ALL\fR,
277 \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
280 \fByacc\fR can handle characters from \fBEUC\fR primary and supplementary
281 codesets as one-token symbols. \fBEUC\fR codes can only be single character
282 quoted terminal symbols. \fByacc\fR expects \fByylex()\fR to return a wide
283 character (\fBwchar_t\fR) value for these one-token symbols.
287 The following exit values are returned:
294 Successful completion.
313 state transitions of the generated parser
322 source code of the generated parser
331 header file for the generated parser
337 \fB\fByacc.acts\fR\fR
346 \fB\fByacc.debug\fR\fR
367 parser prototype for C programs
373 See \fBattributes\fR(5) for descriptions of the following attributes:
381 ATTRIBUTE TYPE ATTRIBUTE VALUE
383 Interface Stability Committed
385 Standard See \fBstandards\fR(5).
391 \fBlex\fR(1), \fBattributes\fR(5), \fBenviron\fR(5), \fBstandards\fR(5)
395 The number of reduce-reduce and shift-reduce conflicts is reported on the
396 standard error output. A more detailed report is found in the \fBy.output\fR
397 file. Similarly, if some rules are not reachable from the start symbol, this
398 instance is also reported.
402 Because file names are fixed, at most one \fByacc\fR process can be active in a
403 given directory at a given time.
406 Users are encouraged to avoid using \fB$\fR as part of any identifier name.