-Ceci est le fichier Info bison.info, produit par Makeinfo version 4.0 à
-partir bison.texinfo.
+Ceci est le fichier Info bison.info, produit par Makeinfo version 4.0b
+à partir bison.texinfo.
START-INFO-DIR-ENTRY
* bison: (bison). GNU Project parser generator (yacc replacement).
included in translations approved by the Free Software Foundation
instead of in the original English.
+\1f
+File: bison.info, Node: Precedence, Next: Contextual Precedence, Prev: Shift/Reduce, Up: Algorithm
+
+Operator Precedence
+===================
+
+ Another situation where shift/reduce conflicts appear is in
+arithmetic expressions. Here shifting is not always the preferred
+resolution; the Bison declarations for operator precedence allow you to
+specify when to shift and when to reduce.
+
+* Menu:
+
+* Why Precedence:: An example showing why precedence is needed.
+* Using Precedence:: How to specify precedence in Bison grammars.
+* Precedence Examples:: How these features are used in the previous example.
+* How Precedence:: How they work.
+
+\1f
+File: bison.info, Node: Why Precedence, Next: Using Precedence, Up: Precedence
+
+When Precedence is Needed
+-------------------------
+
+ Consider the following ambiguous grammar fragment (ambiguous because
+the input `1 - 2 * 3' can be parsed in two different ways):
+
+ expr: expr '-' expr
+ | expr '*' expr
+ | expr '<' expr
+ | '(' expr ')'
+ ...
+ ;
+
+Suppose the parser has seen the tokens `1', `-' and `2'; should it
+reduce them via the rule for the subtraction operator? It depends on
+the next token. Of course, if the next token is `)', we must reduce;
+shifting is invalid because no single rule can reduce the token
+sequence `- 2 )' or anything starting with that. But if the next token
+is `*' or `<', we have a choice: either shifting or reduction would
+allow the parse to complete, but with different results.
+
+ To decide which one Bison should do, we must consider the results.
+If the next operator token OP is shifted, then it must be reduced first
+in order to permit another opportunity to reduce the difference. The
+result is (in effect) `1 - (2 OP 3)'. On the other hand, if the
+subtraction is reduced before shifting OP, the result is
+`(1 - 2) OP 3'. Clearly, then, the choice of shift or reduce should
+depend on the relative precedence of the operators `-' and OP: `*'
+should be shifted first, but not `<'.
+
+ What about input such as `1 - 2 - 5'; should this be `(1 - 2) - 5'
+or should it be `1 - (2 - 5)'? For most operators we prefer the
+former, which is called "left association". The latter alternative,
+"right association", is desirable for assignment operators. The choice
+of left or right association is a matter of whether the parser chooses
+to shift or reduce when the stack contains `1 - 2' and the look-ahead
+token is `-': shifting makes right-associativity.
+
\1f
File: bison.info, Node: Using Precedence, Next: Precedence Examples, Prev: Why Precedence, Up: Precedence
Here INFILE is the grammar file name, which usually ends in `.y'.
The parser file's name is made by replacing the `.y' with `.tab.c'.
Thus, the `bison foo.y' filename yields `foo.tab.c', and the `bison
-hack/foo.y' filename yields `hack/foo.tab.c'.
+hack/foo.y' filename yields `hack/foo.tab.c'. It's is also possible, in
+case you are writting C++ code instead of C in your grammar file, to
+name it `foo.ypp' or `foo.y++'. Then, the output files will take an
+extention like the given one as input (repectively `foo.tab.cpp' and
+`foo.tab.c++'). This feature takes effect with all options that
+manipulate filenames like `-o' or `-d'.
+
+ For example :
+
+ bison -d INFILE.YXX
+ will produce `infile.tab.cxx' and `infile.tab.hxx'. and
+
+ bison -d INFILE.Y -o OUTPUT.C++
+ will produce `output.c++' and `outfile.h++'.
* Menu:
Tuning the parser:
+`-S FILE'
+`--skeleton=FILE'
+ Specify the skeleton to use. You probably don't need this option
+ unless you are developing Bison.
+
`-t'
`--debug'
Output a definition of the macro `YYDEBUG' into the parser file, so
`--no-parser'
Pretend that `%no_parser' was specified. *Note Decl Summary::.
-`-r'
-`--raw'
- Pretend that `%raw' was specified. *Note Decl Summary::.
-
`-k'
`--token-table'
Pretend that `%token_table' was specified. *Note Decl Summary::.
--no-lines -l
--no-parser -n
--output-file=OUTFILE -o OUTFILE
- --raw -r
--token-table -k
--verbose -v
--version -V
`YYLTYPE'
Macro for the data type of `yylloc'; a structure with four
- members. *Note Textual Positions of Tokens: Token Positions.
+ members. *Note Data Types of Locations: Location Type.
`yyltype'
Default value for YYLTYPE.
Bison declaration to request a pure (reentrant) parser. *Note A
Pure (Reentrant) Parser: Pure Decl.
-`%raw'
- Bison declaration to use Bison internal token code numbers in token
- tables instead of the usual Yacc-compatible token code numbers.
- *Note Decl Summary::.
-
`%right'
Bison declaration to assign right associativity to token(s).
*Note Operator Precedence: Precedence Decl.