1 This is bison.info, produced by makeinfo version 4.13 from
2 /Users/akim/src/gnu/bison-2.5/doc/bison.texi.
4 This manual (27 July 2012) is for GNU Bison (version 2.6.1-dirty), the
7 Copyright (C) 1988-1993, 1995, 1998-2012 Free Software Foundation,
10 Permission is granted to copy, distribute and/or modify this
11 document under the terms of the GNU Free Documentation License,
12 Version 1.3 or any later version published by the Free Software
13 Foundation; with no Invariant Sections, with the Front-Cover texts
14 being "A GNU Manual," and with the Back-Cover Texts as in (a)
15 below. A copy of the license is included in the section entitled
16 "GNU Free Documentation License."
18 (a) The FSF's Back-Cover Text is: "You have the freedom to copy and
19 modify this GNU manual. Buying copies from the FSF supports it in
20 developing GNU and promoting software freedom."
22 INFO-DIR-SECTION Software development
24 * bison: (bison). GNU parser generator (Yacc replacement).
28 File: bison.info, Node: Memory Management, Prev: Generalized LR Parsing, Up: Algorithm
30 5.10 Memory Management, and How to Avoid Memory Exhaustion
31 ==========================================================
33 The Bison parser stack can run out of memory if too many tokens are
34 shifted and not reduced. When this happens, the parser function
35 `yyparse' calls `yyerror' and then returns 2.
37 Because Bison parsers have growing stacks, hitting the upper limit
38 usually results from using a right recursion instead of a left
39 recursion, see *note Recursive Rules: Recursion.
41 By defining the macro `YYMAXDEPTH', you can control how deep the
42 parser stack can become before memory is exhausted. Define the macro
43 with a value that is an integer. This value is the maximum number of
44 tokens that can be shifted (and not reduced) before overflow.
46 The stack space allowed is not necessarily allocated. If you
47 specify a large value for `YYMAXDEPTH', the parser normally allocates a
48 small stack at first, and then makes it bigger by stages as needed.
49 This increasing allocation happens automatically and silently.
50 Therefore, you do not need to make `YYMAXDEPTH' painfully small merely
51 to save space for ordinary inputs that do not need much stack.
53 However, do not allow `YYMAXDEPTH' to be a value so large that
54 arithmetic overflow could occur when calculating the size of the stack
55 space. Also, do not allow `YYMAXDEPTH' to be less than `YYINITDEPTH'.
57 The default value of `YYMAXDEPTH', if you do not define it, is 10000.
59 You can control how much stack is allocated initially by defining the
60 macro `YYINITDEPTH' to a positive integer. For the deterministic
61 parser in C, this value must be a compile-time constant unless you are
62 assuming C99 or some other target language or compiler that allows
63 variable-length arrays. The default is 200.
65 Do not allow `YYINITDEPTH' to be greater than `YYMAXDEPTH'.
67 Because of semantic differences between C and C++, the deterministic
68 parsers in C produced by Bison cannot grow when compiled by C++
69 compilers. In this precise case (compiling a C parser as C++) you are
70 suggested to grow `YYINITDEPTH'. The Bison maintainers hope to fix
71 this deficiency in a future release.
74 File: bison.info, Node: Error Recovery, Next: Context Dependency, Prev: Algorithm, Up: Top
79 It is not usually acceptable to have a program terminate on a syntax
80 error. For example, a compiler should recover sufficiently to parse the
81 rest of the input file and check it for errors; a calculator should
82 accept another expression.
84 In a simple interactive command parser where each input is one line,
85 it may be sufficient to allow `yyparse' to return 1 on error and have
86 the caller ignore the rest of the input line when that happens (and
87 then call `yyparse' again). But this is inadequate for a compiler,
88 because it forgets all the syntactic context leading up to the error.
89 A syntax error deep within a function in the compiler input should not
90 cause the compiler to treat the following line like the beginning of a
93 You can define how to recover from a syntax error by writing rules to
94 recognize the special token `error'. This is a terminal symbol that is
95 always defined (you need not declare it) and reserved for error
96 handling. The Bison parser generates an `error' token whenever a
97 syntax error happens; if you have provided a rule to recognize this
98 token in the current context, the parse can continue.
108 The fourth rule in this example says that an error followed by a
109 newline makes a valid addition to any `stmts'.
111 What happens if a syntax error occurs in the middle of an `exp'? The
112 error recovery rule, interpreted strictly, applies to the precise
113 sequence of a `stmts', an `error' and a newline. If an error occurs in
114 the middle of an `exp', there will probably be some additional tokens
115 and subexpressions on the stack after the last `stmts', and there will
116 be tokens to read before the next newline. So the rule is not
117 applicable in the ordinary way.
119 But Bison can force the situation to fit the rule, by discarding
120 part of the semantic context and part of the input. First it discards
121 states and objects from the stack until it gets back to a state in
122 which the `error' token is acceptable. (This means that the
123 subexpressions already parsed are discarded, back to the last complete
124 `stmts'.) At this point the `error' token can be shifted. Then, if
125 the old lookahead token is not acceptable to be shifted next, the
126 parser reads tokens and discards them until it finds a token which is
127 acceptable. In this example, Bison reads and discards input until the
128 next newline so that the fourth rule can apply. Note that discarded
129 symbols are possible sources of memory leaks, see *note Freeing
130 Discarded Symbols: Destructor Decl, for a means to reclaim this memory.
132 The choice of error rules in the grammar is a choice of strategies
133 for error recovery. A simple and useful strategy is simply to skip the
134 rest of the current input line or current statement if an error is
137 stmt: error ';' /* On error, skip until ';' is read. */
139 It is also useful to recover to the matching close-delimiter of an
140 opening-delimiter that has already been parsed. Otherwise the
141 close-delimiter will probably appear to be unmatched, and generate
142 another, spurious error message:
150 Error recovery strategies are necessarily guesses. When they guess
151 wrong, one syntax error often leads to another. In the above example,
152 the error recovery rule guesses that an error is due to bad input
153 within one `stmt'. Suppose that instead a spurious semicolon is
154 inserted in the middle of a valid `stmt'. After the error recovery
155 rule recovers from the first error, another syntax error will be found
156 straightaway, since the text following the spurious semicolon is also
159 To prevent an outpouring of error messages, the parser will output
160 no error message for another syntax error that happens shortly after
161 the first; only after three consecutive input tokens have been
162 successfully shifted will error messages resume.
164 Note that rules which accept the `error' token may have actions, just
165 as any other rules can.
167 You can make error messages resume immediately by using the macro
168 `yyerrok' in an action. If you do this in the error rule's action, no
169 error messages will be suppressed. This macro requires no arguments;
170 `yyerrok;' is a valid C statement.
172 The previous lookahead token is reanalyzed immediately after an
173 error. If this is unacceptable, then the macro `yyclearin' may be used
174 to clear this token. Write the statement `yyclearin;' in the error
175 rule's action. *Note Special Features for Use in Actions: Action
178 For example, suppose that on a syntax error, an error handling
179 routine is called that advances the input stream to some point where
180 parsing should once again commence. The next symbol returned by the
181 lexical scanner is probably correct. The previous lookahead token
182 ought to be discarded with `yyclearin;'.
184 The expression `YYRECOVERING ()' yields 1 when the parser is
185 recovering from a syntax error, and 0 otherwise. Syntax error
186 diagnostics are suppressed while recovering from a syntax error.
189 File: bison.info, Node: Context Dependency, Next: Debugging, Prev: Error Recovery, Up: Top
191 7 Handling Context Dependencies
192 *******************************
194 The Bison paradigm is to parse tokens first, then group them into larger
195 syntactic units. In many languages, the meaning of a token is affected
196 by its context. Although this violates the Bison paradigm, certain
197 techniques (known as "kludges") may enable you to write Bison parsers
202 * Semantic Tokens:: Token parsing can depend on the semantic context.
203 * Lexical Tie-ins:: Token parsing can depend on the syntactic context.
204 * Tie-in Recovery:: Lexical tie-ins have implications for how
205 error recovery rules must be written.
207 (Actually, "kludge" means any technique that gets its job done but is
208 neither clean nor robust.)
211 File: bison.info, Node: Semantic Tokens, Next: Lexical Tie-ins, Up: Context Dependency
213 7.1 Semantic Info in Token Types
214 ================================
216 The C language has a context dependency: the way an identifier is used
217 depends on what its current meaning is. For example, consider this:
221 This looks like a function call statement, but if `foo' is a typedef
222 name, then this is actually a declaration of `x'. How can a Bison
223 parser for C decide how to parse this input?
225 The method used in GNU C is to have two different token types,
226 `IDENTIFIER' and `TYPENAME'. When `yylex' finds an identifier, it
227 looks up the current declaration of the identifier in order to decide
228 which token type to return: `TYPENAME' if the identifier is declared as
229 a typedef, `IDENTIFIER' otherwise.
231 The grammar rules can then express the context dependency by the
232 choice of token type to recognize. `IDENTIFIER' is accepted as an
233 expression, but `TYPENAME' is not. `TYPENAME' can start a declaration,
234 but `IDENTIFIER' cannot. In contexts where the meaning of the
235 identifier is _not_ significant, such as in declarations that can
236 shadow a typedef name, either `TYPENAME' or `IDENTIFIER' is
237 accepted--there is one rule for each of the two token types.
239 This technique is simple to use if the decision of which kinds of
240 identifiers to allow is made at a place close to where the identifier is
241 parsed. But in C this is not always so: C allows a declaration to
242 redeclare a typedef name provided an explicit type has been specified
245 typedef int foo, bar;
248 static bar (bar); /* redeclare `bar' as static variable */
249 extern foo foo (foo); /* redeclare `foo' as function */
253 Unfortunately, the name being declared is separated from the
254 declaration construct itself by a complicated syntactic structure--the
257 As a result, part of the Bison parser for C needs to be duplicated,
258 with all the nonterminal names changed: once for parsing a declaration
259 in which a typedef name can be redefined, and once for parsing a
260 declaration in which that can't be done. Here is a part of the
261 duplication, with actions omitted for brevity:
264 declarator maybeasm '=' init
265 | declarator maybeasm
269 notype_declarator maybeasm '=' init
270 | notype_declarator maybeasm
273 Here `initdcl' can redeclare a typedef name, but `notype_initdcl'
274 cannot. The distinction between `declarator' and `notype_declarator'
275 is the same sort of thing.
277 There is some similarity between this technique and a lexical tie-in
278 (described next), in that information which alters the lexical analysis
279 is changed during parsing by other parts of the program. The
280 difference is here the information is global, and is used for other
281 purposes in the program. A true lexical tie-in has a special-purpose
282 flag controlled by the syntactic context.
285 File: bison.info, Node: Lexical Tie-ins, Next: Tie-in Recovery, Prev: Semantic Tokens, Up: Context Dependency
290 One way to handle context-dependency is the "lexical tie-in": a flag
291 which is set by Bison actions, whose purpose is to alter the way tokens
294 For example, suppose we have a language vaguely like C, but with a
295 special construct `hex (HEX-EXPR)'. After the keyword `hex' comes an
296 expression in parentheses in which all integers are hexadecimal. In
297 particular, the token `a1b' must be treated as an integer rather than
298 as an identifier if it appears in that context. Here is how you can do
304 void yyerror (char const *);
311 | HEX '(' { hexflag = 1; }
312 expr ')' { hexflag = 0; $$ = $4; }
313 | expr '+' expr { $$ = make_sum ($1, $3); }
322 Here we assume that `yylex' looks at the value of `hexflag'; when it is
323 nonzero, all integers are parsed in hexadecimal, and tokens starting
324 with letters are parsed as integers if possible.
326 The declaration of `hexflag' shown in the prologue of the grammar
327 file is needed to make it accessible to the actions (*note The
328 Prologue: Prologue.). You must also write the code in `yylex' to obey
332 File: bison.info, Node: Tie-in Recovery, Prev: Lexical Tie-ins, Up: Context Dependency
334 7.3 Lexical Tie-ins and Error Recovery
335 ======================================
337 Lexical tie-ins make strict demands on any error recovery rules you
338 have. *Note Error Recovery::.
340 The reason for this is that the purpose of an error recovery rule is
341 to abort the parsing of one construct and resume in some larger
342 construct. For example, in C-like languages, a typical error recovery
343 rule is to skip tokens until the next semicolon, and then start a new
344 statement, like this:
348 | IF '(' expr ')' stmt { ... }
350 | error ';' { hexflag = 0; }
353 If there is a syntax error in the middle of a `hex (EXPR)'
354 construct, this error rule will apply, and then the action for the
355 completed `hex (EXPR)' will never run. So `hexflag' would remain set
356 for the entire rest of the input, or until the next `hex' keyword,
357 causing identifiers to be misinterpreted as integers.
359 To avoid this problem the error recovery rule itself clears
362 There may also be an error recovery rule that works within
363 expressions. For example, there could be a rule which applies within
364 parentheses and skips to the close-parenthesis:
368 | '(' expr ')' { $$ = $2; }
372 If this rule acts within the `hex' construct, it is not going to
373 abort that construct (since it applies to an inner level of parentheses
374 within the construct). Therefore, it should not clear the flag: the
375 rest of the `hex' construct should be parsed with the flag still in
378 What if there is an error recovery rule which might abort out of the
379 `hex' construct or might not, depending on circumstances? There is no
380 way you can write the action to determine whether a `hex' construct is
381 being aborted or not. So if you are using a lexical tie-in, you had
382 better make sure your error recovery rules are not of this kind. Each
383 rule must be such that you can be sure that it always will, or always
384 won't, have to clear the flag.
387 File: bison.info, Node: Debugging, Next: Invocation, Prev: Context Dependency, Up: Top
389 8 Debugging Your Parser
390 ***********************
392 Developing a parser can be a challenge, especially if you don't
393 understand the algorithm (*note The Bison Parser Algorithm:
394 Algorithm.). This chapter explains how to generate and read the
395 detailed description of the automaton, and how to enable and understand
396 the parser run-time traces.
400 * Understanding:: Understanding the structure of your parser.
401 * Tracing:: Tracing the execution of your parser.
404 File: bison.info, Node: Understanding, Next: Tracing, Up: Debugging
406 8.1 Understanding Your Parser
407 =============================
409 As documented elsewhere (*note The Bison Parser Algorithm: Algorithm.)
410 Bison parsers are "shift/reduce automata". In some cases (much more
411 frequent than one would hope), looking at this automaton is required to
412 tune or simply fix a parser. Bison provides two different
413 representation of it, either textually or graphically (as a DOT file).
415 The textual file is generated when the options `--report' or
416 `--verbose' are specified, see *note Invoking Bison: Invocation. Its
417 name is made by removing `.tab.c' or `.c' from the parser
418 implementation file name, and adding `.output' instead. Therefore, if
419 the grammar file is `foo.y', then the parser implementation file is
420 called `foo.tab.c' by default. As a consequence, the verbose output
421 file is called `foo.output'.
423 The following grammar file, `calc.y', will be used in the sequel:
441 calc.y: warning: 1 nonterminal useless in grammar
442 calc.y: warning: 1 rule useless in grammar
443 calc.y:11.1-7: warning: nonterminal useless in grammar: useless
444 calc.y:11.10-12: warning: rule useless in grammar: useless: STR
445 calc.y: conflicts: 7 shift/reduce
447 When given `--report=state', in addition to `calc.tab.c', it creates
448 a file `calc.output' with contents detailed below. The order of the
449 output and the exact presentation might vary, but the interpretation is
452 The first section reports useless tokens, nonterminals and rules.
453 Useless nonterminals and rules are removed in order to produce a
454 smaller parser, but useless tokens are preserved, since they might be
455 used by the scanner (note the difference between "useless" and "unused"
458 Nonterminals useless in grammar
461 Terminals unused in grammar
464 Rules useless in grammar
467 The next section lists states that still have conflicts.
469 State 8 conflicts: 1 shift/reduce
470 State 9 conflicts: 1 shift/reduce
471 State 10 conflicts: 1 shift/reduce
472 State 11 conflicts: 4 shift/reduce
474 Then Bison reproduces the exact grammar it used:
486 and reports the uses of the symbols:
488 Terminals, with rules where they appear
499 Nonterminals, with rules where they appear
504 on left: 1 2 3 4 5, on right: 0 1 2 3 4
506 Bison then proceeds onto the automaton itself, describing each state
507 with its set of "items", also known as "pointed rules". Each item is a
508 production rule together with a point (`.') marking the location of the
513 0 $accept: . exp $end
515 NUM shift, and go to state 1
519 This reads as follows: "state 0 corresponds to being at the very
520 beginning of the parsing, in the initial rule, right before the start
521 symbol (here, `exp'). When the parser returns to this state right
522 after having reduced a rule that produced an `exp', the control flow
523 jumps to state 2. If there is no such transition on a nonterminal
524 symbol, and the lookahead is a `NUM', then this token is shifted onto
525 the parse stack, and the control flow jumps to state 1. Any other
526 lookahead triggers a syntax error."
528 Even though the only active rule in state 0 seems to be rule 0, the
529 report lists `NUM' as a lookahead token because `NUM' can be at the
530 beginning of any rule deriving an `exp'. By default Bison reports the
531 so-called "core" or "kernel" of the item set, but if you want to see
532 more detail you can invoke `bison' with `--report=itemset' to list the
533 derived items as well:
537 0 $accept: . exp $end
544 NUM shift, and go to state 1
554 $default reduce using rule 5 (exp)
556 the rule 5, `exp: NUM;', is completed. Whatever the lookahead token
557 (`$default'), the parser will reduce it. If it was coming from state
558 0, then, after this reduction it will return to state 0, and will jump
559 to state 2 (`exp: go to state 2').
563 0 $accept: exp . $end
569 $end shift, and go to state 3
570 '+' shift, and go to state 4
571 '-' shift, and go to state 5
572 '*' shift, and go to state 6
573 '/' shift, and go to state 7
575 In state 2, the automaton can only shift a symbol. For instance,
576 because of the item `exp: exp . '+' exp', if the lookahead is `+' it is
577 shifted onto the parse stack, and the automaton jumps to state 4,
578 corresponding to the item `exp: exp '+' . exp'. Since there is no
579 default action, any lookahead not listed triggers a syntax error.
581 The state 3 is named the "final state", or the "accepting state":
585 0 $accept: exp $end .
589 the initial rule is completed (the start symbol and the end-of-input
590 were read), the parsing exits successfully.
592 The interpretation of states 4 to 7 is straightforward, and is left
599 NUM shift, and go to state 1
608 NUM shift, and go to state 1
617 NUM shift, and go to state 1
626 NUM shift, and go to state 1
630 As was announced in beginning of the report, `State 8 conflicts: 1
641 '*' shift, and go to state 6
642 '/' shift, and go to state 7
644 '/' [reduce using rule 1 (exp)]
645 $default reduce using rule 1 (exp)
647 Indeed, there are two actions associated to the lookahead `/':
648 either shifting (and going to state 7), or reducing rule 1. The
649 conflict means that either the grammar is ambiguous, or the parser lacks
650 information to make the right decision. Indeed the grammar is
651 ambiguous, as, since we did not specify the precedence of `/', the
652 sentence `NUM + NUM / NUM' can be parsed as `NUM + (NUM / NUM)', which
653 corresponds to shifting `/', or as `(NUM + NUM) / NUM', which
654 corresponds to reducing rule 1.
656 Because in deterministic parsing a single decision can be made, Bison
657 arbitrarily chose to disable the reduction, see *note Shift/Reduce
658 Conflicts: Shift/Reduce. Discarded actions are reported between square
661 Note that all the previous states had a single possible action:
662 either shifting the next token and going to the corresponding state, or
663 reducing a single rule. In the other cases, i.e., when shifting _and_
664 reducing is possible or when _several_ reductions are possible, the
665 lookahead is required to select the action. State 8 is one such state:
666 if the lookahead is `*' or `/' then the action is shifting, otherwise
667 the action is reducing rule 1. In other words, the first two items,
668 corresponding to rule 1, are not eligible when the lookahead token is
669 `*', since we specified that `*' has higher precedence than `+'. More
670 generally, some items are eligible only with some set of possible
671 lookahead tokens. When run with `--report=lookahead', Bison specifies
672 these lookahead tokens:
677 1 | exp '+' exp . [$end, '+', '-', '/']
682 '*' shift, and go to state 6
683 '/' shift, and go to state 7
685 '/' [reduce using rule 1 (exp)]
686 $default reduce using rule 1 (exp)
688 Note however that while `NUM + NUM / NUM' is ambiguous (which
689 results in the conflicts on `/'), `NUM + NUM * NUM' is not: the
690 conflict was solved thanks to associativity and precedence directives.
691 If invoked with `--report=solved', Bison includes information about the
692 solved conflicts in the report:
694 Conflict between rule 1 and token '+' resolved as reduce (%left '+').
695 Conflict between rule 1 and token '-' resolved as reduce (%left '-').
696 Conflict between rule 1 and token '*' resolved as shift ('+' < '*').
698 The remaining states are similar:
708 '*' shift, and go to state 6
709 '/' shift, and go to state 7
711 '/' [reduce using rule 2 (exp)]
712 $default reduce using rule 2 (exp)
722 '/' shift, and go to state 7
724 '/' [reduce using rule 3 (exp)]
725 $default reduce using rule 3 (exp)
735 '+' shift, and go to state 4
736 '-' shift, and go to state 5
737 '*' shift, and go to state 6
738 '/' shift, and go to state 7
740 '+' [reduce using rule 4 (exp)]
741 '-' [reduce using rule 4 (exp)]
742 '*' [reduce using rule 4 (exp)]
743 '/' [reduce using rule 4 (exp)]
744 $default reduce using rule 4 (exp)
746 Observe that state 11 contains conflicts not only due to the lack of
747 precedence of `/' with respect to `+', `-', and `*', but also because
748 the associativity of `/' is not specified.
751 File: bison.info, Node: Tracing, Prev: Understanding, Up: Debugging
753 8.2 Tracing Your Parser
754 =======================
756 When a Bison grammar compiles properly but parses "incorrectly", the
757 `yydebug' parser-trace feature helps figuring out why.
761 * Enabling Traces:: Activating run-time trace support
762 * Mfcalc Traces:: Extending `mfcalc' to support traces
763 * The YYPRINT Macro:: Obsolete interface for semantic value reports
766 File: bison.info, Node: Enabling Traces, Next: Mfcalc Traces, Up: Tracing
768 8.2.1 Enabling Traces
769 ---------------------
771 There are several means to enable compilation of trace facilities:
774 Define the macro `YYDEBUG' to a nonzero value when you compile the
775 parser. This is compliant with POSIX Yacc. You could use
776 `-DYYDEBUG=1' as a compiler option or you could put `#define
777 YYDEBUG 1' in the prologue of the grammar file (*note The
778 Prologue: Prologue.).
780 If the `%define' variable `api.prefix' is used (*note Multiple
781 Parsers in the Same Program: Multiple Parsers.), for instance
782 `%define api.prefix x', then if `CDEBUG' is defined, its value
783 controls the tracing feature (enabled iff nonzero); otherwise
784 tracing is enabled iff `YYDEBUG' is nonzero.
786 the option `-t' (POSIX Yacc compliant)
787 the option `--debug' (Bison extension)
788 Use the `-t' option when you run Bison (*note Invoking Bison:
789 Invocation.). With `%define api.prefix c', it defines `CDEBUG' to
790 1, otherwise it defines `YYDEBUG' to 1.
792 the directive `%debug'
793 Add the `%debug' directive (*note Bison Declaration Summary: Decl
794 Summary.). This is a Bison extension, especially useful for
795 languages that don't use a preprocessor. Unless POSIX and Yacc
796 portability matter to you, this is the preferred solution.
798 We suggest that you always enable the debug option so that debugging
801 The trace facility outputs messages with macro calls of the form
802 `YYFPRINTF (stderr, FORMAT, ARGS)' where FORMAT and ARGS are the usual
803 `printf' format and variadic arguments. If you define `YYDEBUG' to a
804 nonzero value but do not define `YYFPRINTF', `<stdio.h>' is
805 automatically included and `YYFPRINTF' is defined to `fprintf'.
807 Once you have compiled the program with trace facilities, the way to
808 request a trace is to store a nonzero value in the variable `yydebug'.
809 You can do this by making the C code do it (in `main', perhaps), or you
810 can alter the value with a C debugger.
812 Each step taken by the parser when `yydebug' is nonzero produces a
813 line or two of trace information, written on `stderr'. The trace
814 messages tell you these things:
816 * Each time the parser calls `yylex', what kind of token was read.
818 * Each time a token is shifted, the depth and complete contents of
819 the state stack (*note Parser States::).
821 * Each time a rule is reduced, which rule it is, and the complete
822 contents of the state stack afterward.
824 To make sense of this information, it helps to refer to the automaton
825 description file (*note Understanding Your Parser: Understanding.).
826 This file shows the meaning of each state in terms of positions in
827 various rules, and also what each state will do with each possible
828 input token. As you read the successive trace messages, you can see
829 that the parser is functioning according to its specification in the
830 listing file. Eventually you will arrive at the place where something
831 undesirable happens, and you will see which parts of the grammar are to
834 The parser implementation file is a C/C++/Java program and you can
835 use debuggers on it, but it's not easy to interpret what it is doing.
836 The parser function is a finite-state machine interpreter, and aside
837 from the actions it executes the same code over and over. Only the
838 values of variables show where in the grammar it is working.
841 File: bison.info, Node: Mfcalc Traces, Next: The YYPRINT Macro, Prev: Enabling Traces, Up: Tracing
843 8.2.2 Enabling Debug Traces for `mfcalc'
844 ----------------------------------------
846 The debugging information normally gives the token type of each token
847 read, but not its semantic value. The `%printer' directive allows
848 specify how semantic values are reported, see *note Printing Semantic
849 Values: Printer Decl. For backward compatibility, Yacc like C parsers
850 may also use the `YYPRINT' (*note The `YYPRINT' Macro: The YYPRINT
851 Macro.), but its use is discouraged.
853 As a demonstration of `%printer', consider the multi-function
854 calculator, `mfcalc' (*note Multi-function Calc::). To enable run-time
855 traces, and semantic value reports, insert the following directives in
858 /* Generate the parser description file. */
860 /* Enable run-time traces (yydebug). */
863 /* Formatting semantic values. */
864 %printer { fprintf (yyoutput, "%s", $$->name); } VAR;
865 %printer { fprintf (yyoutput, "%s()", $$->name); } FNCT;
866 %printer { fprintf (yyoutput, "%g", $$); } <val>;
868 The `%define' directive instructs Bison to generate run-time trace
869 support. Then, activation of these traces is controlled at run-time by
870 the `yydebug' variable, which is disabled by default. Because these
871 traces will refer to the "states" of the parser, it is helpful to ask
872 for the creation of a description of that parser; this is the purpose
873 of (admittedly ill-named) `%verbose' directive.
875 The set of `%printer' directives demonstrates how to format the
876 semantic value in the traces. Note that the specification can be done
877 either on the symbol type (e.g., `VAR' or `FNCT'), or on the type tag:
878 since `<val>' is the type for both `NUM' and `exp', this printer will
881 Here is a sample of the information provided by run-time traces.
882 The traces are sent onto standard error.
884 $ echo 'sin(1-1)' | ./mfcalc -p
887 Reducing stack by rule 1 (line 34):
888 -> $$ = nterm input ()
892 This first batch shows a specific feature of this grammar: the first
893 rule (which is in line 34 of `mfcalc.y' can be reduced without even
894 having to look for the first token. The resulting left-hand symbol
895 (`$$') is a valueless (`()') `input' non terminal (`nterm').
897 Then the parser calls the scanner.
898 Reading a token: Next token is token FNCT (sin())
899 Shifting token FNCT (sin())
902 That token (`token') is a function (`FNCT') whose value is `sin' as
903 formatted per our `%printer' specification: `sin()'. The parser stores
904 (`Shifting') that token, and others, until it can do something about it.
906 Reading a token: Next token is token '(' ()
907 Shifting token '(' ()
909 Reading a token: Next token is token NUM (1.000000)
910 Shifting token NUM (1.000000)
912 Reducing stack by rule 6 (line 44):
913 $1 = token NUM (1.000000)
914 -> $$ = nterm exp (1.000000)
918 The previous reduction demonstrates the `%printer' directive for
919 `<val>': both the token `NUM' and the resulting non-terminal `exp' have
922 Reading a token: Next token is token '-' ()
923 Shifting token '-' ()
925 Reading a token: Next token is token NUM (1.000000)
926 Shifting token NUM (1.000000)
928 Reducing stack by rule 6 (line 44):
929 $1 = token NUM (1.000000)
930 -> $$ = nterm exp (1.000000)
931 Stack now 0 1 6 14 24 17
933 Reading a token: Next token is token ')' ()
934 Reducing stack by rule 11 (line 49):
935 $1 = nterm exp (1.000000)
937 $3 = nterm exp (1.000000)
938 -> $$ = nterm exp (0.000000)
942 The rule for the subtraction was just reduced. The parser is about to
943 discover the end of the call to `sin'.
945 Next token is token ')' ()
946 Shifting token ')' ()
948 Reducing stack by rule 9 (line 47):
949 $1 = token FNCT (sin())
951 $3 = nterm exp (0.000000)
953 -> $$ = nterm exp (0.000000)
957 Finally, the end-of-line allow the parser to complete the computation,
958 and display its result.
960 Reading a token: Next token is token '\n' ()
961 Shifting token '\n' ()
963 Reducing stack by rule 4 (line 40):
964 $1 = nterm exp (0.000000)
967 -> $$ = nterm line ()
970 Reducing stack by rule 2 (line 35):
973 -> $$ = nterm input ()
977 The parser has returned into state 1, in which it is waiting for the
978 next expression to evaluate, or for the end-of-file token, which causes
979 the completion of the parsing.
981 Reading a token: Now at end of input.
982 Shifting token $end ()
985 Cleanup: popping token $end ()
986 Cleanup: popping nterm input ()
989 File: bison.info, Node: The YYPRINT Macro, Prev: Mfcalc Traces, Up: Tracing
991 8.2.3 The `YYPRINT' Macro
992 -------------------------
994 Before `%printer' support, semantic values could be displayed using the
995 `YYPRINT' macro, which works only for terminal symbols and only with
996 the `yacc.c' skeleton.
998 -- Macro: YYPRINT (STREAM, TOKEN, VALUE);
999 If you define `YYPRINT', it should take three arguments. The
1000 parser will pass a standard I/O stream, the numeric code for the
1001 token type, and the token value (from `yylval').
1003 For `yacc.c' only. Obsoleted by `%printer'.
1005 Here is an example of `YYPRINT' suitable for the multi-function
1006 calculator (*note Declarations for `mfcalc': Mfcalc Declarations.):
1009 static void print_token_value (FILE *, int, YYSTYPE);
1010 #define YYPRINT(File, Type, Value) \
1011 print_token_value (File, Type, Value)
1017 print_token_value (FILE *file, int type, YYSTYPE value)
1020 fprintf (file, "%s", value.tptr->name);
1021 else if (type == NUM)
1022 fprintf (file, "%d", value.val);
1026 File: bison.info, Node: Invocation, Next: Other Languages, Prev: Debugging, Up: Top
1031 The usual way to invoke Bison is as follows:
1035 Here INFILE is the grammar file name, which usually ends in `.y'.
1036 The parser implementation file's name is made by replacing the `.y'
1037 with `.tab.c' and removing any leading directory. Thus, the `bison
1038 foo.y' file name yields `foo.tab.c', and the `bison hack/foo.y' file
1039 name yields `foo.tab.c'. It's also possible, in case you are writing
1040 C++ code instead of C in your grammar file, to name it `foo.ypp' or
1041 `foo.y++'. Then, the output files will take an extension like the
1042 given one as input (respectively `foo.tab.cpp' and `foo.tab.c++'). This
1043 feature takes effect with all options that manipulate file names like
1049 will produce `infile.tab.cxx' and `infile.tab.hxx', and
1051 bison -d -o OUTPUT.C++ INFILE.Y
1052 will produce `output.c++' and `outfile.h++'.
1054 For compatibility with POSIX, the standard Bison distribution also
1055 contains a shell script called `yacc' that invokes Bison with the `-y'
1060 * Bison Options:: All the options described in detail,
1061 in alphabetical order by short options.
1062 * Option Cross Key:: Alphabetical list of long options.
1063 * Yacc Library:: Yacc-compatible `yylex' and `main'.
1066 File: bison.info, Node: Bison Options, Next: Option Cross Key, Up: Invocation
1071 Bison supports both traditional single-letter options and mnemonic long
1072 option names. Long option names are indicated with `--' instead of
1073 `-'. Abbreviations for option names are allowed as long as they are
1074 unique. When a long option takes an argument, like `--file-prefix',
1075 connect the option name and the argument with `='.
1077 Here is a list of options that can be used with Bison, alphabetized
1078 by short option. It is followed by a cross key alphabetized by long
1084 Print a summary of the command-line options to Bison and exit.
1088 Print the version number of Bison and exit.
1091 Print the name of the directory containing locale-dependent data.
1094 Print the name of the directory containing skeletons and XSLT.
1098 Act more like the traditional Yacc command. This can cause
1099 different diagnostics to be generated, and may change behavior in
1100 other minor ways. Most importantly, imitate Yacc's output file
1101 name conventions, so that the parser implementation file is called
1102 `y.tab.c', and the other outputs are called `y.output' and
1103 `y.tab.h'. Also, if generating a deterministic parser in C,
1104 generate `#define' statements in addition to an `enum' to associate
1105 token numbers with token names. Thus, the following shell script
1106 can substitute for Yacc, and the Bison distribution contains such
1107 a script for compatibility with POSIX:
1112 The `-y'/`--yacc' option is intended for use with traditional Yacc
1113 grammars. If your grammar uses a Bison extension like
1114 `%glr-parser', Bison might not be Yacc-compatible even if this
1115 option is specified.
1118 `--warnings[=CATEGORY]'
1119 Output warnings falling in CATEGORY. CATEGORY can be one of:
1121 Warn about mid-rule values that are set but not used within
1122 any of the actions of the parent rule. For example, warn
1123 about unused `$2' in:
1125 exp: '1' { $$ = 1; } '+' exp { $$ = $1 + $4; };
1127 Also warn about mid-rule values that are used but not set.
1128 For example, warn about unset `$$' in the mid-rule action in:
1130 exp: '1' { $1 = 1; } '+' exp { $$ = $2 + $4; };
1132 These warnings are not enabled by default since they
1133 sometimes prove to be false alarms in existing grammars
1134 employing the Yacc constructs `$0' or `$-N' (where N is some
1138 Incompatibilities with POSIX Yacc.
1142 S/R and R/R conflicts. These warnings are enabled by
1143 default. However, if the `%expect' or `%expect-rr' directive
1144 is specified, an unexpected number of conflicts is an error,
1145 and an expected number of conflicts is not reported, so `-W'
1146 and `--warning' then have no effect on the conflict report.
1149 All warnings not categorized above. These warnings are
1152 This category is provided merely for the sake of
1153 completeness. Future releases of Bison may move warnings
1154 from this category to new, more specific categories.
1160 Turn off all the warnings.
1163 Treat warnings as errors.
1165 A category can be turned off by prefixing its name with `no-'. For
1166 instance, `-Wno-yacc' will hide the warnings about POSIX Yacc
1173 In the parser implementation file, define the macro `YYDEBUG' to 1
1174 if it is not already defined, so that the debugging facilities are
1175 compiled. *Note Tracing Your Parser: Tracing.
1178 `--define=NAME[=VALUE]'
1180 `--force-define=NAME[=VALUE]'
1181 Each of these is equivalent to `%define NAME "VALUE"' (*note
1182 %define Summary::) except that Bison processes multiple
1183 definitions for the same NAME as follows:
1185 * Bison quietly ignores all command-line definitions for NAME
1188 * If that command-line definition is specified by a `-D' or
1189 `--define', Bison reports an error for any `%define'
1190 definition for NAME.
1192 * If that command-line definition is specified by a `-F' or
1193 `--force-define' instead, Bison quietly ignores all `%define'
1194 definitions for NAME.
1196 * Otherwise, Bison reports an error if there are multiple
1197 `%define' definitions for NAME.
1199 You should avoid using `-F' and `--force-define' in your make
1200 files unless you are confident that it is safe to quietly ignore
1201 any conflicting `%define' that may be added to the grammar file.
1204 `--language=LANGUAGE'
1205 Specify the programming language for the generated parser, as if
1206 `%language' was specified (*note Bison Declaration Summary: Decl
1207 Summary.). Currently supported languages include C, C++, and Java.
1208 LANGUAGE is case-insensitive.
1210 This option is experimental and its effect may be modified in
1214 Pretend that `%locations' was specified. *Note Decl Summary::.
1217 `--name-prefix=PREFIX'
1218 Pretend that `%name-prefix "PREFIX"' was specified (*note Decl
1219 Summary::). Obsoleted by `-Dapi.prefix=PREFIX'. *Note Multiple
1220 Parsers in the Same Program: Multiple Parsers.
1224 Don't put any `#line' preprocessor commands in the parser
1225 implementation file. Ordinarily Bison puts them in the parser
1226 implementation file so that the C compiler and debuggers will
1227 associate errors with your source file, the grammar file. This
1228 option causes them to associate errors with the parser
1229 implementation file, treating it as an independent source file in
1234 Specify the skeleton to use, similar to `%skeleton' (*note Bison
1235 Declaration Summary: Decl Summary.).
1237 If FILE does not contain a `/', FILE is the name of a skeleton
1238 file in the Bison installation directory. If it does, FILE is an
1239 absolute file name or a file name relative to the current working
1240 directory. This is similar to how most shells resolve commands.
1244 Pretend that `%token-table' was specified. *Note Decl Summary::.
1249 Pretend that `%defines' was specified, i.e., write an extra output
1250 file containing macro definitions for the token type names defined
1251 in the grammar, as well as a few other declarations. *Note Decl
1255 This is the same as `--defines' except `-d' does not accept a FILE
1256 argument since POSIX Yacc requires that `-d' can be bundled with
1257 other short options.
1260 `--file-prefix=PREFIX'
1261 Pretend that `%file-prefix' was specified, i.e., specify prefix to
1262 use for all Bison output file names. *Note Decl Summary::.
1266 Write an extra output file containing verbose description of the
1267 comma separated list of THINGS among:
1270 Description of the grammar, conflicts (resolved and
1271 unresolved), and parser's automaton.
1274 Implies `state' and augments the description of the automaton
1275 with each rule's lookahead set.
1278 Implies `state' and augments the description of the automaton
1279 with the full set of items for each state, instead of its
1282 `--report-file=FILE'
1283 Specify the FILE for the verbose description.
1287 Pretend that `%verbose' was specified, i.e., write an extra output
1288 file containing verbose descriptions of the grammar and parser.
1289 *Note Decl Summary::.
1293 Specify the FILE for the parser implementation file.
1295 The other output files' names are constructed from FILE as
1296 described under the `-v' and `-d' options.
1300 Output a graphical representation of the parser's automaton
1301 computed by Bison, in Graphviz (http://www.graphviz.org/) DOT
1302 (http://www.graphviz.org/doc/info/lang.html) format. `FILE' is
1303 optional. If omitted and the grammar file is `foo.y', the output
1304 file will be `foo.dot'.
1308 Output an XML report of the parser's automaton computed by Bison.
1309 `FILE' is optional. If omitted and the grammar file is `foo.y',
1310 the output file will be `foo.xml'. (The current XML schema is
1311 experimental and may evolve. More user feedback will help to
1315 File: bison.info, Node: Option Cross Key, Next: Yacc Library, Prev: Bison Options, Up: Invocation
1317 9.2 Option Cross Key
1318 ====================
1320 Here is a list of options, alphabetized by long option, to help you find
1321 the corresponding short option and directive.
1323 Long Option Short Option Bison Directive
1324 ---------------------------------------------------------------------------------
1325 `--debug' `-t' `%debug'
1326 `--define=NAME[=VALUE]' `-D NAME[=VALUE]' `%define NAME ["VALUE"]'
1327 `--defines[=FILE]' `-d' `%defines ["FILE"]'
1328 `--file-prefix=PREFIX' `-b PREFIX' `%file-prefix "PREFIX"'
1329 `--force-define=NAME[=VALUE]' `-F NAME[=VALUE]' `%define NAME ["VALUE"]'
1330 `--graph[=FILE]' `-g [FILE]'
1332 `--language=LANGUAGE' `-L LANGUAGE' `%language "LANGUAGE"'
1333 `--locations' `%locations'
1334 `--name-prefix=PREFIX' `-p PREFIX' `%name-prefix "PREFIX"'
1335 `--no-lines' `-l' `%no-lines'
1336 `--output=FILE' `-o FILE' `%output "FILE"'
1339 `--report-file=FILE'
1340 `--report=THINGS' `-r THINGS'
1341 `--skeleton=FILE' `-S FILE' `%skeleton "FILE"'
1342 `--token-table' `-k' `%token-table'
1343 `--verbose' `-v' `%verbose'
1345 `--warnings[=CATEGORY]' `-W [CATEGORY]'
1346 `--xml[=FILE]' `-x [FILE]'
1347 `--yacc' `-y' `%yacc'
1350 File: bison.info, Node: Yacc Library, Prev: Option Cross Key, Up: Invocation
1355 The Yacc library contains default implementations of the `yyerror' and
1356 `main' functions. These default implementations are normally not
1357 useful, but POSIX requires them. To use the Yacc library, link your
1358 program with the `-ly' option. Note that Bison's implementation of the
1359 Yacc library is distributed under the terms of the GNU General Public
1360 License (*note Copying::).
1362 If you use the Yacc library's `yyerror' function, you should declare
1363 `yyerror' as follows:
1365 int yyerror (char const *);
1367 Bison ignores the `int' value returned by this `yyerror'. If you
1368 use the Yacc library's `main' function, your `yyparse' function should
1369 have the following type signature:
1374 File: bison.info, Node: Other Languages, Next: FAQ, Prev: Invocation, Up: Top
1376 10 Parsers Written In Other Languages
1377 *************************************
1381 * C++ Parsers:: The interface to generate C++ parser classes
1382 * Java Parsers:: The interface to generate Java parser classes
1385 File: bison.info, Node: C++ Parsers, Next: Java Parsers, Up: Other Languages
1392 * C++ Bison Interface:: Asking for C++ parser generation
1393 * C++ Semantic Values:: %union vs. C++
1394 * C++ Location Values:: The position and location classes
1395 * C++ Parser Interface:: Instantiating and running the parser
1396 * C++ Scanner Interface:: Exchanges between yylex and parse
1397 * A Complete C++ Example:: Demonstrating their use
1400 File: bison.info, Node: C++ Bison Interface, Next: C++ Semantic Values, Up: C++ Parsers
1402 10.1.1 C++ Bison Interface
1403 --------------------------
1405 The C++ deterministic parser is selected using the skeleton directive,
1406 `%skeleton "lalr1.cc"', or the synonymous command-line option
1407 `--skeleton=lalr1.cc'. *Note Decl Summary::.
1409 When run, `bison' will create several entities in the `yy' namespace. Use
1410 the `%define namespace' directive to change the namespace name, see
1411 *note namespace: %define Summary. The various classes are generated in
1412 the following files:
1416 The definition of the classes `position' and `location', used for
1417 location tracking. *Note C++ Location Values::.
1420 An auxiliary class `stack' used by the parser.
1424 (Assuming the extension of the grammar file was `.yy'.) The
1425 declaration and implementation of the C++ parser class. The
1426 basename and extension of these two files follow the same rules as
1427 with regular C parsers (*note Invocation::).
1429 The header is _mandatory_; you must either pass `-d'/`--defines'
1430 to `bison', or use the `%defines' directive.
1432 All these files are documented using Doxygen; run `doxygen' for a
1433 complete and accurate documentation.
1436 File: bison.info, Node: C++ Semantic Values, Next: C++ Location Values, Prev: C++ Bison Interface, Up: C++ Parsers
1438 10.1.2 C++ Semantic Values
1439 --------------------------
1441 The `%union' directive works as for C, see *note The Collection of
1442 Value Types: Union Decl. In particular it produces a genuine
1443 `union'(1), which have a few specific features in C++.
1444 - The type `YYSTYPE' is defined but its use is discouraged: rather
1445 you should refer to the parser's encapsulated type
1446 `yy::parser::semantic_type'.
1448 - Non POD (Plain Old Data) types cannot be used. C++ forbids any
1449 instance of classes with constructors in unions: only _pointers_
1450 to such objects are allowed.
1452 Because objects have to be stored via pointers, memory is not
1453 reclaimed automatically: using the `%destructor' directive is the only
1454 means to avoid leaks. *Note Freeing Discarded Symbols: Destructor Decl.
1456 ---------- Footnotes ----------
1458 (1) In the future techniques to allow complex types within
1459 pseudo-unions (similar to Boost variants) might be implemented to
1460 alleviate these issues.
1463 File: bison.info, Node: C++ Location Values, Next: C++ Parser Interface, Prev: C++ Semantic Values, Up: C++ Parsers
1465 10.1.3 C++ Location Values
1466 --------------------------
1468 When the directive `%locations' is used, the C++ parser supports
1469 location tracking, see *note Tracking Locations::. Two auxiliary
1470 classes define a `position', a single point in a file, and a
1471 `location', a range composed of a pair of `position's (possibly
1472 spanning several files).
1474 In this section `uint' is an abbreviation for `unsigned int': in
1475 genuine code only the latter is used.
1479 * C++ position:: One point in the source file
1480 * C++ location:: Two points in the source file
1483 File: bison.info, Node: C++ position, Next: C++ location, Up: C++ Location Values
1485 10.1.3.1 C++ `position'
1486 .......................
1488 -- Constructor on position: position (std::string* FILE = 0, uint
1489 LINE = 1, uint COL = 1)
1490 Create a `position' denoting a given point. Note that `file' is
1491 not reclaimed when the `position' is destroyed: memory managed
1492 must be handled elsewhere.
1494 -- Method on position: void initialize (std::string* FILE = 0, uint
1495 LINE = 1, uint COL = 1)
1496 Reset the position to the given values.
1498 -- Instance Variable of position: std::string* file
1499 The name of the file. It will always be handled as a pointer, the
1500 parser will never duplicate nor deallocate it. As an experimental
1501 feature you may change it to `TYPE*' using `%define filename_type
1504 -- Instance Variable of position: uint line
1505 The line, starting at 1.
1507 -- Method on position: uint lines (int HEIGHT = 1)
1508 Advance by HEIGHT lines, resetting the column number.
1510 -- Instance Variable of position: uint column
1511 The column, starting at 1.
1513 -- Method on position: uint columns (int WIDTH = 1)
1514 Advance by WIDTH columns, without changing the line number.
1516 -- Method on position: position& operator+= (int WIDTH)
1517 -- Method on position: position operator+ (int WIDTH)
1518 -- Method on position: position& operator-= (int WIDTH)
1519 -- Method on position: position operator- (int WIDTH)
1520 Various forms of syntactic sugar for `columns'.
1522 -- Method on position: bool operator== (const position& THAT)
1523 -- Method on position: bool operator!= (const position& THAT)
1524 Whether `*this' and `that' denote equal/different positions.
1526 -- Function: std::ostream& operator<< (std::ostream& O, const
1528 Report P on O like this: `FILE:LINE.COLUMN', or `LINE.COLUMN' if
1532 File: bison.info, Node: C++ location, Prev: C++ position, Up: C++ Location Values
1534 10.1.3.2 C++ `location'
1535 .......................
1537 -- Constructor on location: location (const position& BEGIN, const
1539 Create a `Location' from the endpoints of the range.
1541 -- Constructor on location: location (const position& POS =
1543 -- Constructor on location: location (std::string* FILE, uint LINE,
1545 Create a `Location' denoting an empty range located at a given
1548 -- Method on location: void initialize (std::string* FILE = 0, uint
1549 LINE = 1, uint COL = 1)
1550 Reset the location to an empty range at the given values.
1552 -- Instance Variable of location: position begin
1553 -- Instance Variable of location: position end
1554 The first, inclusive, position of the range, and the first beyond.
1556 -- Method on location: uint columns (int WIDTH = 1)
1557 -- Method on location: uint lines (int HEIGHT = 1)
1558 Advance the `end' position.
1560 -- Method on location: location operator+ (const location& END)
1561 -- Method on location: location operator+ (int WIDTH)
1562 -- Method on location: location operator+= (int WIDTH)
1563 Various forms of syntactic sugar.
1565 -- Method on location: void step ()
1566 Move `begin' onto `end'.
1568 -- Method on location: bool operator== (const location& THAT)
1569 -- Method on location: bool operator!= (const location& THAT)
1570 Whether `*this' and `that' denote equal/different ranges of
1573 -- Function: std::ostream& operator<< (std::ostream& O, const
1575 Report P on O, taking care of special cases such as: no `filename'
1576 defined, or equal filename/line or column.
1579 File: bison.info, Node: C++ Parser Interface, Next: C++ Scanner Interface, Prev: C++ Location Values, Up: C++ Parsers
1581 10.1.4 C++ Parser Interface
1582 ---------------------------
1584 The output files `OUTPUT.hh' and `OUTPUT.cc' declare and define the
1585 parser class in the namespace `yy'. The class name defaults to
1586 `parser', but may be changed using `%define parser_class_name "NAME"'.
1587 The interface of this class is detailed below. It can be extended
1588 using the `%parse-param' feature: its semantics is slightly changed
1589 since it describes an additional member of the parser class, and an
1590 additional argument for its constructor.
1592 -- Type of parser: semantic_type
1593 -- Type of parser: location_type
1594 The types for semantics value and locations.
1596 -- Type of parser: token
1597 A structure that contains (only) the `yytokentype' enumeration,
1598 which defines the tokens. To refer to the token `FOO', use
1599 `yy::parser::token::FOO'. The scanner can use `typedef
1600 yy::parser::token token;' to "import" the token enumeration (*note
1603 -- Method on parser: parser (TYPE1 ARG1, ...)
1604 Build a new parser object. There are no arguments by default,
1605 unless `%parse-param {TYPE1 ARG1}' was used.
1607 -- Method on parser: int parse ()
1608 Run the syntactic analysis, and return 0 on success, 1 otherwise.
1610 -- Method on parser: std::ostream& debug_stream ()
1611 -- Method on parser: void set_debug_stream (std::ostream& O)
1612 Get or set the stream used for tracing the parsing. It defaults to
1615 -- Method on parser: debug_level_type debug_level ()
1616 -- Method on parser: void set_debug_level (debug_level L)
1617 Get or set the tracing level. Currently its value is either 0, no
1618 trace, or nonzero, full tracing.
1620 -- Method on parser: void error (const location_type& L, const
1622 The definition for this member function must be supplied by the
1623 user: the parser uses it to report a parser error occurring at L,
1627 File: bison.info, Node: C++ Scanner Interface, Next: A Complete C++ Example, Prev: C++ Parser Interface, Up: C++ Parsers
1629 10.1.5 C++ Scanner Interface
1630 ----------------------------
1632 The parser invokes the scanner by calling `yylex'. Contrary to C
1633 parsers, C++ parsers are always pure: there is no point in using the
1634 `%define api.pure' directive. Therefore the interface is as follows.
1636 -- Method on parser: int yylex (semantic_type* YYLVAL, location_type*
1637 YYLLOC, TYPE1 ARG1, ...)
1638 Return the next token. Its type is the return value, its semantic
1639 value and location being YYLVAL and YYLLOC. Invocations of
1640 `%lex-param {TYPE1 ARG1}' yield additional arguments.
1643 File: bison.info, Node: A Complete C++ Example, Prev: C++ Scanner Interface, Up: C++ Parsers
1645 10.1.6 A Complete C++ Example
1646 -----------------------------
1648 This section demonstrates the use of a C++ parser with a simple but
1649 complete example. This example should be available on your system,
1650 ready to compile, in the directory "../bison/examples/calc++". It
1651 focuses on the use of Bison, therefore the design of the various C++
1652 classes is very naive: no accessors, no encapsulation of members etc.
1653 We will use a Lex scanner, and more precisely, a Flex scanner, to
1654 demonstrate the various interaction. A hand written scanner is
1655 actually easier to interface with.
1659 * Calc++ --- C++ Calculator:: The specifications
1660 * Calc++ Parsing Driver:: An active parsing context
1661 * Calc++ Parser:: A parser class
1662 * Calc++ Scanner:: A pure C++ Flex scanner
1663 * Calc++ Top Level:: Conducting the band
1666 File: bison.info, Node: Calc++ --- C++ Calculator, Next: Calc++ Parsing Driver, Up: A Complete C++ Example
1668 10.1.6.1 Calc++ -- C++ Calculator
1669 .................................
1671 Of course the grammar is dedicated to arithmetics, a single expression,
1672 possibly preceded by variable assignments. An environment containing
1673 possibly predefined variables such as `one' and `two', is exchanged
1674 with the parser. An example of valid input follows.
1677 seven := one + two * three
1681 File: bison.info, Node: Calc++ Parsing Driver, Next: Calc++ Parser, Prev: Calc++ --- C++ Calculator, Up: A Complete C++ Example
1683 10.1.6.2 Calc++ Parsing Driver
1684 ..............................
1686 To support a pure interface with the parser (and the scanner) the
1687 technique of the "parsing context" is convenient: a structure
1688 containing all the data to exchange. Since, in addition to simply
1689 launch the parsing, there are several auxiliary tasks to execute (open
1690 the file for parsing, instantiate the parser etc.), we recommend
1691 transforming the simple parsing context structure into a fully blown
1692 "parsing driver" class.
1694 The declaration of this driver class, `calc++-driver.hh', is as
1695 follows. The first part includes the CPP guard and imports the
1696 required standard library components, and the declaration of the parser
1699 #ifndef CALCXX_DRIVER_HH
1700 # define CALCXX_DRIVER_HH
1703 # include "calc++-parser.hh"
1705 Then comes the declaration of the scanning function. Flex expects the
1706 signature of `yylex' to be defined in the macro `YY_DECL', and the C++
1707 parser expects it to be declared. We can factor both as follows.
1709 // Tell Flex the lexer's prototype ...
1711 yy::calcxx_parser::token_type \
1712 yylex (yy::calcxx_parser::semantic_type* yylval, \
1713 yy::calcxx_parser::location_type* yylloc, \
1714 calcxx_driver& driver)
1715 // ... and declare it for the parser's sake.
1718 The `calcxx_driver' class is then declared with its most obvious
1721 // Conducting the whole scanning and parsing of Calc++.
1726 virtual ~calcxx_driver ();
1728 std::map<std::string, int> variables;
1732 To encapsulate the coordination with the Flex scanner, it is useful to
1733 have two members function to open and close the scanning phase.
1735 // Handling the scanner.
1738 bool trace_scanning;
1740 Similarly for the parser itself.
1742 // Run the parser. Return 0 on success.
1743 int parse (const std::string& f);
1747 To demonstrate pure handling of parse errors, instead of simply dumping
1748 them on the standard error output, we will pass them to the compiler
1749 driver using the following two member functions. Finally, we close the
1750 class declaration and CPP guard.
1753 void error (const yy::location& l, const std::string& m);
1754 void error (const std::string& m);
1756 #endif // ! CALCXX_DRIVER_HH
1758 The implementation of the driver is straightforward. The `parse'
1759 member function deserves some attention. The `error' functions are
1760 simple stubs, they should actually register the located error messages
1761 and set error state.
1763 #include "calc++-driver.hh"
1764 #include "calc++-parser.hh"
1766 calcxx_driver::calcxx_driver ()
1767 : trace_scanning (false), trace_parsing (false)
1769 variables["one"] = 1;
1770 variables["two"] = 2;
1773 calcxx_driver::~calcxx_driver ()
1778 calcxx_driver::parse (const std::string &f)
1782 yy::calcxx_parser parser (*this);
1783 parser.set_debug_level (trace_parsing);
1784 int res = parser.parse ();
1790 calcxx_driver::error (const yy::location& l, const std::string& m)
1792 std::cerr << l << ": " << m << std::endl;
1796 calcxx_driver::error (const std::string& m)
1798 std::cerr << m << std::endl;
1802 File: bison.info, Node: Calc++ Parser, Next: Calc++ Scanner, Prev: Calc++ Parsing Driver, Up: A Complete C++ Example
1804 10.1.6.3 Calc++ Parser
1805 ......................
1807 The grammar file `calc++-parser.yy' starts by asking for the C++
1808 deterministic parser skeleton, the creation of the parser header file,
1809 and specifies the name of the parser class. Because the C++ skeleton
1810 changed several times, it is safer to require the version you designed
1813 %skeleton "lalr1.cc" /* -*- C++ -*- */
1814 %require "2.6.1-dirty"
1816 %define parser_class_name "calcxx_parser"
1818 Then come the declarations/inclusions needed to define the `%union'.
1819 Because the parser uses the parsing driver and reciprocally, both
1820 cannot include the header of the other. Because the driver's header
1821 needs detailed knowledge about the parser class (in particular its
1822 inner types), it is the parser's header which will simply use a forward
1823 declaration of the driver. *Note %code Summary::.
1827 class calcxx_driver;
1830 The driver is passed by reference to the parser and to the scanner.
1831 This provides a simple but effective pure interface, not relying on
1834 // The parsing context.
1835 %parse-param { calcxx_driver& driver }
1836 %lex-param { calcxx_driver& driver }
1838 Then we request the location tracking feature, and initialize the first
1839 location's file name. Afterward new locations are computed relatively
1840 to the previous locations: the file name will be automatically
1846 // Initialize the initial location.
1847 @$.begin.filename = @$.end.filename = &driver.file;
1850 Use the two following directives to enable parser tracing and verbose
1851 error messages. However, verbose error messages can contain incorrect
1852 information (*note LAC::).
1857 Semantic values cannot use "real" objects, but only pointers to them.
1866 The code between `%code {' and `}' is output in the `*.cc' file; it
1867 needs detailed knowledge about the driver.
1870 # include "calc++-driver.hh"
1873 The token numbered as 0 corresponds to end of file; the following line
1874 allows for nicer error messages referring to "end of file" instead of
1875 "$end". Similarly user friendly named are provided for each symbol.
1876 Note that the tokens names are prefixed by `TOKEN_' to avoid name
1879 %token END 0 "end of file"
1881 %token <sval> IDENTIFIER "identifier"
1882 %token <ival> NUMBER "number"
1885 To enable memory deallocation during error recovery, use `%destructor'.
1887 %printer { yyoutput << *$$; } "identifier"
1888 %destructor { delete $$; } "identifier"
1890 %printer { yyoutput << $$; } <ival>
1892 The grammar itself is straightforward.
1896 unit: assignments exp { driver.result = $2; };
1900 | assignments assignment {};
1903 "identifier" ":=" exp
1904 { driver.variables[*$1] = $3; delete $1; };
1908 exp: exp '+' exp { $$ = $1 + $3; }
1909 | exp '-' exp { $$ = $1 - $3; }
1910 | exp '*' exp { $$ = $1 * $3; }
1911 | exp '/' exp { $$ = $1 / $3; }
1912 | "identifier" { $$ = driver.variables[*$1]; delete $1; }
1913 | "number" { $$ = $1; };
1916 Finally the `error' member function registers the errors to the driver.
1919 yy::calcxx_parser::error (const yy::calcxx_parser::location_type& l,
1920 const std::string& m)
1922 driver.error (l, m);
1926 File: bison.info, Node: Calc++ Scanner, Next: Calc++ Top Level, Prev: Calc++ Parser, Up: A Complete C++ Example
1928 10.1.6.4 Calc++ Scanner
1929 .......................
1931 The Flex scanner first includes the driver declaration, then the
1932 parser's to get the set of defined tokens.
1934 %{ /* -*- C++ -*- */
1939 # include "calc++-driver.hh"
1940 # include "calc++-parser.hh"
1942 /* Work around an incompatibility in flex (at least versions
1943 2.5.31 through 2.5.33): it generates code that does
1944 not conform to C89. See Debian bug 333231
1945 <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
1949 /* By default yylex returns int, we use token_type.
1950 Unfortunately yyterminate by default returns 0, which is
1951 not of token_type. */
1952 #define yyterminate() return token::END
1955 Because there is no `#include'-like feature we don't need `yywrap', we
1956 don't need `unput' either, and we parse an actual file, this is not an
1957 interactive session with the user. Finally we enable the scanner
1960 %option noyywrap nounput batch debug
1962 Abbreviations allow for more readable rules.
1964 id [a-zA-Z][a-zA-Z_0-9]*
1968 The following paragraph suffices to track locations accurately. Each
1969 time `yylex' is invoked, the begin position is moved onto the end
1970 position. Then when a pattern is matched, the end position is advanced
1971 of its width. In case it matched ends of lines, the end cursor is
1972 adjusted, and each time blanks are matched, the begin cursor is moved
1973 onto the end cursor to effectively ignore the blanks preceding tokens.
1974 Comments would be treated equally.
1977 # define YY_USER_ACTION yylloc->columns (yyleng);
1983 {blank}+ yylloc->step ();
1984 [\n]+ yylloc->lines (yyleng); yylloc->step ();
1986 The rules are simple, just note the use of the driver to report errors.
1987 It is convenient to use a typedef to shorten
1988 `yy::calcxx_parser::token::identifier' into `token::identifier' for
1992 typedef yy::calcxx_parser::token token;
1994 /* Convert ints to the actual type of tokens. */
1995 [-+*/] return yy::calcxx_parser::token_type (yytext[0]);
1996 ":=" return token::ASSIGN;
1999 long n = strtol (yytext, NULL, 10);
2000 if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE))
2001 driver.error (*yylloc, "integer is out of range");
2003 return token::NUMBER;
2005 {id} yylval->sval = new std::string (yytext); return token::IDENTIFIER;
2006 . driver.error (*yylloc, "invalid character");
2009 Finally, because the scanner related driver's member function depend on
2010 the scanner's data, it is simpler to implement them in this file.
2013 calcxx_driver::scan_begin ()
2015 yy_flex_debug = trace_scanning;
2016 if (file.empty () || file == "-")
2018 else if (!(yyin = fopen (file.c_str (), "r")))
2020 error ("cannot open " + file + ": " + strerror(errno));
2021 exit (EXIT_FAILURE);
2026 calcxx_driver::scan_end ()
2032 File: bison.info, Node: Calc++ Top Level, Prev: Calc++ Scanner, Up: A Complete C++ Example
2034 10.1.6.5 Calc++ Top Level
2035 .........................
2037 The top level file, `calc++.cc', poses no problem.
2040 #include "calc++-driver.hh"
2043 main (int argc, char *argv[])
2045 calcxx_driver driver;
2046 for (int i = 1; i < argc; ++i)
2047 if (argv[i] == std::string ("-p"))
2048 driver.trace_parsing = true;
2049 else if (argv[i] == std::string ("-s"))
2050 driver.trace_scanning = true;
2051 else if (!driver.parse (argv[i]))
2052 std::cout << driver.result << std::endl;
2056 File: bison.info, Node: Java Parsers, Prev: C++ Parsers, Up: Other Languages
2063 * Java Bison Interface:: Asking for Java parser generation
2064 * Java Semantic Values:: %type and %token vs. Java
2065 * Java Location Values:: The position and location classes
2066 * Java Parser Interface:: Instantiating and running the parser
2067 * Java Scanner Interface:: Specifying the scanner for the parser
2068 * Java Action Features:: Special features for use in actions
2069 * Java Differences:: Differences between C/C++ and Java Grammars
2070 * Java Declarations Summary:: List of Bison declarations used with Java
2073 File: bison.info, Node: Java Bison Interface, Next: Java Semantic Values, Up: Java Parsers
2075 10.2.1 Java Bison Interface
2076 ---------------------------
2078 (The current Java interface is experimental and may evolve. More user
2079 feedback will help to stabilize it.)
2081 The Java parser skeletons are selected using the `%language "Java"'
2082 directive or the `-L java'/`--language=java' option.
2084 When generating a Java parser, `bison BASENAME.y' will create a
2085 single Java source file named `BASENAME.java' containing the parser
2086 implementation. Using a grammar file without a `.y' suffix is
2087 currently broken. The basename of the parser implementation file can
2088 be changed by the `%file-prefix' directive or the `-p'/`--name-prefix'
2089 option. The entire parser implementation file name can be changed by
2090 the `%output' directive or the `-o'/`--output' option. The parser
2091 implementation file contains a single class for the parser.
2093 You can create documentation for generated parsers using Javadoc.
2095 Contrary to C parsers, Java parsers do not use global variables; the
2096 state of the parser is always local to an instance of the parser class.
2097 Therefore, all Java parsers are "pure", and the `%pure-parser' and
2098 `%define api.pure' directives does not do anything when used in Java.
2100 Push parsers are currently unsupported in Java and `%define
2101 api.push-pull' have no effect.
2103 GLR parsers are currently unsupported in Java. Do not use the
2104 `glr-parser' directive.
2106 No header file can be generated for Java parsers. Do not use the
2107 `%defines' directive or the `-d'/`--defines' options.
2109 Currently, support for debugging and verbose errors are always
2110 compiled in. Thus the `%debug' and `%token-table' directives and the
2111 `-t'/`--debug' and `-k'/`--token-table' options have no effect. This
2112 may change in the future to eliminate unused code in the generated
2113 parser, so use `%debug' and `%verbose-error' explicitly if needed.
2114 Also, in the future the `%token-table' directive might enable a public
2115 interface to access the token names and codes.
2118 File: bison.info, Node: Java Semantic Values, Next: Java Location Values, Prev: Java Bison Interface, Up: Java Parsers
2120 10.2.2 Java Semantic Values
2121 ---------------------------
2123 There is no `%union' directive in Java parsers. Instead, the semantic
2124 values' types (class names) should be specified in the `%type' or
2127 %type <Expression> expr assignment_expr term factor
2128 %type <Integer> number
2130 By default, the semantic stack is declared to have `Object' members,
2131 which means that the class types you specify can be of any class. To
2132 improve the type safety of the parser, you can declare the common
2133 superclass of all the semantic values using the `%define stype'
2134 directive. For example, after the following declaration:
2136 %define stype "ASTNode"
2138 any `%type' or `%token' specifying a semantic type which is not a
2139 subclass of ASTNode, will cause a compile-time error.
2141 Types used in the directives may be qualified with a package name.
2142 Primitive data types are accepted for Java version 1.5 or later. Note
2143 that in this case the autoboxing feature of Java 1.5 will be used.
2144 Generic types may not be used; this is due to a limitation in the
2145 implementation of Bison, and may change in future releases.
2147 Java parsers do not support `%destructor', since the language adopts
2148 garbage collection. The parser will try to hold references to semantic
2149 values for as little time as needed.
2151 Java parsers do not support `%printer', as `toString()' can be used
2152 to print the semantic values. This however may change (in a
2153 backwards-compatible way) in future versions of Bison.
2156 File: bison.info, Node: Java Location Values, Next: Java Parser Interface, Prev: Java Semantic Values, Up: Java Parsers
2158 10.2.3 Java Location Values
2159 ---------------------------
2161 When the directive `%locations' is used, the Java parser supports
2162 location tracking, see *note Tracking Locations::. An auxiliary
2163 user-defined class defines a "position", a single point in a file;
2164 Bison itself defines a class representing a "location", a range
2165 composed of a pair of positions (possibly spanning several files). The
2166 location class is an inner class of the parser; the name is `Location'
2167 by default, and may also be renamed using `%define location_type
2170 The location class treats the position as a completely opaque value.
2171 By default, the class name is `Position', but this can be changed with
2172 `%define position_type "CLASS-NAME"'. This class must be supplied by
2175 -- Instance Variable of Location: Position begin
2176 -- Instance Variable of Location: Position end
2177 The first, inclusive, position of the range, and the first beyond.
2179 -- Constructor on Location: Location (Position LOC)
2180 Create a `Location' denoting an empty range located at a given
2183 -- Constructor on Location: Location (Position BEGIN, Position END)
2184 Create a `Location' from the endpoints of the range.
2186 -- Method on Location: String toString ()
2187 Prints the range represented by the location. For this to work
2188 properly, the position class should override the `equals' and
2189 `toString' methods appropriately.
2192 File: bison.info, Node: Java Parser Interface, Next: Java Scanner Interface, Prev: Java Location Values, Up: Java Parsers
2194 10.2.4 Java Parser Interface
2195 ----------------------------
2197 The name of the generated parser class defaults to `YYParser'. The
2198 `YY' prefix may be changed using the `%name-prefix' directive or the
2199 `-p'/`--name-prefix' option. Alternatively, use `%define
2200 parser_class_name "NAME"' to give a custom name to the class. The
2201 interface of this class is detailed below.
2203 By default, the parser class has package visibility. A declaration
2204 `%define public' will change to public visibility. Remember that,
2205 according to the Java language specification, the name of the `.java'
2206 file should match the name of the class in this case. Similarly, you
2207 can use `abstract', `final' and `strictfp' with the `%define'
2208 declaration to add other modifiers to the parser class.
2210 The Java package name of the parser class can be specified using the
2211 `%define package' directive. The superclass and the implemented
2212 interfaces of the parser class can be specified with the `%define
2213 extends' and `%define implements' directives.
2215 The parser class defines an inner class, `Location', that is used
2216 for location tracking (see *note Java Location Values::), and a inner
2217 interface, `Lexer' (see *note Java Scanner Interface::). Other than
2218 these inner class/interface, and the members described in the interface
2219 below, all the other members and fields are preceded with a `yy' or
2220 `YY' prefix to avoid clashes with user code.
2222 The parser class can be extended using the `%parse-param' directive.
2223 Each occurrence of the directive will add a `protected final' field to
2224 the parser class, and an argument to its constructor, which initialize
2227 Token names defined by `%token' and the predefined `EOF' token name
2228 are added as constant fields to the parser class.
2230 -- Constructor on YYParser: YYParser (LEX_PARAM, ..., PARSE_PARAM,
2232 Build a new parser object with embedded `%code lexer'. There are
2233 no parameters, unless `%parse-param's and/or `%lex-param's are
2236 -- Constructor on YYParser: YYParser (Lexer LEXER, PARSE_PARAM, ...)
2237 Build a new parser object using the specified scanner. There are
2238 no additional parameters unless `%parse-param's are used.
2240 If the scanner is defined by `%code lexer', this constructor is
2241 declared `protected' and is called automatically with a scanner
2242 created with the correct `%lex-param's.
2244 -- Method on YYParser: boolean parse ()
2245 Run the syntactic analysis, and return `true' on success, `false'
2248 -- Method on YYParser: boolean recovering ()
2249 During the syntactic analysis, return `true' if recovering from a
2250 syntax error. *Note Error Recovery::.
2252 -- Method on YYParser: java.io.PrintStream getDebugStream ()
2253 -- Method on YYParser: void setDebugStream (java.io.printStream O)
2254 Get or set the stream used for tracing the parsing. It defaults to
2257 -- Method on YYParser: int getDebugLevel ()
2258 -- Method on YYParser: void setDebugLevel (int L)
2259 Get or set the tracing level. Currently its value is either 0, no
2260 trace, or nonzero, full tracing.
2263 File: bison.info, Node: Java Scanner Interface, Next: Java Action Features, Prev: Java Parser Interface, Up: Java Parsers
2265 10.2.5 Java Scanner Interface
2266 -----------------------------
2268 There are two possible ways to interface a Bison-generated Java parser
2269 with a scanner: the scanner may be defined by `%code lexer', or defined
2270 elsewhere. In either case, the scanner has to implement the `Lexer'
2271 inner interface of the parser class.
2273 In the first case, the body of the scanner class is placed in `%code
2274 lexer' blocks. If you want to pass parameters from the parser
2275 constructor to the scanner constructor, specify them with `%lex-param';
2276 they are passed before `%parse-param's to the constructor.
2278 In the second case, the scanner has to implement the `Lexer'
2279 interface, which is defined within the parser class (e.g.,
2280 `YYParser.Lexer'). The constructor of the parser object will then
2281 accept an object implementing the interface; `%lex-param' is not used
2284 In both cases, the scanner has to implement the following methods.
2286 -- Method on Lexer: void yyerror (Location LOC, String MSG)
2287 This method is defined by the user to emit an error message. The
2288 first parameter is omitted if location tracking is not active.
2289 Its type can be changed using `%define location_type "CLASS-NAME".'
2291 -- Method on Lexer: int yylex ()
2292 Return the next token. Its type is the return value, its semantic
2293 value and location are saved and returned by the their methods in
2296 Use `%define lex_throws' to specify any uncaught exceptions.
2297 Default is `java.io.IOException'.
2299 -- Method on Lexer: Position getStartPos ()
2300 -- Method on Lexer: Position getEndPos ()
2301 Return respectively the first position of the last token that
2302 `yylex' returned, and the first position beyond it. These methods
2303 are not needed unless location tracking is active.
2305 The return type can be changed using `%define position_type
2308 -- Method on Lexer: Object getLVal ()
2309 Return the semantic value of the last token that yylex returned.
2311 The return type can be changed using `%define stype "CLASS-NAME".'
2314 File: bison.info, Node: Java Action Features, Next: Java Differences, Prev: Java Scanner Interface, Up: Java Parsers
2316 10.2.6 Special Features for Use in Java Actions
2317 -----------------------------------------------
2319 The following special constructs can be uses in Java actions. Other
2320 analogous C action features are currently unavailable for Java.
2322 Use `%define throws' to specify any uncaught exceptions from parser
2323 actions, and initial actions specified by `%initial-action'.
2326 The semantic value for the Nth component of the current rule.
2327 This may not be assigned to. *Note Java Semantic Values::.
2329 -- Variable: $<TYPEALT>N
2330 Like `$N' but specifies a alternative type TYPEALT. *Note Java
2334 The semantic value for the grouping made by the current rule. As a
2335 value, this is in the base type (`Object' or as specified by
2336 `%define stype') as in not cast to the declared subtype because
2337 casts are not allowed on the left-hand side of Java assignments.
2338 Use an explicit Java cast if the correct subtype is needed. *Note
2339 Java Semantic Values::.
2341 -- Variable: $<TYPEALT>$
2342 Same as `$$' since Java always allow assigning to the base type.
2343 Perhaps we should use this and `$<>$' for the value and `$$' for
2344 setting the value but there is currently no easy way to distinguish
2345 these constructs. *Note Java Semantic Values::.
2348 The location information of the Nth component of the current rule.
2349 This may not be assigned to. *Note Java Location Values::.
2352 The location information of the grouping made by the current rule.
2353 *Note Java Location Values::.
2355 -- Statement: return YYABORT `;'
2356 Return immediately from the parser, indicating failure. *Note
2357 Java Parser Interface::.
2359 -- Statement: return YYACCEPT `;'
2360 Return immediately from the parser, indicating success. *Note
2361 Java Parser Interface::.
2363 -- Statement: return YYERROR `;'
2364 Start error recovery (without printing an error message). *Note
2367 -- Function: boolean recovering ()
2368 Return whether error recovery is being done. In this state, the
2369 parser reads token until it reaches a known state, and then
2370 restarts normal operation. *Note Error Recovery::.
2372 -- Function: protected void yyerror (String msg)
2373 -- Function: protected void yyerror (Position pos, String msg)
2374 -- Function: protected void yyerror (Location loc, String msg)
2375 Print an error message using the `yyerror' method of the scanner
2379 File: bison.info, Node: Java Differences, Next: Java Declarations Summary, Prev: Java Action Features, Up: Java Parsers
2381 10.2.7 Differences between C/C++ and Java Grammars
2382 --------------------------------------------------
2384 The different structure of the Java language forces several differences
2385 between C/C++ grammars, and grammars designed for Java parsers. This
2386 section summarizes these differences.
2388 * Java lacks a preprocessor, so the `YYERROR', `YYACCEPT', `YYABORT'
2389 symbols (*note Table of Symbols::) cannot obviously be macros.
2390 Instead, they should be preceded by `return' when they appear in
2391 an action. The actual definition of these symbols is opaque to
2392 the Bison grammar, and it might change in the future. The only
2393 meaningful operation that you can do, is to return them. *Note
2394 Java Action Features::.
2396 Note that of these three symbols, only `YYACCEPT' and `YYABORT'
2397 will cause a return from the `yyparse' method(1).
2399 * Java lacks unions, so `%union' has no effect. Instead, semantic
2400 values have a common base type: `Object' or as specified by
2401 `%define stype'. Angle brackets on `%token', `type', `$N' and
2402 `$$' specify subtypes rather than fields of an union. The type of
2403 `$$', even with angle brackets, is the base type since Java casts
2404 are not allow on the left-hand side of assignments. Also, `$N'
2405 and `@N' are not allowed on the left-hand side of assignments.
2406 *Note Java Semantic Values::, and *note Java Action Features::.
2408 * The prologue declarations have a different meaning than in C/C++
2411 blocks are placed at the beginning of the Java source code.
2412 They may include copyright notices. For a `package'
2413 declarations, it is suggested to use `%define package'
2417 blocks are placed inside the parser class.
2420 blocks, if specified, should include the implementation of the
2421 scanner. If there is no such block, the scanner can be any
2422 class that implements the appropriate interface (*note Java
2423 Scanner Interface::).
2425 Other `%code' blocks are not supported in Java parsers. In
2426 particular, `%{ ... %}' blocks should not be used and may give an
2427 error in future versions of Bison.
2429 The epilogue has the same meaning as in C/C++ code and it can be
2430 used to define other classes used by the parser _outside_ the
2433 ---------- Footnotes ----------
2435 (1) Java parsers include the actions in a separate method than
2436 `yyparse' in order to have an intuitive syntax that corresponds to
2440 File: bison.info, Node: Java Declarations Summary, Prev: Java Differences, Up: Java Parsers
2442 10.2.8 Java Declarations Summary
2443 --------------------------------
2445 This summary only include declarations specific to Java or have special
2446 meaning when used in a Java parser.
2448 -- Directive: %language "Java"
2449 Generate a Java class for the parser.
2451 -- Directive: %lex-param {TYPE NAME}
2452 A parameter for the lexer class defined by `%code lexer' _only_,
2453 added as parameters to the lexer constructor and the parser
2454 constructor that _creates_ a lexer. Default is none. *Note Java
2455 Scanner Interface::.
2457 -- Directive: %name-prefix "PREFIX"
2458 The prefix of the parser class name `PREFIXParser' if `%define
2459 parser_class_name' is not used. Default is `YY'. *Note Java
2462 -- Directive: %parse-param {TYPE NAME}
2463 A parameter for the parser class added as parameters to
2464 constructor(s) and as fields initialized by the constructor(s).
2465 Default is none. *Note Java Parser Interface::.
2467 -- Directive: %token <TYPE> TOKEN ...
2468 Declare tokens. Note that the angle brackets enclose a Java
2469 _type_. *Note Java Semantic Values::.
2471 -- Directive: %type <TYPE> NONTERMINAL ...
2472 Declare the type of nonterminals. Note that the angle brackets
2473 enclose a Java _type_. *Note Java Semantic Values::.
2475 -- Directive: %code { CODE ... }
2476 Code appended to the inside of the parser class. *Note Java
2479 -- Directive: %code imports { CODE ... }
2480 Code inserted just after the `package' declaration. *Note Java
2483 -- Directive: %code lexer { CODE ... }
2484 Code added to the body of a inner lexer class within the parser
2485 class. *Note Java Scanner Interface::.
2487 -- Directive: %% CODE ...
2488 Code (after the second `%%') appended to the end of the file,
2489 _outside_ the parser class. *Note Java Differences::.
2491 -- Directive: %{ CODE ... %}
2492 Not supported. Use `%code import' instead. *Note Java
2495 -- Directive: %define abstract
2496 Whether the parser class is declared `abstract'. Default is false.
2497 *Note Java Bison Interface::.
2499 -- Directive: %define extends "SUPERCLASS"
2500 The superclass of the parser class. Default is none. *Note Java
2503 -- Directive: %define final
2504 Whether the parser class is declared `final'. Default is false.
2505 *Note Java Bison Interface::.
2507 -- Directive: %define implements "INTERFACES"
2508 The implemented interfaces of the parser class, a comma-separated
2509 list. Default is none. *Note Java Bison Interface::.
2511 -- Directive: %define lex_throws "EXCEPTIONS"
2512 The exceptions thrown by the `yylex' method of the lexer, a
2513 comma-separated list. Default is `java.io.IOException'. *Note
2514 Java Scanner Interface::.
2516 -- Directive: %define location_type "CLASS"
2517 The name of the class used for locations (a range between two
2518 positions). This class is generated as an inner class of the
2519 parser class by `bison'. Default is `Location'. *Note Java
2522 -- Directive: %define package "PACKAGE"
2523 The package to put the parser class in. Default is none. *Note
2524 Java Bison Interface::.
2526 -- Directive: %define parser_class_name "NAME"
2527 The name of the parser class. Default is `YYParser' or
2528 `NAME-PREFIXParser'. *Note Java Bison Interface::.
2530 -- Directive: %define position_type "CLASS"
2531 The name of the class used for positions. This class must be
2532 supplied by the user. Default is `Position'. *Note Java Location
2535 -- Directive: %define public
2536 Whether the parser class is declared `public'. Default is false.
2537 *Note Java Bison Interface::.
2539 -- Directive: %define stype "CLASS"
2540 The base type of semantic values. Default is `Object'. *Note
2541 Java Semantic Values::.
2543 -- Directive: %define strictfp
2544 Whether the parser class is declared `strictfp'. Default is false.
2545 *Note Java Bison Interface::.
2547 -- Directive: %define throws "EXCEPTIONS"
2548 The exceptions thrown by user-supplied parser actions and
2549 `%initial-action', a comma-separated list. Default is none.
2550 *Note Java Parser Interface::.
2553 File: bison.info, Node: FAQ, Next: Table of Symbols, Prev: Other Languages, Up: Top
2555 11 Frequently Asked Questions
2556 *****************************
2558 Several questions about Bison come up occasionally. Here some of them
2563 * Memory Exhausted:: Breaking the Stack Limits
2564 * How Can I Reset the Parser:: `yyparse' Keeps some State
2565 * Strings are Destroyed:: `yylval' Loses Track of Strings
2566 * Implementing Gotos/Loops:: Control Flow in the Calculator
2567 * Multiple start-symbols:: Factoring closely related grammars
2568 * Secure? Conform?:: Is Bison POSIX safe?
2569 * I can't build Bison:: Troubleshooting
2570 * Where can I find help?:: Troubleshouting
2571 * Bug Reports:: Troublereporting
2572 * More Languages:: Parsers in C++, Java, and so on
2573 * Beta Testing:: Experimenting development versions
2574 * Mailing Lists:: Meeting other Bison users
2577 File: bison.info, Node: Memory Exhausted, Next: How Can I Reset the Parser, Up: FAQ
2579 11.1 Memory Exhausted
2580 =====================
2582 My parser returns with error with a `memory exhausted' message.
2585 This question is already addressed elsewhere, see *note Recursive
2589 File: bison.info, Node: How Can I Reset the Parser, Next: Strings are Destroyed, Prev: Memory Exhausted, Up: FAQ
2591 11.2 How Can I Reset the Parser
2592 ===============================
2594 The following phenomenon has several symptoms, resulting in the
2595 following typical questions:
2597 I invoke `yyparse' several times, and on correct input it works
2598 properly; but when a parse error is found, all the other calls fail
2599 too. How can I reset the error flag of `yyparse'?
2603 My parser includes support for an `#include'-like feature, in
2604 which case I run `yyparse' from `yyparse'. This fails although I
2605 did specify `%define api.pure'.
2607 These problems typically come not from Bison itself, but from
2608 Lex-generated scanners. Because these scanners use large buffers for
2609 speed, they might not notice a change of input file. As a
2610 demonstration, consider the following source file, `first-line.l':
2617 .*\n ECHO; return 1;
2620 yyparse (char const *file)
2622 yyin = fopen (file, "r");
2626 exit (EXIT_FAILURE);
2628 /* One token only. */
2630 if (fclose (yyin) != 0)
2633 exit (EXIT_FAILURE);
2646 If the file `input' contains
2651 then instead of getting the first line twice, you get:
2653 $ flex -ofirst-line.c first-line.l
2654 $ gcc -ofirst-line first-line.c -ll
2659 Therefore, whenever you change `yyin', you must tell the
2660 Lex-generated scanner to discard its current buffer and switch to the
2661 new one. This depends upon your implementation of Lex; see its
2662 documentation for more. For Flex, it suffices to call
2663 `YY_FLUSH_BUFFER' after each change to `yyin'. If your Flex-generated
2664 scanner needs to read from several input streams to handle features
2665 like include files, you might consider using Flex functions like
2666 `yy_switch_to_buffer' that manipulate multiple input buffers.
2668 If your Flex-generated scanner uses start conditions (*note Start
2669 conditions: (flex)Start conditions.), you might also want to reset the
2670 scanner's state, i.e., go back to the initial start condition, through
2671 a call to `BEGIN (0)'.
2674 File: bison.info, Node: Strings are Destroyed, Next: Implementing Gotos/Loops, Prev: How Can I Reset the Parser, Up: FAQ
2676 11.3 Strings are Destroyed
2677 ==========================
2679 My parser seems to destroy old strings, or maybe it loses track of
2680 them. Instead of reporting `"foo", "bar"', it reports `"bar",
2681 "bar"', or even `"foo\nbar", "bar"'.
2683 This error is probably the single most frequent "bug report" sent to
2684 Bison lists, but is only concerned with a misunderstanding of the role
2685 of the scanner. Consider the following Lex code:
2689 char *yylval = NULL;
2692 .* yylval = yytext; return 1;
2698 /* Similar to using $1, $2 in a Bison action. */
2699 char *fst = (yylex (), yylval);
2700 char *snd = (yylex (), yylval);
2701 printf ("\"%s\", \"%s\"\n", fst, snd);
2705 If you compile and run this code, you get:
2707 $ flex -osplit-lines.c split-lines.l
2708 $ gcc -osplit-lines split-lines.c -ll
2709 $ printf 'one\ntwo\n' | ./split-lines
2713 this is because `yytext' is a buffer provided for _reading_ in the
2714 action, but if you want to keep it, you have to duplicate it (e.g.,
2715 using `strdup'). Note that the output may depend on how your
2716 implementation of Lex handles `yytext'. For instance, when given the
2717 Lex compatibility option `-l' (which triggers the option `%array') Flex
2718 generates a different behavior:
2720 $ flex -l -osplit-lines.c split-lines.l
2721 $ gcc -osplit-lines split-lines.c -ll
2722 $ printf 'one\ntwo\n' | ./split-lines
2726 File: bison.info, Node: Implementing Gotos/Loops, Next: Multiple start-symbols, Prev: Strings are Destroyed, Up: FAQ
2728 11.4 Implementing Gotos/Loops
2729 =============================
2731 My simple calculator supports variables, assignments, and
2732 functions, but how can I implement gotos, or loops?
2734 Although very pedagogical, the examples included in the document blur
2735 the distinction to make between the parser--whose job is to recover the
2736 structure of a text and to transmit it to subsequent modules of the
2737 program--and the processing (such as the execution) of this structure.
2738 This works well with so called straight line programs, i.e., precisely
2739 those that have a straightforward execution model: execute simple
2740 instructions one after the others.
2742 If you want a richer model, you will probably need to use the parser
2743 to construct a tree that does represent the structure it has recovered;
2744 this tree is usually called the "abstract syntax tree", or "AST" for
2745 short. Then, walking through this tree, traversing it in various ways,
2746 will enable treatments such as its execution or its translation, which
2747 will result in an interpreter or a compiler.
2749 This topic is way beyond the scope of this manual, and the reader is
2750 invited to consult the dedicated literature.
2753 File: bison.info, Node: Multiple start-symbols, Next: Secure? Conform?, Prev: Implementing Gotos/Loops, Up: FAQ
2755 11.5 Multiple start-symbols
2756 ===========================
2758 I have several closely related grammars, and I would like to share
2759 their implementations. In fact, I could use a single grammar but
2760 with multiple entry points.
2762 Bison does not support multiple start-symbols, but there is a very
2763 simple means to simulate them. If `foo' and `bar' are the two pseudo
2764 start-symbols, then introduce two new tokens, say `START_FOO' and
2765 `START_BAR', and use them as switches from the real start-symbol:
2767 %token START_FOO START_BAR;
2773 These tokens prevents the introduction of new conflicts. As far as
2774 the parser goes, that is all that is needed.
2776 Now the difficult part is ensuring that the scanner will send these
2777 tokens first. If your scanner is hand-written, that should be
2778 straightforward. If your scanner is generated by Lex, them there is
2779 simple means to do it: recall that anything between `%{ ... %}' after
2780 the first `%%' is copied verbatim in the top of the generated `yylex'
2781 function. Make sure a variable `start_token' is available in the
2782 scanner (e.g., a global variable or using `%lex-param' etc.), and use
2790 int t = start_token;
2798 File: bison.info, Node: Secure? Conform?, Next: I can't build Bison, Prev: Multiple start-symbols, Up: FAQ
2800 11.6 Secure? Conform?
2801 ======================
2803 Is Bison secure? Does it conform to POSIX?
2805 If you're looking for a guarantee or certification, we don't provide
2806 it. However, Bison is intended to be a reliable program that conforms
2807 to the POSIX specification for Yacc. If you run into problems, please
2808 send us a bug report.
2811 File: bison.info, Node: I can't build Bison, Next: Where can I find help?, Prev: Secure? Conform?, Up: FAQ
2813 11.7 I can't build Bison
2814 ========================
2816 I can't build Bison because `make' complains that `msgfmt' is not
2817 found. What should I do?
2819 Like most GNU packages with internationalization support, that
2820 feature is turned on by default. If you have problems building in the
2821 `po' subdirectory, it indicates that your system's internationalization
2822 support is lacking. You can re-configure Bison with `--disable-nls' to
2823 turn off this support, or you can install GNU gettext from
2824 `ftp://ftp.gnu.org/gnu/gettext/' and re-configure Bison. See the file
2825 `ABOUT-NLS' for more information.
2828 File: bison.info, Node: Where can I find help?, Next: Bug Reports, Prev: I can't build Bison, Up: FAQ
2830 11.8 Where can I find help?
2831 ===========================
2833 I'm having trouble using Bison. Where can I find help?
2835 First, read this fine manual. Beyond that, you can send mail to
2836 <help-bison@gnu.org>. This mailing list is intended to be populated
2837 with people who are willing to answer questions about using and
2838 installing Bison. Please keep in mind that (most of) the people on the
2839 list have aspects of their lives which are not related to Bison (!), so
2840 you may not receive an answer to your question right away. This can be
2841 frustrating, but please try not to honk them off; remember that any
2842 help they provide is purely voluntary and out of the kindness of their
2846 File: bison.info, Node: Bug Reports, Next: More Languages, Prev: Where can I find help?, Up: FAQ
2851 I found a bug. What should I include in the bug report?
2853 Before you send a bug report, make sure you are using the latest
2854 version. Check `ftp://ftp.gnu.org/pub/gnu/bison/' or one of its
2855 mirrors. Be sure to include the version number in your bug report. If
2856 the bug is present in the latest version but not in a previous version,
2857 try to determine the most recent version which did not contain the bug.
2859 If the bug is parser-related, you should include the smallest grammar
2860 you can which demonstrates the bug. The grammar file should also be
2861 complete (i.e., I should be able to run it through Bison without having
2862 to edit or add anything). The smaller and simpler the grammar, the
2863 easier it will be to fix the bug.
2865 Include information about your compilation environment, including
2866 your operating system's name and version and your compiler's name and
2867 version. If you have trouble compiling, you should also include a
2868 transcript of the build session, starting with the invocation of
2869 `configure'. Depending on the nature of the bug, you may be asked to
2870 send additional files as well (such as `config.h' or `config.cache').
2872 Patches are most welcome, but not required. That is, do not
2873 hesitate to send a bug report just because you cannot provide a fix.
2875 Send bug reports to <bug-bison@gnu.org>.
2878 File: bison.info, Node: More Languages, Next: Beta Testing, Prev: Bug Reports, Up: FAQ
2880 11.10 More Languages
2881 ====================
2883 Will Bison ever have C++ and Java support? How about INSERT YOUR
2884 FAVORITE LANGUAGE HERE?
2886 C++ and Java support is there now, and is documented. We'd love to
2887 add other languages; contributions are welcome.
2890 File: bison.info, Node: Beta Testing, Next: Mailing Lists, Prev: More Languages, Up: FAQ
2895 What is involved in being a beta tester?
2897 It's not terribly involved. Basically, you would download a test
2898 release, compile it, and use it to build and run a parser or two. After
2899 that, you would submit either a bug report or a message saying that
2900 everything is okay. It is important to report successes as well as
2901 failures because test releases eventually become mainstream releases,
2902 but only if they are adequately tested. If no one tests, development is
2905 Beta testers are particularly needed for operating systems to which
2906 the developers do not have easy access. They currently have easy
2907 access to recent GNU/Linux and Solaris versions. Reports about other
2908 operating systems are especially welcome.
2911 File: bison.info, Node: Mailing Lists, Prev: Beta Testing, Up: FAQ
2916 How do I join the help-bison and bug-bison mailing lists?
2918 See `http://lists.gnu.org/'.
2921 File: bison.info, Node: Table of Symbols, Next: Glossary, Prev: FAQ, Up: Top
2923 Annexe A Bison Symbols
2924 **********************
2927 In an action, the location of the left-hand side of the rule.
2928 *Note Tracking Locations::.
2931 In an action, the location of the N-th symbol of the right-hand
2932 side of the rule. *Note Tracking Locations::.
2935 In an action, the location of a symbol addressed by name. *Note
2936 Tracking Locations::.
2938 -- Variable: @[NAME]
2939 In an action, the location of a symbol addressed by name. *Note
2940 Tracking Locations::.
2943 In an action, the semantic value of the left-hand side of the rule.
2947 In an action, the semantic value of the N-th symbol of the
2948 right-hand side of the rule. *Note Actions::.
2951 In an action, the semantic value of a symbol addressed by name.
2954 -- Variable: $[NAME]
2955 In an action, the semantic value of a symbol addressed by name.
2959 Delimiter used to separate the grammar rule section from the Bison
2960 declarations section or the epilogue. *Note The Overall Layout of
2961 a Bison Grammar: Grammar Layout.
2963 -- Delimiter: %{CODE%}
2964 All code listed between `%{' and `%}' is copied verbatim to the
2965 parser implementation file. Such code forms the prologue of the
2966 grammar file. *Note Outline of a Bison Grammar: Grammar Outline.
2968 -- Construct: /*...*/
2969 Comment delimiters, as in C.
2972 Separates a rule's result from its components. *Note Syntax of
2973 Grammar Rules: Rules.
2976 Terminates a rule. *Note Syntax of Grammar Rules: Rules.
2979 Separates alternate rules for the same result nonterminal. *Note
2980 Syntax of Grammar Rules: Rules.
2983 Used to define a default tagged `%destructor' or default tagged
2986 This feature is experimental. More user feedback will help to
2987 determine whether it should become a permanent feature.
2989 *Note Freeing Discarded Symbols: Destructor Decl.
2992 Used to define a default tagless `%destructor' or default tagless
2995 This feature is experimental. More user feedback will help to
2996 determine whether it should become a permanent feature.
2998 *Note Freeing Discarded Symbols: Destructor Decl.
3001 The predefined nonterminal whose only rule is `$accept: START
3002 $end', where START is the start symbol. *Note The Start-Symbol:
3003 Start Decl. It cannot be used in the grammar.
3005 -- Directive: %code {CODE}
3006 -- Directive: %code QUALIFIER {CODE}
3007 Insert CODE verbatim into the output parser source at the default
3008 location or at the location specified by QUALIFIER. *Note %code
3011 -- Directive: %debug
3012 Equip the parser for debugging. *Note Decl Summary::.
3014 -- Directive: %define VARIABLE
3015 -- Directive: %define VARIABLE VALUE
3016 -- Directive: %define VARIABLE "VALUE"
3017 Define a variable to adjust Bison's behavior. *Note %define
3020 -- Directive: %defines
3021 Bison declaration to create a parser header file, which is usually
3022 meant for the scanner. *Note Decl Summary::.
3024 -- Directive: %defines DEFINES-FILE
3025 Same as above, but save in the file DEFINES-FILE. *Note Decl
3028 -- Directive: %destructor
3029 Specify how the parser should reclaim the memory associated to
3030 discarded symbols. *Note Freeing Discarded Symbols: Destructor
3033 -- Directive: %dprec
3034 Bison declaration to assign a precedence to a rule that is used at
3035 parse time to resolve reduce/reduce conflicts. *Note Writing GLR
3036 Parsers: GLR Parsers.
3039 The predefined token marking the end of the token stream. It
3040 cannot be used in the grammar.
3043 A token name reserved for error recovery. This token may be used
3044 in grammar rules so as to allow the Bison parser to recognize an
3045 error in the grammar without halting the process. In effect, a
3046 sentence containing an error may be recognized as valid. On a
3047 syntax error, the token `error' becomes the current lookahead
3048 token. Actions corresponding to `error' are then executed, and
3049 the lookahead token is reset to the token that originally caused
3050 the violation. *Note Error Recovery::.
3052 -- Directive: %error-verbose
3053 Bison declaration to request verbose, specific error message
3054 strings when `yyerror' is called. *Note Error Reporting::.
3056 -- Directive: %file-prefix "PREFIX"
3057 Bison declaration to set the prefix of the output files. *Note
3060 -- Directive: %glr-parser
3061 Bison declaration to produce a GLR parser. *Note Writing GLR
3062 Parsers: GLR Parsers.
3064 -- Directive: %initial-action
3065 Run user code before parsing. *Note Performing Actions before
3066 Parsing: Initial Action Decl.
3068 -- Directive: %language
3069 Specify the programming language for the generated parser. *Note
3073 Bison declaration to assign left associativity to token(s). *Note
3074 Operator Precedence: Precedence Decl.
3076 -- Directive: %lex-param {ARGUMENT-DECLARATION}
3077 Bison declaration to specifying an additional parameter that
3078 `yylex' should accept. *Note Calling Conventions for Pure
3079 Parsers: Pure Calling.
3081 -- Directive: %merge
3082 Bison declaration to assign a merging function to a rule. If
3083 there is a reduce/reduce conflict with a rule having the same
3084 merging function, the function is applied to the two semantic
3085 values to get a single result. *Note Writing GLR Parsers: GLR
3088 -- Directive: %name-prefix "PREFIX"
3089 Obsoleted by the `%define' variable `api.prefix' (*note Multiple
3090 Parsers in the Same Program: Multiple Parsers.).
3092 Rename the external symbols (variables and functions) used in the
3093 parser so that they start with PREFIX instead of `yy'. Contrary to
3094 `api.prefix', do no rename types and macros.
3096 The precise list of symbols renamed in C parsers is `yyparse',
3097 `yylex', `yyerror', `yynerrs', `yylval', `yychar', `yydebug', and
3098 (if locations are used) `yylloc'. If you use a push parser,
3099 `yypush_parse', `yypull_parse', `yypstate', `yypstate_new' and
3100 `yypstate_delete' will also be renamed. For example, if you use
3101 `%name-prefix "c_"', the names become `c_parse', `c_lex', and so
3102 on. For C++ parsers, see the `%define namespace' documentation in
3105 -- Directive: %no-lines
3106 Bison declaration to avoid generating `#line' directives in the
3107 parser implementation file. *Note Decl Summary::.
3109 -- Directive: %nonassoc
3110 Bison declaration to assign nonassociativity to token(s). *Note
3111 Operator Precedence: Precedence Decl.
3113 -- Directive: %output "FILE"
3114 Bison declaration to set the name of the parser implementation
3115 file. *Note Decl Summary::.
3117 -- Directive: %parse-param {ARGUMENT-DECLARATION}
3118 Bison declaration to specifying an additional parameter that
3119 `yyparse' should accept. *Note The Parser Function `yyparse':
3123 Bison declaration to assign a precedence to a specific rule.
3124 *Note Context-Dependent Precedence: Contextual Precedence.
3126 -- Directive: %pure-parser
3127 Deprecated version of `%define api.pure' (*note api.pure: %define
3128 Summary.), for which Bison is more careful to warn about
3131 -- Directive: %require "VERSION"
3132 Require version VERSION or higher of Bison. *Note Require a
3133 Version of Bison: Require Decl.
3135 -- Directive: %right
3136 Bison declaration to assign right associativity to token(s).
3137 *Note Operator Precedence: Precedence Decl.
3139 -- Directive: %skeleton
3140 Specify the skeleton to use; usually for development. *Note Decl
3143 -- Directive: %start
3144 Bison declaration to specify the start symbol. *Note The
3145 Start-Symbol: Start Decl.
3147 -- Directive: %token
3148 Bison declaration to declare token(s) without specifying
3149 precedence. *Note Token Type Names: Token Decl.
3151 -- Directive: %token-table
3152 Bison declaration to include a token name table in the parser
3153 implementation file. *Note Decl Summary::.
3156 Bison declaration to declare nonterminals. *Note Nonterminal
3159 -- Symbol: $undefined
3160 The predefined token onto which all undefined values returned by
3161 `yylex' are mapped. It cannot be used in the grammar, rather, use
3164 -- Directive: %union
3165 Bison declaration to specify several possible data types for
3166 semantic values. *Note The Collection of Value Types: Union Decl.
3169 Macro to pretend that an unrecoverable syntax error has occurred,
3170 by making `yyparse' return 1 immediately. The error reporting
3171 function `yyerror' is not called. *Note The Parser Function
3172 `yyparse': Parser Function.
3174 For Java parsers, this functionality is invoked using `return
3178 Macro to pretend that a complete utterance of the language has been
3179 read, by making `yyparse' return 0 immediately. *Note The Parser
3180 Function `yyparse': Parser Function.
3182 For Java parsers, this functionality is invoked using `return
3186 Macro to discard a value from the parser stack and fake a lookahead
3187 token. *Note Special Features for Use in Actions: Action Features.
3190 External integer variable that contains the integer value of the
3191 lookahead token. (In a pure parser, it is a local variable within
3192 `yyparse'.) Error-recovery rule actions may examine this variable.
3193 *Note Special Features for Use in Actions: Action Features.
3195 -- Variable: yyclearin
3196 Macro used in error-recovery rule actions. It clears the previous
3197 lookahead token. *Note Error Recovery::.
3200 Macro to define to equip the parser with tracing code. *Note
3201 Tracing Your Parser: Tracing.
3203 -- Variable: yydebug
3204 External integer variable set to zero by default. If `yydebug' is
3205 given a nonzero value, the parser will output information on input
3206 symbols and parser action. *Note Tracing Your Parser: Tracing.
3209 Macro to cause parser to recover immediately to its normal mode
3210 after a syntax error. *Note Error Recovery::.
3213 Cause an immediate syntax error. This statement initiates error
3214 recovery just as if the parser itself had detected an error;
3215 however, it does not call `yyerror', and does not print any
3216 message. If you want to print an error message, call `yyerror'
3217 explicitly before the `YYERROR;' statement. *Note Error
3220 For Java parsers, this functionality is invoked using `return
3223 -- Function: yyerror
3224 User-supplied function to be called by `yyparse' on error. *Note
3225 The Error Reporting Function `yyerror': Error Reporting.
3227 -- Macro: YYERROR_VERBOSE
3228 An obsolete macro that you define with `#define' in the prologue
3229 to request verbose, specific error message strings when `yyerror'
3230 is called. It doesn't matter what definition you use for
3231 `YYERROR_VERBOSE', just whether you define it. Supported by the C
3232 skeletons only; using `%error-verbose' is preferred. *Note Error
3236 Macro used to output run-time traces. *Note Enabling Traces::.
3238 -- Macro: YYINITDEPTH
3239 Macro for specifying the initial size of the parser stack. *Note
3240 Memory Management::.
3243 User-supplied lexical analyzer function, called with no arguments
3244 to get the next token. *Note The Lexical Analyzer Function
3247 -- Macro: YYLEX_PARAM
3248 An obsolete macro for specifying an extra argument (or list of
3249 extra arguments) for `yyparse' to pass to `yylex'. The use of this
3250 macro is deprecated, and is supported only for Yacc like parsers.
3251 *Note Calling Conventions for Pure Parsers: Pure Calling.
3254 External variable in which `yylex' should place the line and column
3255 numbers associated with a token. (In a pure parser, it is a local
3256 variable within `yyparse', and its address is passed to `yylex'.)
3257 You can ignore this variable if you don't use the `@' feature in
3258 the grammar actions. *Note Textual Locations of Tokens: Token
3259 Locations. In semantic actions, it stores the location of the
3260 lookahead token. *Note Actions and Locations: Actions and
3264 Data type of `yylloc'; by default, a structure with four members.
3265 *Note Data Types of Locations: Location Type.
3268 External variable in which `yylex' should place the semantic value
3269 associated with a token. (In a pure parser, it is a local
3270 variable within `yyparse', and its address is passed to `yylex'.)
3271 *Note Semantic Values of Tokens: Token Values. In semantic
3272 actions, it stores the semantic value of the lookahead token.
3273 *Note Actions: Actions.
3275 -- Macro: YYMAXDEPTH
3276 Macro for specifying the maximum size of the parser stack. *Note
3277 Memory Management::.
3279 -- Variable: yynerrs
3280 Global variable which Bison increments each time it reports a
3281 syntax error. (In a pure parser, it is a local variable within
3282 `yyparse'. In a pure push parser, it is a member of yypstate.)
3283 *Note The Error Reporting Function `yyerror': Error Reporting.
3285 -- Function: yyparse
3286 The parser function produced by Bison; call this function to start
3287 parsing. *Note The Parser Function `yyparse': Parser Function.
3290 Macro used to output token semantic values. For `yacc.c' only.
3291 Obsoleted by `%printer'. *Note The `YYPRINT' Macro: The YYPRINT
3294 -- Function: yypstate_delete
3295 The function to delete a parser instance, produced by Bison in
3296 push mode; call this function to delete the memory associated with
3297 a parser. *Note The Parser Delete Function `yypstate_delete':
3298 Parser Delete Function. (The current push parsing interface is
3299 experimental and may evolve. More user feedback will help to
3302 -- Function: yypstate_new
3303 The function to create a parser instance, produced by Bison in
3304 push mode; call this function to create a new parser. *Note The
3305 Parser Create Function `yypstate_new': Parser Create Function.
3306 (The current push parsing interface is experimental and may evolve.
3307 More user feedback will help to stabilize it.)
3309 -- Function: yypull_parse
3310 The parser function produced by Bison in push mode; call this
3311 function to parse the rest of the input stream. *Note The Pull
3312 Parser Function `yypull_parse': Pull Parser Function. (The
3313 current push parsing interface is experimental and may evolve.
3314 More user feedback will help to stabilize it.)
3316 -- Function: yypush_parse
3317 The parser function produced by Bison in push mode; call this
3318 function to parse a single token. *Note The Push Parser Function
3319 `yypush_parse': Push Parser Function. (The current push parsing
3320 interface is experimental and may evolve. More user feedback will
3321 help to stabilize it.)
3323 -- Macro: YYPARSE_PARAM
3324 An obsolete macro for specifying the name of a parameter that
3325 `yyparse' should accept. The use of this macro is deprecated, and
3326 is supported only for Yacc like parsers. *Note Calling
3327 Conventions for Pure Parsers: Pure Calling.
3329 -- Macro: YYRECOVERING
3330 The expression `YYRECOVERING ()' yields 1 when the parser is
3331 recovering from a syntax error, and 0 otherwise. *Note Special
3332 Features for Use in Actions: Action Features.
3334 -- Macro: YYSTACK_USE_ALLOCA
3335 Macro used to control the use of `alloca' when the deterministic
3336 parser in C needs to extend its stacks. If defined to 0, the
3337 parser will use `malloc' to extend its stacks. If defined to 1,
3338 the parser will use `alloca'. Values other than 0 and 1 are
3339 reserved for future Bison extensions. If not defined,
3340 `YYSTACK_USE_ALLOCA' defaults to 0.
3342 In the all-too-common case where your code may run on a host with a
3343 limited stack and with unreliable stack-overflow checking, you
3344 should set `YYMAXDEPTH' to a value that cannot possibly result in
3345 unchecked stack overflow on any of your target hosts when `alloca'
3346 is called. You can inspect the code that Bison generates in order
3347 to determine the proper numeric values. This will require some
3348 expertise in low-level implementation details.
3351 Data type of semantic values; `int' by default. *Note Data Types
3352 of Semantic Values: Value Type.
3355 File: bison.info, Node: Glossary, Next: Copying This Manual, Prev: Table of Symbols, Up: Top
3361 A state whose only action is the accept action. The accepting
3362 state is thus a consistent state. *Note Understanding::.
3364 Backus-Naur Form (BNF; also called "Backus Normal Form")
3365 Formal method of specifying context-free grammars originally
3366 proposed by John Backus, and slightly improved by Peter Naur in
3367 his 1960-01-02 committee document contributing to what became the
3368 Algol 60 report. *Note Languages and Context-Free Grammars:
3369 Language and Grammar.
3372 A state containing only one possible action. *Note Default
3375 Context-free grammars
3376 Grammars specified as rules that can be applied regardless of
3377 context. Thus, if there is a rule which says that an integer can
3378 be used as an expression, integers are allowed _anywhere_ an
3379 expression is permitted. *Note Languages and Context-Free
3380 Grammars: Language and Grammar.
3383 The reduction that a parser should perform if the current parser
3384 state contains no other action for the lookahead token. In
3385 permitted parser states, Bison declares the reduction with the
3386 largest lookahead set to be the default reduction and removes that
3387 lookahead set. *Note Default Reductions::.
3390 A consistent state with a default reduction. *Note Default
3394 Allocation of memory that occurs during execution, rather than at
3395 compile time or on entry to a function.
3398 Analogous to the empty set in set theory, the empty string is a
3399 character string of length zero.
3401 Finite-state stack machine
3402 A "machine" that has discrete states in which it is said to exist
3403 at each instant in time. As input to the machine is processed, the
3404 machine moves from state to state as specified by the logic of the
3405 machine. In the case of the parser, the input is the language
3406 being parsed, and the states correspond to various stages in the
3407 grammar rules. *Note The Bison Parser Algorithm: Algorithm.
3409 Generalized LR (GLR)
3410 A parsing algorithm that can handle all context-free grammars,
3411 including those that are not LR(1). It resolves situations that
3412 Bison's deterministic parsing algorithm cannot by effectively
3413 splitting off multiple parsers, trying all possible parsers, and
3414 discarding those that fail in the light of additional right
3415 context. *Note Generalized LR Parsing: Generalized LR Parsing.
3418 A language construct that is (in general) grammatically divisible;
3419 for example, `expression' or `declaration' in C. *Note Languages
3420 and Context-Free Grammars: Language and Grammar.
3422 IELR(1) (Inadequacy Elimination LR(1))
3423 A minimal LR(1) parser table construction algorithm. That is,
3424 given any context-free grammar, IELR(1) generates parser tables
3425 with the full language-recognition power of canonical LR(1) but
3426 with nearly the same number of parser states as LALR(1). This
3427 reduction in parser states is often an order of magnitude. More
3428 importantly, because canonical LR(1)'s extra parser states may
3429 contain duplicate conflicts in the case of non-LR(1) grammars, the
3430 number of conflicts for IELR(1) is often an order of magnitude
3431 less as well. This can significantly reduce the complexity of
3432 developing a grammar. *Note LR Table Construction::.
3435 An arithmetic operator that is placed between the operands on
3436 which it performs some operation.
3439 A continuous flow of data between devices or programs.
3441 LAC (Lookahead Correction)
3442 A parsing mechanism that fixes the problem of delayed syntax error
3443 detection, which is caused by LR state merging, default
3444 reductions, and the use of `%nonassoc'. Delayed syntax error
3445 detection results in unexpected semantic actions, initiation of
3446 error recovery in the wrong syntactic context, and an incorrect
3447 list of expected tokens in a verbose syntax error message. *Note
3451 One of the typical usage schemas of the language. For example,
3452 one of the constructs of the C language is the `if' statement.
3453 *Note Languages and Context-Free Grammars: Language and Grammar.
3456 Operators having left associativity are analyzed from left to
3457 right: `a+b+c' first computes `a+b' and then combines with `c'.
3458 *Note Operator Precedence: Precedence.
3461 A rule whose result symbol is also its first component symbol; for
3462 example, `expseq1 : expseq1 ',' exp;'. *Note Recursive Rules:
3465 Left-to-right parsing
3466 Parsing a sentence of a language by analyzing it token by token
3467 from left to right. *Note The Bison Parser Algorithm: Algorithm.
3469 Lexical analyzer (scanner)
3470 A function that reads an input stream and returns tokens one by
3471 one. *Note The Lexical Analyzer Function `yylex': Lexical.
3474 A flag, set by actions in the grammar rules, which alters the way
3475 tokens are parsed. *Note Lexical Tie-ins::.
3477 Literal string token
3478 A token which consists of two or more fixed characters. *Note
3482 A token already read but not yet shifted. *Note Lookahead Tokens:
3486 The class of context-free grammars that Bison (like most other
3487 parser generators) can handle by default; a subset of LR(1).
3488 *Note Mysterious Conflicts::.
3491 The class of context-free grammars in which at most one token of
3492 lookahead is needed to disambiguate the parsing of any piece of
3496 A grammar symbol standing for a grammatical construct that can be
3497 expressed through rules in terms of smaller constructs; in other
3498 words, a construct that is not a token. *Note Symbols::.
3501 A function that recognizes valid sentences of a language by
3502 analyzing the syntax structure of a set of tokens passed to it
3503 from a lexical analyzer.
3506 An arithmetic operator that is placed after the operands upon
3507 which it performs some operation.
3510 Replacing a string of nonterminals and/or terminals with a single
3511 nonterminal, according to a grammar rule. *Note The Bison Parser
3512 Algorithm: Algorithm.
3515 A reentrant subprogram is a subprogram which can be in invoked any
3516 number of times in parallel, without interference between the
3517 various invocations. *Note A Pure (Reentrant) Parser: Pure Decl.
3519 Reverse polish notation
3520 A language in which all operators are postfix operators.
3523 A rule whose result symbol is also its last component symbol; for
3524 example, `expseq1: exp ',' expseq1;'. *Note Recursive Rules:
3528 In computer languages, the semantics are specified by the actions
3529 taken for each instance of the language, i.e., the meaning of each
3530 statement. *Note Defining Language Semantics: Semantics.
3533 A parser is said to shift when it makes the choice of analyzing
3534 further input from the stream rather than reducing immediately some
3535 already-recognized rule. *Note The Bison Parser Algorithm:
3538 Single-character literal
3539 A single character that is recognized and interpreted as is.
3540 *Note From Formal Rules to Bison Input: Grammar in Bison.
3543 The nonterminal symbol that stands for a complete valid utterance
3544 in the language being parsed. The start symbol is usually listed
3545 as the first nonterminal symbol in a language specification.
3546 *Note The Start-Symbol: Start Decl.
3549 A data structure where symbol names and associated data are stored
3550 during parsing to allow for recognition and use of existing
3551 information in repeated uses of a symbol. *Note Multi-function
3555 An error encountered during parsing of an input stream due to
3556 invalid syntax. *Note Error Recovery::.
3559 A basic, grammatically indivisible unit of a language. The symbol
3560 that describes a token in the grammar is a terminal symbol. The
3561 input of the Bison parser is a stream of tokens which comes from
3562 the lexical analyzer. *Note Symbols::.
3565 A grammar symbol that has no rules in the grammar and therefore is
3566 grammatically indivisible. The piece of text it represents is a
3567 token. *Note Languages and Context-Free Grammars: Language and
3571 A parser state to which there does not exist a sequence of
3572 transitions from the parser's start state. A state can become
3573 unreachable during conflict resolution. *Note Unreachable
3577 File: bison.info, Node: Copying This Manual, Next: Bibliography, Prev: Glossary, Up: Top
3579 Annexe C Copying This Manual
3580 ****************************
3582 Version 1.3, 3 November 2008
3584 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
3587 Everyone is permitted to copy and distribute verbatim copies
3588 of this license document, but changing it is not allowed.
3592 The purpose of this License is to make a manual, textbook, or other
3593 functional and useful document "free" in the sense of freedom: to
3594 assure everyone the effective freedom to copy and redistribute it,
3595 with or without modifying it, either commercially or
3596 noncommercially. Secondarily, this License preserves for the
3597 author and publisher a way to get credit for their work, while not
3598 being considered responsible for modifications made by others.
3600 This License is a kind of "copyleft", which means that derivative
3601 works of the document must themselves be free in the same sense.
3602 It complements the GNU General Public License, which is a copyleft
3603 license designed for free software.
3605 We have designed this License in order to use it for manuals for
3606 free software, because free software needs free documentation: a
3607 free program should come with manuals providing the same freedoms
3608 that the software does. But this License is not limited to
3609 software manuals; it can be used for any textual work, regardless
3610 of subject matter or whether it is published as a printed book.
3611 We recommend this License principally for works whose purpose is
3612 instruction or reference.
3614 1. APPLICABILITY AND DEFINITIONS
3616 This License applies to any manual or other work, in any medium,
3617 that contains a notice placed by the copyright holder saying it
3618 can be distributed under the terms of this License. Such a notice
3619 grants a world-wide, royalty-free license, unlimited in duration,
3620 to use that work under the conditions stated herein. The
3621 "Document", below, refers to any such manual or work. Any member
3622 of the public is a licensee, and is addressed as "you". You
3623 accept the license if you copy, modify or distribute the work in a
3624 way requiring permission under copyright law.
3626 A "Modified Version" of the Document means any work containing the
3627 Document or a portion of it, either copied verbatim, or with
3628 modifications and/or translated into another language.
3630 A "Secondary Section" is a named appendix or a front-matter section
3631 of the Document that deals exclusively with the relationship of the
3632 publishers or authors of the Document to the Document's overall
3633 subject (or to related matters) and contains nothing that could
3634 fall directly within that overall subject. (Thus, if the Document
3635 is in part a textbook of mathematics, a Secondary Section may not
3636 explain any mathematics.) The relationship could be a matter of
3637 historical connection with the subject or with related matters, or
3638 of legal, commercial, philosophical, ethical or political position
3641 The "Invariant Sections" are certain Secondary Sections whose
3642 titles are designated, as being those of Invariant Sections, in
3643 the notice that says that the Document is released under this
3644 License. If a section does not fit the above definition of
3645 Secondary then it is not allowed to be designated as Invariant.
3646 The Document may contain zero Invariant Sections. If the Document
3647 does not identify any Invariant Sections then there are none.
3649 The "Cover Texts" are certain short passages of text that are
3650 listed, as Front-Cover Texts or Back-Cover Texts, in the notice
3651 that says that the Document is released under this License. A
3652 Front-Cover Text may be at most 5 words, and a Back-Cover Text may
3653 be at most 25 words.
3655 A "Transparent" copy of the Document means a machine-readable copy,
3656 represented in a format whose specification is available to the
3657 general public, that is suitable for revising the document
3658 straightforwardly with generic text editors or (for images
3659 composed of pixels) generic paint programs or (for drawings) some
3660 widely available drawing editor, and that is suitable for input to
3661 text formatters or for automatic translation to a variety of
3662 formats suitable for input to text formatters. A copy made in an
3663 otherwise Transparent file format whose markup, or absence of
3664 markup, has been arranged to thwart or discourage subsequent
3665 modification by readers is not Transparent. An image format is
3666 not Transparent if used for any substantial amount of text. A
3667 copy that is not "Transparent" is called "Opaque".
3669 Examples of suitable formats for Transparent copies include plain
3670 ASCII without markup, Texinfo input format, LaTeX input format,
3671 SGML or XML using a publicly available DTD, and
3672 standard-conforming simple HTML, PostScript or PDF designed for
3673 human modification. Examples of transparent image formats include
3674 PNG, XCF and JPG. Opaque formats include proprietary formats that
3675 can be read and edited only by proprietary word processors, SGML or
3676 XML for which the DTD and/or processing tools are not generally
3677 available, and the machine-generated HTML, PostScript or PDF
3678 produced by some word processors for output purposes only.
3680 The "Title Page" means, for a printed book, the title page itself,
3681 plus such following pages as are needed to hold, legibly, the
3682 material this License requires to appear in the title page. For
3683 works in formats which do not have any title page as such, "Title
3684 Page" means the text near the most prominent appearance of the
3685 work's title, preceding the beginning of the body of the text.
3687 The "publisher" means any person or entity that distributes copies
3688 of the Document to the public.
3690 A section "Entitled XYZ" means a named subunit of the Document
3691 whose title either is precisely XYZ or contains XYZ in parentheses
3692 following text that translates XYZ in another language. (Here XYZ
3693 stands for a specific section name mentioned below, such as
3694 "Acknowledgements", "Dedications", "Endorsements", or "History".)
3695 To "Preserve the Title" of such a section when you modify the
3696 Document means that it remains a section "Entitled XYZ" according
3699 The Document may include Warranty Disclaimers next to the notice
3700 which states that this License applies to the Document. These
3701 Warranty Disclaimers are considered to be included by reference in
3702 this License, but only as regards disclaiming warranties: any other
3703 implication that these Warranty Disclaimers may have is void and
3704 has no effect on the meaning of this License.
3708 You may copy and distribute the Document in any medium, either
3709 commercially or noncommercially, provided that this License, the
3710 copyright notices, and the license notice saying this License
3711 applies to the Document are reproduced in all copies, and that you
3712 add no other conditions whatsoever to those of this License. You
3713 may not use technical measures to obstruct or control the reading
3714 or further copying of the copies you make or distribute. However,
3715 you may accept compensation in exchange for copies. If you
3716 distribute a large enough number of copies you must also follow
3717 the conditions in section 3.
3719 You may also lend copies, under the same conditions stated above,
3720 and you may publicly display copies.
3722 3. COPYING IN QUANTITY
3724 If you publish printed copies (or copies in media that commonly
3725 have printed covers) of the Document, numbering more than 100, and
3726 the Document's license notice requires Cover Texts, you must
3727 enclose the copies in covers that carry, clearly and legibly, all
3728 these Cover Texts: Front-Cover Texts on the front cover, and
3729 Back-Cover Texts on the back cover. Both covers must also clearly
3730 and legibly identify you as the publisher of these copies. The
3731 front cover must present the full title with all words of the
3732 title equally prominent and visible. You may add other material
3733 on the covers in addition. Copying with changes limited to the
3734 covers, as long as they preserve the title of the Document and
3735 satisfy these conditions, can be treated as verbatim copying in
3738 If the required texts for either cover are too voluminous to fit
3739 legibly, you should put the first ones listed (as many as fit
3740 reasonably) on the actual cover, and continue the rest onto
3743 If you publish or distribute Opaque copies of the Document
3744 numbering more than 100, you must either include a
3745 machine-readable Transparent copy along with each Opaque copy, or
3746 state in or with each Opaque copy a computer-network location from
3747 which the general network-using public has access to download
3748 using public-standard network protocols a complete Transparent
3749 copy of the Document, free of added material. If you use the
3750 latter option, you must take reasonably prudent steps, when you
3751 begin distribution of Opaque copies in quantity, to ensure that
3752 this Transparent copy will remain thus accessible at the stated
3753 location until at least one year after the last time you
3754 distribute an Opaque copy (directly or through your agents or
3755 retailers) of that edition to the public.
3757 It is requested, but not required, that you contact the authors of
3758 the Document well before redistributing any large number of
3759 copies, to give them a chance to provide you with an updated
3760 version of the Document.
3764 You may copy and distribute a Modified Version of the Document
3765 under the conditions of sections 2 and 3 above, provided that you
3766 release the Modified Version under precisely this License, with
3767 the Modified Version filling the role of the Document, thus
3768 licensing distribution and modification of the Modified Version to
3769 whoever possesses a copy of it. In addition, you must do these
3770 things in the Modified Version:
3772 A. Use in the Title Page (and on the covers, if any) a title
3773 distinct from that of the Document, and from those of
3774 previous versions (which should, if there were any, be listed
3775 in the History section of the Document). You may use the
3776 same title as a previous version if the original publisher of
3777 that version gives permission.
3779 B. List on the Title Page, as authors, one or more persons or
3780 entities responsible for authorship of the modifications in
3781 the Modified Version, together with at least five of the
3782 principal authors of the Document (all of its principal
3783 authors, if it has fewer than five), unless they release you
3784 from this requirement.
3786 C. State on the Title page the name of the publisher of the
3787 Modified Version, as the publisher.
3789 D. Preserve all the copyright notices of the Document.
3791 E. Add an appropriate copyright notice for your modifications
3792 adjacent to the other copyright notices.
3794 F. Include, immediately after the copyright notices, a license
3795 notice giving the public permission to use the Modified
3796 Version under the terms of this License, in the form shown in
3799 G. Preserve in that license notice the full lists of Invariant
3800 Sections and required Cover Texts given in the Document's
3803 H. Include an unaltered copy of this License.
3805 I. Preserve the section Entitled "History", Preserve its Title,
3806 and add to it an item stating at least the title, year, new
3807 authors, and publisher of the Modified Version as given on
3808 the Title Page. If there is no section Entitled "History" in
3809 the Document, create one stating the title, year, authors,
3810 and publisher of the Document as given on its Title Page,
3811 then add an item describing the Modified Version as stated in
3812 the previous sentence.
3814 J. Preserve the network location, if any, given in the Document
3815 for public access to a Transparent copy of the Document, and
3816 likewise the network locations given in the Document for
3817 previous versions it was based on. These may be placed in
3818 the "History" section. You may omit a network location for a
3819 work that was published at least four years before the
3820 Document itself, or if the original publisher of the version
3821 it refers to gives permission.
3823 K. For any section Entitled "Acknowledgements" or "Dedications",
3824 Preserve the Title of the section, and preserve in the
3825 section all the substance and tone of each of the contributor
3826 acknowledgements and/or dedications given therein.
3828 L. Preserve all the Invariant Sections of the Document,
3829 unaltered in their text and in their titles. Section numbers
3830 or the equivalent are not considered part of the section
3833 M. Delete any section Entitled "Endorsements". Such a section
3834 may not be included in the Modified Version.
3836 N. Do not retitle any existing section to be Entitled
3837 "Endorsements" or to conflict in title with any Invariant
3840 O. Preserve any Warranty Disclaimers.
3842 If the Modified Version includes new front-matter sections or
3843 appendices that qualify as Secondary Sections and contain no
3844 material copied from the Document, you may at your option
3845 designate some or all of these sections as invariant. To do this,
3846 add their titles to the list of Invariant Sections in the Modified
3847 Version's license notice. These titles must be distinct from any
3848 other section titles.
3850 You may add a section Entitled "Endorsements", provided it contains
3851 nothing but endorsements of your Modified Version by various
3852 parties--for example, statements of peer review or that the text
3853 has been approved by an organization as the authoritative
3854 definition of a standard.
3856 You may add a passage of up to five words as a Front-Cover Text,
3857 and a passage of up to 25 words as a Back-Cover Text, to the end
3858 of the list of Cover Texts in the Modified Version. Only one
3859 passage of Front-Cover Text and one of Back-Cover Text may be
3860 added by (or through arrangements made by) any one entity. If the
3861 Document already includes a cover text for the same cover,
3862 previously added by you or by arrangement made by the same entity
3863 you are acting on behalf of, you may not add another; but you may
3864 replace the old one, on explicit permission from the previous
3865 publisher that added the old one.
3867 The author(s) and publisher(s) of the Document do not by this
3868 License give permission to use their names for publicity for or to
3869 assert or imply endorsement of any Modified Version.
3871 5. COMBINING DOCUMENTS
3873 You may combine the Document with other documents released under
3874 this License, under the terms defined in section 4 above for
3875 modified versions, provided that you include in the combination
3876 all of the Invariant Sections of all of the original documents,
3877 unmodified, and list them all as Invariant Sections of your
3878 combined work in its license notice, and that you preserve all
3879 their Warranty Disclaimers.
3881 The combined work need only contain one copy of this License, and
3882 multiple identical Invariant Sections may be replaced with a single
3883 copy. If there are multiple Invariant Sections with the same name
3884 but different contents, make the title of each such section unique
3885 by adding at the end of it, in parentheses, the name of the
3886 original author or publisher of that section if known, or else a
3887 unique number. Make the same adjustment to the section titles in
3888 the list of Invariant Sections in the license notice of the
3891 In the combination, you must combine any sections Entitled
3892 "History" in the various original documents, forming one section
3893 Entitled "History"; likewise combine any sections Entitled
3894 "Acknowledgements", and any sections Entitled "Dedications". You
3895 must delete all sections Entitled "Endorsements."
3897 6. COLLECTIONS OF DOCUMENTS
3899 You may make a collection consisting of the Document and other
3900 documents released under this License, and replace the individual
3901 copies of this License in the various documents with a single copy
3902 that is included in the collection, provided that you follow the
3903 rules of this License for verbatim copying of each of the
3904 documents in all other respects.
3906 You may extract a single document from such a collection, and
3907 distribute it individually under this License, provided you insert
3908 a copy of this License into the extracted document, and follow
3909 this License in all other respects regarding verbatim copying of
3912 7. AGGREGATION WITH INDEPENDENT WORKS
3914 A compilation of the Document or its derivatives with other
3915 separate and independent documents or works, in or on a volume of
3916 a storage or distribution medium, is called an "aggregate" if the
3917 copyright resulting from the compilation is not used to limit the
3918 legal rights of the compilation's users beyond what the individual
3919 works permit. When the Document is included in an aggregate, this
3920 License does not apply to the other works in the aggregate which
3921 are not themselves derivative works of the Document.
3923 If the Cover Text requirement of section 3 is applicable to these
3924 copies of the Document, then if the Document is less than one half
3925 of the entire aggregate, the Document's Cover Texts may be placed
3926 on covers that bracket the Document within the aggregate, or the
3927 electronic equivalent of covers if the Document is in electronic
3928 form. Otherwise they must appear on printed covers that bracket
3929 the whole aggregate.
3933 Translation is considered a kind of modification, so you may
3934 distribute translations of the Document under the terms of section
3935 4. Replacing Invariant Sections with translations requires special
3936 permission from their copyright holders, but you may include
3937 translations of some or all Invariant Sections in addition to the
3938 original versions of these Invariant Sections. You may include a
3939 translation of this License, and all the license notices in the
3940 Document, and any Warranty Disclaimers, provided that you also
3941 include the original English version of this License and the
3942 original versions of those notices and disclaimers. In case of a
3943 disagreement between the translation and the original version of
3944 this License or a notice or disclaimer, the original version will
3947 If a section in the Document is Entitled "Acknowledgements",
3948 "Dedications", or "History", the requirement (section 4) to
3949 Preserve its Title (section 1) will typically require changing the
3954 You may not copy, modify, sublicense, or distribute the Document
3955 except as expressly provided under this License. Any attempt
3956 otherwise to copy, modify, sublicense, or distribute it is void,
3957 and will automatically terminate your rights under this License.
3959 However, if you cease all violation of this License, then your
3960 license from a particular copyright holder is reinstated (a)
3961 provisionally, unless and until the copyright holder explicitly
3962 and finally terminates your license, and (b) permanently, if the
3963 copyright holder fails to notify you of the violation by some
3964 reasonable means prior to 60 days after the cessation.
3966 Moreover, your license from a particular copyright holder is
3967 reinstated permanently if the copyright holder notifies you of the
3968 violation by some reasonable means, this is the first time you have
3969 received notice of violation of this License (for any work) from
3970 that copyright holder, and you cure the violation prior to 30 days
3971 after your receipt of the notice.
3973 Termination of your rights under this section does not terminate
3974 the licenses of parties who have received copies or rights from
3975 you under this License. If your rights have been terminated and
3976 not permanently reinstated, receipt of a copy of some or all of
3977 the same material does not give you any rights to use it.
3979 10. FUTURE REVISIONS OF THIS LICENSE
3981 The Free Software Foundation may publish new, revised versions of
3982 the GNU Free Documentation License from time to time. Such new
3983 versions will be similar in spirit to the present version, but may
3984 differ in detail to address new problems or concerns. See
3985 `http://www.gnu.org/copyleft/'.
3987 Each version of the License is given a distinguishing version
3988 number. If the Document specifies that a particular numbered
3989 version of this License "or any later version" applies to it, you
3990 have the option of following the terms and conditions either of
3991 that specified version or of any later version that has been
3992 published (not as a draft) by the Free Software Foundation. If
3993 the Document does not specify a version number of this License,
3994 you may choose any version ever published (not as a draft) by the
3995 Free Software Foundation. If the Document specifies that a proxy
3996 can decide which future versions of this License can be used, that
3997 proxy's public statement of acceptance of a version permanently
3998 authorizes you to choose that version for the Document.
4002 "Massive Multiauthor Collaboration Site" (or "MMC Site") means any
4003 World Wide Web server that publishes copyrightable works and also
4004 provides prominent facilities for anybody to edit those works. A
4005 public wiki that anybody can edit is an example of such a server.
4006 A "Massive Multiauthor Collaboration" (or "MMC") contained in the
4007 site means any set of copyrightable works thus published on the MMC
4010 "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
4011 license published by Creative Commons Corporation, a not-for-profit
4012 corporation with a principal place of business in San Francisco,
4013 California, as well as future copyleft versions of that license
4014 published by that same organization.
4016 "Incorporate" means to publish or republish a Document, in whole or
4017 in part, as part of another Document.
4019 An MMC is "eligible for relicensing" if it is licensed under this
4020 License, and if all works that were first published under this
4021 License somewhere other than this MMC, and subsequently
4022 incorporated in whole or in part into the MMC, (1) had no cover
4023 texts or invariant sections, and (2) were thus incorporated prior
4024 to November 1, 2008.
4026 The operator of an MMC Site may republish an MMC contained in the
4027 site under CC-BY-SA on the same site at any time before August 1,
4028 2009, provided the MMC is eligible for relicensing.
4031 ADDENDUM: How to use this License for your documents
4032 ====================================================
4034 To use this License in a document you have written, include a copy of
4035 the License in the document and put the following copyright and license
4036 notices just after the title page:
4038 Copyright (C) YEAR YOUR NAME.
4039 Permission is granted to copy, distribute and/or modify this document
4040 under the terms of the GNU Free Documentation License, Version 1.3
4041 or any later version published by the Free Software Foundation;
4042 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
4043 Texts. A copy of the license is included in the section entitled ``GNU
4044 Free Documentation License''.
4046 If you have Invariant Sections, Front-Cover Texts and Back-Cover
4047 Texts, replace the "with...Texts." line with this:
4049 with the Invariant Sections being LIST THEIR TITLES, with
4050 the Front-Cover Texts being LIST, and with the Back-Cover Texts
4053 If you have Invariant Sections without Cover Texts, or some other
4054 combination of the three, merge those two alternatives to suit the
4057 If your document contains nontrivial examples of program code, we
4058 recommend releasing these examples in parallel under your choice of
4059 free software license, such as the GNU General Public License, to
4060 permit their use in free software.
4063 File: bison.info, Node: Bibliography, Next: Index of Terms, Prev: Copying This Manual, Up: Top
4069 Joel E. Denny and Brian A. Malloy, IELR(1): Practical LR(1) Parser
4070 Tables for Non-LR(1) Grammars with Conflict Resolution, in
4071 `Proceedings of the 2008 ACM Symposium on Applied Computing'
4072 (SAC'08), ACM, New York, NY, USA, pp. 240-245.
4073 `http://dx.doi.org/10.1145/1363686.1363747'
4076 Joel E. Denny, PSLR(1): Pseudo-Scannerless Minimal LR(1) for the
4077 Deterministic Parsing of Composite Languages, Ph.D. Dissertation,
4078 Clemson University, Clemson, SC, USA (May 2010).
4079 `http://proquest.umi.com/pqdlink?did=2041473591&Fmt=7&clientId=79356&RQT=309&VName=PQD'
4081 [Denny 2010 November]
4082 Joel E. Denny and Brian A. Malloy, The IELR(1) Algorithm for
4083 Generating Minimal LR(1) Parser Tables for Non-LR(1) Grammars with
4084 Conflict Resolution, in `Science of Computer Programming', Vol.
4085 75, Issue 11 (November 2010), pp. 943-979.
4086 `http://dx.doi.org/10.1016/j.scico.2009.08.001'
4089 Frank DeRemer and Thomas Pennello, Efficient Computation of LALR(1)
4090 Look-Ahead Sets, in `ACM Transactions on Programming Languages and
4091 Systems', Vol. 4, No. 4 (October 1982), pp. 615-649.
4092 `http://dx.doi.org/10.1145/69622.357187'
4095 Donald E. Knuth, On the Translation of Languages from Left to
4096 Right, in `Information and Control', Vol. 8, Issue 6 (December
4098 `http://dx.doi.org/10.1016/S0019-9958(65)90426-2'
4101 Elizabeth Scott, Adrian Johnstone, and Shamsa Sadaf Hussain,
4102 `Tomita-Style Generalised LR Parsers', Royal Holloway, University
4103 of London, Department of Computer Science, TR-00-12 (December
4105 `http://www.cs.rhul.ac.uk/research/languages/publications/tomita_style_1.ps'
4108 File: bison.info, Node: Index of Terms, Prev: Bibliography, Up: Top
4116 * $ <1>: Action Features. (line 14)
4117 * $ <2>: Table of Symbols. (line 31)
4118 * $ <3>: Java Action Features.
4120 * $: Table of Symbols. (line 35)
4121 * $$ <1>: Java Action Features.
4123 * $$ <2>: Actions. (line 6)
4124 * $$ <3>: Action Features. (line 10)
4125 * $$: Table of Symbols. (line 23)
4126 * $< <1>: Action Features. (line 23)
4127 * $<: Java Action Features.
4129 * $[NAME]: Actions. (line 6)
4130 * $accept: Table of Symbols. (line 81)
4131 * $end: Table of Symbols. (line 119)
4132 * $N: Actions. (line 6)
4133 * $NAME: Actions. (line 6)
4134 * $undefined: Table of Symbols. (line 240)
4135 * % <1>: Table of Symbols. (line 44)
4136 * %: Java Declarations Summary.
4138 * %% <1>: Table of Symbols. (line 39)
4139 * %%: Java Declarations Summary.
4141 * %code <1>: Decl Summary. (line 47)
4142 * %code <2>: Java Declarations Summary.
4144 * %code <3>: %code Summary. (line 6)
4145 * %code <4>: Prologue Alternatives.
4147 * %code <5>: Table of Symbols. (line 86)
4148 * %code <6>: %code Summary. (line 27)
4149 * %code <7>: Table of Symbols. (line 87)
4150 * %code: Calc++ Parser. (line 65)
4151 * %code imports <1>: Java Declarations Summary.
4153 * %code imports: %code Summary. (line 83)
4154 * %code lexer: Java Declarations Summary.
4156 * %code provides <1>: Decl Summary. (line 95)
4157 * %code provides <2>: %code Summary. (line 55)
4158 * %code provides: Prologue Alternatives.
4160 * %code requires <1>: Prologue Alternatives.
4162 * %code requires <2>: Decl Summary. (line 95)
4163 * %code requires <3>: %code Summary. (line 41)
4164 * %code requires: Calc++ Parser. (line 17)
4165 * %code top <1>: Prologue Alternatives.
4167 * %code top: %code Summary. (line 67)
4168 * %debug <1>: Table of Symbols. (line 92)
4169 * %debug <2>: Enabling Traces. (line 28)
4170 * %debug: Decl Summary. (line 52)
4171 * %define <1>: Decl Summary. (line 61)
4172 * %define <2>: %define Summary. (line 15)
4173 * %define <3>: Decl Summary. (line 59)
4174 * %define <4>: Table of Symbols. (line 95)
4175 * %define: %define Summary. (line 14)
4176 * %define abstract: Java Declarations Summary.
4178 * %define api.prefix: %define Summary. (line 49)
4179 * %define api.pure <1>: %define Summary. (line 62)
4180 * %define api.pure: Pure Decl. (line 6)
4181 * %define api.push-pull <1>: Push Decl. (line 6)
4182 * %define api.push-pull: %define Summary. (line 73)
4183 * %define extends: Java Declarations Summary.
4185 * %define final: Java Declarations Summary.
4187 * %define implements: Java Declarations Summary.
4189 * %define lex_throws: Java Declarations Summary.
4191 * %define location_type: Java Declarations Summary.
4193 * %define lr.default-reductions <1>: Default Reductions. (line 6)
4194 * %define lr.default-reductions: %define Summary. (line 86)
4195 * %define lr.default-reductions WHERE: Default Reductions. (line 84)
4196 * %define lr.keep-unreachable-states <1>: %define Summary. (line 103)
4197 * %define lr.keep-unreachable-states: Unreachable States. (line 6)
4198 * %define lr.keep-unreachable-states VALUE: Unreachable States.
4200 * %define lr.type <1>: %define Summary. (line 114)
4201 * %define lr.type: LR Table Construction.
4203 * %define lr.type TYPE: LR Table Construction.
4205 * %define namespace <1>: %define Summary. (line 126)
4206 * %define namespace: C++ Bison Interface. (line 10)
4207 * %define package: Java Declarations Summary.
4209 * %define parse.lac <1>: LAC. (line 6)
4210 * %define parse.lac: %define Summary. (line 166)
4211 * %define parse.lac VALUE: LAC. (line 29)
4212 * %define parser_class_name: Java Declarations Summary.
4214 * %define position_type: Java Declarations Summary.
4216 * %define public: Java Declarations Summary.
4218 * %define strictfp: Java Declarations Summary.
4220 * %define stype: Java Declarations Summary.
4222 * %define throws: Java Declarations Summary.
4224 * %defines <1>: Decl Summary. (line 65)
4225 * %defines: Table of Symbols. (line 101)
4226 * %destructor <1>: Table of Symbols. (line 109)
4227 * %destructor <2>: Decl Summary. (line 102)
4228 * %destructor <3>: Destructor Decl. (line 6)
4229 * %destructor: Mid-Rule Actions. (line 59)
4230 * %dprec <1>: Merging GLR Parses. (line 6)
4231 * %dprec: Table of Symbols. (line 114)
4232 * %error-verbose <1>: Error Reporting. (line 17)
4233 * %error-verbose: Table of Symbols. (line 133)
4234 * %expect <1>: Decl Summary. (line 38)
4235 * %expect: Expect Decl. (line 6)
4236 * %expect-rr <1>: Expect Decl. (line 6)
4237 * %expect-rr: Simple GLR Parsers. (line 6)
4238 * %file-prefix <1>: Table of Symbols. (line 137)
4239 * %file-prefix: Decl Summary. (line 107)
4240 * %glr-parser <1>: Simple GLR Parsers. (line 6)
4241 * %glr-parser <2>: Table of Symbols. (line 141)
4242 * %glr-parser: GLR Parsers. (line 6)
4243 * %initial-action <1>: Table of Symbols. (line 145)
4244 * %initial-action: Initial Action Decl. (line 11)
4245 * %language <1>: Table of Symbols. (line 149)
4246 * %language: Decl Summary. (line 111)
4247 * %language "Java": Java Declarations Summary.
4249 * %left <1>: Table of Symbols. (line 153)
4250 * %left <2>: Using Precedence. (line 6)
4251 * %left: Decl Summary. (line 21)
4252 * %lex-param <1>: Table of Symbols. (line 157)
4253 * %lex-param <2>: Java Declarations Summary.
4255 * %lex-param: Pure Calling. (line 31)
4256 * %locations: Decl Summary. (line 119)
4257 * %merge <1>: Merging GLR Parses. (line 6)
4258 * %merge: Table of Symbols. (line 162)
4259 * %name-prefix <1>: Java Declarations Summary.
4261 * %name-prefix: Table of Symbols. (line 169)
4262 * %no-lines <1>: Table of Symbols. (line 186)
4263 * %no-lines: Decl Summary. (line 126)
4264 * %nonassoc <1>: Decl Summary. (line 25)
4265 * %nonassoc <2>: Table of Symbols. (line 190)
4266 * %nonassoc <3>: Default Reductions. (line 6)
4267 * %nonassoc <4>: LR Table Construction.
4269 * %nonassoc: Using Precedence. (line 6)
4270 * %output <1>: Table of Symbols. (line 194)
4271 * %output: Decl Summary. (line 135)
4272 * %parse-param <1>: Parser Function. (line 36)
4273 * %parse-param <2>: Java Declarations Summary.
4275 * %parse-param <3>: Parser Function. (line 36)
4276 * %parse-param: Table of Symbols. (line 198)
4277 * %prec <1>: Contextual Precedence.
4279 * %prec: Table of Symbols. (line 203)
4280 * %printer: Printer Decl. (line 6)
4281 * %pure-parser <1>: Table of Symbols. (line 207)
4282 * %pure-parser: Decl Summary. (line 138)
4283 * %require <1>: Require Decl. (line 6)
4284 * %require <2>: Decl Summary. (line 143)
4285 * %require: Table of Symbols. (line 212)
4286 * %right <1>: Using Precedence. (line 6)
4287 * %right <2>: Table of Symbols. (line 216)
4288 * %right: Decl Summary. (line 17)
4289 * %skeleton <1>: Table of Symbols. (line 220)
4290 * %skeleton: Decl Summary. (line 147)
4291 * %start <1>: Start Decl. (line 6)
4292 * %start <2>: Decl Summary. (line 34)
4293 * %start: Table of Symbols. (line 224)
4294 * %token <1>: Decl Summary. (line 13)
4295 * %token <2>: Java Declarations Summary.
4297 * %token <3>: Table of Symbols. (line 228)
4298 * %token: Token Decl. (line 6)
4299 * %token-table <1>: Decl Summary. (line 155)
4300 * %token-table: Table of Symbols. (line 232)
4301 * %type <1>: Type Decl. (line 6)
4302 * %type <2>: Table of Symbols. (line 236)
4303 * %type <3>: Decl Summary. (line 30)
4304 * %type: Java Declarations Summary.
4306 * %union <1>: Decl Summary. (line 9)
4307 * %union <2>: Union Decl. (line 6)
4308 * %union: Table of Symbols. (line 245)
4309 * %verbose: Decl Summary. (line 188)
4310 * %yacc: Decl Summary. (line 194)
4311 * /*: Table of Symbols. (line 49)
4312 * :: Table of Symbols. (line 52)
4313 * ;: Table of Symbols. (line 56)
4314 * <*> <1>: Printer Decl. (line 6)
4315 * <*> <2>: Table of Symbols. (line 63)
4316 * <*>: Destructor Decl. (line 6)
4317 * <> <1>: Printer Decl. (line 6)
4318 * <> <2>: Table of Symbols. (line 72)
4319 * <>: Destructor Decl. (line 6)
4320 * @$ <1>: Table of Symbols. (line 7)
4321 * @$ <2>: Actions and Locations.
4323 * @$ <3>: Action Features. (line 98)
4324 * @$: Java Action Features.
4326 * @[: Table of Symbols. (line 19)
4327 * @[NAME]: Actions and Locations.
4329 * @N <1>: Action Features. (line 104)
4330 * @N <2>: Actions and Locations.
4332 * @N <3>: Java Action Features.
4334 * @N: Table of Symbols. (line 11)
4335 * @NAME <1>: Actions and Locations.
4337 * @NAME: Table of Symbols. (line 15)
4338 * abstract syntax tree: Implementing Gotos/Loops.
4340 * accepting state: Understanding. (line 178)
4341 * action: Actions. (line 6)
4342 * action data types: Action Types. (line 6)
4343 * action features summary: Action Features. (line 6)
4344 * actions in mid-rule <1>: Destructor Decl. (line 88)
4345 * actions in mid-rule: Mid-Rule Actions. (line 6)
4346 * actions, location: Actions and Locations.
4348 * actions, semantic: Semantic Actions. (line 6)
4349 * additional C code section: Epilogue. (line 6)
4350 * algorithm of parser: Algorithm. (line 6)
4351 * ambiguous grammars <1>: Generalized LR Parsing.
4353 * ambiguous grammars: Language and Grammar.
4355 * associativity: Why Precedence. (line 34)
4356 * AST: Implementing Gotos/Loops.
4358 * Backus-Naur form: Language and Grammar.
4360 * begin of Location: Java Location Values.
4362 * begin of location: C++ location. (line 22)
4363 * Bison declaration summary: Decl Summary. (line 6)
4364 * Bison declarations: Declarations. (line 6)
4365 * Bison declarations (introduction): Bison Declarations. (line 6)
4366 * Bison grammar: Grammar in Bison. (line 6)
4367 * Bison invocation: Invocation. (line 6)
4368 * Bison parser: Bison Parser. (line 6)
4369 * Bison parser algorithm: Algorithm. (line 6)
4370 * Bison symbols, table of: Table of Symbols. (line 6)
4371 * Bison utility: Bison Parser. (line 6)
4372 * bison-i18n.m4: Internationalization.
4374 * bison-po: Internationalization.
4376 * BISON_I18N: Internationalization.
4378 * BISON_LOCALEDIR: Internationalization.
4380 * BNF: Language and Grammar.
4382 * braced code: Rules. (line 29)
4383 * C code, section for additional: Epilogue. (line 6)
4384 * C-language interface: Interface. (line 6)
4385 * calc: Infix Calc. (line 6)
4386 * calculator, infix notation: Infix Calc. (line 6)
4387 * calculator, location tracking: Location Tracking Calc.
4389 * calculator, multi-function: Multi-function Calc. (line 6)
4390 * calculator, simple: RPN Calc. (line 6)
4391 * canonical LR <1>: Mysterious Conflicts.
4393 * canonical LR: LR Table Construction.
4395 * character token: Symbols. (line 37)
4396 * column of position: C++ position. (line 29)
4397 * columns on location: C++ location. (line 26)
4398 * columns on position: C++ position. (line 32)
4399 * compiling the parser: Rpcalc Compile. (line 6)
4400 * conflicts <1>: Shift/Reduce. (line 6)
4401 * conflicts <2>: Merging GLR Parses. (line 6)
4402 * conflicts <3>: Simple GLR Parsers. (line 6)
4403 * conflicts: GLR Parsers. (line 6)
4404 * conflicts, reduce/reduce: Reduce/Reduce. (line 6)
4405 * conflicts, suppressing warnings of: Expect Decl. (line 6)
4406 * consistent states: Default Reductions. (line 17)
4407 * context-dependent precedence: Contextual Precedence.
4409 * context-free grammar: Language and Grammar.
4411 * controlling function: Rpcalc Main. (line 6)
4412 * core, item set: Understanding. (line 125)
4413 * dangling else: Shift/Reduce. (line 6)
4414 * data type of locations: Location Type. (line 6)
4415 * data types in actions: Action Types. (line 6)
4416 * data types of semantic values: Value Type. (line 6)
4417 * debug_level on parser: C++ Parser Interface.
4419 * debug_stream on parser: C++ Parser Interface.
4421 * debugging: Tracing. (line 6)
4422 * declaration summary: Decl Summary. (line 6)
4423 * declarations: Prologue. (line 6)
4424 * declarations section: Prologue. (line 6)
4425 * declarations, Bison: Declarations. (line 6)
4426 * declarations, Bison (introduction): Bison Declarations. (line 6)
4427 * declaring literal string tokens: Token Decl. (line 6)
4428 * declaring operator precedence: Precedence Decl. (line 6)
4429 * declaring the start symbol: Start Decl. (line 6)
4430 * declaring token type names: Token Decl. (line 6)
4431 * declaring value types: Union Decl. (line 6)
4432 * declaring value types, nonterminals: Type Decl. (line 6)
4433 * default action: Actions. (line 62)
4434 * default data type: Value Type. (line 6)
4435 * default location type: Location Type. (line 6)
4436 * default reductions: Default Reductions. (line 6)
4437 * default stack limit: Memory Management. (line 30)
4438 * default start symbol: Start Decl. (line 6)
4439 * defaulted states: Default Reductions. (line 17)
4440 * deferred semantic actions: GLR Semantic Actions.
4442 * defining language semantics: Semantics. (line 6)
4443 * delayed syntax error detection <1>: LR Table Construction.
4445 * delayed syntax error detection: Default Reductions. (line 43)
4446 * delayed yylex invocations: Default Reductions. (line 17)
4447 * discarded symbols: Destructor Decl. (line 98)
4448 * discarded symbols, mid-rule actions: Mid-Rule Actions. (line 59)
4449 * else, dangling: Shift/Reduce. (line 6)
4450 * end of location: C++ location. (line 23)
4451 * end of Location: Java Location Values.
4453 * epilogue: Epilogue. (line 6)
4454 * error <1>: Error Recovery. (line 20)
4455 * error: Table of Symbols. (line 123)
4456 * error on parser: C++ Parser Interface.
4458 * error recovery: Error Recovery. (line 6)
4459 * error recovery, mid-rule actions: Mid-Rule Actions. (line 59)
4460 * error recovery, simple: Simple Error Recovery.
4462 * error reporting function: Error Reporting. (line 6)
4463 * error reporting routine: Rpcalc Error. (line 6)
4464 * examples, simple: Examples. (line 6)
4465 * exercises: Exercises. (line 6)
4466 * file format: Grammar Layout. (line 6)
4467 * file of position: C++ position. (line 17)
4468 * finite-state machine: Parser States. (line 6)
4469 * formal grammar: Grammar in Bison. (line 6)
4470 * format of grammar file: Grammar Layout. (line 6)
4471 * freeing discarded symbols: Destructor Decl. (line 6)
4472 * frequently asked questions: FAQ. (line 6)
4473 * generalized LR (GLR) parsing <1>: Language and Grammar.
4475 * generalized LR (GLR) parsing <2>: GLR Parsers. (line 6)
4476 * generalized LR (GLR) parsing: Generalized LR Parsing.
4478 * generalized LR (GLR) parsing, ambiguous grammars: Merging GLR Parses.
4480 * generalized LR (GLR) parsing, unambiguous grammars: Simple GLR Parsers.
4482 * getDebugLevel on YYParser: Java Parser Interface.
4484 * getDebugStream on YYParser: Java Parser Interface.
4486 * getEndPos on Lexer: Java Scanner Interface.
4488 * getLVal on Lexer: Java Scanner Interface.
4490 * getStartPos on Lexer: Java Scanner Interface.
4492 * gettext: Internationalization.
4494 * glossary: Glossary. (line 6)
4495 * GLR parsers and inline: Compiler Requirements.
4497 * GLR parsers and yychar: GLR Semantic Actions.
4499 * GLR parsers and yyclearin: GLR Semantic Actions.
4501 * GLR parsers and YYERROR: GLR Semantic Actions.
4503 * GLR parsers and yylloc: GLR Semantic Actions.
4505 * GLR parsers and YYLLOC_DEFAULT: Location Default Action.
4507 * GLR parsers and yylval: GLR Semantic Actions.
4509 * GLR parsing <1>: Generalized LR Parsing.
4511 * GLR parsing <2>: GLR Parsers. (line 6)
4512 * GLR parsing: Language and Grammar.
4514 * GLR parsing, ambiguous grammars: Merging GLR Parses. (line 6)
4515 * GLR parsing, unambiguous grammars: Simple GLR Parsers. (line 6)
4516 * GLR with LALR: LR Table Construction.
4518 * grammar file: Grammar Layout. (line 6)
4519 * grammar rule syntax: Rules. (line 6)
4520 * grammar rules section: Grammar Rules. (line 6)
4521 * grammar, Bison: Grammar in Bison. (line 6)
4522 * grammar, context-free: Language and Grammar.
4524 * grouping, syntactic: Language and Grammar.
4526 * i18n: Internationalization.
4528 * IELR <1>: LR Table Construction.
4530 * IELR: Mysterious Conflicts.
4532 * IELR grammars: Language and Grammar.
4534 * infix notation calculator: Infix Calc. (line 6)
4535 * initialize on location: C++ location. (line 19)
4536 * initialize on position: C++ position. (line 14)
4537 * inline: Compiler Requirements.
4539 * interface: Interface. (line 6)
4540 * internationalization: Internationalization.
4542 * introduction: Introduction. (line 6)
4543 * invoking Bison: Invocation. (line 6)
4544 * item: Understanding. (line 103)
4545 * item set core: Understanding. (line 125)
4546 * kernel, item set: Understanding. (line 125)
4547 * LAC <1>: LR Table Construction.
4549 * LAC <2>: Default Reductions. (line 54)
4550 * LAC: LAC. (line 6)
4551 * LALR <1>: Mysterious Conflicts.
4553 * LALR: LR Table Construction.
4555 * LALR grammars: Language and Grammar.
4557 * language semantics, defining: Semantics. (line 6)
4558 * layout of Bison grammar: Grammar Layout. (line 6)
4559 * left recursion: Recursion. (line 17)
4560 * lex-param: Pure Calling. (line 31)
4561 * lexical analyzer: Lexical. (line 6)
4562 * lexical analyzer, purpose: Bison Parser. (line 6)
4563 * lexical analyzer, writing: Rpcalc Lexer. (line 6)
4564 * lexical tie-in: Lexical Tie-ins. (line 6)
4565 * line of position: C++ position. (line 23)
4566 * lines on location: C++ location. (line 27)
4567 * lines on position: C++ position. (line 26)
4568 * literal string token: Symbols. (line 59)
4569 * literal token: Symbols. (line 37)
4570 * location <1>: Tracking Locations. (line 6)
4571 * location: Locations. (line 6)
4572 * location actions: Actions and Locations.
4574 * Location on Location: Java Location Values.
4576 * location on location: C++ location. (line 8)
4577 * Location on Location: Java Location Values.
4579 * location tracking calculator: Location Tracking Calc.
4581 * location, textual <1>: Locations. (line 6)
4582 * location, textual: Tracking Locations. (line 6)
4583 * location_type: C++ Parser Interface.
4585 * lookahead correction: LAC. (line 6)
4586 * lookahead token: Lookahead. (line 6)
4587 * LR: Mysterious Conflicts.
4589 * LR grammars: Language and Grammar.
4591 * ltcalc: Location Tracking Calc.
4593 * main function in simple example: Rpcalc Main. (line 6)
4594 * memory exhaustion: Memory Management. (line 6)
4595 * memory management: Memory Management. (line 6)
4596 * mfcalc: Multi-function Calc. (line 6)
4597 * mid-rule actions <1>: Mid-Rule Actions. (line 6)
4598 * mid-rule actions: Destructor Decl. (line 88)
4599 * multi-function calculator: Multi-function Calc. (line 6)
4600 * multicharacter literal: Symbols. (line 59)
4601 * mutual recursion: Recursion. (line 34)
4602 * Mysterious Conflict: LR Table Construction.
4604 * Mysterious Conflicts: Mysterious Conflicts.
4606 * named references: Named References. (line 6)
4607 * NLS: Internationalization.
4609 * nondeterministic parsing <1>: Generalized LR Parsing.
4611 * nondeterministic parsing: Language and Grammar.
4613 * nonterminal symbol: Symbols. (line 6)
4614 * nonterminal, useless: Understanding. (line 49)
4615 * operator precedence: Precedence. (line 6)
4616 * operator precedence, declaring: Precedence Decl. (line 6)
4617 * operator!= on location: C++ location. (line 39)
4618 * operator!= on position: C++ position. (line 42)
4619 * operator+ on location: C++ location. (line 30)
4620 * operator+ on position: C++ position. (line 36)
4621 * operator+= on location: C++ location. (line 32)
4622 * operator+= on position: C++ position. (line 35)
4623 * operator- on position: C++ position. (line 38)
4624 * operator-= on position: C++ position. (line 37)
4625 * operator<< <1>: C++ position. (line 46)
4626 * operator<<: C++ location. (line 44)
4627 * operator== on location: C++ location. (line 38)
4628 * operator== on position: C++ position. (line 41)
4629 * options for invoking Bison: Invocation. (line 6)
4630 * overflow of parser stack: Memory Management. (line 6)
4631 * parse error: Error Reporting. (line 6)
4632 * parse on parser: C++ Parser Interface.
4634 * parse on YYParser: Java Parser Interface.
4636 * parser: Bison Parser. (line 6)
4637 * parser on parser: C++ Parser Interface.
4639 * parser stack: Algorithm. (line 6)
4640 * parser stack overflow: Memory Management. (line 6)
4641 * parser state: Parser States. (line 6)
4642 * pointed rule: Understanding. (line 103)
4643 * polish notation calculator: RPN Calc. (line 6)
4644 * position on position: C++ position. (line 8)
4645 * precedence declarations: Precedence Decl. (line 6)
4646 * precedence of operators: Precedence. (line 6)
4647 * precedence, context-dependent: Contextual Precedence.
4649 * precedence, unary operator: Contextual Precedence.
4651 * preventing warnings about conflicts: Expect Decl. (line 6)
4652 * printing semantic values: Printer Decl. (line 6)
4653 * Prologue <1>: Prologue. (line 6)
4654 * Prologue: %code Summary. (line 6)
4655 * Prologue Alternatives: Prologue Alternatives.
4657 * pure parser: Pure Decl. (line 6)
4658 * push parser: Push Decl. (line 6)
4659 * questions: FAQ. (line 6)
4660 * recovering: Java Action Features.
4662 * recovering on YYParser: Java Parser Interface.
4664 * recovery from errors: Error Recovery. (line 6)
4665 * recursive rule: Recursion. (line 6)
4666 * reduce/reduce conflict: Reduce/Reduce. (line 6)
4667 * reduce/reduce conflicts <1>: Merging GLR Parses. (line 6)
4668 * reduce/reduce conflicts <2>: GLR Parsers. (line 6)
4669 * reduce/reduce conflicts: Simple GLR Parsers. (line 6)
4670 * reduction: Algorithm. (line 6)
4671 * reentrant parser: Pure Decl. (line 6)
4672 * requiring a version of Bison: Require Decl. (line 6)
4673 * reverse polish notation: RPN Calc. (line 6)
4674 * right recursion: Recursion. (line 17)
4675 * rpcalc: RPN Calc. (line 6)
4676 * rule syntax: Rules. (line 6)
4677 * rule, pointed: Understanding. (line 103)
4678 * rule, useless: Understanding. (line 49)
4679 * rules section for grammar: Grammar Rules. (line 6)
4680 * running Bison (introduction): Rpcalc Generate. (line 6)
4681 * semantic actions: Semantic Actions. (line 6)
4682 * semantic value: Semantic Values. (line 6)
4683 * semantic value type: Value Type. (line 6)
4684 * semantic_type: C++ Parser Interface.
4686 * set_debug_level on parser: C++ Parser Interface.
4688 * set_debug_stream on parser: C++ Parser Interface.
4690 * setDebugLevel on YYParser: Java Parser Interface.
4692 * setDebugStream on YYParser: Java Parser Interface.
4694 * shift/reduce conflicts <1>: Shift/Reduce. (line 6)
4695 * shift/reduce conflicts <2>: Simple GLR Parsers. (line 6)
4696 * shift/reduce conflicts: GLR Parsers. (line 6)
4697 * shifting: Algorithm. (line 6)
4698 * simple examples: Examples. (line 6)
4699 * single-character literal: Symbols. (line 37)
4700 * stack overflow: Memory Management. (line 6)
4701 * stack, parser: Algorithm. (line 6)
4702 * stages in using Bison: Stages. (line 6)
4703 * start symbol: Language and Grammar.
4705 * start symbol, declaring: Start Decl. (line 6)
4706 * state (of parser): Parser States. (line 6)
4707 * step on location: C++ location. (line 35)
4708 * string token: Symbols. (line 59)
4709 * summary, action features: Action Features. (line 6)
4710 * summary, Bison declaration: Decl Summary. (line 6)
4711 * suppressing conflict warnings: Expect Decl. (line 6)
4712 * symbol: Symbols. (line 6)
4713 * symbol table example: Mfcalc Symbol Table. (line 6)
4714 * symbols (abstract): Language and Grammar.
4716 * symbols in Bison, table of: Table of Symbols. (line 6)
4717 * syntactic grouping: Language and Grammar.
4719 * syntax error: Error Reporting. (line 6)
4720 * syntax of grammar rules: Rules. (line 6)
4721 * terminal symbol: Symbols. (line 6)
4722 * textual location <1>: Tracking Locations. (line 6)
4723 * textual location: Locations. (line 6)
4724 * token <1>: Language and Grammar.
4726 * token: C++ Parser Interface.
4728 * token type: Symbols. (line 6)
4729 * token type names, declaring: Token Decl. (line 6)
4730 * token, useless: Understanding. (line 49)
4731 * toString on Location: Java Location Values.
4733 * tracing the parser: Tracing. (line 6)
4734 * uint: C++ Location Values. (line 12)
4735 * unary operator precedence: Contextual Precedence.
4737 * unreachable states: Unreachable States. (line 6)
4738 * useless nonterminal: Understanding. (line 49)
4739 * useless rule: Understanding. (line 49)
4740 * useless token: Understanding. (line 49)
4741 * using Bison: Stages. (line 6)
4742 * value type, semantic: Value Type. (line 6)
4743 * value types, declaring: Union Decl. (line 6)
4744 * value types, nonterminals, declaring: Type Decl. (line 6)
4745 * value, semantic: Semantic Values. (line 6)
4746 * version requirement: Require Decl. (line 6)
4747 * warnings, preventing: Expect Decl. (line 6)
4748 * writing a lexical analyzer: Rpcalc Lexer. (line 6)
4749 * YYABORT <1>: Java Action Features.
4751 * YYABORT <2>: Parser Function. (line 29)
4752 * YYABORT <3>: Table of Symbols. (line 249)
4753 * YYABORT: Action Features. (line 28)
4754 * YYACCEPT <1>: Action Features. (line 32)
4755 * YYACCEPT <2>: Java Action Features.
4757 * YYACCEPT <3>: Table of Symbols. (line 258)
4758 * YYACCEPT: Parser Function. (line 26)
4759 * YYBACKUP <1>: Table of Symbols. (line 266)
4760 * YYBACKUP: Action Features. (line 36)
4761 * yychar <1>: Table of Symbols. (line 270)
4762 * yychar <2>: Lookahead. (line 49)
4763 * yychar <3>: Action Features. (line 69)
4764 * yychar: GLR Semantic Actions.
4766 * yyclearin <1>: Table of Symbols. (line 276)
4767 * yyclearin <2>: Error Recovery. (line 99)
4768 * yyclearin <3>: GLR Semantic Actions.
4770 * yyclearin: Action Features. (line 76)
4771 * YYDEBUG: Table of Symbols. (line 280)
4772 * yydebug <1>: Table of Symbols. (line 284)
4773 * yydebug: Tracing. (line 6)
4774 * YYDEBUG: Enabling Traces. (line 9)
4775 * YYEMPTY: Action Features. (line 49)
4776 * YYENABLE_NLS: Internationalization.
4778 * YYEOF: Action Features. (line 52)
4779 * yyerrok <1>: Error Recovery. (line 94)
4780 * yyerrok <2>: Action Features. (line 81)
4781 * yyerrok: Table of Symbols. (line 289)
4782 * yyerror: Java Action Features.
4784 * YYERROR: Java Action Features.
4786 * yyerror: Java Action Features.
4788 * YYERROR: Table of Symbols. (line 293)
4789 * yyerror: Table of Symbols. (line 304)
4790 * YYERROR <1>: GLR Semantic Actions.
4792 * YYERROR: Action Features. (line 56)
4793 * yyerror: Error Reporting. (line 6)
4794 * yyerror on Lexer: Java Scanner Interface.
4796 * YYERROR_VERBOSE: Table of Symbols. (line 308)
4797 * YYFPRINTF <1>: Table of Symbols. (line 316)
4798 * YYFPRINTF: Enabling Traces. (line 36)
4799 * YYINITDEPTH <1>: Memory Management. (line 32)
4800 * YYINITDEPTH: Table of Symbols. (line 319)
4801 * yylex <1>: Table of Symbols. (line 323)
4802 * yylex: Lexical. (line 6)
4803 * yylex on Lexer: Java Scanner Interface.
4805 * yylex on parser: C++ Scanner Interface.
4807 * YYLEX_PARAM: Table of Symbols. (line 328)
4808 * yylloc <1>: GLR Semantic Actions.
4810 * yylloc <2>: Table of Symbols. (line 334)
4811 * yylloc <3>: Action Features. (line 86)
4812 * yylloc <4>: Actions and Locations.
4814 * yylloc <5>: Token Locations. (line 6)
4815 * yylloc: Lookahead. (line 49)
4816 * YYLLOC_DEFAULT: Location Default Action.
4818 * YYLTYPE <1>: Table of Symbols. (line 344)
4819 * YYLTYPE: Token Locations. (line 19)
4820 * yylval <1>: Lookahead. (line 49)
4821 * yylval <2>: Token Values. (line 6)
4822 * yylval <3>: GLR Semantic Actions.
4824 * yylval <4>: Actions. (line 87)
4825 * yylval <5>: Table of Symbols. (line 348)
4826 * yylval: Action Features. (line 92)
4827 * YYMAXDEPTH <1>: Table of Symbols. (line 356)
4828 * YYMAXDEPTH: Memory Management. (line 14)
4829 * yynerrs <1>: Error Reporting. (line 94)
4830 * yynerrs: Table of Symbols. (line 360)
4831 * yyoutput: Printer Decl. (line 16)
4832 * yyparse <1>: Parser Function. (line 6)
4833 * yyparse <2>: Table of Symbols. (line 366)
4834 * yyparse: Parser Function. (line 13)
4835 * YYPARSE_PARAM: Table of Symbols. (line 404)
4836 * YYParser on YYParser: Java Parser Interface.
4838 * YYPRINT <1>: Table of Symbols. (line 370)
4839 * YYPRINT: The YYPRINT Macro. (line 11)
4840 * yypstate_delete <1>: Parser Delete Function.
4842 * yypstate_delete: Table of Symbols. (line 375)
4843 * yypstate_new <1>: Table of Symbols. (line 383)
4844 * yypstate_new: Parser Create Function.
4846 * yypull_parse <1>: Table of Symbols. (line 390)
4847 * yypull_parse: Pull Parser Function.
4849 * yypush_parse <1>: Push Parser Function.
4851 * yypush_parse <2>: Table of Symbols. (line 397)
4852 * yypush_parse: Push Parser Function.
4854 * YYRECOVERING <1>: Table of Symbols. (line 410)
4855 * YYRECOVERING <2>: Error Recovery. (line 111)
4856 * YYRECOVERING: Action Features. (line 64)
4857 * YYSTACK_USE_ALLOCA: Table of Symbols. (line 415)
4858 * YYSTYPE: Table of Symbols. (line 431)
4859 * | <1>: Table of Symbols. (line 59)
4860 * |: Rules. (line 48)