bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RFC: doc: use only @example, not @smallexample


From: Akim Demaille
Subject: Re: RFC: doc: use only @example, not @smallexample
Date: Fri, 16 Mar 2012 14:35:30 +0100

Le 16 mars 2012 à 09:24, Paul Eggert a écrit :

> On 03/16/2012 01:20 AM, Akim Demaille wrote:
>> I prefer the following style (which does help to stay
>> within a more reasonable width).
> 
> That style is OK by me.  Some might prefer indenting the
> "|" and ";" lines by a couple of spaces, which would also
> be fine and would scale nearly as well.

I have tried to do that first, but one example did not fit
this way, and it was significantly more painful to adjust to
that style instead of sticking to colon 0 (where M-\ and C-x
r k are very effective tools).

I propose the attached changes.

From bb864b6a2304e0eea7595ea68788e4a1d1a3c9bb Mon Sep 17 00:00:00 2001
From: Akim Demaille <address@hidden>
Date: Fri, 16 Mar 2012 14:26:00 +0100
Subject: [PATCH 1/3] doc: reformat grammar snippets.

* doc/bison.texinfo: Convert the grammar examples to
use a narrower style.  This helps fitting into the
@smallbook constraints.
http://lists.gnu.org/archive/html/bison-patches/2012-03/msg00011.html
---
 doc/bison.texinfo |  819 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 430 insertions(+), 389 deletions(-)

diff --git a/doc/bison.texinfo b/doc/bison.texinfo
index 9824781..b2012c6 100644
--- a/doc/bison.texinfo
+++ b/doc/bison.texinfo
@@ -642,8 +642,7 @@ the statement; the naked semicolon, and the colon, are 
Bison punctuation
 used in every rule.
 
 @example
-stmt:   RETURN expr ';'
-        ;
+stmt: RETURN expr ';' ;
 @end example
 
 @noindent
@@ -715,8 +714,7 @@ For example, here is a rule that says an expression can be 
the sum of
 two subexpressions:
 
 @example
-expr: expr '+' expr   @{ $$ = $1 + $3; @}
-        ;
+expr: expr '+' expr   @{ $$ = $1 + $3; @} ;
 @end example
 
 @noindent
@@ -896,30 +894,32 @@ parses a vastly simplified form of Pascal type 
declarations.
 %%
 
 @group
-type_decl : TYPE ID '=' type ';'
-     ;
+type_decl: TYPE ID '=' type ';' ;
 @end group
 
 @group
-type : '(' id_list ')'
-     | expr DOTDOT expr
-     ;
+type:
+  '(' id_list ')'
+| expr DOTDOT expr
+;
 @end group
 
 @group
-id_list : ID
-     | id_list ',' ID
-     ;
+id_list:
+  ID
+| id_list ',' ID
+;
 @end group
 
 @group
-expr : '(' expr ')'
-     | expr '+' expr
-     | expr '-' expr
-     | expr '*' expr
-     | expr '/' expr
-     | ID
-     ;
+expr:
+  '(' expr ')'
+| expr '+' expr
+| expr '-' expr
+| expr '*' expr
+| expr '/' expr
+| ID
+;
 @end group
 @end example
 
@@ -999,30 +999,35 @@ Let's consider an example, vastly simplified from a C++ 
grammar.
 
 %%
 
-prog :
-     | prog stmt   @{ printf ("\n"); @}
-     ;
+prog:
+  /* Nothing.  */
+| prog stmt   @{ printf ("\n"); @}
+;
 
-stmt : expr ';'  %dprec 1
-     | decl      %dprec 2
-     ;
+stmt:
+  expr ';'  %dprec 1
+| decl      %dprec 2
+;
 
-expr : ID               @{ printf ("%s ", $$); @}
-     | TYPENAME '(' expr ')'
-                        @{ printf ("%s <cast> ", $1); @}
-     | expr '+' expr    @{ printf ("+ "); @}
-     | expr '=' expr    @{ printf ("= "); @}
-     ;
+expr:
+  ID               @{ printf ("%s ", $$); @}
+| TYPENAME '(' expr ')'
+                   @{ printf ("%s <cast> ", $1); @}
+| expr '+' expr    @{ printf ("+ "); @}
+| expr '=' expr    @{ printf ("= "); @}
+;
 
-decl : TYPENAME declarator ';'
-                        @{ printf ("%s <declare> ", $1); @}
-     | TYPENAME declarator '=' expr ';'
-                        @{ printf ("%s <init-declare> ", $1); @}
-     ;
+decl:
+  TYPENAME declarator ';'
+                   @{ printf ("%s <declare> ", $1); @}
+| TYPENAME declarator '=' expr ';'
+                   @{ printf ("%s <init-declare> ", $1); @}
+;
 
