Home | History | Annotate | Download | only in doc
      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, 2009-2012 Free Software Foundation, Inc.
     23 %
     24 % This file is part of Bison.
     25 %
     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.
     30 %
     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.
     35 %
     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/>.
     38 %
     39 % This file is intended to be processed by plain TeX (TeX82).
     40 %
     41 % The final reference card has two columns:
     42 % This file can be used to produce it in any of three ways:
     43 % 1 column per page
     44 %    produces two separate pages, each of which needs to be reduced to 80%.
     45 %    This gives the best resolution.
     46 % 2 columns per page
     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.
     50 %
     51 % Authors:
     52 %  Brendan Kehoe
     53 %  UUCP: widener!brendan
     54 %  Internet: brendan (a] cs.widener.edu
     55 %
     56 %  Gavin Nicol
     57 %  Internet: nick (a] nsis.cl.co.jp
     58 %
     59 % This refcard format was created by Steve Gildea.
     60 %
     61 % Thanks to Paul Rubin, Bob Chassell, Len Tower, and Richard Mlynarik
     62 % for their many good ideas.
     63 
     64 % We only change the following to change the version numbers and
     65 % such.
     66 
     67 \def\bisonversion{1.31}                    % the bison version
     68 
     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}
     73 
     74 % for copyright notices
     75 \def\small{\smallfont\textfont2=\smallsy\baselineskip=.8\baselineskip}
     76 \def\medium{\mediumfont\textfont2=\mediumsy\baselineskip=.8\baselineskip}
     77 
     78 \def\copyrightnotice{
     79 \vskip .15ex plus .25 fill
     80 \begingroup\medium
     81 \centerline{Copyright \copyright\ \year\ Free Software Foundation, Inc.}
     82 \vskip .2\baselineskip
     83 \centerline{\version}
     84 \vskip .2\baselineskip
     85 \centerline{designed by Brendan Kehoe and Gavin Nicol}
     86 \vskip .2\baselineskip
     87 \centerline{for Bison \bisonversion}
     88 
     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}
    100 \endgroup}
    101 
    102 %%%% smallcopyrightnotice for two column printing on one page.
    103 \def\smallcopyrightnotice{
    104 \vskip .15ex plus .25 fill
    105 \begingroup\small
    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}
    113 
    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}
    125 \endgroup}
    126 
    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}
    130 
    131 \newdimen\intercolumnskip
    132 \newbox\columna
    133 \newbox\columnb
    134 
    135 \def\ncolumns{\the\columnsperpage}
    136 
    137 \message{[\ncolumns\space
    138   column\if 1\ncolumns\else s\fi\space per page]}
    139 
    140 \def\scaledmag#1{ scaled \magstep #1}
    141 
    142 % This multi-way format was designed by Stephen Gildea
    143 % October 1986.
    144 \if 1\ncolumns
    145   \hsize 4in
    146   \vsize 10in
    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
    151   \font\smallfont=cmr6
    152   \font\smallsy=cmsy6
    153   \font\mediumfont=cmr10
    154   \font\mediumsy=cmsy10
    155 
    156 
    157 % two lines below commented out in Yet Another Attempt to eliminate
    158 % page numbers from the output.
    159   \footline{\hss}
    160 % \footline{\hss\folio}
    161   \def\makefootline{\baselineskip10pt\hsize6.5in\line{\the\footline}}
    162 \else
    163   \hsize 3.2in
    164   \vsize 7.95in
    165   \hoffset -.75in
    166   \voffset -.745in
    167   \font\titlefont=cmbx10 \scaledmag2
    168   \font\headingfont=cmbx10 \scaledmag1
    169   \font\smallfont=cmr6
    170   \font\smallsy=cmsy6
    171   \font\eightrm=cmr8
    172   \font\eightbf=cmbx8
    173   \font\eightit=cmti8
    174   \font\eighttt=cmtt8
    175   \font\eightsy=cmsy8
    176   \textfont0=\eightrm
    177   \textfont2=\eightsy
    178   \def\rm{\eightrm}
    179   \def\bf{\eightbf}
    180   \def\it{\eightit}
    181   \def\tt{\eighttt}
    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
    187 
    188   \if 2\ncolumns
    189     \let\maxcolumn=b
    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
    194 
    195 % Leave 3 column code here in case size increases.
    196   \else \if 3\ncolumns
    197     \let\maxcolumn=c
    198     \nopagenumbers
    199   \font\mediumfont=cmr10
    200   \font\mediumsy=cmsy10
    201 
    202   \else
    203     \errhelp{You must set \columnsperpage equal to 1, 2, or 3.}
    204     \errmessage{Illegal number of columns per page}
    205   \fi\fi
    206 
    207   \intercolumnskip=.46in
    208   \def\abc{a}
    209   \output={%
    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}
    213       \else\if a\abc
    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{}
    217       \else
    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}}
    224 
    225   \def\bye{\par\vfill\supereject
    226     \if a\abc \else\null\vfill\eject\fi
    227     \if a\abc \else\null\vfill\eject\fi
    228     \end}
    229 \fi
    230 
    231 % we won't be using math mode much, so redefine some of the characters
    232 % we might want to talk about
    233 \catcode`\^=12
    234 \catcode`\_=12
    235 
    236 \chardef\\=`\\
    237 \chardef\{=`\{
    238 \chardef\}=`\}
    239 
    240 \hyphenation{mini-buf-fer}
    241 
    242 \parindent 0pt
    243 % \parskip 1ex plus .5ex minus .5ex
    244 \parskip 0.5ex plus .25ex minus .25ex
    245 
    246 \outer\def\newcolumn{\vfill\eject}
    247 
    248 \outer\def\title#1{{\titlefont\centerline{#1}}\vskip 1ex plus .5ex}
    249 
    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}
    253 
    254 \newdimen\keyindent
    255 
    256 \def\beginindentedkeys{\keyindent=1em}
    257 \def\endindentedkeys{\keyindent=0em}
    258 \endindentedkeys
    259 
    260 \def\paralign{\vskip\parskip\halign}
    261 
    262 \def\<#1>{$\langle${\rm #1}$\rangle$}
    263 
    264 \def\kbd#1{{\tt#1}\null}        %\null so not an abbrev even if period follows
    265 
    266 \def\beginexample{\par\leavevmode\begingroup
    267   \obeylines\obeyspaces\parskip0pt\tt}
    268 {\obeyspaces\global\let =\ }
    269 \def\endexample{\endgroup}
    270 \def\begincexample{%
    271   \par\leavevmode\begingroup%
    272   \obeylines\obeyspaces%
    273   % bpk--added indentation
    274   \advance\leftskip.25truein
    275 %  \parskip0pt%
    276   \tt}
    277 {\obeyspaces\global\let =\ }
    278 \def\endcexample{\endgroup}
    279 
    280 %%%%% Prime definition of key; redefined below to prevent overful hboxes
    281 
    282 \def\key#1#2{\leavevmode\hbox to \hsize
    283   {\vtop {\hsize=.67\hsize \rightskip=1em #1}
    284   \kbd{#2}\hfil}}
    285 
    286 \newbox\metaxbox
    287 \setbox\metaxbox\hbox{\kbd{M-x }}
    288 \newdimen\metaxwidth
    289 \metaxwidth=\wd\metaxbox
    290 
    291 \def\metax#1#2{\leavevmode\hbox to \hsize{\hbox to .75\hsize
    292   {\hskip\keyindent\relax#1\hfil}%
    293   \hskip -\metaxwidth minus 1fil
    294   \kbd{#2}\hfil}}
    295 
    296 \def\threecol#1#2#3{\hskip\keyindent\relax#1\hfil&\kbd{#2}\quad
    297   &\kbd{#3}\quad\cr}
    298 
    299 %**end of header
    300 
    302 %     ************
    303 %     **  BISON **
    304 %     ************
    305 
    306 \title{Bison Quick Reference}
    307 
    308 \section{Starting Bison}
    309 %***********************
    310 
    311 To use Bison, type: \kbd{bison {\it filename}}
    312 
    313 Options can be used as: \kbd{bison {\it options} {\it filename}}
    314 
    315 \section{Command Line Options}
    316 %*****************************
    317 
    318 \key{Display usage information.}                         {-h}
    319 \key{Display version information.}                       {-V}
    320 \key{Generate token and {\tt YYSTYPE} definitions.}      {-d}
    321 \key{Prepend a prefix to external symbols.}              {-p {\it prefix}}
    322 \key{Don't put {\tt \#line} directives in the parser.}   {-l}
    323 \key{Specify the output file.}                           {-o {\it filename}}
    324 \key{Debug or {\it trace} mode.}                      {-t}
    325 \key{Verbose description of the parser.}                 {-v}
    326 \key{Emulate {\tt yacc} (generate {\tt y.tab.*} files).} {-y}
    327 
    328 \vskip .10truein
    329 {\bf Note:} The token and {\tt YYSTYPE} definitions are generated
    330 to a file called {\tt y.tab.h} if the {\tt -y} option is used,
    331 otherwise it will have the format {\tt {\it name}.tab.h}, where
    332 {\it name} is the leading part of the parser definition filename.
    333 
    334 \section{Definitions}
    335 %********************
    336 
    337 \key{Declare a terminal symbol.}{\%token <{\it t\/}>
    338       {\it n}}
    339 
    340 \key{Declare a terminal symbol, and define its association.}
    341       {{\it association} <{\it t\/}> {\it n}}
    342 
    343 \vskip .2\baselineskip
    344 \key{Generate a reentrant (pure) parser.}
    345       {\%pure_parser}
    346 
    347 \key{Define the union of all data types used in the parser.}
    348       {\%union\{{\it field list}\} }
    349 
    350 \vskip .2\baselineskip
    351 \key{Tell {\tt bison} where to start parsing.}
    352       {\%start {\it m}}
    353 
    354 \key{Tell {\tt bison} the data type of symbols.}
    355       {\%type <{\it t\/}> {\it s1}\dots{\it sn}}
    356 
    357 \vskip .10truein
    358 
    359 In the above, {\it t} is a {\it type} defined in the {\tt \%union}
    360 definition,  {\it n} is a {\it terminal} symbol name, {\it m} is a
    361 {\it non-terminal} symbol name, and {\it association} can be one of
    362 {\tt \%left}, {\tt \%right}, or {\tt \%nonassoc}.
    363 
    364 \vskip .10truein
    365 
    366 The {\tt <{\it t\/}>} after {\tt \%token, \%left, \%right} and {\tt
    367   \%nonassoc} is optional. Additionally, precedence may be overridden
    368 in the rules with {\tt \%prec} commands.
    369 
    370 \section{Parser Definition Files}
    371 %*********************************
    372 
    373 The general form for a parser definition is:
    374 
    375 \begincexample
    376 \{\%
    377    /* Initial C code.  */
    378 \%\}
    379 
    380  {\it Token and type definitions}
    381 
    382 \%\%
    383 
    384    Rule definition 1
    385           \vdots
    386    Rule definition {\it n}
    387 
    388 \%\%
    389 
    390   /* Other C code.  */
    391 \endcexample
    392 
    393 
    394 % Decrease standard baselineskip for the second page
    395  \baselineskip = .9\baselineskip
    396 
    397 \section {Rule definitions}
    398 %**************************
    399 
    400 Rules take the form:
    401 
    402 \vskip -\baselineskip
    403 \beginexample
    404      non-terminal : {\it statement} 1
    405                   | {\it statement} 2
    406                       \vdots
    407                   | {\it statement n}
    408                   ;
    409 \endexample
    410 
    411 Where {\it statements} can be either empty, or contain
    412 a mixture of C code (enclosed in {\tt \{...\}}), and the
    413 symbols that make up the non-terminal. For example:
    414 
    415 \vskip -\baselineskip
    416 \beginexample
    417      expression : number '$+$' number \{ \$\$ $=$ \$1 $+$ \$3 \}
    418                 | number '$-$' number \{ \$\$ $=$ \$1 $-$ \$3 \}
    419                 | number '$/$' number \{ \$\$ $=$ \$1 $/$ \$3 \}
    420                 | number '$*$' number \{ \$\$ $=$ \$1 $*$ \$3 \}
    421                 ;
    422 \endexample
    423 
    424 For altering the precedence of a symbol use:
    425 \vskip -\baselineskip
    426 
    427 \beginexample
    428      \%prec name
    429 \endexample
    430 
    431 For example:
    432 \vskip -\baselineskip
    433 \beginexample
    434      foo : gnu bar gnu      \%prec bar
    435          ;
    436 \endexample
    437 
    438 \section{Grammar Variables and Symbols}
    439 %**************************************
    440 
    441 \key{Recognize an error \& continue parsing.}{error}
    442 \key{Access data associated with a symbol.}  {\$\$, \$0\dots\${\it n}}
    443 \key{Access a field of the  data union.}    {\$\$.{\it t},
    444                                      \$0.{\it t}\dots\${\it n}.{\it t}}
    445 \key{Access symbol's location.}             {@\$, @0\dots@{\it n}}
    446 \key{Access data's line location.}          {@{\it x}.{\it line\_spec}}
    447 \key{Access data's column location.}        {@{\it x}.{\it column\_spec}}
    448 
    449 
    450 \vskip .10truein
    451 %
    452 Where {\it t} is a type defined in the {\tt \%union}, {\it n} is a
    453 number, {\it x} is a number or \$, {\it line\_spec} one of {\tt
    454   first_line} and {\tt last_line}, and {\it column\_spec} is specified
    455 as either {\tt first_column} or {\tt last_column}.
    456 
    457 \section {Variables and Types}
    458 %*****************************
    459 
    460 \key{Current lookahead token.}                 {yychar}
    461 \key{Debug mode flag.}                         {yydebug}
    462 \key{Data associated with the current token.}  {yylval}
    463 \key{Source position of current token.}        {yylloc}
    464 \key{Number of errors encountered.}            {yynerrs}
    465 \key{Position information type.}               {YYLTYPE}
    466 \key{Data type associated with symbols.}       {YYSTYPE}
    467 
    468 \section {Functions}
    469 %*******************
    470 
    471 % Redefine to prevent overfull hboxes
    472 \def\key#1#2{\leavevmode\hbox to \hsize
    473   {\vtop {\hsize=.625\hsize \rightskip=1em #1}
    474   \kbd{#2}\hfil}}
    475 
    476 \key{User defined error handler.}         {int yyerror(char *)}
    477 \key{User defined lexical analyzer.}      {int yylex()}
    478 \key{The grammar parser.}                 {int yyparse()}
    479 
    480 % Return to previous size
    481 \def\key#1#2{\leavevmode\hbox to \hsize
    482   {\vtop {\hsize=.67\hsize \rightskip=1em #1}
    483   \kbd{#2}\hfil}}
    484 
    485 \section{Macros}
    486 %***************
    487 
    488 \key{Quit parsing immediately. Return 1.}           {YYABORT}
    489 \key{Quit parsing immediately. Return 0.}           {YYACCEPT}
    490 \key{Pretend a syntax error occurred.}              {YYERROR}
    491 \key{Value in {\tt yychar} if no lookahead token.}  {YYEMPTY}
    492 \key{Clear previous lookahead token.}               {yyclearin}
    493 \key{Recover normally from an error.}               {yyerrok}
    494 
    495 % **************
    496 % ** The end  **
    497 % **************
    498 
    499 \vskip \baselineskip
    500 \if 1\ncolumns
    501 \copyrightnotice
    502 \else
    503 \smallcopyrightnotice
    504 \fi
    505 
    506 \bye
    507 
    508 
    510 % Local variables:
    511 % compile-command: "tex refcard"
    512 % End:
    513