home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / gnu / info / bison.info-3 (.txt) < prev    next >
GNU Info File  |  1994-11-17  |  51KB  |  982 lines

  1. This is Info file bison.info, produced by Makeinfo-1.54 from the input
  2. file /home/gd2/gnu/bison/bison.texinfo.
  3.    This file documents the Bison parser generator.
  4.    Copyright (C) 1988, 1989, 1990, 1991, 1992 Free Software Foundation,
  5.    Permission is granted to make and distribute verbatim copies of this
  6. manual provided the copyright notice and this permission notice are
  7. preserved on all copies.
  8.    Permission is granted to copy and distribute modified versions of
  9. this manual under the conditions for verbatim copying, provided also
  10. that the sections entitled "GNU General Public License" and "Conditions
  11. for Using Bison" are included exactly as in the original, and provided
  12. that the entire resulting derived work is distributed under the terms
  13. of a permission notice identical to this one.
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that the sections entitled "GNU General Public
  17. License", "Conditions for Using Bison" and this permission notice may be
  18. included in translations approved by the Free Software Foundation
  19. instead of in the original English.
  20. File: bison.info,  Node: Mid-Rule Actions,  Prev: Action Types,  Up: Semantics
  21. Actions in Mid-Rule
  22. -------------------
  23.    Occasionally it is useful to put an action in the middle of a rule.
  24. These actions are written just like usual end-of-rule actions, but they
  25. are executed before the parser even recognizes the following components.
  26.    A mid-rule action may refer to the components preceding it using
  27. `$N', but it may not refer to subsequent components because it is run
  28. before they are parsed.
  29.    The mid-rule action itself counts as one of the components of the
  30. rule.  This makes a difference when there is another action later in
  31. the same rule (and usually there is another at the end): you have to
  32. count the actions along with the symbols when working out which number
  33. N to use in `$N'.
  34.    The mid-rule action can also have a semantic value.  The action can
  35. set its value with an assignment to `$$', and actions later in the rule
  36. can refer to the value using `$N'.  Since there is no symbol to name
  37. the action, there is no way to declare a data type for the value in
  38. advance, so you must use the `$<...>' construct to specify a data type
  39. each time you refer to this value.
  40.    There is no way to set the value of the entire rule with a mid-rule
  41. action, because assignments to `$$' do not have that effect.  The only
  42. way to set the value for the entire rule is with an ordinary action at
  43. the end of the rule.
  44.    Here is an example from a hypothetical compiler, handling a `let'
  45. statement that looks like `let (VARIABLE) STATEMENT' and serves to
  46. create a variable named VARIABLE temporarily for the duration of
  47. STATEMENT.  To parse this construct, we must put VARIABLE into the
  48. symbol table while STATEMENT is parsed, then remove it afterward.  Here
  49. is how it is done:
  50.      stmt:   LET '(' var ')'
  51.                      { $<context>$ = push_context ();
  52.                        declare_variable ($3); }
  53.              stmt    { $$ = $6;
  54.                        pop_context ($<context>5); }
  55. As soon as `let (VARIABLE)' has been recognized, the first action is
  56. run.  It saves a copy of the current semantic context (the list of
  57. accessible variables) as its semantic value, using alternative
  58. `context' in the data-type union.  Then it calls `declare_variable' to
  59. add the new variable to that list.  Once the first action is finished,
  60. the embedded statement `stmt' can be parsed.  Note that the mid-rule
  61. action is component number 5, so the `stmt' is component number 6.
  62.    After the embedded statement is parsed, its semantic value becomes
  63. the value of the entire `let'-statement.  Then the semantic value from
  64. the earlier action is used to restore the prior list of variables.  This
  65. removes the temporary `let'-variable from the list so that it won't
  66. appear to exist while the rest of the program is parsed.
  67.    Taking action before a rule is completely recognized often leads to
  68. conflicts since the parser must commit to a parse in order to execute
  69. the action.  For example, the following two rules, without mid-rule
  70. actions, can coexist in a working parser because the parser can shift
  71. the open-brace token and look at what follows before deciding whether
  72. there is a declaration or not:
  73.      compound: '{' declarations statements '}'
  74.              | '{' statements '}'
  75.              ;
  76. But when we add a mid-rule action as follows, the rules become
  77. nonfunctional:
  78.      compound: { prepare_for_local_variables (); }
  79.                '{' declarations statements '}'
  80.              | '{' statements '}'
  81.              ;
  82. Now the parser is forced to decide whether to run the mid-rule action
  83. when it has read no farther than the open-brace.  In other words, it
  84. must commit to using one rule or the other, without sufficient
  85. information to do it correctly.  (The open-brace token is what is called
  86. the "look-ahead" token at this time, since the parser is still deciding
  87. what to do about it.  *Note Look-Ahead Tokens: Look-Ahead.)
  88.    You might think that you could correct the problem by putting
  89. identical actions into the two rules, like this:
  90.      compound: { prepare_for_local_variables (); }
  91.                '{' declarations statements '}'
  92.              | { prepare_for_local_variables (); }
  93.                '{' statements '}'
  94.              ;
  95. But this does not help, because Bison does not realize that the two
  96. actions are identical.  (Bison never tries to understand the C code in
  97. an action.)
  98.    If the grammar is such that a declaration can be distinguished from a
  99. statement by the first token (which is true in C), then one solution
  100. which does work is to put the action after the open-brace, like this:
  101.      compound: '{' { prepare_for_local_variables (); }
  102.                declarations statements '}'
  103.              | '{' statements '}'
  104.              ;
  105. Now the first token of the following declaration or statement, which
  106. would in any case tell Bison which rule to use, can still do so.
  107.    Another solution is to bury the action inside a nonterminal symbol
  108. which serves as a subroutine:
  109.      subroutine: /* empty */
  110.                { prepare_for_local_variables (); }
  111.              ;
  112.      
  113.      compound: subroutine
  114.                '{' declarations statements '}'
  115.              | subroutine
  116.                '{' statements '}'
  117.              ;
  118. Now Bison can execute the action in the rule for `subroutine' without
  119. deciding which rule for `compound' it will eventually use.  Note that
  120. the action is now at the end of its rule.  Any mid-rule action can be
  121. converted to an end-of-rule action in this way, and this is what Bison
  122. actually does to implement mid-rule actions.
  123. File: bison.info,  Node: Declarations,  Next: Multiple Parsers,  Prev: Semantics,  Up: Grammar File
  124. Bison Declarations
  125. ==================
  126.    The "Bison declarations" section of a Bison grammar defines the
  127. symbols used in formulating the grammar and the data types of semantic
  128. values.  *Note Symbols::.
  129.    All token type names (but not single-character literal tokens such as
  130. `'+'' and `'*'') must be declared.  Nonterminal symbols must be
  131. declared if you need to specify which data type to use for the semantic
  132. value (*note More Than One Value Type: Multiple Types.).
  133.    The first rule in the file also specifies the start symbol, by
  134. default.  If you want some other symbol to be the start symbol, you
  135. must declare it explicitly (*note Languages and Context-Free Grammars:
  136. Language and Grammar.).
  137. * Menu:
  138. * Token Decl::        Declaring terminal symbols.
  139. * Precedence Decl::   Declaring terminals with precedence and associativity.
  140. * Union Decl::        Declaring the set of all semantic value types.
  141. * Type Decl::         Declaring the choice of type for a nonterminal symbol.
  142. * Expect Decl::       Suppressing warnings about shift/reduce conflicts.
  143. * Start Decl::        Specifying the start symbol.
  144. * Pure Decl::         Requesting a reentrant parser.
  145. * Decl Summary::      Table of all Bison declarations.
  146. File: bison.info,  Node: Token Decl,  Next: Precedence Decl,  Up: Declarations
  147. Token Type Names
  148. ----------------
  149.    The basic way to declare a token type name (terminal symbol) is as
  150. follows:
  151.      %token NAME
  152.    Bison will convert this into a `#define' directive in the parser, so
  153. that the function `yylex' (if it is in this file) can use the name NAME
  154. to stand for this token type's code.
  155.    Alternatively, you can use `%left', `%right', or `%nonassoc' instead
  156. of `%token', if you wish to specify precedence.  *Note Operator
  157. Precedence: Precedence Decl.
  158.    You can explicitly specify the numeric code for a token type by
  159. appending an integer value in the field immediately following the token
  160. name:
  161.      %token NUM 300
  162. It is generally best, however, to let Bison choose the numeric codes for
  163. all token types.  Bison will automatically select codes that don't
  164. conflict with each other or with ASCII characters.
  165.    In the event that the stack type is a union, you must augment the
  166. `%token' or other token declaration to include the data type
  167. alternative delimited by angle-brackets (*note More Than One Value
  168. Type: Multiple Types.).
  169.    For example:
  170.      %union {              /* define stack type */
  171.        double val;
  172.        symrec *tptr;
  173.      }
  174.      %token <val> NUM      /* define token NUM and its type */
  175. File: bison.info,  Node: Precedence Decl,  Next: Union Decl,  Prev: Token Decl,  Up: Declarations
  176. Operator Precedence
  177. -------------------
  178.    Use the `%left', `%right' or `%nonassoc' declaration to declare a
  179. token and specify its precedence and associativity, all at once.  These
  180. are called "precedence declarations".  *Note Operator Precedence:
  181. Precedence, for general information on operator precedence.
  182.    The syntax of a precedence declaration is the same as that of
  183. `%token': either
  184.      %left SYMBOLS...
  185.      %left <TYPE> SYMBOLS...
  186.    And indeed any of these declarations serves the purposes of `%token'.
  187. But in addition, they specify the associativity and relative precedence
  188. for all the SYMBOLS:
  189.    * The associativity of an operator OP determines how repeated uses
  190.      of the operator nest: whether `X OP Y OP Z' is parsed by grouping
  191.      X with Y first or by grouping Y with Z first.  `%left' specifies
  192.      left-associativity (grouping X with Y first) and `%right'
  193.      specifies right-associativity (grouping Y with Z first).
  194.      `%nonassoc' specifies no associativity, which means that `X OP Y
  195.      OP Z' is considered a syntax error.
  196.    * The precedence of an operator determines how it nests with other
  197.      operators.  All the tokens declared in a single precedence
  198.      declaration have equal precedence and nest together according to
  199.      their associativity.  When two tokens declared in different
  200.      precedence declarations associate, the one declared later has the
  201.      higher precedence and is grouped first.
  202. File: bison.info,  Node: Union Decl,  Next: Type Decl,  Prev: Precedence Decl,  Up: Declarations
  203. The Collection of Value Types
  204. -----------------------------
  205.    The `%union' declaration specifies the entire collection of possible
  206. data types for semantic values.  The keyword `%union' is followed by a
  207. pair of braces containing the same thing that goes inside a `union' in
  208.    For example:
  209.      %union {
  210.        double val;
  211.        symrec *tptr;
  212.      }
  213. This says that the two alternative types are `double' and `symrec *'.
  214. They are given names `val' and `tptr'; these names are used in the
  215. `%token' and `%type' declarations to pick one of the types for a
  216. terminal or nonterminal symbol (*note Nonterminal Symbols: Type Decl.).
  217.    Note that, unlike making a `union' declaration in C, you do not write
  218. a semicolon after the closing brace.
  219. File: bison.info,  Node: Type Decl,  Next: Expect Decl,  Prev: Union Decl,  Up: Declarations
  220. Nonterminal Symbols
  221. -------------------
  222. When you use `%union' to specify multiple value types, you must declare
  223. the value type of each nonterminal symbol for which values are used.
  224. This is done with a `%type' declaration, like this:
  225.      %type <TYPE> NONTERMINAL...
  226. Here NONTERMINAL is the name of a nonterminal symbol, and TYPE is the
  227. name given in the `%union' to the alternative that you want (*note The
  228. Collection of Value Types: Union Decl.).  You can give any number of
  229. nonterminal symbols in the same `%type' declaration, if they have the
  230. same value type.  Use spaces to separate the symbol names.
  231. File: bison.info,  Node: Expect Decl,  Next: Start Decl,  Prev: Type Decl,  Up: Declarations
  232. Suppressing Conflict Warnings
  233. -----------------------------
  234.    Bison normally warns if there are any conflicts in the grammar
  235. (*note Shift/Reduce Conflicts: Shift/Reduce.), but most real grammars
  236. have harmless shift/reduce conflicts which are resolved in a
  237. predictable way and would be difficult to eliminate.  It is desirable
  238. to suppress the warning about these conflicts unless the number of
  239. conflicts changes.  You can do this with the `%expect' declaration.
  240.    The declaration looks like this:
  241.      %expect N
  242.    Here N is a decimal integer.  The declaration says there should be no
  243. warning if there are N shift/reduce conflicts and no reduce/reduce
  244. conflicts.  The usual warning is given if there are either more or fewer
  245. conflicts, or if there are any reduce/reduce conflicts.
  246.    In general, using `%expect' involves these steps:
  247.    * Compile your grammar without `%expect'.  Use the `-v' option to
  248.      get a verbose list of where the conflicts occur.  Bison will also
  249.      print the number of conflicts.
  250.    * Check each of the conflicts to make sure that Bison's default
  251.      resolution is what you really want.  If not, rewrite the grammar
  252.      and go back to the beginning.
  253.    * Add an `%expect' declaration, copying the number N from the number
  254.      which Bison printed.
  255.    Now Bison will stop annoying you about the conflicts you have
  256. checked, but it will warn you again if changes in the grammar result in
  257. additional conflicts.
  258. File: bison.info,  Node: Start Decl,  Next: Pure Decl,  Prev: Expect Decl,  Up: Declarations
  259. The Start-Symbol
  260. ----------------
  261.    Bison assumes by default that the start symbol for the grammar is
  262. the first nonterminal specified in the grammar specification section.
  263. The programmer may override this restriction with the `%start'
  264. declaration as follows:
  265.      %start SYMBOL
  266. File: bison.info,  Node: Pure Decl,  Next: Decl Summary,  Prev: Start Decl,  Up: Declarations
  267. A Pure (Reentrant) Parser
  268. -------------------------
  269.    A "reentrant" program is one which does not alter in the course of
  270. execution; in other words, it consists entirely of "pure" (read-only)
  271. code.  Reentrancy is important whenever asynchronous execution is
  272. possible; for example, a nonreentrant program may not be safe to call
  273. from a signal handler.  In systems with multiple threads of control, a
  274. nonreentrant program must be called only within interlocks.
  275.    The Bison parser is not normally a reentrant program, because it uses
  276. statically allocated variables for communication with `yylex'.  These
  277. variables include `yylval' and `yylloc'.
  278.    The Bison declaration `%pure_parser' says that you want the parser
  279. to be reentrant.  It looks like this:
  280.      %pure_parser
  281.    The effect is that the two communication variables become local
  282. variables in `yyparse', and a different calling convention is used for
  283. the lexical analyzer function `yylex'.  *Note Calling for Pure Parsers:
  284. Pure Calling, for the details of this.  The variable `yynerrs' also
  285. becomes local in `yyparse' (*note The Error Reporting Function
  286. `yyerror': Error Reporting.).  The convention for calling `yyparse'
  287. itself is unchanged.
  288. File: bison.info,  Node: Decl Summary,  Prev: Pure Decl,  Up: Declarations
  289. Bison Declaration Summary
  290. -------------------------
  291.    Here is a summary of all Bison declarations:
  292. `%union'
  293.      Declare the collection of data types that semantic values may have
  294.      (*note The Collection of Value Types: Union Decl.).
  295. `%token'
  296.      Declare a terminal symbol (token type name) with no precedence or
  297.      associativity specified (*note Token Type Names: Token Decl.).
  298. `%right'
  299.      Declare a terminal symbol (token type name) that is
  300.      right-associative (*note Operator Precedence: Precedence Decl.).
  301. `%left'
  302.      Declare a terminal symbol (token type name) that is
  303.      left-associative (*note Operator Precedence: Precedence Decl.).
  304. `%nonassoc'
  305.      Declare a terminal symbol (token type name) that is nonassociative
  306.      (using it in a way that would be associative is a syntax error)
  307.      (*note Operator Precedence: Precedence Decl.).
  308. `%type'
  309.      Declare the type of semantic values for a nonterminal symbol
  310.      (*note Nonterminal Symbols: Type Decl.).
  311. `%start'
  312.      Specify the grammar's start symbol (*note The Start-Symbol: Start
  313.      Decl.).
  314. `%expect'
  315.      Declare the expected number of shift-reduce conflicts (*note
  316.      Suppressing Conflict Warnings: Expect Decl.).
  317. `%pure_parser'
  318.      Request a pure (reentrant) parser program (*note A Pure
  319.      (Reentrant) Parser: Pure Decl.).
  320. File: bison.info,  Node: Multiple Parsers,  Prev: Declarations,  Up: Grammar File
  321. Multiple Parsers in the Same Program
  322. ====================================
  323.    Most programs that use Bison parse only one language and therefore
  324. contain only one Bison parser.  But what if you want to parse more than
  325. one language with the same program?  Then you need to avoid a name
  326. conflict between different definitions of `yyparse', `yylval', and so
  327.    The easy way to do this is to use the option `-p PREFIX' (*note
  328. Invoking Bison: Invocation.).  This renames the interface functions and
  329. variables of the Bison parser to start with PREFIX instead of `yy'.
  330. You can use this to give each parser distinct names that do not
  331. conflict.
  332.    The precise list of symbols renamed is `yyparse', `yylex',
  333. `yyerror', `yylval', `yychar' and `yydebug'.  For example, if you use
  334. `-p c', the names become `cparse', `clex', and so on.
  335.    *All the other variables and macros associated with Bison are not
  336. renamed.* These others are not global; there is no conflict if the same
  337. name is used in different parsers.  For example, `YYSTYPE' is not
  338. renamed, but defining this in different ways in different parsers causes
  339. no trouble (*note Data Types of Semantic Values: Value Type.).
  340.    The `-p' option works by adding macro definitions to the beginning
  341. of the parser source file, defining `yyparse' as `PREFIXparse', and so
  342. on.  This effectively substitutes one name for the other in the entire
  343. parser file.
  344. File: bison.info,  Node: Interface,  Next: Algorithm,  Prev: Grammar File,  Up: Top
  345. Parser C-Language Interface
  346. ***************************
  347.    The Bison parser is actually a C function named `yyparse'.  Here we
  348. describe the interface conventions of `yyparse' and the other functions
  349. that it needs to use.
  350.    Keep in mind that the parser uses many C identifiers starting with
  351. `yy' and `YY' for internal purposes.  If you use such an identifier
  352. (aside from those in this manual) in an action or in additional C code
  353. in the grammar file, you are likely to run into trouble.
  354. * Menu:
  355. * Parser Function::   How to call `yyparse' and what it returns.
  356. * Lexical::           You must supply a function `yylex'
  357.                         which reads tokens.
  358. * Error Reporting::   You must supply a function `yyerror'.
  359. * Action Features::   Special features for use in actions.
  360. File: bison.info,  Node: Parser Function,  Next: Lexical,  Up: Interface
  361. The Parser Function `yyparse'
  362. =============================
  363.    You call the function `yyparse' to cause parsing to occur.  This
  364. function reads tokens, executes actions, and ultimately returns when it
  365. encounters end-of-input or an unrecoverable syntax error.  You can also
  366. write an action which directs `yyparse' to return immediately without
  367. reading further.
  368.    The value returned by `yyparse' is 0 if parsing was successful
  369. (return is due to end-of-input).
  370.    The value is 1 if parsing failed (return is due to a syntax error).
  371.    In an action, you can cause immediate return from `yyparse' by using
  372. these macros:
  373. `YYACCEPT'
  374.      Return immediately with value 0 (to report success).
  375. `YYABORT'
  376.      Return immediately with value 1 (to report failure).
  377. File: bison.info,  Node: Lexical,  Next: Error Reporting,  Prev: Parser Function,  Up: Interface
  378. The Lexical Analyzer Function `yylex'
  379. =====================================
  380.    The "lexical analyzer" function, `yylex', recognizes tokens from the
  381. input stream and returns them to the parser.  Bison does not create
  382. this function automatically; you must write it so that `yyparse' can
  383. call it.  The function is sometimes referred to as a lexical scanner.
  384.    In simple programs, `yylex' is often defined at the end of the Bison
  385. grammar file.  If `yylex' is defined in a separate source file, you
  386. need to arrange for the token-type macro definitions to be available
  387. there.  To do this, use the `-d' option when you run Bison, so that it
  388. will write these macro definitions into a separate header file
  389. `NAME.tab.h' which you can include in the other source files that need
  390. it.  *Note Invoking Bison: Invocation.
  391. * Menu:
  392. * Calling Convention::  How `yyparse' calls `yylex'.
  393. * Token Values::      How `yylex' must return the semantic value
  394.                         of the token it has read.
  395. * Token Positions::   How `yylex' must return the text position
  396.                         (line number, etc.) of the token, if the
  397.                         actions want that.
  398. * Pure Calling::      How the calling convention differs
  399.                         in a pure parser (*note A Pure (Reentrant) Parser: Pure Decl.).
  400. File: bison.info,  Node: Calling Convention,  Next: Token Values,  Up: Lexical
  401. Calling Convention for `yylex'
  402. ------------------------------
  403.    The value that `yylex' returns must be the numeric code for the type
  404. of token it has just found, or 0 for end-of-input.
  405.    When a token is referred to in the grammar rules by a name, that name
  406. in the parser file becomes a C macro whose definition is the proper
  407. numeric code for that token type.  So `yylex' can use the name to
  408. indicate that type.  *Note Symbols::.
  409.    When a token is referred to in the grammar rules by a character
  410. literal, the numeric code for that character is also the code for the
  411. token type.  So `yylex' can simply return that character code.  The
  412. null character must not be used this way, because its code is zero and
  413. that is what signifies end-of-input.
  414.    Here is an example showing these things:
  415.      yylex ()
  416.      {
  417.        ...
  418.        if (c == EOF)     /* Detect end of file. */
  419.          return 0;
  420.        ...
  421.        if (c == '+' || c == '-')
  422.          return c;      /* Assume token type for `+' is '+'. */
  423.        ...
  424.        return INT;      /* Return the type of the token. */
  425.        ...
  426.      }
  427. This interface has been designed so that the output from the `lex'
  428. utility can be used without change as the definition of `yylex'.
  429. File: bison.info,  Node: Token Values,  Next: Token Positions,  Prev: Calling Convention,  Up: Lexical
  430. Semantic Values of Tokens
  431. -------------------------
  432.    In an ordinary (nonreentrant) parser, the semantic value of the
  433. token must be stored into the global variable `yylval'.  When you are
  434. using just one data type for semantic values, `yylval' has that type.
  435. Thus, if the type is `int' (the default), you might write this in
  436. `yylex':
  437.        ...
  438.        yylval = value;  /* Put value onto Bison stack. */
  439.        return INT;      /* Return the type of the token. */
  440.        ...
  441.    When you are using multiple data types, `yylval''s type is a union
  442. made from the `%union' declaration (*note The Collection of Value
  443. Types: Union Decl.).  So when you store a token's value, you must use
  444. the proper member of the union.  If the `%union' declaration looks like
  445. this:
  446.      %union {
  447.        int intval;
  448.        double val;
  449.        symrec *tptr;
  450.      }
  451. then the code in `yylex' might look like this:
  452.        ...
  453.        yylval.intval = value; /* Put value onto Bison stack. */
  454.        return INT;          /* Return the type of the token. */
  455.        ...
  456. File: bison.info,  Node: Token Positions,  Next: Pure Calling,  Prev: Token Values,  Up: Lexical
  457. Textual Positions of Tokens
  458. ---------------------------
  459.    If you are using the `@N'-feature (*note Special Features for Use in
  460. Actions: Action Features.) in actions to keep track of the textual
  461. locations of tokens and groupings, then you must provide this
  462. information in `yylex'.  The function `yyparse' expects to find the
  463. textual location of a token just parsed in the global variable
  464. `yylloc'.  So `yylex' must store the proper data in that variable.  The
  465. value of `yylloc' is a structure and you need only initialize the
  466. members that are going to be used by the actions.  The four members are
  467. called `first_line', `first_column', `last_line' and `last_column'.
  468. Note that the use of this feature makes the parser noticeably slower.
  469.    The data type of `yylloc' has the name `YYLTYPE'.
  470. File: bison.info,  Node: Pure Calling,  Prev: Token Positions,  Up: Lexical
  471. Calling for Pure Parsers
  472. ------------------------
  473.    When you use the Bison declaration `%pure_parser' to request a pure,
  474. reentrant parser, the global communication variables `yylval' and
  475. `yylloc' cannot be used.  (*Note A Pure (Reentrant) Parser: Pure Decl.)
  476. In such parsers the two global variables are replaced by pointers
  477. passed as arguments to `yylex'.  You must declare them as shown here,
  478. and pass the information back by storing it through those pointers.
  479.      yylex (lvalp, llocp)
  480.           YYSTYPE *lvalp;
  481.           YYLTYPE *llocp;
  482.      {
  483.        ...
  484.        *lvalp = value;  /* Put value onto Bison stack.  */
  485.        return INT;      /* Return the type of the token.  */
  486.        ...
  487.      }
  488.    If the grammar file does not use the `@' constructs to refer to
  489. textual positions, then the type `YYLTYPE' will not be defined.  In
  490. this case, omit the second argument; `yylex' will be called with only
  491. one argument.
  492. File: bison.info,  Node: Error Reporting,  Next: Action Features,  Prev: Lexical,  Up: Interface
  493. The Error Reporting Function `yyerror'
  494. ======================================
  495.    The Bison parser detects a "parse error" or "syntax error" whenever
  496. it reads a token which cannot satisfy any syntax rule.  A action in the
  497. grammar can also explicitly proclaim an error, using the macro
  498. `YYERROR' (*note Special Features for Use in Actions: Action Features.).
  499.    The Bison parser expects to report the error by calling an error
  500. reporting function named `yyerror', which you must supply.  It is
  501. called by `yyparse' whenever a syntax error is found, and it receives
  502. one argument.  For a parse error, the string is normally
  503. `"parse error"'.
  504.    If you define the macro `YYERROR_VERBOSE' in the Bison declarations
  505. section (*note The Bison Declarations Section: Bison Declarations.),
  506. then Bison provides a more verbose and specific error message string
  507. instead of just plain `"parse error"'.  It doesn't matter what
  508. definition you use for `YYERROR_VERBOSE', just whether you define it.
  509.    The parser can detect one other kind of error: stack overflow.  This
  510. happens when the input contains constructions that are very deeply
  511. nested.  It isn't likely you will encounter this, since the Bison
  512. parser extends its stack automatically up to a very large limit.  But
  513. if overflow happens, `yyparse' calls `yyerror' in the usual fashion,
  514. except that the argument string is `"parser stack overflow"'.
  515.    The following definition suffices in simple programs:
  516.      yyerror (s)
  517.           char *s;
  518.      {
  519.        fprintf (stderr, "%s\n", s);
  520.      }
  521.    After `yyerror' returns to `yyparse', the latter will attempt error
  522. recovery if you have written suitable error recovery grammar rules
  523. (*note Error Recovery::.).  If recovery is impossible, `yyparse' will
  524. immediately return 1.
  525.    The variable `yynerrs' contains the number of syntax errors
  526. encountered so far.  Normally this variable is global; but if you
  527. request a pure parser (*note A Pure (Reentrant) Parser: Pure Decl.)
  528. then it is a local variable which only the actions can access.
  529. File: bison.info,  Node: Action Features,  Prev: Error Reporting,  Up: Interface
  530. Special Features for Use in Actions
  531. ===================================
  532.    Here is a table of Bison constructs, variables and macros that are
  533. useful in actions.
  534.      Acts like a variable that contains the semantic value for the
  535.      grouping made by the current rule.  *Note Actions::.
  536.      Acts like a variable that contains the semantic value for the Nth
  537.      component of the current rule.  *Note Actions::.
  538. `$<TYPEALT>$'
  539.      Like `$$' but specifies alternative TYPEALT in the union specified
  540.      by the `%union' declaration.  *Note Data Types of Values in
  541.      Actions: Action Types.
  542. `$<TYPEALT>N'
  543.      Like `$N' but specifies alternative TYPEALT in the union specified
  544.      by the `%union' declaration.  *Note Data Types of Values in
  545.      Actions: Action Types.
  546. `YYABORT;'
  547.      Return immediately from `yyparse', indicating failure.  *Note The
  548.      Parser Function `yyparse': Parser Function.
  549. `YYACCEPT;'
  550.      Return immediately from `yyparse', indicating success.  *Note The
  551.      Parser Function `yyparse': Parser Function.
  552. `YYBACKUP (TOKEN, VALUE);'
  553.      Unshift a token.  This macro is allowed only for rules that reduce
  554.      a single value, and only when there is no look-ahead token.  It
  555.      installs a look-ahead token with token type TOKEN and semantic
  556.      value VALUE; then it discards the value that was going to be
  557.      reduced by this rule.
  558.      If the macro is used when it is not valid, such as when there is a
  559.      look-ahead token already, then it reports a syntax error with a
  560.      message `cannot back up' and performs ordinary error recovery.
  561.      In either case, the rest of the action is not executed.
  562. `YYEMPTY'
  563.      Value stored in `yychar' when there is no look-ahead token.
  564. `YYERROR;'
  565.      Cause an immediate syntax error.  This statement initiates error
  566.      recovery just as if the parser itself had detected an error;
  567.      however, it does not call `yyerror', and does not print any
  568.      message.  If you want to print an error message, call `yyerror'
  569.      explicitly before the `YYERROR;' statement.  *Note Error
  570.      Recovery::.
  571. `YYRECOVERING'
  572.      This macro stands for an expression that has the value 1 when the
  573.      parser is recovering from a syntax error, and 0 the rest of the
  574.      time.  *Note Error Recovery::.
  575. `yychar'
  576.      Variable containing the current look-ahead token.  (In a pure
  577.      parser, this is actually a local variable within `yyparse'.)  When
  578.      there is no look-ahead token, the value `YYEMPTY' is stored in the
  579.      variable.  *Note Look-Ahead Tokens: Look-Ahead.
  580. `yyclearin;'
  581.      Discard the current look-ahead token.  This is useful primarily in
  582.      error rules.  *Note Error Recovery::.
  583. `yyerrok;'
  584.      Resume generating error messages immediately for subsequent syntax
  585.      errors.  This is useful primarily in error rules.  *Note Error
  586.      Recovery::.
  587.      Acts like a structure variable containing information on the line
  588.      numbers and column numbers of the Nth component of the current
  589.      rule.  The structure has four members, like this:
  590.           struct {
  591.             int first_line, last_line;
  592.             int first_column, last_column;
  593.           };
  594.      Thus, to get the starting line number of the third component, use
  595.      `@3.first_line'.
  596.      In order for the members of this structure to contain valid
  597.      information, you must make `yylex' supply this information about
  598.      each token.  If you need only certain members, then `yylex' need
  599.      only fill in those members.
  600.      The use of this feature makes the parser noticeably slower.
  601. File: bison.info,  Node: Algorithm,  Next: Error Recovery,  Prev: Interface,  Up: Top
  602. The Bison Parser Algorithm
  603. **************************
  604.    As Bison reads tokens, it pushes them onto a stack along with their
  605. semantic values.  The stack is called the "parser stack".  Pushing a
  606. token is traditionally called "shifting".
  607.    For example, suppose the infix calculator has read `1 + 5 *', with a
  608. `3' to come.  The stack will have four elements, one for each token
  609. that was shifted.
  610.    But the stack does not always have an element for each token read.
  611. When the last N tokens and groupings shifted match the components of a
  612. grammar rule, they can be combined according to that rule.  This is
  613. called "reduction".  Those tokens and groupings are replaced on the
  614. stack by a single grouping whose symbol is the result (left hand side)
  615. of that rule.  Running the rule's action is part of the process of
  616. reduction, because this is what computes the semantic value of the
  617. resulting grouping.
  618.    For example, if the infix calculator's parser stack contains this:
  619.      1 + 5 * 3
  620. and the next input token is a newline character, then the last three
  621. elements can be reduced to 15 via the rule:
  622.      expr: expr '*' expr;
  623. Then the stack contains just these three elements:
  624.      1 + 15
  625. At this point, another reduction can be made, resulting in the single
  626. value 16.  Then the newline token can be shifted.
  627.    The parser tries, by shifts and reductions, to reduce the entire
  628. input down to a single grouping whose symbol is the grammar's
  629. start-symbol (*note Languages and Context-Free Grammars: Language and
  630. Grammar.).
  631.    This kind of parser is known in the literature as a bottom-up parser.
  632. * Menu:
  633. * Look-Ahead::        Parser looks one token ahead when deciding what to do.
  634. * Shift/Reduce::      Conflicts: when either shifting or reduction is valid.
  635. * Precedence::        Operator precedence works by resolving conflicts.
  636. * Contextual Precedence::  When an operator's precedence depends on context.
  637. * Parser States::     The parser is a finite-state-machine with stack.
  638. * Reduce/Reduce::     When two rules are applicable in the same situation.
  639. * Mystery Conflicts::  Reduce/reduce conflicts that look unjustified.
  640. * Stack Overflow::    What happens when stack gets full.  How to avoid it.
  641. File: bison.info,  Node: Look-Ahead,  Next: Shift/Reduce,  Up: Algorithm
  642. Look-Ahead Tokens
  643. =================
  644.    The Bison parser does *not* always reduce immediately as soon as the
  645. last N tokens and groupings match a rule.  This is because such a
  646. simple strategy is inadequate to handle most languages.  Instead, when a
  647. reduction is possible, the parser sometimes "looks ahead" at the next
  648. token in order to decide what to do.
  649.    When a token is read, it is not immediately shifted; first it
  650. becomes the "look-ahead token", which is not on the stack.  Now the
  651. parser can perform one or more reductions of tokens and groupings on
  652. the stack, while the look-ahead token remains off to the side.  When no
  653. more reductions should take place, the look-ahead token is shifted onto
  654. the stack.  This does not mean that all possible reductions have been
  655. done; depending on the token type of the look-ahead token, some rules
  656. may choose to delay their application.
  657.    Here is a simple case where look-ahead is needed.  These three rules
  658. define expressions which contain binary addition operators and postfix
  659. unary factorial operators (`!'), and allow parentheses for grouping.
  660.      expr:     term '+' expr
  661.              | term
  662.              ;
  663.      
  664.      term:     '(' expr ')'
  665.              | term '!'
  666.              | NUMBER
  667.              ;
  668.    Suppose that the tokens `1 + 2' have been read and shifted; what
  669. should be done?  If the following token is `)', then the first three
  670. tokens must be reduced to form an `expr'.  This is the only valid
  671. course, because shifting the `)' would produce a sequence of symbols
  672. `term ')'', and no rule allows this.
  673.    If the following token is `!', then it must be shifted immediately so
  674. that `2 !' can be reduced to make a `term'.  If instead the parser were
  675. to reduce before shifting, `1 + 2' would become an `expr'.  It would
  676. then be impossible to shift the `!' because doing so would produce on
  677. the stack the sequence of symbols `expr '!''.  No rule allows that
  678. sequence.
  679.    The current look-ahead token is stored in the variable `yychar'.
  680. *Note Special Features for Use in Actions: Action Features.
  681. File: bison.info,  Node: Shift/Reduce,  Next: Precedence,  Prev: Look-Ahead,  Up: Algorithm
  682. Shift/Reduce Conflicts
  683. ======================
  684.    Suppose we are parsing a language which has if-then and if-then-else
  685. statements, with a pair of rules like this:
  686.      if_stmt:
  687.                IF expr THEN stmt
  688.              | IF expr THEN stmt ELSE stmt
  689.              ;
  690. Here we assume that `IF', `THEN' and `ELSE' are terminal symbols for
  691. specific keyword tokens.
  692.    When the `ELSE' token is read and becomes the look-ahead token, the
  693. contents of the stack (assuming the input is valid) are just right for
  694. reduction by the first rule.  But it is also legitimate to shift the
  695. `ELSE', because that would lead to eventual reduction by the second
  696. rule.
  697.    This situation, where either a shift or a reduction would be valid,
  698. is called a "shift/reduce conflict".  Bison is designed to resolve
  699. these conflicts by choosing to shift, unless otherwise directed by
  700. operator precedence declarations.  To see the reason for this, let's
  701. contrast it with the other alternative.
  702.    Since the parser prefers to shift the `ELSE', the result is to attach
  703. the else-clause to the innermost if-statement, making these two inputs
  704. equivalent:
  705.      if x then if y then win (); else lose;
  706.      
  707.      if x then do; if y then win (); else lose; end;
  708.    But if the parser chose to reduce when possible rather than shift,
  709. the result would be to attach the else-clause to the outermost
  710. if-statement, making these two inputs equivalent:
  711.      if x then if y then win (); else lose;
  712.      
  713.      if x then do; if y then win (); end; else lose;
  714.    The conflict exists because the grammar as written is ambiguous:
  715. either parsing of the simple nested if-statement is legitimate.  The
  716. established convention is that these ambiguities are resolved by
  717. attaching the else-clause to the innermost if-statement; this is what
  718. Bison accomplishes by choosing to shift rather than reduce.  (It would
  719. ideally be cleaner to write an unambiguous grammar, but that is very
  720. hard to do in this case.) This particular ambiguity was first
  721. encountered in the specifications of Algol 60 and is called the
  722. "dangling `else'" ambiguity.
  723.    To avoid warnings from Bison about predictable, legitimate
  724. shift/reduce conflicts, use the `%expect N' declaration.  There will be
  725. no warning as long as the number of shift/reduce conflicts is exactly N.
  726. *Note Suppressing Conflict Warnings: Expect Decl.
  727.    The definition of `if_stmt' above is solely to blame for the
  728. conflict, but the conflict does not actually appear without additional
  729. rules.  Here is a complete Bison input file that actually manifests the
  730. conflict:
  731.      %token IF THEN ELSE variable
  732.      %%
  733.      stmt:     expr
  734.              | if_stmt
  735.              ;
  736.      
  737.      if_stmt:
  738.                IF expr THEN stmt
  739.              | IF expr THEN stmt ELSE stmt
  740.              ;
  741.      
  742.      expr:     variable
  743.              ;
  744. File: bison.info,  Node: Precedence,  Next: Contextual Precedence,  Prev: Shift/Reduce,  Up: Algorithm
  745. Operator Precedence
  746. ===================
  747.    Another situation where shift/reduce conflicts appear is in
  748. arithmetic expressions.  Here shifting is not always the preferred
  749. resolution; the Bison declarations for operator precedence allow you to
  750. specify when to shift and when to reduce.
  751. * Menu:
  752. * Why Precedence::    An example showing why precedence is needed.
  753. * Using Precedence::  How to specify precedence in Bison grammars.
  754. * Precedence Examples::  How these features are used in the previous example.
  755. * How Precedence::    How they work.
  756. File: bison.info,  Node: Why Precedence,  Next: Using Precedence,  Up: Precedence
  757. When Precedence is Needed
  758. -------------------------
  759.    Consider the following ambiguous grammar fragment (ambiguous because
  760. the input `1 - 2 * 3' can be parsed in two different ways):
  761.      expr:     expr '-' expr
  762.              | expr '*' expr
  763.              | expr '<' expr
  764.              | '(' expr ')'
  765.              ...
  766.              ;
  767. Suppose the parser has seen the tokens `1', `-' and `2'; should it
  768. reduce them via the rule for the addition operator?  It depends on the
  769. next token.  Of course, if the next token is `)', we must reduce;
  770. shifting is invalid because no single rule can reduce the token
  771. sequence `- 2 )' or anything starting with that.  But if the next token
  772. is `*' or `<', we have a choice: either shifting or reduction would
  773. allow the parse to complete, but with different results.
  774.    To decide which one Bison should do, we must consider the results.
  775. If the next operator token OP is shifted, then it must be reduced first
  776. in order to permit another opportunity to reduce the sum.  The result
  777. is (in effect) `1 - (2 OP 3)'.  On the other hand, if the subtraction
  778. is reduced before shifting OP, the result is `(1 - 2) OP 3'.  Clearly,
  779. then, the choice of shift or reduce should depend on the relative
  780. precedence of the operators `-' and OP: `*' should be shifted first,
  781. but not `<'.
  782.    What about input such as `1 - 2 - 5'; should this be `(1 - 2) - 5'
  783. or should it be `1 - (2 - 5)'?  For most operators we prefer the
  784. former, which is called "left association".  The latter alternative,
  785. "right association", is desirable for assignment operators.  The choice
  786. of left or right association is a matter of whether the parser chooses
  787. to shift or reduce when the stack contains `1 - 2' and the look-ahead
  788. token is `-': shifting makes right-associativity.
  789. File: bison.info,  Node: Using Precedence,  Next: Precedence Examples,  Prev: Why Precedence,  Up: Precedence
  790. Specifying Operator Precedence
  791. ------------------------------
  792.    Bison allows you to specify these choices with the operator
  793. precedence declarations `%left' and `%right'.  Each such declaration
  794. contains a list of tokens, which are operators whose precedence and
  795. associativity is being declared.  The `%left' declaration makes all
  796. those operators left-associative and the `%right' declaration makes
  797. them right-associative.  A third alternative is `%nonassoc', which
  798. declares that it is a syntax error to find the same operator twice "in a
  799. row".
  800.    The relative precedence of different operators is controlled by the
  801. order in which they are declared.  The first `%left' or `%right'
  802. declaration in the file declares the operators whose precedence is
  803. lowest, the next such declaration declares the operators whose
  804. precedence is a little higher, and so on.
  805. File: bison.info,  Node: Precedence Examples,  Next: How Precedence,  Prev: Using Precedence,  Up: Precedence
  806. Precedence Examples
  807. -------------------
  808.    In our example, we would want the following declarations:
  809.      %left '<'
  810.      %left '-'
  811.      %left '*'
  812.    In a more complete example, which supports other operators as well,
  813. we would declare them in groups of equal precedence.  For example,
  814. `'+'' is declared with `'-'':
  815.      %left '<' '>' '=' NE LE GE
  816.      %left '+' '-'
  817.      %left '*' '/'
  818. (Here `NE' and so on stand for the operators for "not equal" and so on.
  819. We assume that these tokens are more than one character long and
  820. therefore are represented by names, not character literals.)
  821. File: bison.info,  Node: How Precedence,  Prev: Precedence Examples,  Up: Precedence
  822. How Precedence Works
  823. --------------------
  824.    The first effect of the precedence declarations is to assign
  825. precedence levels to the terminal symbols declared.  The second effect
  826. is to assign precedence levels to certain rules: each rule gets its
  827. precedence from the last terminal symbol mentioned in the components.
  828. (You can also specify explicitly the precedence of a rule.  *Note
  829. Context-Dependent Precedence: Contextual Precedence.)
  830.    Finally, the resolution of conflicts works by comparing the
  831. precedence of the rule being considered with that of the look-ahead
  832. token.  If the token's precedence is higher, the choice is to shift.
  833. If the rule's precedence is higher, the choice is to reduce.  If they
  834. have equal precedence, the choice is made based on the associativity of
  835. that precedence level.  The verbose output file made by `-v' (*note
  836. Invoking Bison: Invocation.) says how each conflict was resolved.
  837.    Not all rules and not all tokens have precedence.  If either the
  838. rule or the look-ahead token has no precedence, then the default is to
  839. shift.
  840. File: bison.info,  Node: Contextual Precedence,  Next: Parser States,  Prev: Precedence,  Up: Algorithm
  841. Context-Dependent Precedence
  842. ============================
  843.    Often the precedence of an operator depends on the context.  This
  844. sounds outlandish at first, but it is really very common.  For example,
  845. a minus sign typically has a very high precedence as a unary operator,
  846. and a somewhat lower precedence (lower than multiplication) as a binary
  847. operator.
  848.    The Bison precedence declarations, `%left', `%right' and
  849. `%nonassoc', can only be used once for a given token; so a token has
  850. only one precedence declared in this way.  For context-dependent
  851. precedence, you need to use an additional mechanism: the `%prec'
  852. modifier for rules.
  853.    The `%prec' modifier declares the precedence of a particular rule by
  854. specifying a terminal symbol whose precedence should be used for that
  855. rule.  It's not necessary for that symbol to appear otherwise in the
  856. rule.  The modifier's syntax is:
  857.      %prec TERMINAL-SYMBOL
  858. and it is written after the components of the rule.  Its effect is to
  859. assign the rule the precedence of TERMINAL-SYMBOL, overriding the
  860. precedence that would be deduced for it in the ordinary way.  The
  861. altered rule precedence then affects how conflicts involving that rule
  862. are resolved (*note Operator Precedence: Precedence.).
  863.    Here is how `%prec' solves the problem of unary minus.  First,
  864. declare a precedence for a fictitious terminal symbol named `UMINUS'.
  865. There are no tokens of this type, but the symbol serves to stand for its
  866. precedence:
  867.      ...
  868.      %left '+' '-'
  869.      %left '*'
  870.      %left UMINUS
  871.    Now the precedence of `UMINUS' can be used in specific rules:
  872.      exp:    ...
  873.              | exp '-' exp
  874.              ...
  875.              | '-' exp %prec UMINUS
  876. File: bison.info,  Node: Parser States,  Next: Reduce/Reduce,  Prev: Contextual Precedence,  Up: Algorithm
  877. Parser States
  878. =============
  879.    The function `yyparse' is implemented using a finite-state machine.
  880. The values pushed on the parser stack are not simply token type codes;
  881. they represent the entire sequence of terminal and nonterminal symbols
  882. at or near the top of the stack.  The current state collects all the
  883. information about previous input which is relevant to deciding what to
  884. do next.
  885.    Each time a look-ahead token is read, the current parser state
  886. together with the type of look-ahead token are looked up in a table.
  887. This table entry can say, "Shift the look-ahead token."  In this case,
  888. it also specifies the new parser state, which is pushed onto the top of
  889. the parser stack.  Or it can say, "Reduce using rule number N." This
  890. means that a certain number of tokens or groupings are taken off the
  891. top of the stack, and replaced by one grouping.  In other words, that
  892. number of states are popped from the stack, and one new state is pushed.
  893.    There is one other alternative: the table can say that the
  894. look-ahead token is erroneous in the current state.  This causes error
  895. processing to begin (*note Error Recovery::.).
  896. File: bison.info,  Node: Reduce/Reduce,  Next: Mystery Conflicts,  Prev: Parser States,  Up: Algorithm
  897. Reduce/Reduce Conflicts
  898. =======================
  899.    A reduce/reduce conflict occurs if there are two or more rules that
  900. apply to the same sequence of input.  This usually indicates a serious
  901. error in the grammar.
  902.    For example, here is an erroneous attempt to define a sequence of
  903. zero or more `word' groupings.
  904.      sequence: /* empty */
  905.                      { printf ("empty sequence\n"); }
  906.              | maybeword
  907.              | sequence word
  908.                      { printf ("added word %s\n", $2); }
  909.              ;
  910.      
  911.      maybeword: /* empty */
  912.                      { printf ("empty maybeword\n"); }
  913.              | word
  914.                      { printf ("single word %s\n", $1); }
  915.              ;
  916. The error is an ambiguity: there is more than one way to parse a single
  917. `word' into a `sequence'.  It could be reduced to a `maybeword' and
  918. then into a `sequence' via the second rule.  Alternatively,
  919. nothing-at-all could be reduced into a `sequence' via the first rule,
  920. and this could be combined with the `word' using the third rule for
  921. `sequence'.
  922.    There is also more than one way to reduce nothing-at-all into a
  923. `sequence'.  This can be done directly via the first rule, or
  924. indirectly via `maybeword' and then the second rule.
  925.    You might think that this is a distinction without a difference,
  926. because it does not change whether any particular input is valid or
  927. not.  But it does affect which actions are run.  One parsing order runs
  928. the second rule's action; the other runs the first rule's action and
  929. the third rule's action.  In this example, the output of the program
  930. changes.
  931.    Bison resolves a reduce/reduce conflict by choosing to use the rule
  932. that appears first in the grammar, but it is very risky to rely on
  933. this.  Every reduce/reduce conflict must be studied and usually
  934. eliminated.  Here is the proper way to define `sequence':
  935.      sequence: /* empty */
  936.                      { printf ("empty sequence\n"); }
  937.              | sequence word
  938.                      { printf ("added word %s\n", $2); }
  939.              ;
  940.    Here is another common error that yields a reduce/reduce conflict:
  941.      sequence: /* empty */
  942.              | sequence words
  943.              | sequence redirects
  944.              ;
  945.      
  946.      words:    /* empty */
  947.              | words word
  948.              ;
  949.      
  950.      redirects:/* empty */
  951.              | redirects redirect
  952.              ;
  953. The intention here is to define a sequence which can contain either
  954. `word' or `redirect' groupings.  The individual definitions of
  955. `sequence', `words' and `redirects' are error-free, but the three
  956. together make a subtle ambiguity: even an empty input can be parsed in
  957. infinitely many ways!
  958.    Consider: nothing-at-all could be a `words'.  Or it could be two
  959. `words' in a row, or three, or any number.  It could equally well be a
  960. `redirects', or two, or any number.  Or it could be a `words' followed
  961. by three `redirects' and another `words'.  And so on.
  962.    Here are two ways to correct these rules.  First, to make it a
  963. single level of sequence:
  964.      sequence: /* empty */
  965.              | sequence word
  966.              | sequence redirect
  967.              ;
  968.    Second, to prevent either a `words' or a `redirects' from being
  969. empty:
  970.      sequence: /* empty */
  971.              | sequence words
  972.              | sequence redirects
  973.              ;
  974.      
  975.      words:    word
  976.              | words word
  977.              ;
  978.      
  979.      redirects:redirect
  980.              | redirects redirect
  981.              ;
  982.