-declarator : ID         @{ printf ("\"%s\" ", $1); @}
-     | '(' declarator ')'
-     ;
+declarator:
+  ID               @{ printf ("\"%s\" ", $1); @}
+| '(' declarator ')'
+;
 @end example
 
 @noindent
@@ -1091,9 +1096,10 @@ other.  To do so, you could change the declaration of 
@code{stmt} as
 follows:
 
 @example
-stmt : expr ';'  %merge <stmtMerge>
-     | decl      %merge <stmtMerge>
-     ;
+stmt:
+  expr ';'  %merge <stmtMerge>
+| decl      %merge <stmtMerge>
+;
 @end example
 
 @noindent
@@ -1207,9 +1213,9 @@ evolve.  We welcome user feedback.)  For example,
 
 @example
 widget:
-         address@hidden new_syntax @} "widget" id new_args   @{ $$ = f($3, 
$4); @}
-      |  address@hidden !new_syntax @} "widget" id old_args  @{ $$ = f($3, 
$4); @}
-      ;
+  address@hidden  new_syntax @} "widget" id new_args  @{ $$ = f($3, $4); @}
+| address@hidden !new_syntax @} "widget" id old_args  @{ $$ = f($3, $4); @}
+;
 @end example
 
 @noindent
@@ -1233,11 +1239,11 @@ For example, we could try to rewrite the previous 
example as
 
 @example
 widget:
-         @{ if (!new_syntax) YYERROR; @}
-              "widget" id new_args  @{ $$ = f($3, $4); @}
-      |  @{ if (new_syntax) YYERROR; @}
-              "widget" id old_args   @{ $$ = f($3, $4); @}
-      ;
+  @{ if (!new_syntax) YYERROR; @}
+    "widget" id new_args  @{ $$ = f($3, $4); @}
+|  @{ if (new_syntax) YYERROR; @}
+    "widget" id old_args   @{ $$ = f($3, $4); @}
+;
 @end example
 
 @noindent
@@ -1575,25 +1581,28 @@ Here are the grammar rules for the reverse polish 
notation calculator.
 @comment file: rpcalc.y
 @example
 @group
-input:    /* empty */
-        | input line
+input:
+  /* empty */
+| input line
 ;
 @end group
 
 @group
-line:     '\n'
-        | exp '\n'      @{ printf ("%.10g\n", $1); @}
+line:
+  '\n'
+| exp '\n'      @{ printf ("%.10g\n", $1); @}
 ;
 @end group
 
 @group
-exp:      NUM           @{ $$ = $1;           @}
-        | exp exp '+'   @{ $$ = $1 + $2;      @}
-        | exp exp '-'   @{ $$ = $1 - $2;      @}
-        | exp exp '*'   @{ $$ = $1 * $2;      @}
-        | exp exp '/'   @{ $$ = $1 / $2;      @}
-        | exp exp '^'   @{ $$ = pow ($1, $2); @}  /* Exponentiation */
-        | exp 'n'       @{ $$ = -$1;          @}  /* Unary minus    */
+exp:
+  NUM           @{ $$ = $1;           @}
+| exp exp '+'   @{ $$ = $1 + $2;      @}
+| exp exp '-'   @{ $$ = $1 - $2;      @}
+| exp exp '*'   @{ $$ = $1 * $2;      @}
+| exp exp '/'   @{ $$ = $1 / $2;      @}
+| exp exp '^'   @{ $$ = pow ($1, $2); @}  /* Exponentiation */
+| exp 'n'       @{ $$ = -$1;          @}  /* Unary minus    */
 ;
 @end group
 %%
@@ -1629,8 +1638,9 @@ rule are referred to as @code{$1}, @code{$2}, and so on.
 Consider the definition of @code{input}:
 
 @example
-input:    /* empty */
-        | input line
+input:
+  /* empty */
+| input line
 ;
 @end example
 
@@ -1663,8 +1673,9 @@ input tokens; we will arrange for the latter to happen at 
end-of-input.
 Now consider the definition of @code{line}:
 
 @example
-line:     '\n'
-        | exp '\n'  @{ printf ("%.10g\n", $1); @}
+line:
+  '\n'
+| exp '\n'  @{ printf ("%.10g\n", $1); @}
 ;
 @end example
 
@@ -1691,21 +1702,22 @@ The second handles an addition-expression, which looks 
like two expressions
 followed by a plus-sign.  The third handles subtraction, and so on.
 
 @example
-exp:      NUM
-        | exp exp '+'     @{ $$ = $1 + $2;    @}
-        | exp exp '-'     @{ $$ = $1 - $2;    @}
-        @dots{}
-        ;
+exp:
+  NUM
+| exp exp '+'     @{ $$ = $1 + $2;    @}
+| exp exp '-'     @{ $$ = $1 - $2;    @}
address@hidden
+;
 @end example
 
 We have used @samp{|} to join all the rules for @code{exp}, but we could
 equally well have written them separately:
 
 @example
-exp:      NUM ;
-exp:      exp exp '+'     @{ $$ = $1 + $2;    @} ;
-exp:      exp exp '-'     @{ $$ = $1 - $2;    @} ;
-        @dots{}
+exp: NUM ;
+exp: exp exp '+'     @{ $$ = $1 + $2; @};
+exp: exp exp '-'     @{ $$ = $1 - $2; @};
address@hidden
 @end example
 
 Most of the rules have actions that compute the value of the expression in
@@ -1726,16 +1738,17 @@ not require it.  You can add or change white space as 
much as you wish.
 For example, this:
 
 @example
-exp   : NUM | exp exp '+' @{$$ = $1 + $2; @} | @dots{} ;
+exp: NUM | exp exp '+' @{$$ = $1 + $2; @} | @dots{} ;
 @end example
 
 @noindent
 means the same thing as this:
 
 @example
-exp:      NUM
-        | exp exp '+'    @{ $$ = $1 + $2; @}
-        | @dots{}
+exp:
+  NUM
+| exp exp '+'    @{ $$ = $1 + $2; @}
+| @dots{}
 ;
 @end example
 
@@ -1983,26 +1996,29 @@ parentheses nested to arbitrary depth.  Here is the 
Bison code for
 
 %% /* The grammar follows.  */
 @group
-input:    /* empty */
-        | input line
+input:
+  /* empty */
+| input line
 ;
 @end group
 
 @group
-line:     '\n'
-        | exp '\n'  @{ printf ("\t%.10g\n", $1); @}
+line:
+  '\n'
+| exp '\n'  @{ printf ("\t%.10g\n", $1); @}
 ;
 @end group
 
 @group
-exp:      NUM                @{ $$ = $1;           @}
-        | exp '+' exp        @{ $$ = $1 + $3;      @}
-        | exp '-' exp        @{ $$ = $1 - $3;      @}
-        | exp '*' exp        @{ $$ = $1 * $3;      @}
-        | exp '/' exp        @{ $$ = $1 / $3;      @}
-        | '-' exp  %prec NEG @{ $$ = -$2;          @}
-        | exp '^' exp        @{ $$ = pow ($1, $3); @}
-        | '(' exp ')'        @{ $$ = $2;           @}
+exp:
+  NUM                @{ $$ = $1;           @}
+| exp '+' exp        @{ $$ = $1 + $3;      @}
+| exp '-' exp        @{ $$ = $1 - $3;      @}
+| exp '*' exp        @{ $$ = $1 * $3;      @}
+| exp '/' exp        @{ $$ = $1 / $3;      @}
+| '-' exp  %prec NEG @{ $$ = -$2;          @}
+| exp '^' exp        @{ $$ = pow ($1, $3); @}
+| '(' exp ')'        @{ $$ = $2;           @}
 ;
 @end group
 %%
@@ -2066,9 +2082,10 @@ been added to one of the alternatives for @code{line}:
 
 @example
 @group
-line:     '\n'
-        | exp '\n'   @{ printf ("\t%.10g\n", $1); @}
-        | error '\n' @{ yyerrok;                  @}
+line:
+  '\n'
+| exp '\n'   @{ printf ("\t%.10g\n", $1); @}
+| error '\n' @{ yyerrok;                  @}
 ;
 @end group
 @end example
@@ -2159,41 +2176,44 @@ wrong expressions or subexpressions.
 
 @example
 @group
-input   : /* empty */
-        | input line
+input:
+  /* empty */
+| input line
 ;
 @end group
 
 @group
-line    : '\n'
-        | exp '\n' @{ printf ("%d\n", $1); @}
+line:
+  '\n'
+| exp '\n' @{ printf ("%d\n", $1); @}
 ;
 @end group
 
 @group
-exp     : NUM           @{ $$ = $1; @}
-        | exp '+' exp   @{ $$ = $1 + $3; @}
-        | exp '-' exp   @{ $$ = $1 - $3; @}
-        | exp '*' exp   @{ $$ = $1 * $3; @}
+exp:
+  NUM           @{ $$ = $1; @}
+| exp '+' exp   @{ $$ = $1 + $3; @}
+| exp '-' exp   @{ $$ = $1 - $3; @}
+| exp '*' exp   @{ $$ = $1 * $3; @}
 @end group
 @group
-        | exp '/' exp
-            @{
-              if ($3)
-                $$ = $1 / $3;
-              else
-                @{
-                  $$ = 1;
-                  fprintf (stderr, "%d.%d-%d.%d: division by zero",
-                           @@3.first_line, @@3.first_column,
-                           @@3.last_line, @@3.last_column);
-                @}
-            @}
+| exp '/' exp
+    @{
+      if ($3)
+        $$ = $1 / $3;
+      else
+        @{
+          $$ = 1;
+          fprintf (stderr, "%d.%d-%d.%d: division by zero",
+                   @@3.first_line, @@3.first_column,
+                   @@3.last_line, @@3.last_column);
+        @}
+    @}
 @end group
 @group
-        | '-' exp %prec NEG     @{ $$ = -$2; @}
-        | exp '^' exp           @{ $$ = pow ($1, $3); @}
-        | '(' exp ')'           @{ $$ = $2; @}
+| '-' exp %prec NEG     @{ $$ = -$2; @}
+| exp '^' exp           @{ $$ = pow ($1, $3); @}
+| '(' exp ')'           @{ $$ = $2; @}
 @end group
 @end example
 
@@ -2588,31 +2608,33 @@ those which mention @code{VAR} or @code{FNCT}, are new.
 @example
 %% /* The grammar follows.  */
 @group
-input:   /* empty */
-        | input line
+input:
+  /* empty */
+| input line
 ;
 @end group
 
 @group
 line:
-          '\n'
-        | exp '\n'   @{ printf ("%.10g\n", $1); @}
-        | error '\n' @{ yyerrok;                @}
+  '\n'
+| exp '\n'   @{ printf ("%.10g\n", $1); @}
+| error '\n' @{ yyerrok;                @}
 ;
 @end group
 
 @group
-exp:      NUM                @{ $$ = $1;                         @}
-        | VAR                @{ $$ = $1->value.var;              @}
-        | VAR '=' exp        @{ $$ = $3; $1->value.var = $3;     @}
-        | FNCT '(' exp ')'   @{ $$ = (*($1->value.fnctptr))($3); @}
-        | exp '+' exp        @{ $$ = $1 + $3;                    @}
-        | exp '-' exp        @{ $$ = $1 - $3;                    @}
-        | exp '*' exp        @{ $$ = $1 * $3;                    @}
-        | exp '/' exp        @{ $$ = $1 / $3;                    @}
-        | '-' exp  %prec NEG @{ $$ = -$2;                        @}
-        | exp '^' exp        @{ $$ = pow ($1, $3);               @}
-        | '(' exp ')'        @{ $$ = $2;                         @}
+exp:
+  NUM                @{ $$ = $1;                         @}
+| VAR                @{ $$ = $1->value.var;              @}
+| VAR '=' exp        @{ $$ = $3; $1->value.var = $3;     @}
+| FNCT '(' exp ')'   @{ $$ = (*($1->value.fnctptr))($3); @}
+| exp '+' exp        @{ $$ = $1 + $3;                    @}
+| exp '-' exp        @{ $$ = $1 - $3;                    @}
+| exp '*' exp        @{ $$ = $1 * $3;                    @}
+| exp '/' exp        @{ $$ = $1 / $3;                    @}
+| '-' exp  %prec NEG @{ $$ = -$2;                        @}
+| exp '^' exp        @{ $$ = pow ($1, $3);               @}
+| '(' exp ')'        @{ $$ = $2;                         @}
 ;
 @end group
 /* End of grammar.  */
@@ -3531,8 +3553,7 @@ A Bison grammar rule has the following general form:
 
 @example
 @group
address@hidden: @address@hidden
-        ;
address@hidden: @address@hidden;
 @end group
 @end example
 
@@ -3545,8 +3566,7 @@ For example,
 
 @example
 @group
-exp:      exp '+' exp
-        ;
+exp: exp '+' exp;
 @end group
 @end example
 
@@ -3591,10 +3611,11 @@ be joined with the vertical-bar character @samp{|} as 
follows:
 
 @example
 @group
address@hidden:    @address@hidden
-        | @address@hidden
-        @dots{}
-        ;
address@hidden:
+  @address@hidden
+| @address@hidden
address@hidden
+;
 @end group
 @end example
 
@@ -3607,15 +3628,17 @@ comma-separated sequence of zero or more @code{exp} 
groupings:
 
 @example
 @group
-expseq:   /* empty */
-        | expseq1
-        ;
+expseq:
+  /* empty */
+| expseq1
+;
 @end group
 
 @group
-expseq1:  exp
-        | expseq1 ',' exp
-        ;
+expseq1:
+  exp
+| expseq1 ',' exp
+;
 @end group
 @end example
 
@@ -3635,9 +3658,10 @@ comma-separated sequence of one or more expressions:
 
 @example
 @group
-expseq1:  exp
-        | expseq1 ',' exp
-        ;
+expseq1:
+  exp
+| expseq1 ',' exp
+;
 @end group
 @end example
 
@@ -3650,9 +3674,10 @@ the same construct is defined using @dfn{right 
recursion}:
 
 @example
 @group
-expseq1:  exp
-        | exp ',' expseq1
-        ;
+expseq1:
+  exp
+| exp ',' expseq1
+;
 @end group
 @end example
 
@@ -3676,15 +3701,17 @@ For example:
 
 @example
 @group
-expr:     primary
-        | primary '+' primary
-        ;
+expr:
+  primary
+| primary '+' primary
+;
 @end group
 
 @group
-primary:  constant
-        | '(' expr ')'
-        ;
+primary:
+  constant
+| '(' expr ')'
+;
 @end group
 @end example
 
@@ -3806,9 +3833,9 @@ Here is a typical example:
 
 @example
 @group
-exp:    @dots{}
-        | exp '+' exp
-            @{ $$ = $1 + $3; @}
+exp:
address@hidden
+| exp '+' exp     @{ $$ = $1 + $3; @}
 @end group
 @end example
 
@@ -3816,9 +3843,9 @@ Or, in terms of named references:
 
 @example
 @group
-exp[result]:    @dots{}
-        | exp[left] '+' exp[right]
-            @{ $result = $left + $right; @}
+exp[result]:
address@hidden
+| exp[left] '+' exp[right]  @{ $result = $left + $right; @}
 @end group
 @end example
 
@@ -3865,15 +3892,16 @@ is a case in which you can use this reliably:
 
 @example
 @group
-foo:      expr bar '+' expr  @{ @dots{} @}
-        | expr bar '-' expr  @{ @dots{} @}
-        ;
+foo:
+  expr bar '+' expr  @{ @dots{} @}
+| expr bar '-' expr  @{ @dots{} @}
+;
 @end group
 
 @group
-bar:      /* empty */
-        @{ previous_expr = $0; @}
-        ;
+bar:
+  /* empty */    @{ previous_expr = $0; @}
+;
 @end group
 @end example
 
@@ -3903,9 +3931,9 @@ in the rule.  In this example,
 
 @example
 @group
-exp:    @dots{}
-        | exp '+' exp
-            @{ $$ = $1 + $3; @}
+exp:
+  @dots{}
+| exp '+' exp    @{ $$ = $1 + $3; @}
 @end group
 @end example
 
@@ -3972,11 +4000,11 @@ remove it afterward.  Here is how it is done:
 
 @example
 @group
-stmt:   LET '(' var ')'
-                @{ $<context>$ = push_context ();
-                  declare_variable ($3); @}
-        stmt    @{ $$ = $6;
-                  pop_context ($<context>5); @}
+stmt:
+  LET '(' var ')'
+    @{ $<context>$ = push_context (); declare_variable ($3); @}
+  stmt
+    @{ $$ = $6; pop_context ($<context>5); @}
 @end group
 @end example
 
@@ -4018,15 +4046,19 @@ declare a destructor for that symbol:
 
 %%
 
-stmt:  let stmt
-               @{ $$ = $2;
-                 pop_context ($1); @}
-       ;
+stmt:
+  let stmt
+    @{
+      $$ = $2;
+      pop_context ($1);
+    @};
 
-let:   LET '(' var ')'
-               @{ $$ = push_context ();
-                 declare_variable ($3); @}
-       ;
+let:
+  LET '(' var ')'
+    @{
+      $$ = push_context ();
+      declare_variable ($3);
+    @};
 
 @end group
 @end example
@@ -4045,9 +4077,10 @@ declaration or not:
 
 @example
 @group
-compound: '@{' declarations statements '@}'
-        | '@{' statements '@}'
-        ;
+compound:
+  '@{' declarations statements '@}'
+| '@{' statements '@}'
+;
 @end group
 @end example
 
@@ -4056,12 +4089,13 @@ But when we add a mid-rule action as follows, the rules 
become nonfunctional:
 
 @example
 @group
-compound: @{ prepare_for_local_variables (); @}
-          '@{' declarations statements '@}'
+compound:
+  @{ prepare_for_local_variables (); @}
+     '@{' declarations statements '@}'
 @end group
 @group
-        | '@{' statements '@}'
-        ;
+|    '@{' statements '@}'
+;
 @end group
 @end example
 
@@ -4078,11 +4112,12 @@ actions into the two rules, like this:
 
 @example
 @group
-compound: @{ prepare_for_local_variables (); @}
-          '@{' declarations statements '@}'
-        | @{ prepare_for_local_variables (); @}
-          '@{' statements '@}'
-        ;
+compound:
+  @{ prepare_for_local_variables (); @}
+    '@{' declarations statements '@}'
+| @{ prepare_for_local_variables (); @}
+    '@{' statements '@}'
+;
 @end group
 @end example
 
@@ -4096,10 +4131,11 @@ does work is to put the action after the open-brace, 
like this:
 
 @example
 @group
-compound: '@{' @{ prepare_for_local_variables (); @}
-          declarations statements '@}'
-        | '@{' statements '@}'
-        ;
+compound:
+  '@{' @{ prepare_for_local_variables (); @}
+    declarations statements '@}'
+| '@{' statements '@}'
+;
 @end group
 @end example
 
@@ -4112,18 +4148,16 @@ serves as a subroutine:
 
 @example
 @group
