1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
'\" t
.\" %W% %R% (Berkeley) %E%
.\"
.TH BYACC 1 "January\ 18,\ 1993"
.UC 6
.SH NAME
byacc \- an LALR(1) parser generator
.SH SYNOPSIS
.B byacc [ -CPcdlrtv ] [ -b
.I file_prefix
.B ] [ -p
.I symbol_prefix
.B ]
.I filename
.SH DESCRIPTION
.I byacc
reads the grammar specification in the file
.I filename
and generates an LR(1) parser for it.
The parsers consist of a set of LALR(1) parsing tables and a driver routine
written in the C or Perl programming languages.
.I byacc
normally writes the parse tables and the driver routine to the file
.IR y.tab.c ,
using the C programming language.
.PP
The following options are available:
.RS
.TP
\fB-b \fIfile_prefix\fP
The
.B -b
option changes the prefix prepended to the output file names to
the string denoted by
.IR file_prefix .
The default prefix is the character
.IR y.
.TP
.BR -C " or " -c
Use the C programming language (default).
.TP
.B -d
The \fB-d\fP option causes the header file
.IR y.tab.h
to be written (or
.IR y.tab.ph ,
for Perl).
.TP
.B -l
If the
.B -l
option is not specified,
.I byacc
will insert \#line directives in the generated code.
The \#line directives let the C compiler relate errors in the
generated code to the user's original code.
If the \fB-l\fP option is specified,
.I byacc
will not insert the \#line directives.
\&\#line directives specified by the user will be retained.
.TP
\fB-p \fIsymbol_prefix\fP
Change the prefix in symbols in the generated code to the string
denoted by \fIsymbol_prefix\fP rather than the default of "\fIyy\fP".
Only symbols generated by \fIbyacc\fP are affected. Symbols in the
definition and user subroutine sections are not changed.
.IP
The \fIsymbol_prefix\fP can contain upper or lower case letters,
digits, or _ (underline or underscore). It must start with either
an underline or a letter and must contain at least one lower case
letter.
.IP
All lower case letters in the symbol prefix will be converted to
upper case letters when defined values or typedefs are generated.
.IP
For example, if '\fB-p\fP ftp_' is specifed on the \fIbyacc\fP command
line:
.in +.5i
.TS
tab (/) box;
a | a .
old symbol/new symbol
=
YYABORT/FTP_ABORT
YYACCEPT/FTP_ACCEPT
YYBYACC/FTP_BYACC
YYDEBUG/FTP_DEBUG
YYSTYPE/FTP_STYPE
yyabort/ftp_abort
yyerrok/ftp_errok
yylex/ftp_lex
yylval/ftp_lval
yyparse/ftp_parse
.TE
.in -.5i
Note: The above list is not complete.
.TP
.B -P
Use the Perl programming language. The output files have extensions
.I .tab.pl
and
.IR .tab.ph .
.TP
.B -r
The
.B -r
option causes
.I byacc
to produce separate files for code and tables. The code file
is named
.IR y.code.c,
and the tables file is named
.IR y.tab.c.
In Perl mode, the file name extension is
.IR .pl ,
but the use of this option is not recommended.
.TP
.B -t
The
.B -t
option changes the preprocessor directives generated by \fIbyacc\fP
so that debugging statements will be incorporated in the compiled code.
.TP
.B -v
The
.B -v
option causes a human-readable description of the generated parser to
be written to the file
.IR y.output .
.RE
.PP
If the environment variable TMPDIR is set, the string denoted by
TMPDIR will be used as the name of the directory where the temporary
files are created.
.PP
In C mode, the user's code at the end of the
.SM BYACC
file is inserted before the
.I yyparse
subroutine,
but in Perl mode, it is appended to
.I yyparse
so it can contain the main program.
In Perl mode, there is no library, so the user must
supply the
.I yyerror
and
.I yylex
subroutines and a main program that calls
.IR yyparse .
For example:
.sp
.RS
.nf
%%
.I ...grammar...
%%
sub yyerror { print STDERR "$.: $@\en"; }
sub yylex { ... }
exit &yyparse;
.fi
.RE
.SH FILES
.PD 0
.TP 12
.B y.code.c
output parser code in C
.TP
.B y.tab.c
output parser code and tables in C or, if
.I \-r
switch specified, output parser tables in C
.TP
.B y.tab.h
defines for token names and, if
.I %union
used in grammar, the union definition for C parsers
.TP
.B y.code.pl
output parser code in PERL
.TP
.B y.tab.pl
output parser code and tables in PERL or, if
.I -r
switch specified, output parser tables in PERL
.TP
.B y.tab.ph
PERL assignment statements for token names
.TP
.B y.output
description of parser states, state transitions, and conflicts
.TP
.BR /tmp/byacc.aXXXXXX ",\ " /tmp/byacc.tXXXXXX ",\ " /tmp/byacc.uXXXXXX
temporary files
.TP
.B /usr/local/lib/libby.a
library containing simple versions of
.I main(\|)
(calls
.I yyparse(\|)
then exits) and
.I yyerror(\|)
(prints message to
.B stderr
then returns)
.PD
.SH "SEE ALSO"
.BR flex "(1),\ " lex (1)
.LP
.I "Yacc: Yet Another Compiler-Compiler"
.br
Stephen C. Johnson
.br
Originally (?) published as Comp. Sci. Tech. Rep. No. 32. Bell
Laboratories, July 1975. Reprinted in many different places.
.LP
.I "Introduction to Compiler Construction with UNIX"
.br
Axel T. Schreiner and H. George Friedman, Jr.
.br
Prentice Hall, 1985.
.LP
.I "lex & yacc, Second Edition"
.br
John R. Levine, Tony Mason, and Doug Brown
.br
O'Reilly & Associates, Inc., 1992.
.in +.5i
Possibly the best book yet on lex and yacc. (My opinion only. Others
may disagree. - Rick Ohnemus)
.in -.5i
.LP
.I "comp.compilers monthly message and Frequently Asked Questions"
.br
Posted monthly in comp.compilers and news.answers USENET newsgroups.
.SH DIAGNOSTICS
If there are rules that are never reduced, the number of such rules is
reported on standard error.
.LP
If there are any LALR(1) conflicts, the number of conflicts is reported
on standard error.
.SH RESTRICTIONS
A symbol prefix specified using the \fB-p\fP switch must contain at least
one lower case character. This is to allow a distinction between variables,
defined values, and typedefs.
.SH BUGS
|