]> git.saurik.com Git - bison.git/blame - doc/refcard.tex
doc: clean up quotation style in NEWS.
[bison.git] / doc / refcard.tex
CommitLineData
649d71cc
JT
1% Bison Quick Reference
2
3%**start of header
4\newcount\columnsperpage
5
6% This file can be printed with 1 or 2 columns per page (see below).
7% Specify how many you want here. Nothing else needs to be changed
8% unless you are maintaining the documentation.
92fcb5ef 9% For printing reference cards to use in books, specify one column
649d71cc
JT
10% per page and reduce to 80%.
11% Note that if columnsperpage is set to 2, there will be a few overfull
12% boxes, but they are not serious. Just uncomment \finalout.
13
14\columnsperpage=1
15
16% comment out this line if you want page numbers to appear.
17\nopagenumbers
18
19\def\finalout{\overfullrule=0pt}
20%\finalout
21
575619af 22% Copyright (c) 1998, 2001, 2009-2011 Free Software Foundation, Inc.
649d71cc
JT
23%
24% This file is part of Bison.
25%
f16b0819
PE
26% This program is free software: you can redistribute it and/or modify
27% it under the terms of the GNU General Public License as published by
28% the Free Software Foundation, either version 3 of the License, or
29% (at your option) any later version.
649d71cc 30%
f16b0819
PE
31% This program is distributed in the hope that it will be useful,
32% but WITHOUT ANY WARRANTY; without even the implied warranty of
33% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34% GNU General Public License for more details.
649d71cc
JT
35%
36% You should have received a copy of the GNU General Public License
f16b0819 37% along with this program. If not, see <http://www.gnu.org/licenses/>.
649d71cc
JT
38%
39% This file is intended to be processed by plain TeX (TeX82).
40%
41% The final reference card has two columns:
42% This file can be used to produce it in any of three ways:
43% 1 column per page
44% produces two separate pages, each of which needs to be reduced to 80%.
45% This gives the best resolution.
46% 2 columns per page
47% produces a single page.
48% You will still need to cut and paste.
49% Which mode to use is controlled by setting \columnsperpage above.
50%
51% Authors:
92fcb5ef 52% Brendan Kehoe
649d71cc 53% UUCP: widener!brendan
92fcb5ef 54% Internet: brendan@cs.widener.edu
649d71cc 55%
92fcb5ef 56% Gavin Nicol
649d71cc
JT
57% Internet: nick@nsis.cl.co.jp
58%
59% This refcard format was created by Steve Gildea.
60%
61% Thanks to Paul Rubin, Bob Chassell, Len Tower, and Richard Mlynarik
62% for their many good ideas.
63
64% We only change the following to change the version numbers and
65% such.
66
92fcb5ef 67\def\bisonversion{1.31} % the bison version
649d71cc 68
92fcb5ef
AD
69\def\refcardversion{0.5} % reference card version
70\def\month{November} % month
71\def\year{2001} % year
72\def\version{\month\ \year, Bison Refcard Version \refcardversion}
649d71cc
JT
73
74% for copyright notices
75\def\small{\smallfont\textfont2=\smallsy\baselineskip=.8\baselineskip}
76\def\medium{\mediumfont\textfont2=\mediumsy\baselineskip=.8\baselineskip}
77
78\def\copyrightnotice{
79\vskip .15ex plus .25 fill
80\begingroup\medium
81\centerline{Copyright \copyright\ \year\ Free Software Foundation, Inc.}
82\vskip .2\baselineskip
83\centerline{\version}
84\vskip .2\baselineskip
85\centerline{designed by Brendan Kehoe and Gavin Nicol}
86\vskip .2\baselineskip
87\centerline{for Bison \bisonversion}
88
89Permission is granted to make and distribute copies of this card
90provided the copyright notice and this permission notice
92fcb5ef 91are preserved on all copies.
649d71cc
JT
92\vskip .2\baselineskip
93For information, write to the:
94\vskip .2\baselineskip
95\centerline{Free Software Foundation, Inc.}
96\vskip .2\baselineskip
0fb669f9 97\centerline{51 Franklin Street, Fifth Floor}
649d71cc 98\vskip .2\baselineskip
0fb669f9 99\centerline{Boston, MA 02110-1301 USA}
649d71cc
JT
100\endgroup}
101
102%%%% smallcopyrightnotice for two column printing on one page.
103\def\smallcopyrightnotice{
104\vskip .15ex plus .25 fill
105\begingroup\small
106\centerline{Copyright \copyright\ \year\ Free Software Foundation, Inc.}
107\vskip .2\baselineskip
108\centerline{\version}
109\vskip .2\baselineskip
110\centerline{designed by Brendan Kehoe and Gavin Nicol}
111\vskip .2\baselineskip
112\centerline{for Bison \bisonversion}
113
114Permission is granted to make and distribute copies of this card
115provided the copyright notice and this permission notice
92fcb5ef 116are preserved on all copies.
649d71cc
JT
117\vskip .2\baselineskip
118For information, write to the:
119\vskip .2\baselineskip
120\centerline{Free Software Foundation, Inc.}
121\vskip .2\baselineskip
0fb669f9 122\centerline{51 Franklin Street, Fifth Floor}
649d71cc 123\vskip .2\baselineskip
0fb669f9 124\centerline{Boston, MA 02110-1301 USA}
649d71cc
JT
125\endgroup}
126
127% make \bye not \outer so that the \def\bye in the \else clause below
128% can be scanned without complaint.
129\def\bye{\par\vfill\supereject\end}
130
131\newdimen\intercolumnskip
132\newbox\columna
133\newbox\columnb
134
135\def\ncolumns{\the\columnsperpage}
136
92fcb5ef 137\message{[\ncolumns\space
649d71cc
JT
138 column\if 1\ncolumns\else s\fi\space per page]}
139
140\def\scaledmag#1{ scaled \magstep #1}
141
142% This multi-way format was designed by Stephen Gildea
143% October 1986.
144\if 1\ncolumns
145 \hsize 4in
146 \vsize 10in
147% We want output .3 inch *from top of paper edge*; i.e. -.7in from TeX default
148 \voffset -.7in % Comment out for xdvi viewing; include for printing.
149 \font\titlefont=\fontname\tenbf \scaledmag3
150 \font\headingfont=\fontname\tenbf \scaledmag2
151 \font\smallfont=cmr6
152 \font\smallsy=cmsy6
153 \font\mediumfont=cmr10
154 \font\mediumsy=cmsy10
155
156
157% two lines below commented out in Yet Another Attempt to eliminate
158% page numbers from the output.
159 \footline{\hss}
160% \footline{\hss\folio}
161 \def\makefootline{\baselineskip10pt\hsize6.5in\line{\the\footline}}
162\else
163 \hsize 3.2in
164 \vsize 7.95in
165 \hoffset -.75in
166 \voffset -.745in
167 \font\titlefont=cmbx10 \scaledmag2
168 \font\headingfont=cmbx10 \scaledmag1
169 \font\smallfont=cmr6
170 \font\smallsy=cmsy6
171 \font\eightrm=cmr8
172 \font\eightbf=cmbx8
173 \font\eightit=cmti8
174 \font\eighttt=cmtt8
175 \font\eightsy=cmsy8
176 \textfont0=\eightrm
177 \textfont2=\eightsy
178 \def\rm{\eightrm}
179 \def\bf{\eightbf}
180 \def\it{\eightit}
181 \def\tt{\eighttt}
182%%%% Reduce skip from .8 to .75 to permit printing on two pages.
183 \normalbaselineskip=.75\normalbaselineskip
184 \normallineskip=.75\normallineskip
185 \normallineskiplimit=.75\normallineskiplimit
186 \normalbaselines\rm %make definitions take effect
187
188 \if 2\ncolumns
189 \let\maxcolumn=b
190 \footline{\hss\rm\folio\hss}
191 \def\makefootline{\vskip 2in \hsize=6.86in\line{\the\footline}}
192 \font\mediumfont=cmr10
193 \font\mediumsy=cmsy10
194
195% Leave 3 column code here in case size increases.
196 \else \if 3\ncolumns
197 \let\maxcolumn=c
198 \nopagenumbers
199 \font\mediumfont=cmr10
200 \font\mediumsy=cmsy10
201
202 \else
203 \errhelp{You must set \columnsperpage equal to 1, 2, or 3.}
204 \errmessage{Illegal number of columns per page}
205 \fi\fi
206
207 \intercolumnskip=.46in
208 \def\abc{a}
209 \output={%
210 % This next line is useful when designing the layout.
211 %\immediate\write16{Column \folio\abc\space starts with \firstmark}
212 \if \maxcolumn\abc \multicolumnformat \global\def\abc{a}
213 \else\if a\abc
214 \global\setbox\columna\columnbox \global\def\abc{b}
215 %% in case we never use \columnb (two-column mode)
216 \global\setbox\columnb\hbox to -\intercolumnskip{}
217 \else
218 \global\setbox\columnb\columnbox \global\def\abc{c}\fi\fi}
219 \def\multicolumnformat{\shipout\vbox{\makeheadline
220 \hbox{\box\columna\hskip\intercolumnskip
221 \box\columnb\hskip\intercolumnskip\columnbox}
222 \makefootline}\advancepageno}
223 \def\columnbox{\leftline{\pagebody}}
224
225 \def\bye{\par\vfill\supereject
226 \if a\abc \else\null\vfill\eject\fi
227 \if a\abc \else\null\vfill\eject\fi
92fcb5ef 228 \end}
649d71cc
JT
229\fi
230
231% we won't be using math mode much, so redefine some of the characters
232% we might want to talk about
233\catcode`\^=12
234\catcode`\_=12
235
236\chardef\\=`\\
237\chardef\{=`\{
238\chardef\}=`\}
239
240\hyphenation{mini-buf-fer}
241
242\parindent 0pt
243% \parskip 1ex plus .5ex minus .5ex
244\parskip 0.5ex plus .25ex minus .25ex
245
246\outer\def\newcolumn{\vfill\eject}
247
248\outer\def\title#1{{\titlefont\centerline{#1}}\vskip 1ex plus .5ex}
249
250\outer\def\section#1{\par\filbreak
251 \vskip 1.5ex plus 1ex minus 1ex {\headingfont #1}\mark{#1}%
252 \vskip 1ex plus .5ex minus 0.75ex}
253
254\newdimen\keyindent
255
256\def\beginindentedkeys{\keyindent=1em}
257\def\endindentedkeys{\keyindent=0em}
258\endindentedkeys
259
260\def\paralign{\vskip\parskip\halign}
261
262\def\<#1>{$\langle${\rm #1}$\rangle$}
263
264\def\kbd#1{{\tt#1}\null} %\null so not an abbrev even if period follows
265
266\def\beginexample{\par\leavevmode\begingroup
267 \obeylines\obeyspaces\parskip0pt\tt}
268{\obeyspaces\global\let =\ }
269\def\endexample{\endgroup}
270\def\begincexample{%
271 \par\leavevmode\begingroup%
272 \obeylines\obeyspaces%
273 % bpk--added indentation
274 \advance\leftskip.25truein
275% \parskip0pt%
276 \tt}
277{\obeyspaces\global\let =\ }
278\def\endcexample{\endgroup}
279
280%%%%% Prime definition of key; redefined below to prevent overful hboxes
281
282\def\key#1#2{\leavevmode\hbox to \hsize
283 {\vtop {\hsize=.67\hsize \rightskip=1em #1}
284 \kbd{#2}\hfil}}
285
286\newbox\metaxbox
287\setbox\metaxbox\hbox{\kbd{M-x }}
288\newdimen\metaxwidth
289\metaxwidth=\wd\metaxbox
290
291\def\metax#1#2{\leavevmode\hbox to \hsize{\hbox to .75\hsize
292 {\hskip\keyindent\relax#1\hfil}%
293 \hskip -\metaxwidth minus 1fil
294 \kbd{#2}\hfil}}
295
296\def\threecol#1#2#3{\hskip\keyindent\relax#1\hfil&\kbd{#2}\quad
297 &\kbd{#3}\quad\cr}
298
299%**end of header
300\f
301% ************
302% ** BISON **
303% ************
304
305\title{Bison Quick Reference}
306
307\section{Starting Bison}
308%***********************
309
310To use Bison, type: \kbd{bison {\it filename}}
311
312Options can be used as: \kbd{bison {\it options} {\it filename}}
313
314\section{Command Line Options}
315%*****************************
316
92fcb5ef
AD
317\key{Display usage information.} {-h}
318\key{Display version information.} {-V}
649d71cc 319\key{Generate token and {\tt YYSTYPE} definitions.} {-d}
92fcb5ef 320\key{Prepend a prefix to external symbols.} {-p {\it prefix}}
649d71cc
JT
321\key{Don't put {\tt \#line} directives in the parser.} {-l}
322\key{Specify the output file.} {-o {\it filename}}
92fcb5ef 323\key{Debug or {\it trace} mode.} {-t}
649d71cc
JT
324\key{Verbose description of the parser.} {-v}
325\key{Emulate {\tt yacc} (generate {\tt y.tab.*} files).} {-y}
326
327\vskip .10truein
92fcb5ef
AD
328{\bf Note:} The token and {\tt YYSTYPE} definitions are generated
329to a file called {\tt y.tab.h} if the {\tt -y} option is used,
649d71cc
JT
330otherwise it will have the format {\tt {\it name}.tab.h}, where
331{\it name} is the leading part of the parser definition filename.
332
333\section{Definitions}
334%********************
335
92fcb5ef 336\key{Declare a terminal symbol.}{\%token <{\it t\/}>
649d71cc
JT
337 {\it n}}
338
92fcb5ef 339\key{Declare a terminal symbol, and define its association.}
649d71cc
JT
340 {{\it association} <{\it t\/}> {\it n}}
341
342\vskip .2\baselineskip
92fcb5ef 343\key{Generate a reentrant (pure) parser.}
649d71cc
JT
344 {\%pure_parser}
345
92fcb5ef 346\key{Define the union of all data types used in the parser.}
649d71cc
JT
347 {\%union\{{\it field list}\} }
348
349\vskip .2\baselineskip
92fcb5ef
AD
350\key{Tell {\tt bison} where to start parsing.}
351 {\%start {\it m}}
649d71cc 352
92fcb5ef
AD
353\key{Tell {\tt bison} the data type of symbols.}
354 {\%type <{\it t\/}> {\it s1}\dots{\it sn}}
649d71cc
JT
355
356\vskip .10truein
357
358In the above, {\it t} is a {\it type} defined in the {\tt \%union}
359definition, {\it n} is a {\it terminal} symbol name, {\it m} is a
360{\it non-terminal} symbol name, and {\it association} can be one of
361{\tt \%left}, {\tt \%right}, or {\tt \%nonassoc}.
362
363\vskip .10truein
364
365The {\tt <{\it t\/}>} after {\tt \%token, \%left, \%right} and {\tt
92fcb5ef
AD
366 \%nonassoc} is optional. Additionally, precedence may be overridden
367in the rules with {\tt \%prec} commands.
649d71cc
JT
368
369\section{Parser Definition Files}
370%*********************************
371
372The general form for a parser definition is:
373
374\begincexample
375\{\%
376 /* Initial C code. */
377\%\}
378
379 {\it Token and type definitions}
380
381\%\%
382
92fcb5ef 383 Rule definition 1
649d71cc
JT
384 \vdots
385 Rule definition {\it n}
386
387\%\%
388
389 /* Other C code. */
390\endcexample
391
392
393% Decrease standard baselineskip for the second page
394 \baselineskip = .9\baselineskip
395
396\section {Rule definitions}
397%**************************
398
399Rules take the form:
400
92fcb5ef 401\vskip -\baselineskip
649d71cc 402\beginexample
92fcb5ef 403 non-terminal : {\it statement} 1
649d71cc
JT
404 | {\it statement} 2
405 \vdots
406 | {\it statement n}
407 ;
408\endexample
409
410Where {\it statements} can be either empty, or contain
92fcb5ef 411a mixture of C code (enclosed in {\tt \{...\}}), and the
649d71cc
JT
412symbols that make up the non-terminal. For example:
413
414\vskip -\baselineskip
415\beginexample
92fcb5ef 416 expression : number '$+$' number \{ \$\$ $=$ \$1 $+$ \$3 \}
649d71cc
JT
417 | number '$-$' number \{ \$\$ $=$ \$1 $-$ \$3 \}
418 | number '$/$' number \{ \$\$ $=$ \$1 $/$ \$3 \}
419 | number '$*$' number \{ \$\$ $=$ \$1 $*$ \$3 \}
420 ;
421\endexample
422
423For altering the precedence of a symbol use:
424\vskip -\baselineskip
425
426\beginexample
427 \%prec name
428\endexample
429
430For example:
431\vskip -\baselineskip
432\beginexample
92fcb5ef 433 foo : gnu bar gnu \%prec bar
649d71cc
JT
434 ;
435\endexample
436
437\section{Grammar Variables and Symbols}
438%**************************************
439
440\key{Recognize an error \& continue parsing.}{error}
441\key{Access data associated with a symbol.} {\$\$, \$0\dots\${\it n}}
442\key{Access a field of the data union.} {\$\$.{\it t},
92fcb5ef
AD
443 \$0.{\it t}\dots\${\it n}.{\it t}}
444\key{Access symbol's location.} {@\$, @0\dots@{\it n}}
445\key{Access data's line location.} {@{\it x}.{\it line\_spec}}
446\key{Access data's column location.} {@{\it x}.{\it column\_spec}}
649d71cc
JT
447
448
449\vskip .10truein
92fcb5ef 450%
649d71cc 451Where {\it t} is a type defined in the {\tt \%union}, {\it n} is a
92fcb5ef
AD
452number, {\it x} is a number or \$, {\it line\_spec} one of {\tt
453 first_line} and {\tt last_line}, and {\it column\_spec} is specified
454as either {\tt first_column} or {\tt last_column}.
649d71cc
JT
455
456\section {Variables and Types}
457%*****************************
458
9e6e7ed2 459\key{Current lookahead token.} {yychar}
649d71cc
JT
460\key{Debug mode flag.} {yydebug}
461\key{Data associated with the current token.} {yylval}
462\key{Source position of current token.} {yylloc}
463\key{Number of errors encountered.} {yynerrs}
464\key{Position information type.} {YYLTYPE}
465\key{Data type associated with symbols.} {YYSTYPE}
466
467\section {Functions}
468%*******************
469
470% Redefine to prevent overfull hboxes
471\def\key#1#2{\leavevmode\hbox to \hsize
472 {\vtop {\hsize=.625\hsize \rightskip=1em #1}
473 \kbd{#2}\hfil}}
474
475\key{User defined error handler.} {int yyerror(char *)}
476\key{User defined lexical analyzer.} {int yylex()}
477\key{The grammar parser.} {int yyparse()}
478
479% Return to previous size
480\def\key#1#2{\leavevmode\hbox to \hsize
481 {\vtop {\hsize=.67\hsize \rightskip=1em #1}
482 \kbd{#2}\hfil}}
483
484\section{Macros}
485%***************
486
487\key{Quit parsing immediately. Return 1.} {YYABORT}
488\key{Quit parsing immediately. Return 0.} {YYACCEPT}
489\key{Pretend a syntax error occurred.} {YYERROR}
9e6e7ed2
PE
490\key{Value in {\tt yychar} if no lookahead token.} {YYEMPTY}
491\key{Clear previous lookahead token.} {yyclearin}
649d71cc
JT
492\key{Recover normally from an error.} {yyerrok}
493
494% **************
495% ** The end **
496% **************
497
498\vskip \baselineskip
499\if 1\ncolumns
500\copyrightnotice
501\else
502\smallcopyrightnotice
503\fi
504
505\bye
506
507\f
508% Local variables:
509% compile-command: "tex refcard"
510% End: