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 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., 59 Temple Place - Suite 330,
39 % Boston, MA 02111-1307, 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.20} % the bison version
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}
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{59 Temple Place - Suite
330}
100 \vskip .2\baselineskip
101 \centerline{Boston, MA
02111-
1307 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{59 Temple Place - Suite
330}
125 \vskip .2\baselineskip
126 \centerline{Boston, MA
02111-
1307 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{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
}
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.
332 \section{Definitions
}
333 %********************
335 \key{Declare a terminal symbol.
}{\%token <
{\it t\/
}>
338 \key{Declare a terminal symbol, and define its association.
}
339 {{\it association
} <
{\it t\/
}>
{\it n
}}
341 \vskip .2\baselineskip
342 \key{Generate a reentrant (pure) parser.
}
345 \key{Define the union of all data types used in the parser.
}
346 {\%union\
{{\it field list
}\
} }
348 \vskip .2\baselineskip
349 \key{Tell
{\tt bison
} where to start parsing.
}
352 \key{Tell
{\tt bison
} the data type of symbols.
}
353 {\%type <
{\it t\/
}>
{\it s1
}\dots{\it sn
}}
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
}.
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.
368 \section{Parser Definition Files
}
369 %*********************************
371 The general form for a parser definition is:
375 /* Initial C code. */
378 {\it Token and type definitions
}
384 Rule definition
{\it n
}
392 % Decrease standard baselineskip for the second page
393 \baselineskip =
.9\baselineskip
395 \section {Rule definitions
}
396 %**************************
401 non-terminal :
{\it statement
} 1
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:
412 \vskip -
\baselineskip
414 expression : number '$+$' number \
{ \$\$ $=$ \$
1 $+$ \$
3 \
}
415 | number '$-$' number \
{ \$\$ $=$ \$
1 $-$ \$
3 \
}
416 | number '$/$' number \
{ \$\$ $=$ \$
1 $/$ \$
3 \
}
417 | number '$*$' number \
{ \$\$ $=$ \$
1 $*$ \$
3 \
}
421 For altering the precedence of a symbol use:
422 \vskip -
\baselineskip
429 \vskip -
\baselineskip
431 foo : gnu bar gnu \%prec bar
435 \section{Grammar Variables and Symbols
}
436 %**************************************
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}}
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
452 \section {Variables and Types
}
453 %*****************************
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
}
466 % Redefine to prevent overfull hboxes
467 \def\key#1#2{\leavevmode\hbox to
\hsize
468 {\vtop {\hsize=
.625\hsize \rightskip=
1em
#1}
471 \key{User defined error handler.
} {int yyerror(char *)
}
472 \key{User defined lexical analyzer.
} {int yylex()
}
473 \key{The grammar parser.
} {int yyparse()
}
475 % Return to previous size
476 \def\key#1#2{\leavevmode\hbox to
\hsize
477 {\vtop {\hsize=
.67\hsize \rightskip=
1em
#1}
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
}
498 \smallcopyrightnotice
505 % compile-command: "tex refcard"