]> git.saurik.com Git - bison.git/blobdiff - doc/bison.texinfo
Use "%no-default-prec" instead of "%default-prec 0".
[bison.git] / doc / bison.texinfo
index b316d4307dd2e14e0627240c2872d486ce7be6a0..a6e2ee37011f443b9fb9133df0d5784431412357 100644 (file)
@@ -3679,9 +3679,14 @@ Declare a terminal symbol (token type name) that is left-associative
 
 @deffn {Directive} %nonassoc
 Declare a terminal symbol (token type name) that is nonassociative
-(using it in a way that would be associative is a syntax error)
-@end deffn
 (@pxref{Precedence Decl, ,Operator Precedence}).
+Using it in a way that would be associative is a syntax error.
+@end deffn
+
+@deffn {Directive} %default-prec
+Assign a precedence to rules lacking an explicit @code{%prec} modifier
+(@pxref{Contextual Precedence, ,Context-Dependent Precedence}).
+@end deffn
 
 @deffn {Directive} %type
 Declare the type of semantic values for a nonterminal symbol
@@ -3753,6 +3758,12 @@ and so on.  @xref{Multiple Parsers, ,Multiple Parsers in the Same
 Program}.
 @end deffn
 
+@deffn {Directive} %no-default-prec
+Do not assign a precedence to rules lacking an explicit @code{%prec}
+modifier (@pxref{Contextual Precedence, ,Context-Dependent
+Precedence}).
+@end deffn
+
 @deffn {Directive} %no-parser
 Do not include any C code in the parser file; generate tables only.  The
 parser file contains just @code{#define} directives and static variable
@@ -4851,6 +4862,26 @@ exp:    @dots{}
 @end group
 @end example
 
+If you forget to append @code{%prec UMINUS} to the rule for unary
+minus, Bison silently assumes that minus has its usual precedence.
+This kind of problem can be tricky to debug, since one typically
+discovers the mistake only by testing the code.
+
+The @code{%no-default-prec;} declaration makes it easier to discover
+this kind of problem systematically.  It causes rules that lack a
+@code{%prec} modifier to have no precedence, even if the last terminal
+symbol mentioned in their components has a declared precedence.
+
+If @code{%no-default-prec;} is in effect, you must specify @code{%prec}
+for all rules that participate in precedence conflict resolution.
+Then you will see any shift/reduce conflict until you tell Bison how
+to resolve it, either by changing your grammar or by adding an
+explicit precedence.  This will probably add declarations to the
+grammar, but it helps to protect against incorrect rule precedences.
+
+The effect of @code{%no-default-prec;} can be reversed by giving
+@code{%default-prec;}, which is the default.
+
 @node Parser States
 @section Parser States
 @cindex finite-state machine
@@ -6782,6 +6813,12 @@ parsing.  @xref{Parser Function, ,The Parser Function @code{yyparse}}.
 Equip the parser for debugging.  @xref{Decl Summary}.
 @end deffn
 
+@deffn {Directive} %default-prec
+Assign a precedence to rules that lack an explicit @samp{%prec}
+modifier.  @xref{Contextual Precedence, ,Context-Dependent
+Precedence}.
+@end deffn
+
 @deffn {Directive} %defines
 Bison declaration to create a header file meant for the scanner.
 @xref{Decl Summary}.
@@ -6835,6 +6872,12 @@ function is applied to the two semantic values to get a single result.
 Bison declaration to rename the external symbols.  @xref{Decl Summary}.
 @end deffn
 
+@deffn {Directive} %no-default-prec
+Do not assign a precedence to rules that lack an explicit @samp{%prec}
+modifier.  @xref{Contextual Precedence, ,Context-Dependent
+Precedence}.
+@end deffn
+
 @deffn {Directive} %no-lines
 Bison declaration to avoid generating @code{#line} directives in the
 parser file.  @xref{Decl Summary}.