-subroutine: /* empty */
-          @{ prepare_for_local_variables (); @}
-        ;
-
+subroutine:
+  /* empty */  @{ prepare_for_local_variables (); @}
+;
 @end group
 
 @group
-compound: subroutine
-          '@{' declarations statements '@}'
-        | subroutine
-          '@{' statements '@}'
-        ;
+compound:
+  subroutine '@{' declarations statements '@}'
+| subroutine '@{' statements '@}'
+;
 @end group
 @end example
 
@@ -4208,24 +4242,25 @@ Here is a basic example using the default data type for 
locations:
 
 @example
 @group
-exp:    @dots{}
-        | exp '/' exp
-            @{
-              @@$.first_column = @@1.first_column;
-              @@$.first_line = @@1.first_line;
-              @@$.last_column = @@3.last_column;
-              @@$.last_line = @@3.last_line;
-              if ($3)
-                $$ = $1 / $3;
-              else
-                @{
-                  $$ = 1;
-                  fprintf (stderr,
-                           "Division by zero, l%d,c%d-l%d,c%d",
-                           @@3.first_line, @@3.first_column,
-                           @@3.last_line, @@3.last_column);
-                @}
-            @}
+exp:
+  @dots{}
+| exp '/' exp
+    @{
+      @@$.first_column = @@1.first_column;
+      @@$.first_line = @@1.first_line;
+      @@$.last_column = @@3.last_column;
+      @@$.last_line = @@3.last_line;
+      if ($3)
+        $$ = $1 / $3;
+      else
+        @{
+          $$ = 1;
+          fprintf (stderr,
+                   "Division by zero, l%d,c%d-l%d,c%d",
+                   @@3.first_line, @@3.first_column,
+                   @@3.last_line, @@3.last_column);
+        @}
+    @}
 @end group
 @end example
 
@@ -4239,20 +4274,21 @@ example above simply rewrites this way:
 
 @example
 @group
-exp:    @dots{}
-        | exp '/' exp
-            @{
-              if ($3)
-                $$ = $1 / $3;
-              else
-                @{
-                  $$ = 1;
-                  fprintf (stderr,
-                           "Division by zero, l%d,c%d-l%d,c%d",
-                           @@3.first_line, @@3.first_column,
-                           @@3.last_line, @@3.last_column);
-                @}
-            @}
+exp:
+  @dots{}
+| exp '/' exp
+    @{
+      if ($3)
+        $$ = $1 / $3;
+      else
+        @{
+          $$ = 1;
+          fprintf (stderr,
+                   "Division by zero, l%d,c%d-l%d,c%d",
+                   @@3.first_line, @@3.first_column,
+                   @@3.last_line, @@3.last_column);
+        @}
+    @}
 @end group
 @end example
 
@@ -6804,16 +6840,18 @@ factorial operators (@samp{!}), and allow parentheses 
for grouping.
 
 @example
 @group
-expr:     term '+' expr
-        | term
-        ;
+expr:
+  term '+' expr
+| term
+;
 @end group
 
 @group
-term:     '(' expr ')'
-        | term '!'
-        | NUMBER
-        ;
+term:
+  '(' expr ')'
+| term '!'
+| NUMBER
+;
 @end group
 @end example
 
@@ -6851,9 +6889,9 @@ statements, with a pair of rules like this:
 @example
 @group
 if_stmt:
-          IF expr THEN stmt
-        | IF expr THEN stmt ELSE stmt
-        ;
+  IF expr THEN stmt
+| IF expr THEN stmt ELSE stmt
+;
 @end group
 @end example
 
@@ -6920,20 +6958,22 @@ the conflict:
 %%
 @end group
 @group
-stmt:     expr
-        | if_stmt
-        ;
+stmt:
+  expr
+| if_stmt
+;
 @end group
 
 @group
 if_stmt:
-          IF expr THEN stmt
-        | IF expr THEN stmt ELSE stmt
-        ;
+  IF expr THEN stmt
+| IF expr THEN stmt ELSE stmt
+;
 @end group
 
-expr:     variable
-        ;
+expr:
+  variable
+;
 @end example
 
 @node Precedence
@@ -6962,12 +7002,13 @@ input @address@hidden - 2 * 3}} can be parsed in two 
different ways):
 
 @example
 @group
-expr:     expr '-' expr
-        | expr '*' expr
-        | expr '<' expr
-        | '(' expr ')'
-        @dots{}
-        ;
+expr:
+  expr '-' expr
+| expr '*' expr
+| expr '<' expr
+| '(' expr ')'
address@hidden
+;
 @end group
 @end example
 
@@ -7172,10 +7213,11 @@ Now the precedence of @code{UMINUS} can be used in 
specific rules:
 
 @example
 @group
