]> git.saurik.com Git - bison.git/blob - doc/refcard.tex
* src/scan-gram.l (SC_PROLOGUE): Don't eat characters amongst
[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, 2001 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.31} % the bison version
70
71 \def\refcardversion{0.5} % reference card version
72 \def\month{November} % month
73 \def\year{2001} % 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{Display usage information.} {-h}
320 \key{Display version information.} {-V}
321 \key{Generate token and {\tt YYSTYPE} definitions.} {-d}
322 \key{Prepend a prefix to external symbols.} {-p {\it prefix}}
323 \key{Don't put {\tt \#line} directives in the parser.} {-l}
324 \key{Specify the output file.} {-o {\it filename}}
325 \key{Debug or {\it trace} mode.} {-t}
326 \key{Verbose description of the parser.} {-v}
327 \key{Emulate {\tt yacc} (generate {\tt y.tab.*} files).} {-y}
328
329 \vskip .10truein
330 {\bf Note:} The token and {\tt YYSTYPE} definitions are generated
331 to a file called {\tt y.tab.h} if the {\tt -y} option is used,
332 otherwise it will have the format {\tt {\it name}.tab.h}, where
333 {\it name} is the leading part of the parser definition filename.
334
335 \section{Definitions}
336 %********************
337
338 \key{Declare a terminal symbol.}{\%token <{\it t\/}>
339 {\it n}}
340
341 \key{Declare a terminal symbol, and define its association.}
342 {{\it association} <{\it t\/}> {\it n}}
343
344 \vskip .2\baselineskip
345 \key{Generate a reentrant (pure) parser.}
346 {\%pure_parser}
347
348 \key{Define the union of all data types used in the parser.}
349 {\%union\{{\it field list}\} }
350
351 \vskip .2\baselineskip
352 \key{Tell {\tt bison} where to start parsing.}
353 {\%start {\it m}}
354
355 \key{Tell {\tt bison} the data type of symbols.}
356 {\%type <{\it t\/}> {\it s1}\dots{\it sn}}
357
358 \vskip .10truein
359
360 In the above, {\it t} is a {\it type} defined in the {\tt \%union}
361 definition, {\it n} is a {\it terminal} symbol name, {\it m} is a
362 {\it non-terminal} symbol name, and {\it association} can be one of
363 {\tt \%left}, {\tt \%right}, or {\tt \%nonassoc}.
364
365 \vskip .10truein
366
367 The {\tt <{\it t\/}>} after {\tt \%token, \%left, \%right} and {\tt
368 \%nonassoc} is optional. Additionally, precedence may be overridden
369 in the rules with {\tt \%prec} commands.
370
371 \section{Parser Definition Files}
372 %*********************************
373
374 The general form for a parser definition is:
375
376 \begincexample
377 \{\%
378 /* Initial C code. */
379 \%\}
380
381 {\it Token and type definitions}
382
383 \%\%
384
385 Rule definition 1
386 \vdots
387 Rule definition {\it n}
388
389 \%\%
390
391 /* Other C code. */
392 \endcexample
393
394
395 % Decrease standard baselineskip for the second page
396 \baselineskip = .9\baselineskip
397
398 \section {Rule definitions}
399 %**************************
400
401 Rules take the form:
402
403 \vskip -\baselineskip
404 \beginexample
405 non-terminal : {\it statement} 1
406 | {\it statement} 2
407 \vdots
408 | {\it statement n}
409 ;
410 \endexample
411
412 Where {\it statements} can be either empty, or contain
413 a mixture of C code (enclosed in {\tt \{...\}}), and the
414 symbols that make up the non-terminal. For example:
415
416 \vskip -\baselineskip
417 \beginexample
418 expression : number '$+$' number \{ \$\$ $=$ \$1 $+$ \$3 \}
419 | number '$-$' number \{ \$\$ $=$ \$1 $-$ \$3 \}
420 | number '$/$' number \{ \$\$ $=$ \$1 $/$ \$3 \}
421 | number '$*$' number \{ \$\$ $=$ \$1 $*$ \$3 \}
422 ;
423 \endexample
424
425 For altering the precedence of a symbol use:
426 \vskip -\baselineskip
427
428 \beginexample
429 \%prec name
430 \endexample
431
432 For example:
433 \vskip -\baselineskip
434 \beginexample
435 foo : gnu bar gnu \%prec bar
436 ;
437 \endexample
438
439 \section{Grammar Variables and Symbols}
440 %**************************************
441
442 \key{Recognize an error \& continue parsing.}{error}
443 \key{Access data associated with a symbol.} {\$\$, \$0\dots\${\it n}}
444 \key{Access a field of the data union.} {\$\$.{\it t},
445 \$0.{\it t}\dots\${\it n}.{\it t}}
446 \key{Access symbol's location.} {@\$, @0\dots@{\it n}}
447 \key{Access data's line location.} {@{\it x}.{\it line\_spec}}
448 \key{Access data's column location.} {@{\it x}.{\it column\_spec}}
449
450
451 \vskip .10truein
452 %
453 Where {\it t} is a type defined in the {\tt \%union}, {\it n} is a
454 number, {\it x} is a number or \$, {\it line\_spec} one of {\tt
455 first_line} and {\tt last_line}, and {\it column\_spec} is specified
456 as either {\tt first_column} or {\tt last_column}.
457
458 \section {Variables and Types}
459 %*****************************
460
461 \key{Current look ahead token.} {yychar}
462 \key{Debug mode flag.} {yydebug}
463 \key{Data associated with the current token.} {yylval}
464 \key{Source position of current token.} {yylloc}
465 \key{Number of errors encountered.} {yynerrs}
466 \key{Position information type.} {YYLTYPE}
467 \key{Data type associated with symbols.} {YYSTYPE}
468
469 \section {Functions}
470 %*******************
471
472 % Redefine to prevent overfull hboxes
473 \def\key#1#2{\leavevmode\hbox to \hsize
474 {\vtop {\hsize=.625\hsize \rightskip=1em #1}
475 \kbd{#2}\hfil}}
476
477 \key{User defined error handler.} {int yyerror(char *)}
478 \key{User defined lexical analyzer.} {int yylex()}
479 \key{The grammar parser.} {int yyparse()}
480
481 % Return to previous size
482 \def\key#1#2{\leavevmode\hbox to \hsize
483 {\vtop {\hsize=.67\hsize \rightskip=1em #1}
484 \kbd{#2}\hfil}}
485
486 \section{Macros}
487 %***************
488
489 \key{Quit parsing immediately. Return 1.} {YYABORT}
490 \key{Quit parsing immediately. Return 0.} {YYACCEPT}
491 \key{Pretend a syntax error occurred.} {YYERROR}
492 \key{Value in {\tt yychar} if no look-ahead token.} {YYEMPTY}
493 \key{Clear previous look ahead token.} {yyclearin}
494 \key{Recover normally from an error.} {yyerrok}
495
496 % **************
497 % ** The end **
498 % **************
499
500 \vskip \baselineskip
501 \if 1\ncolumns
502 \copyrightnotice
503 \else
504 \smallcopyrightnotice
505 \fi
506
507 \bye
508
509 \f
510 % Local variables:
511 % compile-command: "tex refcard"
512 % End: