Imported Upstream version 20100216
[platform/upstream/byacc.git] / yacc.1
1 .\" $Id: yacc.1,v 1.7 2010/02/17 02:01:24 tom Exp $
2 .\"
3 .\" .TH YACC 1 "July\ 15,\ 1990"
4 .\" .UC 6
5 .TH YACC 1 "February 16, 2010" "Berkeley Yacc" "User Commands"
6 .SH NAME
7 Yacc \- an LALR(1) parser generator
8 .SH SYNOPSIS
9 .B yacc [ -dglrtv ] [ \-b
10 .I file_prefix
11 .B ] [ \-p
12 .I symbol_prefix
13 .B ]
14 .I filename
15 .SH DESCRIPTION
16 .B Yacc
17 reads the grammar specification in the file
18 .I filename
19 and generates an LALR(1) parser for it.
20 The parsers consist of a set of LALR(1) parsing tables and a driver routine
21 written in the C programming language.
22 .B Yacc
23 normally writes the parse tables and the driver routine to the file
24 .IR y.tab.c.
25 .PP
26 The following options are available:
27 .TP
28 \fB\-b \fP\fIfile_prefix\fR
29 The
30 .B \-b
31 option changes the prefix prepended to the output file names to
32 the string denoted by
33 .IR file_prefix.
34 The default prefix is the character
35 .IR y.
36 .TP
37 .B \-d
38 The \fB-d\fR option causes the header file
39 .IR y.tab.h
40 to be written.
41 .TP
42 .B \-g
43 The
44 .B \-g
45 option causes a graphical description of the generated LALR(1) parser to
46 be written to the file
47 .IR y.dot
48 in graphviz format, ready to be processed by dot(1).
49 .TP
50 .B \-l
51 If the
52 .B \-l
53 option is not specified,
54 .B yacc
55 will insert \fI#line\fP directives in the generated code.
56 The \fI#line\fP directives let the C compiler relate errors in the
57 generated code to the user's original code.
58 If the \fB-l\fR option is specified,
59 .B yacc
60 will not insert the \fI#line\fP directives.
61 \&\fI#line\fP directives specified by the user will be retained.
62 .TP
63 \fB\-o \fP\fIoutput_file\fR
64 specify the filename for the parser file.
65 If this option is not given, the output filename is
66 the file prefix concatenated with the file suffix, e.g., \fBy.tab.c\fP.
67 This overrides the \fB-p\fP option.
68 .TP
69 \fB\-p \fP\fIsymbol_prefix\fR
70 The
71 .B \-p
72 option changes the prefix prepended to yacc-generated symbols to
73 the string denoted by
74 .IR symbol_prefix.
75 The default prefix is the string
76 .IR yy.
77 .TP
78 .B \-P
79 create a reentrant parser, e.g., "%pure-parser".
80 .TP
81 .B \-r
82 The
83 .B \-r
84 option causes
85 .B yacc
86 to produce separate files for code and tables.  The code file
87 is named
88 .IR y.code.c,
89 and the tables file is named
90 .IR y.tab.c.
91 .TP
92 .B \-t
93 The
94 .B \-t
95 option changes the preprocessor directives generated by
96 .B yacc
97 so that debugging statements will be incorporated in the compiled code.
98 .TP
99 .B \-v
100 The
101 .B \-v
102 option causes a human-readable description of the generated parser to
103 be written to the file
104 .IR y.output.
105 .TP
106 .B \-V
107 print the version number to the standard output.
108 .SH EXTENSIONS
109 .B yacc
110 provides some extensions for compatibility with bison and other implementations
111 of yacc:
112 .TP
113 \fB %expect\fP \fInumber\fP
114 tell \fByacc\fP the expected number of shift/reduce conflicts.
115 That makes it only report the number if it differs.
116 .TP
117 \fB %expect-rr\fP \fInumber\fP
118 tell \fByacc\fP the expected number of reduce/reduce conflicts.
119 That makes it only report the number if it differs.
120 This is (unlike bison) allowable in LALR parsers.
121 .TP
122 \fB %pure-parser\fP
123 Most variables (other than \fByydebug\fP and \fByynerrs\fP) are
124 allocated on the stack within \fByyparse\fP, making the parser reasonably
125 reentrant.
126 .
127 .SH DIAGNOSTICS
128 If there are rules that are never reduced, the number of such rules is
129 reported on standard error.
130 If there are any LALR(1) conflicts, the number of conflicts is reported
131 on standard error.