-exp:    @dots{}
-        | exp '-' exp
-        @dots{}
-        | '-' exp %prec UMINUS
+exp:
+  @dots{}
+| exp '-' exp
+  @dots{}
+| '-' exp %prec UMINUS
 @end group
 @end example
 
@@ -7241,20 +7283,18 @@ of zero or more @code{word} groupings.
 
 @example
 @group
-sequence: /* empty */
-                @{ printf ("empty sequence\n"); @}
-        | maybeword
-        | sequence word
-                @{ printf ("added word %s\n", $2); @}
-        ;
+sequence:
+  /* empty */    @{ printf ("empty sequence\n"); @}
+| maybeword
+| sequence word  @{ printf ("added word %s\n", $2); @}
+;
 @end group
 
 @group
-maybeword: /* empty */
-                @{ printf ("empty maybeword\n"); @}
-        | word
-                @{ printf ("single word %s\n", $1); @}
-        ;
+maybeword:
+  /* empty */   @{ printf ("empty maybeword\n"); @}
+| word          @{ printf ("single word %s\n", $1); @}
+;
 @end group
 @end example
 
@@ -7282,28 +7322,30 @@ reduce/reduce conflict must be studied and usually 
eliminated.  Here is the
 proper way to define @code{sequence}:
 
 @example
-sequence: /* empty */
-                @{ printf ("empty sequence\n"); @}
-        | sequence word
-                @{ printf ("added word %s\n", $2); @}
-        ;
+sequence:
+  /* empty */    @{ printf ("empty sequence\n"); @}
+| sequence word  @{ printf ("added word %s\n", $2); @}
+;
 @end example
 
 Here is another common error that yields a reduce/reduce conflict:
 
 @example
-sequence: /* empty */
-        | sequence words
-        | sequence redirects
-        ;
+sequence:
+  /* empty */
+| sequence words
+| sequence redirects
+;
 
-words:    /* empty */
-        | words word
-        ;
+words:
+  /* empty */
+| words word
+;
 
-redirects:/* empty */
-        | redirects redirect
-        ;
+redirects:
+  /* empty */
+| redirects redirect
+;
 @end example
 
 @noindent
@@ -7322,10 +7364,11 @@ Here are two ways to correct these rules.  First, to 
make it a single level
 of sequence:
 
 @example
-sequence: /* empty */
-        | sequence word
-        | sequence redirect
-        ;
+sequence:
+  /* empty */
+| sequence word
+| sequence redirect
+;
 @end example
 
 Second, to prevent either a @code{words} or a @code{redirects}
@@ -7333,22 +7376,25 @@ from being empty:
 
 @example
 @group
-sequence: /* empty */
-        | sequence words
-        | sequence redirects
-        ;
+sequence:
+  /* empty */
+| sequence words
+| sequence redirects
+;
 @end group
 
 @group
-words:    word
-        | words word
-        ;
+words:
+  word
+| words word
+;
 @end group
 
 @group
-redirects:redirect
-        | redirects redirect
-        ;
+redirects:
+  redirect
+| redirects redirect
+;
 @end group
 @end example
 
@@ -7364,30 +7410,27 @@ Here is an example:
 %token ID
 
 %%
-def:    param_spec return_spec ','
-        ;
+def: param_spec return_spec ',';
 param_spec:
-             type
-        |    name_list ':' type
-        ;
+  type
+| name_list ':' type
+;
 @end group
 @group
 return_spec:
-             type
-        |    name ':' type
-        ;
+  type
+| name ':' type
+;
 @end group
 @group
-type:        ID
-        ;
+type: ID;
 @end group
 @group
-name:        ID
-        ;
+name: ID;
 name_list:
-             name
-        |    name ',' name_list
-        ;
+  name
+| name ',' name_list
+;
 @end group
 @end example
 
@@ -7436,11 +7479,10 @@ distinct.  In the above example, adding one rule to
 %%
 @dots{}
 return_spec:
-             type
-        |    name ':' type
-        /* This rule is never used.  */
-        |    ID BOGUS
-        ;
+  type
+| name ':' type
+| ID BOGUS       /* This rule is never used.  */
+;
 @end group
 @end example
 
@@ -7460,13 +7502,13 @@ rather than the one for @code{name}.
 
 @example
 param_spec:
-             type
-        |    name_list ':' type
-        ;
+  type
+| name_list ':' type
+;
 return_spec:
-             type
-        |    ID ':' type
-        ;
+  type
+| ID ':' type
+;
 @end example
 
 For a more detailed exposition of LALR(1) parsers and parser
@@ -8043,10 +8085,11 @@ in the current context, the parse can continue.
 For example:
 
 @example
-stmnts:  /* empty string */
-        | stmnts '\n'
-        | stmnts exp '\n'
-        | stmnts error '\n'
+stmnts:
+  /* empty string */
+| stmnts '\n'
+| stmnts exp '\n'
+| stmnts error '\n'
 @end example
 
 The fourth rule in this example says that an error followed by a newline
