1.\" $OpenBSD: yacc.1,v 1.34 2021/03/08 02:47:29 jsg Exp $ 2.\" 3.\" Copyright (c) 1989, 1990 The Regents of the University of California. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to Berkeley by 7.\" Robert Paul Corbett. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. Neither the name of the University nor the names of its contributors 18.\" may be used to endorse or promote products derived from this software 19.\" without specific prior written permission. 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" SUCH DAMAGE. 32.\" 33.\" from: @(#)yacc.1 5.7 (Berkeley) 7/30/91 34.\" 35.Dd $Mdocdate: March 8 2021 $ 36.Dt YACC 1 37.Os 38.Sh NAME 39.Nm yacc 40.Nd an LALR(1) parser generator 41.Sh SYNOPSIS 42.Nm yacc 43.Op Fl dlrtv 44.Op Fl b Ar file_prefix 45.Op Fl o Ar output_file 46.Op Fl p Ar symbol_prefix 47.Ar file 48.Sh DESCRIPTION 49.Nm 50reads the grammar specification in 51.Ar file 52and generates an LR(1) parser for it. 53The parsers consist of a set of LALR(1) 54parsing tables and a driver routine 55written in the C programming language. 56.Nm 57normally writes the parse tables and the driver routine to the file 58.Pa y.tab.c . 59.Pp 60The options are as follows: 61.Bl -tag -width Ds 62.It Fl b Ar file_prefix 63The 64.Fl b 65option changes the prefix prepended to the output file names to 66the string denoted by 67.Ar file_prefix . 68The default prefix is the character 69.Ar y . 70.It Fl d 71The 72.Fl d 73option causes the header file 74.Pa y.tab.h 75to be written. 76.It Fl l 77If the 78.Fl l 79option is not specified, 80.Nm 81will insert #line directives in the generated code. 82The #line directives let the C compiler relate errors in the 83generated code to the user's original code. 84If the 85.Fl l 86option is specified, 87.Nm 88will not insert the #line directives. 89#line directives specified by the user will be retained. 90.It Fl o Ar output_file 91The 92.Fl o 93option specifies an explicit name for the parser's output file name instead 94of the default. 95The names of the other output files are constructed from 96.Pa output_file 97as described under the 98.Fl d 99and 100.Fl v 101options. 102.It Fl p Ar symbol_prefix 103The 104.Fl p 105option changes the prefix prepended to yacc-generated symbols to 106the string denoted by 107.Ar symbol_prefix . 108The default prefix is the string 109.Ar yy . 110.It Fl r 111The 112.Fl r 113option causes 114.Nm 115to produce separate files for code and tables. 116The code file is named 117.Pa y.code.c , 118and the tables file is named 119.Pa y.tab.c . 120.It Fl t 121The 122.Fl t 123option changes the preprocessor directives generated by 124.Nm 125so that debugging statements will be incorporated in the compiled code. 126.It Fl v 127The 128.Fl v 129option causes a human-readable description of the generated parser to 130be written to the file 131.Pa y.output . 132.El 133.Sh TABLES 134The names of the tables generated by this version of 135.Nm 136are 137.Dq yylhs , 138.Dq yylen , 139.Dq yydefred , 140.Dq yydgoto , 141.Dq yysindex , 142.Dq yyrindex , 143.Dq yygindex , 144.Dq yytable , 145and 146.Dq yycheck . 147Two additional tables, 148.Dq yyname 149and 150.Dq yyrule , 151are created if 152.Dv YYDEBUG 153is defined and non-zero. 154.Sh FILES 155.Bl -tag -width /tmp/yacc.uXXXXXXXXXX -compact 156.It Pa y.code.c 157.It Pa y.tab.c 158.It Pa y.tab.h 159.It Pa y.output 160.El 161.Sh EXIT STATUS 162.Ex -std yacc 163.Sh DIAGNOSTICS 164If there are rules that are never reduced, the number of such rules is 165written to the standard error. 166If there are any LALR(1) 167conflicts, the number of conflicts is also written 168to the standard error. 169.Sh SEE ALSO 170.Xr yyfix 1 171.Rs 172.\" 4.4BSD PSD:15 173.%A S. C. Johnson 174.%T Yacc \(em Yet Another Compiler-Compiler 175.%I AT&T Bell Laboratories 176.%R Computing Science Technical Report 177.%N 32 178.%D July 1975 179.Re 180.Rs 181.%A F. DeRemer 182.%A T. J. Pennello 183.%D 1982 184.%J TOPLAS 185.%N Issue 4 186.%P pp. 615\(en649 187.%T Efficient Computation of LALR(1) Look-Ahead Sets 188.%V Volume 4 189.Re 190.Sh STANDARDS 191The 192.Nm 193utility is compliant with the 194.St -p1003.1-2008 195specification, 196though its presence is optional. 197.Pp 198The flags 199.Op Fl or 200are extensions to that specification. 201.Sh HISTORY 202.Nm 203was originally developed at AT&T by 204.An Stephen C. Johnson . 205.Pp 206Berkeley 207.Nm 208was originally developed using PCC on a VAX with the 209intent of being as compatible as possible with 210.At 211.Nm . 212Much is owed to the unflagging efforts of Keith Bostic. 213His badgering kept me working on 214.Nm 215long after I was ready to quit. 216.Pp 217Berkeley 218.Nm 219is based on the excellent algorithm for computing 220LALR(1) lookaheads developed by 221.An Tom Pennello 222and 223.An Frank DeRemer . 224The algorithm is described in their almost impenetrable article in 225TOPLAS (see above). 226.Pp 227Finally, much credit must go to those who pointed out deficiencies 228of earlier releases. 229Among the most prolific contributors were 230Benson I. Margulies, 231Dave Gentzel, 232Antoine Verheijen, 233Peter S. Housel, 234Dale Smith, 235Ozan Yigit, 236John Campbell, 237Bill Sommerfeld, 238Paul Hilfinger, 239Gary Bridgewater, 240Dave Bakken, 241Dan Lanciani, 242Richard Sargent, 243and 244Parag Patel. 245.Sh AUTHORS 246The 247.Nm 248utility was written by 249.An Robert Corbett . 250