1 Ceci est le fichier Info bison.info, produit par Makeinfo version 4.0b
2 à partir bison.texinfo.
5 * bison: (bison). GNU Project parser generator (yacc replacement).
8 This file documents the Bison parser generator.
10 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1995, 1998, 1999,
11 2000 Free Software Foundation, Inc.
13 Permission is granted to make and distribute verbatim copies of this
14 manual provided the copyright notice and this permission notice are
15 preserved on all copies.
17 Permission is granted to copy and distribute modified versions of
18 this manual under the conditions for verbatim copying, provided also
19 that the sections entitled "GNU General Public License" and "Conditions
20 for Using Bison" are included exactly as in the original, and provided
21 that the entire resulting derived work is distributed under the terms
22 of a permission notice identical to this one.
24 Permission is granted to copy and distribute translations of this
25 manual into another language, under the above conditions for modified
26 versions, except that the sections entitled "GNU General Public
27 License", "Conditions for Using Bison" and this permission notice may be
28 included in translations approved by the Free Software Foundation
29 instead of in the original English.
32 File: bison.info, Node: Table of Symbols, Next: Glossary, Prev: Invocation, Up: Top
38 A token name reserved for error recovery. This token may be used
39 in grammar rules so as to allow the Bison parser to recognize an
40 error in the grammar without halting the process. In effect, a
41 sentence containing an error may be recognized as valid. On a
42 parse error, the token `error' becomes the current look-ahead
43 token. Actions corresponding to `error' are then executed, and
44 the look-ahead token is reset to the token that originally caused
45 the violation. *Note Error Recovery::.
48 Macro to pretend that an unrecoverable syntax error has occurred,
49 by making `yyparse' return 1 immediately. The error reporting
50 function `yyerror' is not called. *Note The Parser Function
51 `yyparse': Parser Function.
54 Macro to pretend that a complete utterance of the language has been
55 read, by making `yyparse' return 0 immediately. *Note The Parser
56 Function `yyparse': Parser Function.
59 Macro to discard a value from the parser stack and fake a
60 look-ahead token. *Note Special Features for Use in Actions:
64 Macro to pretend that a syntax error has just been detected: call
65 `yyerror' and then perform normal error recovery if possible
66 (*note Error Recovery::), or (if recovery is impossible) make
67 `yyparse' return 1. *Note Error Recovery::.
70 Macro that you define with `#define' in the Bison declarations
71 section to request verbose, specific error message strings when
75 Macro for specifying the initial size of the parser stack. *Note
79 Macro for specifying an extra argument (or list of extra
80 arguments) for `yyparse' to pass to `yylex'. *Note Calling
81 Conventions for Pure Parsers: Pure Calling.
84 Macro for the data type of `yylloc'; a structure with four
85 members. *Note Data Types of Locations: Location Type.
88 Default value for YYLTYPE.
91 Macro for specifying the maximum size of the parser stack. *Note
95 Macro for specifying the name of a parameter that `yyparse' should
96 accept. *Note Calling Conventions for Pure Parsers: Pure Calling.
99 Macro whose value indicates whether the parser is recovering from a
100 syntax error. *Note Special Features for Use in Actions: Action
104 Macro for the data type of semantic values; `int' by default.
105 *Note Data Types of Semantic Values: Value Type.
108 External integer variable that contains the integer value of the
109 current look-ahead token. (In a pure parser, it is a local
110 variable within `yyparse'.) Error-recovery rule actions may
111 examine this variable. *Note Special Features for Use in Actions:
115 Macro used in error-recovery rule actions. It clears the previous
116 look-ahead token. *Note Error Recovery::.
119 External integer variable set to zero by default. If `yydebug' is
120 given a nonzero value, the parser will output information on input
121 symbols and parser action. *Note Debugging Your Parser: Debugging.
124 Macro to cause parser to recover immediately to its normal mode
125 after a parse error. *Note Error Recovery::.
128 User-supplied function to be called by `yyparse' on error. The
129 function receives one argument, a pointer to a character string
130 containing an error message. *Note The Error Reporting Function
131 `yyerror': Error Reporting.
134 User-supplied lexical analyzer function, called with no arguments
135 to get the next token. *Note The Lexical Analyzer Function
139 External variable in which `yylex' should place the semantic value
140 associated with a token. (In a pure parser, it is a local
141 variable within `yyparse', and its address is passed to `yylex'.)
142 *Note Semantic Values of Tokens: Token Values.
145 External variable in which `yylex' should place the line and column
146 numbers associated with a token. (In a pure parser, it is a local
147 variable within `yyparse', and its address is passed to `yylex'.)
148 You can ignore this variable if you don't use the `@' feature in
149 the grammar actions. *Note Textual Positions of Tokens: Token
153 Global variable which Bison increments each time there is a parse
154 error. (In a pure parser, it is a local variable within
155 `yyparse'.) *Note The Error Reporting Function `yyerror': Error
159 The parser function produced by Bison; call this function to start
160 parsing. *Note The Parser Function `yyparse': Parser Function.
163 Equip the parser for debugging. *Note Decl Summary::.
166 Bison declaration to create a header file meant for the scanner.
167 *Note Decl Summary::.
170 Bison declaration to assign left associativity to token(s). *Note
171 Operator Precedence: Precedence Decl.
174 Bison declaration to avoid generating `#line' directives in the
175 parser file. *Note Decl Summary::.
178 Bison declaration to assign non-associativity to token(s). *Note
179 Operator Precedence: Precedence Decl.
182 Bison declaration to assign a precedence to a specific rule.
183 *Note Context-Dependent Precedence: Contextual Precedence.
186 Bison declaration to request a pure (reentrant) parser. *Note A
187 Pure (Reentrant) Parser: Pure Decl.
190 Bison declaration to assign right associativity to token(s).
191 *Note Operator Precedence: Precedence Decl.
194 Bison declaration to specify the start symbol. *Note The
195 Start-Symbol: Start Decl.
198 Bison declaration to declare token(s) without specifying
199 precedence. *Note Token Type Names: Token Decl.
202 Bison declaration to include a token name table in the parser file.
203 *Note Decl Summary::.
206 Bison declaration to declare nonterminals. *Note Nonterminal
210 Bison declaration to specify several possible data types for
211 semantic values. *Note The Collection of Value Types: Union Decl.
213 These are the punctuation and delimiters used in Bison input:
216 Delimiter used to separate the grammar rule section from the Bison
217 declarations section or the additional C code section. *Note The
218 Overall Layout of a Bison Grammar: Grammar Layout.
221 All code listed between `%{' and `%}' is copied directly to the
222 output file uninterpreted. Such code forms the "C declarations"
223 section of the input file. *Note Outline of a Bison Grammar:
227 Comment delimiters, as in C.
230 Separates a rule's result from its components. *Note Syntax of
231 Grammar Rules: Rules.
234 Terminates a rule. *Note Syntax of Grammar Rules: Rules.
237 Separates alternate rules for the same result nonterminal. *Note
238 Syntax of Grammar Rules: Rules.
241 File: bison.info, Node: Glossary, Next: Index, Prev: Table of Symbols, Up: Top
246 Backus-Naur Form (BNF)
247 Formal method of specifying context-free grammars. BNF was first
248 used in the `ALGOL-60' report, 1963. *Note Languages and
249 Context-Free Grammars: Language and Grammar.
251 Context-free grammars
252 Grammars specified as rules that can be applied regardless of
253 context. Thus, if there is a rule which says that an integer can
254 be used as an expression, integers are allowed _anywhere_ an
255 expression is permitted. *Note Languages and Context-Free
256 Grammars: Language and Grammar.
259 Allocation of memory that occurs during execution, rather than at
260 compile time or on entry to a function.
263 Analogous to the empty set in set theory, the empty string is a
264 character string of length zero.
266 Finite-state stack machine
267 A "machine" that has discrete states in which it is said to exist
268 at each instant in time. As input to the machine is processed, the
269 machine moves from state to state as specified by the logic of the
270 machine. In the case of the parser, the input is the language
271 being parsed, and the states correspond to various stages in the
272 grammar rules. *Note The Bison Parser Algorithm: Algorithm.
275 A language construct that is (in general) grammatically divisible;
276 for example, `expression' or `declaration' in C. *Note Languages
277 and Context-Free Grammars: Language and Grammar.
280 An arithmetic operator that is placed between the operands on
281 which it performs some operation.
284 A continuous flow of data between devices or programs.
287 One of the typical usage schemas of the language. For example,
288 one of the constructs of the C language is the `if' statement.
289 *Note Languages and Context-Free Grammars: Language and Grammar.
292 Operators having left associativity are analyzed from left to
293 right: `a+b+c' first computes `a+b' and then combines with `c'.
294 *Note Operator Precedence: Precedence.
297 A rule whose result symbol is also its first component symbol; for
298 example, `expseq1 : expseq1 ',' exp;'. *Note Recursive Rules:
301 Left-to-right parsing
302 Parsing a sentence of a language by analyzing it token by token
303 from left to right. *Note The Bison Parser Algorithm: Algorithm.
305 Lexical analyzer (scanner)
306 A function that reads an input stream and returns tokens one by
307 one. *Note The Lexical Analyzer Function `yylex': Lexical.
310 A flag, set by actions in the grammar rules, which alters the way
311 tokens are parsed. *Note Lexical Tie-ins::.
314 A token which consists of two or more fixed characters. *Note
318 A token already read but not yet shifted. *Note Look-Ahead
322 The class of context-free grammars that Bison (like most other
323 parser generators) can handle; a subset of LR(1). *Note
324 Mysterious Reduce/Reduce Conflicts: Mystery Conflicts.
327 The class of context-free grammars in which at most one token of
328 look-ahead is needed to disambiguate the parsing of any piece of
332 A grammar symbol standing for a grammatical construct that can be
333 expressed through rules in terms of smaller constructs; in other
334 words, a construct that is not a token. *Note Symbols::.
337 An error encountered during parsing of an input stream due to
338 invalid syntax. *Note Error Recovery::.
341 A function that recognizes valid sentences of a language by
342 analyzing the syntax structure of a set of tokens passed to it
343 from a lexical analyzer.
346 An arithmetic operator that is placed after the operands upon
347 which it performs some operation.
350 Replacing a string of nonterminals and/or terminals with a single
351 nonterminal, according to a grammar rule. *Note The Bison Parser
352 Algorithm: Algorithm.
355 A reentrant subprogram is a subprogram which can be in invoked any
356 number of times in parallel, without interference between the
357 various invocations. *Note A Pure (Reentrant) Parser: Pure Decl.
359 Reverse polish notation
360 A language in which all operators are postfix operators.
363 A rule whose result symbol is also its last component symbol; for
364 example, `expseq1: exp ',' expseq1;'. *Note Recursive Rules:
368 In computer languages, the semantics are specified by the actions
369 taken for each instance of the language, i.e., the meaning of each
370 statement. *Note Defining Language Semantics: Semantics.
373 A parser is said to shift when it makes the choice of analyzing
374 further input from the stream rather than reducing immediately some
375 already-recognized rule. *Note The Bison Parser Algorithm:
378 Single-character literal
379 A single character that is recognized and interpreted as is.
380 *Note From Formal Rules to Bison Input: Grammar in Bison.
383 The nonterminal symbol that stands for a complete valid utterance
384 in the language being parsed. The start symbol is usually listed
385 as the first nonterminal symbol in a language specification.
386 *Note The Start-Symbol: Start Decl.
389 A data structure where symbol names and associated data are stored
390 during parsing to allow for recognition and use of existing
391 information in repeated uses of a symbol. *Note Multi-function
395 A basic, grammatically indivisible unit of a language. The symbol
396 that describes a token in the grammar is a terminal symbol. The
397 input of the Bison parser is a stream of tokens which comes from
398 the lexical analyzer. *Note Symbols::.
401 A grammar symbol that has no rules in the grammar and therefore is
402 grammatically indivisible. The piece of text it represents is a
403 token. *Note Languages and Context-Free Grammars: Language and
407 File: bison.info, Node: Index, Prev: Glossary, Up: Top
416 * %expect: Expect Decl.
417 * %left: Using Precedence.
418 * %nonassoc: Using Precedence.
419 * %prec: Contextual Precedence.
420 * %pure_parser: Pure Decl.
421 * %right: Using Precedence.
422 * %start: Start Decl.
423 * %token: Token Decl.
425 * %union: Union Decl.
426 * @$ <1>: Action Features.
427 * @$: Actions and Locations.
428 * @N <1>: Action Features.
429 * @N: Actions and Locations.
431 * action data types: Action Types.
432 * action features summary: Action Features.
433 * actions in mid-rule: Mid-Rule Actions.
434 * actions, location: Actions and Locations.
435 * actions, semantic: Semantic Actions.
436 * additional C code section: C Code.
437 * algorithm of parser: Algorithm.
438 * associativity: Why Precedence.
439 * Backus-Naur form: Language and Grammar.
440 * Bison declaration summary: Decl Summary.
441 * Bison declarations: Declarations.
442 * Bison declarations (introduction): Bison Declarations.
443 * Bison grammar: Grammar in Bison.
444 * Bison invocation: Invocation.
445 * Bison parser: Bison Parser.
446 * Bison parser algorithm: Algorithm.
447 * Bison symbols, table of: Table of Symbols.
448 * Bison utility: Bison Parser.
449 * BISON_HAIRY: Environment Variables.
450 * BISON_SIMPLE: Environment Variables.
451 * BNF: Language and Grammar.
452 * C code, section for additional: C Code.
453 * C declarations section: C Declarations.
454 * C-language interface: Interface.
456 * calculator, infix notation: Infix Calc.
457 * calculator, multi-function: Multi-function Calc.
458 * calculator, simple: RPN Calc.
459 * character token: Symbols.
460 * compiling the parser: Rpcalc Compile.
461 * conflicts: Shift/Reduce.
462 * conflicts, reduce/reduce: Reduce/Reduce.
463 * conflicts, suppressing warnings of: Expect Decl.
464 * context-dependent precedence: Contextual Precedence.
465 * context-free grammar: Language and Grammar.
466 * controlling function: Rpcalc Main.
467 * dangling else: Shift/Reduce.
468 * data type of locations: Location Type.
469 * data types in actions: Action Types.
470 * data types of semantic values: Value Type.
471 * debugging: Debugging.
472 * declaration summary: Decl Summary.
473 * declarations, Bison: Declarations.
474 * declarations, Bison (introduction): Bison Declarations.
475 * declarations, C: C Declarations.
476 * declaring literal string tokens: Token Decl.
477 * declaring operator precedence: Precedence Decl.
478 * declaring the start symbol: Start Decl.
479 * declaring token type names: Token Decl.
480 * declaring value types: Union Decl.
481 * declaring value types, nonterminals: Type Decl.
482 * default action: Actions.
483 * default data type: Value Type.
484 * default location type: Location Type.
485 * default stack limit: Stack Overflow.
486 * default start symbol: Start Decl.
487 * defining language semantics: Semantics.
488 * else, dangling: Shift/Reduce.
489 * environment variables: Environment Variables.
490 * error: Error Recovery.
491 * error recovery: Error Recovery.
492 * error recovery, simple: Simple Error Recovery.
493 * error reporting function: Error Reporting.
494 * error reporting routine: Rpcalc Error.
495 * examples, simple: Examples.
496 * exercises: Exercises.
497 * file format: Grammar Layout.
498 * finite-state machine: Parser States.
499 * formal grammar: Grammar in Bison.
500 * format of grammar file: Grammar Layout.
501 * glossary: Glossary.
502 * grammar file: Grammar Layout.
503 * grammar rule syntax: Rules.
504 * grammar rules section: Grammar Rules.
505 * grammar, Bison: Grammar in Bison.
506 * grammar, context-free: Language and Grammar.
507 * grouping, syntactic: Language and Grammar.
508 * infix notation calculator: Infix Calc.
509 * interface: Interface.
510 * introduction: Introduction.
511 * invoking Bison: Invocation.
512 * invoking Bison under VMS: VMS Invocation.
513 * LALR(1): Mystery Conflicts.
514 * language semantics, defining: Semantics.
515 * layout of Bison grammar: Grammar Layout.
516 * left recursion: Recursion.
517 * lexical analyzer: Lexical.
518 * lexical analyzer, purpose: Bison Parser.
519 * lexical analyzer, writing: Rpcalc Lexer.
520 * lexical tie-in: Lexical Tie-ins.
521 * literal string token: Symbols.
522 * literal token: Symbols.
523 * location <1>: Locations.
524 * location: Locations Overview.
525 * location actions: Actions and Locations.
526 * look-ahead token: Look-Ahead.
527 * LR(1): Mystery Conflicts.
528 * main function in simple example: Rpcalc Main.
529 * mfcalc: Multi-function Calc.
530 * mid-rule actions: Mid-Rule Actions.
531 * multi-function calculator: Multi-function Calc.
532 * multicharacter literal: Symbols.
533 * mutual recursion: Recursion.
534 * nonterminal symbol: Symbols.
535 * operator precedence: Precedence.
536 * operator precedence, declaring: Precedence Decl.
537 * options for invoking Bison: Invocation.
538 * overflow of parser stack: Stack Overflow.
539 * parse error: Error Reporting.
540 * parser: Bison Parser.
541 * parser stack: Algorithm.
542 * parser stack overflow: Stack Overflow.
543 * parser state: Parser States.
544 * polish notation calculator: RPN Calc.
545 * position, textual <1>: Locations.
546 * position, textual: Locations Overview.
547 * precedence declarations: Precedence Decl.
548 * precedence of operators: Precedence.
549 * precedence, context-dependent: Contextual Precedence.
550 * precedence, unary operator: Contextual Precedence.
551 * preventing warnings about conflicts: Expect Decl.
552 * pure parser: Pure Decl.
553 * recovery from errors: Error Recovery.
554 * recursive rule: Recursion.
555 * reduce/reduce conflict: Reduce/Reduce.
556 * reduction: Algorithm.
557 * reentrant parser: Pure Decl.
558 * reverse polish notation: RPN Calc.
559 * right recursion: Recursion.
561 * rule syntax: Rules.
562 * rules section for grammar: Grammar Rules.
563 * running Bison (introduction): Rpcalc Gen.
564 * semantic actions: Semantic Actions.
565 * semantic value: Semantic Values.
566 * semantic value type: Value Type.
567 * shift/reduce conflicts: Shift/Reduce.
568 * shifting: Algorithm.
569 * simple examples: Examples.
570 * single-character literal: Symbols.
571 * stack overflow: Stack Overflow.
572 * stack, parser: Algorithm.
573 * stages in using Bison: Stages.
574 * start symbol: Language and Grammar.
575 * start symbol, declaring: Start Decl.
576 * state (of parser): Parser States.
577 * string token: Symbols.
578 * summary, action features: Action Features.
579 * summary, Bison declaration: Decl Summary.
580 * suppressing conflict warnings: Expect Decl.
582 * symbol table example: Mfcalc Symtab.
583 * symbols (abstract): Language and Grammar.
584 * symbols in Bison, table of: Table of Symbols.
585 * syntactic grouping: Language and Grammar.
586 * syntax error: Error Reporting.
587 * syntax of grammar rules: Rules.
588 * terminal symbol: Symbols.
589 * textual position <1>: Locations.
590 * textual position: Locations Overview.
591 * token: Language and Grammar.
592 * token type: Symbols.
593 * token type names, declaring: Token Decl.
594 * tracing the parser: Debugging.
595 * unary operator precedence: Contextual Precedence.
596 * using Bison: Stages.
597 * value type, semantic: Value Type.
598 * value types, declaring: Union Decl.
599 * value types, nonterminals, declaring: Type Decl.
600 * value, semantic: Semantic Values.
601 * VMS: VMS Invocation.
602 * warnings, preventing: Expect Decl.
603 * writing a lexical analyzer: Rpcalc Lexer.
604 * YYABORT: Parser Function.
605 * YYACCEPT: Parser Function.
606 * YYBACKUP: Action Features.
607 * yychar: Look-Ahead.
608 * yyclearin: Error Recovery.
609 * yydebug: Debugging.
610 * YYDEBUG: Debugging.
611 * YYEMPTY: Action Features.
612 * yyerrok: Error Recovery.
613 * YYERROR: Action Features.
614 * yyerror: Error Reporting.
615 * YYERROR_VERBOSE: Error Reporting.
616 * YYINITDEPTH: Stack Overflow.
618 * YYLEX_PARAM: Pure Calling.
619 * yylloc: Token Positions.
620 * YYLLOC_DEFAULT: Location Default Action.
621 * YYLTYPE: Token Positions.
622 * yylval: Token Values.
623 * YYMAXDEPTH: Stack Overflow.
624 * yynerrs: Error Reporting.
625 * yyparse: Parser Function.
626 * YYPARSE_PARAM: Pure Calling.
627 * YYPRINT: Debugging.
628 * YYRECOVERING: Error Recovery.