@@ -8087,10 +8130,11 @@ close-delimiter will probably appear to be unmatched, 
and generate another,
 spurious error message:
 
 @example
-primary:  '(' expr ')'
-        | '(' error ')'
-        @dots{}
-        ;
+primary:
+  '(' expr ')'
+| '(' error ')'
address@hidden
+;
 @end example
 
 Error recovery strategies are necessarily guesses.  When they guess wrong,
@@ -8212,18 +8256,16 @@ duplication, with actions omitted for brevity:
 @example
 @group
 initdcl:
-          declarator maybeasm '='
-          init
-        | declarator maybeasm
-        ;
+  declarator maybeasm '=' init
+| declarator maybeasm
+;
 @end group
 
 @group
 notype_initdcl:
-          notype_declarator maybeasm '='
-          init
-        | notype_declarator maybeasm
-        ;
+  notype_declarator maybeasm '=' init
+| notype_declarator maybeasm
+;
 @end group
 @end example
 
@@ -8264,24 +8306,21 @@ as an identifier if it appears in that context.  Here 
is how you can do it:
 @dots{}
 @end group
 @group
-expr:   IDENTIFIER
-        | constant
-        | HEX '('
-                @{ hexflag = 1; @}
-          expr ')'
-                @{ hexflag = 0;
-                   $$ = $4; @}
-        | expr '+' expr
-                @{ $$ = make_sum ($1, $3); @}
-        @dots{}
-        ;
+expr:
+  IDENTIFIER
+| constant
+| HEX '('        @{ hexflag = 1; @}
+    expr ')'     @{ hexflag = 0; $$ = $4; @}
+| expr '+' expr  @{ $$ = make_sum ($1, $3); @}
address@hidden
+;
 @end group
 
 @group
 constant:
-          INTEGER
-        | STRING
-        ;
+  INTEGER
+| STRING
+;
 @end group
 @end example
 
@@ -8307,12 +8346,12 @@ For example, in C-like languages, a typical error 
recovery rule is to skip
 tokens until the next semicolon, and then start a new statement, like this:
 
 @example
-stmt:   expr ';'
-        | IF '(' expr ')' stmt @{ @dots{} @}
-        @dots{}
-        error ';'
-                @{ hexflag = 0; @}
-        ;
+stmt:
+  expr ';'
+| IF '(' expr ')' stmt @{ @dots{} @}
address@hidden
+| error ';'  @{ hexflag = 0; @}
+;
 @end example
 
 If there is a syntax error in the middle of a @samp{hex (@var{expr})}
@@ -8329,11 +8368,11 @@ and skips to the close-parenthesis:
 
 @example
 @group
-expr:   @dots{}
-        | '(' expr ')'
-                @{ $$ = $2; @}
-        | '(' error ')'
-        @dots{}
+expr:
+  @dots{}
+| '(' expr ')'   @{ $$ = $2; @}
+| '(' error ')'
address@hidden
 @end group
 @end example
 
@@ -8391,12 +8430,13 @@ The following grammar file, @file{calc.y}, will be used 
in the sequel:
 %left '+' '-'
 %left '*'
 %%
-exp: exp '+' exp
-   | exp '-' exp
-   | exp '*' exp
-   | exp '/' exp
-   | NUM
-   ;
+exp:
+  exp '+' exp
+| exp '-' exp
+| exp '*' exp
+| exp '/' exp
+| NUM
+;
 useless: STR;
 %%
 @end example
@@ -9022,7 +9062,7 @@ Also warn about mid-rule values that are used but not set.
 For example, warn about unset @code{$$} in the mid-rule action in:
 
 @example
- exp: '1' @{ $1 = 1; @} '+' exp @{ $$ = $2 + $4; @};
+exp: '1' @{ $1 = 1; @} '+' exp @{ $$ = $2 + $4; @};
 @end example
 
 These warnings are not enabled by default since they sometimes prove to
@@ -10078,8 +10118,8 @@ Location Tracking Calculator: @code{ltcalc}}).
 unit: assignments exp  @{ driver.result = $2; @};
 
 assignments:
-  assignments assignment @address@hidden
-| /* Nothing.  */        @address@hidden;
+  /* Nothing.  */        @address@hidden
+| assignments assignment @address@hidden;
 
 assignment:
   "identifier" ":=" exp @{ driver.variables[$1] = $3; @};
@@ -11149,8 +11189,9 @@ real start-symbol:
 @example
 %token START_FOO START_BAR;
 %start start;
-start: START_FOO foo
-     | START_BAR bar;
+start:
+  START_FOO foo
+| START_BAR bar;
 @end example
 
 These tokens prevents the introduction of new conflicts.  As far as the
-- 
1.7.9.2





reply via email to

[Prev in Thread] Current Thread [Next in Thread]