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