]> git.saurik.com Git - bison.git/blame - doc/bison.1
Add Yacc Library.
[bison.git] / doc / bison.1
CommitLineData
a641b0da
DM
1.TH BISON 1 local
2.SH NAME
3bison \- GNU Project parser generator (yacc replacement)
4.SH SYNOPSIS
5.B bison
6[
7.BI \-b " file-prefix"
8] [
9.BI \-\-file-prefix= file-prefix
10] [
11.B \-d
12] [
342b8b6e
AD
13.BI \-\-defines= defines-file
14] [
15.B \-g
16] [
17.BI \-\-graph= graph-file
a641b0da 18] [
333ccc01
RS
19.B \-k
20] [
21.B \-\-token-table
22] [
a641b0da
DM
23.B \-l
24] [
25.B \-\-no-lines
26] [
333ccc01
RS
27.B \-n
28] [
29.B \-\-no-parser
30] [
a641b0da
DM
31.BI \-o " outfile"
32] [
33.BI \-\-output-file= outfile
34] [
35.BI \-p " prefix"
36] [
37.BI \-\-name-prefix= prefix
38] [
39.B \-t
40] [
41.B \-\-debug
42] [
43.B \-v
44] [
45.B \-\-verbose
46] [
47.B \-V
48] [
49.B \-\-version
50] [
51.B \-y
52] [
53.B \-\-yacc
54] [
55.B \-h
56] [
57.B \-\-help
58] [
59.B \-\-fixed-output-files
60]
61file
62.SH DESCRIPTION
63.I Bison
64is a parser generator in the style of
65.IR yacc (1).
66It should be upwardly compatible with input files designed
67for
68.IR yacc .
69.PP
70Input files should follow the
71.I yacc
72convention of ending in
73.BR .y .
74Unlike
75.IR yacc ,
76the generated files do not have fixed names, but instead use the prefix
77of the input file.
4e0813a6
PE
78Moreover, if you need to put
79.I C++
234a3be3 80code in the input file, you can end his name by a C++-like extension
4e0813a6 81(.ypp or .y++), then bison will follow your extension to name the
234a3be3 82output file (.cpp or .c++).
a641b0da 83For instance, a grammar description file named
234a3be3 84.B parse.yxx
a641b0da 85would produce the generated parser in a file named
234a3be3 86.BR parse.tab.cxx ,
a641b0da
DM
87instead of
88.IR yacc 's
4e0813a6
PE
89.B y.tab.c
90or old
91.I Bison
92version's
234a3be3 93.BR parse.tab.c .
a641b0da
DM
94.PP
95This description of the options that can be given to
96.I bison
97is adapted from the node
98.B Invocation
99in the
100.B bison.texinfo
101manual, which should be taken as authoritative.
102.PP
103.I Bison
104supports both traditional single-letter options and mnemonic long
105option names. Long option names are indicated with
106.B \-\-
107instead of
108.BR \- .
109Abbreviations for option names are allowed as long as they
110are unique. When a long option takes an argument, like
111.BR \-\-file-prefix ,
112connect the option name and the argument with
113.BR = .
114.SS OPTIONS
115.TP
116.BI \-b " file-prefix"
117.br
118.ns
119.TP
120.BI \-\-file-prefix= file-prefix
121Specify a prefix to use for all
122.I bison
123output file names. The names are
124chosen as if the input file were named
4e0813a6 125\fIfile-prefix\fP\fB.c\fP.
a641b0da
DM
126.TP
127.B \-d
128.br
129.ns
a641b0da
DM
130Write an extra output file containing macro definitions for the token
131type names defined in the grammar and the semantic value type
132.BR YYSTYPE ,
133as well as a few
134.B extern
135variable declarations.
136.sp
137If the parser output file is named
4e0813a6 138.IB name .c
a641b0da
DM
139then this file
140is named
4e0813a6 141\fIname\fP\fB.h\fP.
a641b0da
DM
142.sp
143This output file is essential if you wish to put the definition of
144.B yylex
145in a separate source file, because
146.B yylex
147needs to be able to refer to token type codes and the variable
148.BR yylval .
149.TP
342b8b6e 150.BI \-\-defines= defines-file
4e0813a6
PE
151The behavior of
152.B \-\-defines
153is the same than
154.B \-d
155option.
156The only difference is that it has an optional argument which is
342b8b6e
AD
157the name of the output filename.
158.TP
159.BI \-g
160.br
161.ns
162Output a VCG definition of the LALR(1) grammar automaton computed by
4e0813a6 163Bison. If the grammar file is
342b8b6e
AD
164.BR foo.y
165, the VCG output file will be
166.BR foo.vcg .
167.TP
168.BI \-\-graph= graph-file
4e0813a6
PE
169The behavior of
170.BI \-\-graph
342b8b6e
AD
171is the same than
172.BI \-g
4e0813a6 173option. The only difference is that it has an optional argument which
342b8b6e
AD
174is the name of the output graph filename.
175.TP
333ccc01
RS
176.B \-k
177.br
178.ns
179.TP
180.B \-\-token-table
4e0813a6
PE
181This switch causes the
182.IB name .tab.c
183output to include a list of
184token names in order by their token numbers; this is defined in the array
333ccc01 185.IR yytname .
62ab6972
AD
186Also generated
187are #defines for
333ccc01
RS
188.IR YYNTOKENS ,
189.IR YYNNTS ,
190.IR YYNRULES ,
62ab6972 191and
333ccc01
RS
192.IR YYNSTATES .
193.TP
a641b0da
DM
194.B \-l
195.br
196.ns
197.TP
198.B \-\-no-lines
199Don't put any
200.B #line
201preprocessor commands in the parser file.
202Ordinarily
203.I bison
204puts them in the parser file so that the C compiler
205and debuggers will associate errors with your source file, the
206grammar file. This option causes them to associate errors with the
207parser file, treating it an independent source file in its own right.
208.TP
333ccc01
RS
209.B \-n
210.br
211.ns
212.TP
213.B \-\-no-parser
4e0813a6
PE
214Do not generate the parser code into the output; generate only
215declarations. The generated
216.IB name .tab.c
217file will have only
218constant declarations. In addition, a
219.IB name .act
220file is
333ccc01 221generated containing a switch statement body containing all the
62ab6972 222translated actions.
333ccc01 223.TP
a641b0da
DM
224.BI \-o " outfile"
225.br
226.ns
227.TP
228.BI \-\-output-file= outfile
229Specify the name
230.I outfile
231for the parser file.
232.sp
233The other output files' names are constructed from
234.I outfile
235as described under the
236.B \-v
237and
238.B \-d
239switches.
240.TP
241.BI \-p " prefix"
242.br
243.ns
244.TP
245.BI \-\-name-prefix= prefix
246Rename the external symbols used in the parser so that they start with
247.I prefix
248instead of
249.BR yy .
250The precise list of symbols renamed is
251.BR yyparse ,
252.BR yylex ,
253.BR yyerror ,
254.BR yylval ,
62ab6972 255.BR yychar ,
a641b0da
DM
256and
257.BR yydebug .
258.sp
259For example, if you use
260.BR "\-p c" ,
261the names become
262.BR cparse ,
263.BR clex ,
264and so on.
265.TP
266.B \-t
267.br
268.ns
269.TP
270.B \-\-debug
4947ebdb 271In the parser file, define the macro
62ab6972 272.B YYDEBUG
4947ebdb 273to 1 if it is not already defined,
a641b0da
DM
274so that the debugging facilities are compiled.
275.TP
276.B \-v
277.br
278.ns
279.TP
280.B \-\-verbose
281Write an extra output file containing verbose descriptions of the
282parser states and what is done for each type of look-ahead token in
283that state.
284.sp
285This file also describes all the conflicts, both those resolved by
286operator precedence and the unresolved ones.
287.sp
288The file's name is made by removing
289.B .tab.c
290or
291.B .c
292from the parser output file name, and adding
293.B .output
294instead.
295.sp
296Therefore, if the input file is
297.BR foo.y ,
298then the parser file is called
299.B foo.tab.c
300by default. As a consequence, the verbose
301output file is called
302.BR foo.output .
303.TP
304.B \-V
305.br
306.ns
307.TP
308.B \-\-version
309Print the version number of
310.I bison
311and exit.
312.TP
313.B \-h
314.br
315.ns
5fcfb6e7 316.TP
a641b0da
DM
317.B \-\-help
318Print a summary of the options to
319.I bison
320and exit.
321.TP
322.B \-y
323.br
324.ns
325.TP
326.B \-\-yacc
327.br
328.ns
329.TP
330.B \-\-fixed-output-files
331Equivalent to
332.BR "\-o y.tab.c" ;
333the parser output file is called
334.BR y.tab.c ,
335and the other outputs are called
336.B y.output
337and
338.BR y.tab.h .
339The purpose of this switch is to imitate
340.IR yacc 's
341output file name conventions.
342Thus, the following shell script can substitute for
343.IR yacc :
344.sp
345.RS
346.ft B
347bison \-y $*
348.ft R
349.sp
350.RE
a641b0da 351.SH FILES
342b8b6e 352/usr/local/share/bison/bison.simple simple parser
a641b0da 353.br
342b8b6e 354/usr/local/share/bison/bison.hairy complicated parser
9e4e995a
JT
355.SH "ENVIRONMENT VARIABLES"
356.TP
357.SM BISON_SIMPLE
358If this is set, it specifies the location in which the
359.B bison.simple
360parser can be found.
361.TP
362.SM BISON_HAIRY
363If this is set, it specifies the location in which the
364.B bison.hairy
365parser can be found.
a641b0da
DM
366.SH SEE ALSO
367.IR yacc (1)
368.br
369The
370.IR "Bison Reference Manual" ,
371included as the file
372.B bison.texinfo
373in the
374.I bison
375source distribution.
376.SH DIAGNOSTICS
377Self explanatory.