bug-bison
[Top][All Lists]
Advanced

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

Comments in %union processed incorrectly


From: Ernst Christen
Subject: Comments in %union processed incorrectly
Date: Fri, 28 Dec 2001 22:06:22 -0800

Problem Report
==============
Submitted by Ernst Christen, address@hidden

1. Problem Description
----------------------
The leading slash of a comment occuring in a %union specification
appears twice in the generated output, i.e.

%union {
double val;             /* For returning numbers. */
symrec *tptr;           /* For returning symbol-table pointers */
}

produces

typedef union {
double val;             //* For returning numbers. */
symrec *tptr;           //* For returning symbol-table pointers */
} YYSTYPE;


2. Code Defect
--------------
Function parse_union_decl in file reader.c copies the characters it
reads to output before interpreting them. When encountering a '/' it
calls copy_comment2, which has at its beginning the following code:

  /* We read a `/', output it. */
  obstack_1grow (oout1, '/');
  if (oout2)
    obstack_1grow (oout2, '/');

This code outputs the slash a second time.

3. Proposed Fix
---------------
Replace the above four lines by

  /* We read a `/', output it if not yet done. */
  if (oout2 == NULL)
    obstack_1grow (oout1, '/');

4. Bison Version
----------------
ksh% bison --version
bison (GNU Bison) 1.29

Copyright 1984, 1986, 1989, 1992, 2000, 2001 Free Software
Foundation, Inc.
This is free software; see the source for copying conditions.  There
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

5. Test Example
---------------
This is the multi-function calculator from the Bison manual.

%{
#include <math.h>       /* For math functions, cos(), sin(), etc. */
#include "calc.h"       /* Contains definition of `symrec' */
%}
%union {
double val;             /* For returning numbers. */
symrec *tptr;           /* For returning symbol-table pointers */
}

%token <val> NUM        /* Simple double precision number */
%token <tptr> VAR FNCT  /* Variable and Function */
%type <val> exp

%right '='
%left '-' '+'
%left '*' '/'
%left NEG               /* Negation--unary minus */
%right '^'              /* Exponentiation */
/* Grammar follows */
%%
input:  /* empty */
        | input line
;

line:
        '\n'
        | exp '\n'              { printf ("\t%.10g\n", $1); }
        | error '\n'            { yyerrok; }
;

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 of grammar */
%%

-- Ernst Christen, address@hidden on 12/28/2001






reply via email to

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