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, 2009-2011 Free Software Foundation, Inc.
24 % This file is part of Bison.
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.
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.
36 % You should have received a copy of the GNU General Public License
37 % along with this program. If not, see <http://www.gnu.org/licenses/>.
39 % This file is intended to be processed by plain TeX (TeX82).
41 % The final reference card has two columns:
42 % This file can be used to produce it in any of three ways:
44 % produces two separate pages, each of which needs to be reduced to 80%.
45 % This gives the best resolution.
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.
53 % UUCP: widener!brendan
54 % Internet: brendan@cs.widener.edu
57 % Internet: nick@nsis.cl.co.jp
59 % This refcard format was created by Steve Gildea.
61 % Thanks to Paul Rubin, Bob Chassell, Len Tower, and Richard Mlynarik
62 % for their many good ideas.
64 % We only change the following to change the version numbers and
67 \def\bisonversion{1.31} % the bison version
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}
74 % for copyright notices
75 \def\small{\smallfont\textfont2=
\smallsy\baselineskip=
.8\baselineskip}
76 \def\medium{\mediumfont\textfont2=
\mediumsy\baselineskip=
.8\baselineskip}
79 \vskip .15ex plus
.25 fill
81 \centerline{Copyright
\copyright\
\year\ Free Software Foundation, Inc.
}
82 \vskip .2\baselineskip
84 \vskip .2\baselineskip
85 \centerline{designed by Brendan Kehoe and Gavin Nicol
}
86 \vskip .2\baselineskip
87 \centerline{for Bison
\bisonversion}
89 Permission is granted to make and distribute copies of this card
90 provided the copyright notice and this permission notice
91 are preserved on all copies.
92 \vskip .2\baselineskip
93 For information, write to the:
94 \vskip .2\baselineskip
95 \centerline{Free Software Foundation, Inc.
}
96 \vskip .2\baselineskip
97 \centerline{51 Franklin Street, Fifth Floor
}
98 \vskip .2\baselineskip
99 \centerline{Boston, MA
02110-
1301 USA
}
102 %%%% smallcopyrightnotice for two column printing on one page.
103 \def\smallcopyrightnotice{
104 \vskip .15ex plus
.25 fill
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}
114 Permission is granted to make and distribute copies of this card
115 provided the copyright notice and this permission notice
116 are preserved on all copies.
117 \vskip .2\baselineskip
118 For information, write to the:
119 \vskip .2\baselineskip
120 \centerline{Free Software Foundation, Inc.
}
121 \vskip .2\baselineskip
122 \centerline{51 Franklin Street, Fifth Floor
}
123 \vskip .2\baselineskip
124 \centerline{Boston, MA
02110-
1301 USA
}
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}
131 \newdimen\intercolumnskip
135 \def\ncolumns{\the\columnsperpage}
137 \message{[\ncolumns\space
138 column
\if 1\ncolumns\else s
\fi\space per page
]}
140 \def\scaledmag#1{ scaled
\magstep #1}
142 % This multi-way format was designed by Stephen Gildea
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
153 \font\mediumfont=cmr10
154 \font\mediumsy=cmsy10
157 % two lines below commented out in Yet Another Attempt to eliminate
158 % page numbers from the output.
160 % \footline{\hss\folio}
161 \def\makefootline{\baselineskip10pt\hsize6.5in
\line{\the\footline}}
167 \font\titlefont=cmbx10
\scaledmag2
168 \font\headingfont=cmbx10
\scaledmag1
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
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
195 % Leave 3 column code here in case size increases.
199 \font\mediumfont=cmr10
200 \font\mediumsy=cmsy10
203 \errhelp{You must set
\columnsperpage equal to
1,
2, or
3.
}
204 \errmessage{Illegal number of columns per page
}
207 \intercolumnskip=
.46in
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
}
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{}
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}}
225 \def\bye{\par\vfill\supereject
226 \if a
\abc \else\null\vfill\eject\fi
227 \if a
\abc \else\null\vfill\eject\fi
231 % we won't be using math mode much, so redefine some of the characters
232 % we might want to talk about
240 \hyphenation{mini-buf-fer
}
243 % \parskip 1ex plus .5ex minus .5ex
244 \parskip 0.5ex plus
.25ex minus
.25ex
246 \outer\def\newcolumn{\vfill\eject}
248 \outer\def\title#1{{\titlefont\centerline{#1}}\vskip 1ex plus
.5ex
}
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
}
256 \def\beginindentedkeys{\keyindent=
1em
}
257 \def\endindentedkeys{\keyindent=
0em
}
260 \def\paralign{\vskip\parskip\halign}
262 \def\<
#1>
{$
\langle$
{\rm #1}$
\rangle$
}
264 \def\kbd#1{{\tt#1}\null} %\null so not an abbrev even if period follows
266 \def\beginexample{\par\leavevmode\begingroup
267 \obeylines\obeyspaces\parskip0pt\tt}
268 {\obeyspaces\global\let =\
}
269 \def\endexample{\endgroup}
271 \par\leavevmode\begingroup%
272 \obeylines\obeyspaces%
273 % bpk--added indentation
274 \advance\leftskip.25truein
277 {\obeyspaces\global\let =\
}
278 \def\endcexample{\endgroup}
280 %%%%% Prime definition of key; redefined below to prevent overful hboxes
282 \def\key#1#2{\leavevmode\hbox to
\hsize
283 {\vtop {\hsize=
.67\hsize \rightskip=
1em
#1}
287 \setbox\metaxbox\hbox{\kbd{M-x
}}
289 \metaxwidth=
\wd\metaxbox
291 \def\metax#1#2{\leavevmode\hbox to
\hsize{\hbox to
.75\hsize
292 {\hskip\keyindent\relax#1\hfil}%
293 \hskip -
\metaxwidth minus
1fil
296 \def\threecol#1#2#3{\hskip\keyindent\relax#1\hfil&
\kbd{#2}\quad
305 \title{Bison Quick Reference
}
307 \section{Starting Bison
}
308 %***********************
310 To use Bison, type:
\kbd{bison
{\it filename
}}
312 Options can be used as:
\kbd{bison
{\it options
} {\it filename
}}
314 \section{Command Line Options
}
315 %*****************************
317 \key{Display usage information.
} {-h
}
318 \key{Display version information.
} {-V
}
319 \key{Generate token and
{\tt YYSTYPE
} definitions.
} {-d
}
320 \key{Prepend a prefix to external symbols.
} {-p
{\it prefix
}}
321 \key{Don't put
{\tt \#line
} directives in the parser.
} {-l
}
322 \key{Specify the output file.
} {-o
{\it filename
}}
323 \key{Debug or
{\it trace
} mode.
} {-t
}
324 \key{Verbose description of the parser.
} {-v
}
325 \key{Emulate
{\tt yacc
} (generate
{\tt y.tab.*
} files).
} {-y
}
328 {\bf Note:
} The token and
{\tt YYSTYPE
} definitions are generated
329 to a file called
{\tt y.tab.h
} if the
{\tt -y
} option is used,
330 otherwise it will have the format
{\tt {\it name
}.tab.h
}, where
331 {\it name
} is the leading part of the parser definition filename.
333 \section{Definitions
}
334 %********************
336 \key{Declare a terminal symbol.
}{\%token <
{\it t\/
}>
339 \key{Declare a terminal symbol, and define its association.
}
340 {{\it association
} <
{\it t\/
}>
{\it n
}}
342 \vskip .2\baselineskip
343 \key{Generate a reentrant (pure) parser.
}
346 \key{Define the union of all data types used in the parser.
}
347 {\%union\
{{\it field list
}\
} }
349 \vskip .2\baselineskip
350 \key{Tell
{\tt bison
} where to start parsing.
}
353 \key{Tell
{\tt bison
} the data type of symbols.
}
354 {\%type <
{\it t\/
}>
{\it s1
}\dots{\it sn
}}
358 In the above,
{\it t
} is a
{\it type
} defined in the
{\tt \%union
}
359 definition,
{\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
}.
365 The
{\tt <
{\it t\/
}>
} after
{\tt \%token, \%left, \%right
} and
{\tt
366 \%nonassoc
} is optional. Additionally, precedence may be overridden
367 in the rules with
{\tt \%prec
} commands.
369 \section{Parser Definition Files
}
370 %*********************************
372 The general form for a parser definition is:
376 /* Initial C code. */
379 {\it Token and type definitions
}
385 Rule definition
{\it n
}
393 % Decrease standard baselineskip for the second page
394 \baselineskip =
.9\baselineskip
396 \section {Rule definitions
}
397 %**************************
401 \vskip -
\baselineskip
403 non-terminal :
{\it statement
} 1
410 Where
{\it statements
} can be either empty, or contain
411 a mixture of C code (enclosed in
{\tt \
{...\
}}), and the
412 symbols that make up the non-terminal. For example:
414 \vskip -
\baselineskip
416 expression : number '$+$' number \
{ \$\$ $=$ \$
1 $+$ \$
3 \
}
417 | number '$-$' number \
{ \$\$ $=$ \$
1 $-$ \$
3 \
}
418 | number '$/$' number \
{ \$\$ $=$ \$
1 $/$ \$
3 \
}
419 | number '$*$' number \
{ \$\$ $=$ \$
1 $*$ \$
3 \
}
423 For altering the precedence of a symbol use:
424 \vskip -
\baselineskip
431 \vskip -
\baselineskip
433 foo : gnu bar gnu \%prec bar
437 \section{Grammar Variables and Symbols
}
438 %**************************************
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
},
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}}
451 Where
{\it t
} is a type defined in the
{\tt \%union
},
{\it n
} is a
452 number,
{\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
454 as either
{\tt first_column
} or
{\tt last_column
}.
456 \section {Variables and Types
}
457 %*****************************
459 \key{Current lookahead token.
} {yychar
}
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
}
470 % Redefine to prevent overfull hboxes
471 \def\key#1#2{\leavevmode\hbox to
\hsize
472 {\vtop {\hsize=
.625\hsize \rightskip=
1em
#1}
475 \key{User defined error handler.
} {int yyerror(char *)
}
476 \key{User defined lexical analyzer.
} {int yylex()
}
477 \key{The grammar parser.
} {int yyparse()
}
479 % Return to previous size
480 \def\key#1#2{\leavevmode\hbox to
\hsize
481 {\vtop {\hsize=
.67\hsize \rightskip=
1em
#1}
487 \key{Quit parsing immediately. Return
1.
} {YYABORT
}
488 \key{Quit parsing immediately. Return
0.
} {YYACCEPT
}
489 \key{Pretend a syntax error occurred.
} {YYERROR
}
490 \key{Value in
{\tt yychar
} if no lookahead token.
} {YYEMPTY
}
491 \key{Clear previous lookahead token.
} {yyclearin
}
492 \key{Recover normally from an error.
} {yyerrok
}
502 \smallcopyrightnotice
509 % compile-command: "tex refcard"