doc: use %precedence instead of nonassoc when associativity is not wanted

* doc/bison.texi: here.
Formatting changes in some grammars.
Fix a %prec into %precedence.
This commit is contained in:
Akim Demaille
2012-11-26 09:49:23 +01:00
parent c6b1772473
commit 589149dccf

View File

@@ -896,10 +896,7 @@ parses a vastly simplified form of Pascal type declarations.
@end group @end group
%% %%
@group
type_decl: TYPE ID '=' type ';' ; type_decl: TYPE ID '=' type ';' ;
@end group
@group @group
type: type:
@@ -1869,9 +1866,7 @@ here is the definition we will use:
@comment file: rpcalc.y @comment file: rpcalc.y
@example @example
@group
#include <stdio.h> #include <stdio.h>
@end group
@group @group
/* Called by yyparse on error. */ /* Called by yyparse on error. */
@@ -2641,9 +2636,7 @@ operators in @code{yylex}.
@comment file: mfcalc.y: 3 @comment file: mfcalc.y: 3
@example @example
@group
#include <ctype.h> #include <ctype.h>
@end group
@group @group
int int
@@ -3395,9 +3388,7 @@ one of your tokens with a @code{%token} declaration.
A Bison grammar rule has the following general form: A Bison grammar rule has the following general form:
@example @example
@group
@var{result}: @var{components}@dots{}; @var{result}: @var{components}@dots{};
@end group
@end example @end example
@noindent @noindent
@@ -3408,9 +3399,7 @@ are put together by this rule (@pxref{Symbols}).
For example, For example,
@example @example
@group
exp: exp '+' exp; exp: exp '+' exp;
@end group
@end example @end example
@noindent @noindent
@@ -3714,9 +3703,7 @@ difference with tools like Flex, for which @samp{|} stands for either
following example, the action is triggered only when @samp{b} is found: following example, the action is triggered only when @samp{b} is found:
@example @example
@group
a-or-b: 'a'|'b' @{ a_or_b_found = 1; @}; a-or-b: 'a'|'b' @{ a_or_b_found = 1; @};
@end group
@end example @end example
@cindex default action @cindex default action
@@ -6984,9 +6971,7 @@ rules. Here is a complete Bison grammar file that actually manifests
the conflict: the conflict:
@example @example
@group
%% %%
@end group
@group @group
stmt: stmt:
expr expr
@@ -7205,8 +7190,8 @@ instance as follows:
@example @example
@group @group
%nonassoc "then" %precedence "then"
%nonassoc "else" %precedence "else"
@end group @end group
@end example @end example
@@ -7219,7 +7204,7 @@ use right associativity:
@end example @end example
Neither solution is perfect however. Since Bison does not provide, so far, Neither solution is perfect however. Since Bison does not provide, so far,
support for ``scoped'' precedence, both force you to declare the precedence ``scoped'' precedence, both force you to declare the precedence
of these keywords with respect to the other operators your grammar. of these keywords with respect to the other operators your grammar.
Therefore, instead of being warned about new conflicts you would be unaware Therefore, instead of being warned about new conflicts you would be unaware
of (e.g., a shift/reduce conflict due to @samp{if test then 1 else 2 + 3} of (e.g., a shift/reduce conflict due to @samp{if test then 1 else 2 + 3}
@@ -7397,8 +7382,8 @@ sequence:
Here is another common error that yields a reduce/reduce conflict: Here is another common error that yields a reduce/reduce conflict:
@example @example
sequence:
@group @group
sequence:
/* empty */ /* empty */
| sequence words | sequence words
| sequence redirects | sequence redirects
@@ -7488,8 +7473,8 @@ relies on precedences: use @code{%prec} to give a lower precedence to the
rule: rule:
@example @example
%nonassoc "word" %precedence "word"
%nonassoc "sequence" %precedence "sequence"
%% %%
@group @group
sequence: sequence:
@@ -7538,15 +7523,16 @@ param_spec:
| name_list ':' type | name_list ':' type
; ;
@end group @end group
@group @group
return_spec: return_spec:
type type
| name ':' type | name ':' type
; ;
@end group @end group
@group
type: "id"; type: "id";
@end group
@group @group
name: "id"; name: "id";
name_list: name_list:
@@ -7620,14 +7606,19 @@ contexts to have different sets of active rules, because the one for
rather than the one for @code{name}. rather than the one for @code{name}.
@example @example
@group
param_spec: param_spec:
type type
| name_list ':' type | name_list ':' type
; ;
@end group
@group
return_spec: return_spec:
type type
| "id" ':' type | "id" ':' type
; ;
@end group
@end example @end example
For a more detailed exposition of LALR(1) parsers and parser For a more detailed exposition of LALR(1) parsers and parser
@@ -7732,7 +7723,8 @@ There are at least two scenarios where LALR can be worthwhile:
@cindex GLR with LALR @cindex GLR with LALR
When employing GLR parsers (@pxref{GLR Parsers}), if you do not resolve any When employing GLR parsers (@pxref{GLR Parsers}), if you do not resolve any
conflicts statically (for example, with @code{%left} or @code{%prec}), then conflicts statically (for example, with @code{%left} or @code{%precedence}),
then
the parser explores all potential parses of any given input. In this case, the parser explores all potential parses of any given input. In this case,
the choice of parser table construction algorithm is guaranteed not to alter the choice of parser table construction algorithm is guaranteed not to alter
the language accepted by the parser. LALR parser tables are the smallest the language accepted by the parser. LALR parser tables are the smallest