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