1 % Bison Quick Reference
4 \newcount\columnsperpage
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.
16 % comment out this line if you want page numbers to appear.
19 \def\finalout{\overfullrule=
0pt
}
22 % Copyright (c) 1998, 2001 Free Software Foundation, Inc.
24 % This file is part of Bison.
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
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
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., 51 Franklin Street, Fifth Floor,
39 % Boston, MA 02110-1301, USA.
41 % This file is intended to be processed by plain TeX (TeX82).
43 % The final reference card has two columns:
44 % This file can be used to produce it in any of three ways:
46 % produces two separate pages, each of which needs to be reduced to 80%.
47 % This gives the best resolution.
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.
55 % UUCP: widener!brendan
56 % Internet: brendan@cs.widener.edu
59 % Internet: nick@nsis.cl.co.jp
61 % This refcard format was created by Steve Gildea.
63 % Thanks to Paul Rubin, Bob Chassell, Len Tower, and Richard Mlynarik
64 % for their many good ideas.
66 % We only change the following to change the version numbers and
69 \def\bisonversion{1.31} % the bison version
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}
76 % for copyright notices
77 \def\small{\smallfont\textfont2=
\smallsy\baselineskip=
.8\baselineskip}
78 \def\medium{\mediumfont\textfont2=
\mediumsy\baselineskip=
.8\baselineskip}
81 \vskip .15ex plus
.25 fill
83 \centerline{Copyright
\copyright\
\year\ Free Software Foundation, Inc.
}
84 \vskip .2\baselineskip
86 \vskip .2\baselineskip
87 \centerline{designed by Brendan Kehoe and Gavin Nicol
}
88 \vskip .2\baselineskip
89 \centerline{for Bison
\bisonversion}
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{51 Franklin Street, Fifth Floor
}
100 \vskip .2\baselineskip
101 \centerline{Boston, MA
02110-
1301 USA
}
104 %%%% smallcopyrightnotice for two column printing on one page.
105 \def\smallcopyrightnotice{
106 \vskip .15ex plus
.25 fill
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}
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{51 Franklin Street, Fifth Floor
}
125 \vskip .2\baselineskip
126 \centerline{Boston, MA
02110-
1301 USA
}
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}
133 \newdimen\intercolumnskip
137 \def\ncolumns{\the\columnsperpage}
139 \message{[\ncolumns\space
140 column
\if 1\ncolumns\else s
\fi\space per page
]}
142 \def\scaledmag#1{ scaled
\magstep #1}
144 % This multi-way format was designed by Stephen Gildea
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
155 \font\mediumfont=cmr10
156 \font\mediumsy=cmsy10
159 % two lines below commented out in Yet Another Attempt to eliminate
160 % page numbers from the output.
162 % \footline{\hss\folio}
163 \def\makefootline{\baselineskip10pt\hsize6.5in
\line{\the\footline}}
169 \font\titlefont=cmbx10
\scaledmag2
170 \font\headingfont=cmbx10
\scaledmag1
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
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
197 % Leave 3 column code here in case size increases.
201 \font\mediumfont=cmr10
202 \font\mediumsy=cmsy10
205 \errhelp{You must set
\columnsperpage equal to
1,
2, or
3.
}
206 \errmessage{Illegal number of columns per page
}
209 \intercolumnskip=
.46in
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
}
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{}
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}}
227 \def\bye{\par\vfill\supereject
228 \if a
\abc \else\null\vfill\eject\fi
229 \if a
\abc \else\null\vfill\eject\fi
233 % we won't be using math mode much, so redefine some of the characters
234 % we might want to talk about
242 \hyphenation{mini-buf-fer
}
245 % \parskip 1ex plus .5ex minus .5ex
246 \parskip 0.5ex plus
.25ex minus
.25ex
248 \outer\def\newcolumn{\vfill\eject}
250 \outer\def\title#1{{\titlefont\centerline{#1}}\vskip 1ex plus
.5ex
}
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
}
258 \def\beginindentedkeys{\keyindent=
1em
}
259 \def\endindentedkeys{\keyindent=
0em
}
262 \def\paralign{\vskip\parskip\halign}
264 \def\<
#1>
{$
\langle$
{\rm #1}$
\rangle$
}
266 \def\kbd#1{{\tt#1}\null} %\null so not an abbrev even if period follows
268 \def\beginexample{\par\leavevmode\begingroup
269 \obeylines\obeyspaces\parskip0pt\tt}
270 {\obeyspaces\global\let =\
}
271 \def\endexample{\endgroup}
273 \par\leavevmode\begingroup%
274 \obeylines\obeyspaces%
275 % bpk--added indentation
276 \advance\leftskip.25truein
279 {\obeyspaces\global\let =\
}
280 \def\endcexample{\endgroup}
282 %%%%% Prime definition of key; redefined below to prevent overful hboxes
284 \def\key#1#2{\leavevmode\hbox to
\hsize
285 {\vtop {\hsize=
.67\hsize \rightskip=
1em
#1}
289 \setbox\metaxbox\hbox{\kbd{M-x
}}
291 \metaxwidth=
\wd\metaxbox
293 \def\metax#1#2{\leavevmode\hbox to
\hsize{\hbox to
.75\hsize
294 {\hskip\keyindent\relax#1\hfil}%
295 \hskip -
\metaxwidth minus
1fil
298 \def\threecol#1#2#3{\hskip\keyindent\relax#1\hfil&
\kbd{#2}\quad
307 \title{Bison Quick Reference
}
309 \section{Starting Bison
}
310 %***********************
312 To use Bison, type:
\kbd{bison
{\it filename
}}
314 Options can be used as:
\kbd{bison
{\it options
} {\it filename
}}
316 \section{Command Line Options
}
317 %*****************************
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
}
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.
335 \section{Definitions
}
336 %********************
338 \key{Declare a terminal symbol.
}{\%token <
{\it t\/
}>
341 \key{Declare a terminal symbol, and define its association.
}
342 {{\it association
} <
{\it t\/
}>
{\it n
}}
344 \vskip .2\baselineskip
345 \key{Generate a reentrant (pure) parser.
}
348 \key{Define the union of all data types used in the parser.
}
349 {\%union\
{{\it field list
}\
} }
351 \vskip .2\baselineskip
352 \key{Tell
{\tt bison
} where to start parsing.
}
355 \key{Tell
{\tt bison
} the data type of symbols.
}
356 {\%type <
{\it t\/
}>
{\it s1
}\dots{\it sn
}}
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
}.
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.
371 \section{Parser Definition Files
}
372 %*********************************
374 The general form for a parser definition is:
378 /* Initial C code. */
381 {\it Token and type definitions
}
387 Rule definition
{\it n
}
395 % Decrease standard baselineskip for the second page
396 \baselineskip =
.9\baselineskip
398 \section {Rule definitions
}
399 %**************************
403 \vskip -
\baselineskip
405 non-terminal :
{\it statement
} 1
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:
416 \vskip -
\baselineskip
418 expression : number '$+$' number \
{ \$\$ $=$ \$
1 $+$ \$
3 \
}
419 | number '$-$' number \
{ \$\$ $=$ \$
1 $-$ \$
3 \
}
420 | number '$/$' number \
{ \$\$ $=$ \$
1 $/$ \$
3 \
}
421 | number '$*$' number \
{ \$\$ $=$ \$
1 $*$ \$
3 \
}
425 For altering the precedence of a symbol use:
426 \vskip -
\baselineskip
433 \vskip -
\baselineskip
435 foo : gnu bar gnu \%prec bar
439 \section{Grammar Variables and Symbols
}
440 %**************************************
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}}
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
}.
458 \section {Variables and Types
}
459 %*****************************
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
}
472 % Redefine to prevent overfull hboxes
473 \def\key#1#2{\leavevmode\hbox to
\hsize
474 {\vtop {\hsize=
.625\hsize \rightskip=
1em
#1}
477 \key{User defined error handler.
} {int yyerror(char *)
}
478 \key{User defined lexical analyzer.
} {int yylex()
}
479 \key{The grammar parser.
} {int yyparse()
}
481 % Return to previous size
482 \def\key#1#2{\leavevmode\hbox to
\hsize
483 {\vtop {\hsize=
.67\hsize \rightskip=
1em
#1}
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
}
504 \smallcopyrightnotice
511 % compile-command: "tex refcard"