bug-bison
[Top][All Lists]
Advanced

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

Re: Misc. minor bison 1.33 bugs and annoyances patched


From: Bruce Lilly
Subject: Re: Misc. minor bison 1.33 bugs and annoyances patched
Date: Fri, 22 Feb 2002 06:06:25 -0500

Bruce Lilly wrote:
> 
> Hello,
> 
> The attached patch fixes the following minor bugs and
> (some not-so-minor) annoyances in bison 1.33 (some of
> which also afflicted earlier versions):
> 
> 1. use of ugly and error-prone pointer casts is no longer
>    required with YYPURE if YYPARSE_PARAM_PTR_TYPE
>    is defined (see revised documentation for details).
> 2. explanation of yydebug for "--akim".
> 3. avoided compiler diagnostics for bison.simple regarding
>    possible loss of information due to integral type
>    promotion.
> 4. avoided "constant conditional" compiler diagnostics for
>    bison.simple due to useless do - while (0) in macros.
> 5. proper prototype declaration for __STDC__ as well as
>    for __cplusplus.
> 
> Best regards,
>   Bruce Lilly

The patch had a small bug; a corrected patch is attached.
*** doc/bison.texinfo.orig      Thu Feb 21 22:55:18 2002
--- doc/bison.texinfo   Thu Feb 21 23:01:54 2002
***************
*** 3652,3664 ****
  If you use a reentrant parser, you can optionally pass additional
  parameter information to it in a reentrant way.  To do so, define the
  macro @code{YYPARSE_PARAM} as a variable name.  This modifies the
! @code{yyparse} function to accept one argument, of type @code{void *},
! with that name.
  
! When you call @code{yyparse}, pass the address of an object, casting the
! address to @code{void *}.  The grammar actions can refer to the contents
! of the object by casting the pointer value back to its proper type and
! then dereferencing it.  Here's an example.  Write this in the parser:
  
  @example
  address@hidden
--- 3652,3666 ----
  If you use a reentrant parser, you can optionally pass additional
  parameter information to it in a reentrant way.  To do so, define the
  macro @code{YYPARSE_PARAM} as a variable name.  This modifies the
! @code{yyparse} function to accept one argument, of type
! @code{YYPARSE_PARAM_PTR_TYPE *}, with that name.
  
! If you do not define @code{YYPARSE_PARAM_PTR_TYPE,} it defaults to
! @code{void}.
! 
! When you call @code{yyparse}, pass the address of an object of type
! @code{YYPARSE_PARAME_PTR_TYPE}.  Here's an example.  Write this in the
! parser:
  
  @example
  address@hidden
***************
*** 3669,3674 ****
--- 3671,3677 ----
  @};
  
  #define YYPARSE_PARAM parm
+ #define YYPARSE_PARAM_PTR_TYPE struct parser_control
  address@hidden
  @end example
  
***************
*** 3687,3704 ****
  @{
    struct parser_control foo;
    @dots{}  /* @r{Store proper data in @code{foo}.}  */
!   value = yyparse ((void *) &foo);
    @dots{}
  @}
  @end example
  
- @noindent
- In the grammar actions, use expressions like this to refer to the data:
- 
- @example
- ((struct parser_control *) parm)->randomness
- @end example
- 
  @vindex YYLEX_PARAM
  If you wish to pass the additional parameter data to @code{yylex},
  define the macro @code{YYLEX_PARAM} just like @code{YYPARSE_PARAM}, as
--- 3690,3700 ----
  @{
    struct parser_control foo;
    @dots{}  /* @r{Store proper data in @code{foo}.}  */
!   value = yyparse (&foo);
    @dots{}
  @}
  @end example
  
  @vindex YYLEX_PARAM
  If you wish to pass the additional parameter data to @code{yylex},
  define the macro @code{YYLEX_PARAM} just like @code{YYPARSE_PARAM}, as
***************
*** 3722,3728 ****
  arguments in total, depending on whether an argument of type
  @code{YYLTYPE} is passed.)  You can declare the argument as a pointer to
  the proper object type, or you can declare it as @code{void *} and
! access the contents as shown above.
  
  You can use @samp{%pure_parser} to request a reentrant parser without
  also using @code{YYPARSE_PARAM}.  Then you should call @code{yyparse}
--- 3718,3724 ----
  arguments in total, depending on whether an argument of type
  @code{YYLTYPE} is passed.)  You can declare the argument as a pointer to
  the proper object type, or you can declare it as @code{void *} and
! access the contents using ugly and error-prone pointer casts.
  
  You can use @samp{%pure_parser} to request a reentrant parser without
  also using @code{YYPARSE_PARAM}.  Then you should call @code{yyparse}
*** src/bison.simple.orig       Thu Feb 21 22:26:18 2002
--- src/bison.simple    Fri Feb 22 00:35:26 2002
***************
*** 109,115 ****
     stack.  Advance YYPTR to a properly aligned location for the next
     stack.  */
  # define YYSTACK_RELOCATE(Type, Stack)                                        
\
-     do                                                                        
\
        {                                                                       
\
        YYSIZE_T yynewbytes;                                            \
        yymemcpy ((char *) yyptr, (char *) (Stack),                     \
--- 109,114 ----
***************
*** 118,124 ****
        yynewbytes = yystacksize * sizeof (Type) + YYSTACK_GAP_MAX;     \
        yyptr += yynewbytes / sizeof (*yyptr);                          \
        }                                                                       
\
!     while (0)
  
  #endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */
  
--- 117,123 ----
        yynewbytes = yystacksize * sizeof (Type) + YYSTACK_GAP_MAX;     \
        yyptr += yynewbytes / sizeof (*yyptr);                          \
        }                                                                       
\
!     Stack = Stack
  
  #endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */
  
***************
*** 224,237 ****
  #  define YYFPRINTF YYSTD (fprintf)
  # endif
  
! # define YYDPRINTF(Args)                      \
! do {                                          \
!   if (yydebug)                                        \
!     YYFPRINTF Args;                           \
! } while (0)
  /* Nonzero means print parse trace. [The following comment makes no
     sense to me.  Could someone clarify it?  --akim] Since this is
     uninitialized, it does not stop multiple parsers from coexisting.
     */
  int yydebug;
  #else /* !YYDEBUG */
--- 223,235 ----
  #  define YYFPRINTF YYSTD (fprintf)
  # endif
  
! # define YYDPRINTF(Args) if (yydebug) YYFPRINTF Args
  /* Nonzero means print parse trace. [The following comment makes no
     sense to me.  Could someone clarify it?  --akim] Since this is
     uninitialized, it does not stop multiple parsers from coexisting.
+    1. yydebug is not initialized
+    2. therefore there will not be a link error when linking multiple parsers
+    3. however, all parsers will be affected by any change to the global 
yydebug
     */
  int yydebug;
  #else /* !YYDEBUG */
***************
*** 340,369 ****
  #line
  
  /* The user can define YYPARSE_PARAM as the name of an argument to be passed
!    into yyparse.  The argument should have type void *.
!    It should actually point to an object.
!    Grammar actions can access the variable by casting it
!    to the proper pointer type.  */
  
  #ifdef YYPARSE_PARAM
! # ifdef __cplusplus
! #  define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
  #  define YYPARSE_PARAM_DECL
! # else /* !__cplusplus */
  #  define YYPARSE_PARAM_ARG YYPARSE_PARAM
! #  define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
! # endif /* !__cplusplus */
  #else /* !YYPARSE_PARAM */
! # define YYPARSE_PARAM_ARG
  # define YYPARSE_PARAM_DECL
  #endif /* !YYPARSE_PARAM */
  
  /* Prevent warning if -Wstrict-prototypes.  */
  #ifdef __GNUC__
  # ifdef YYPARSE_PARAM
! int yyparse (void *);
  # else
! int yyparse (void);
  # endif
  #endif
  
--- 338,372 ----
  #line
  
  /* The user can define YYPARSE_PARAM as the name of an argument to be passed
!    into yyparse.  The argument should have type YYPARSE_PARAM_PTR_TYPE *.
! */
  
  #ifdef YYPARSE_PARAM
! # ifndef YYPARSE_PARAM_PTR_TYPE
! #  define YYPARSE_PARAM_PTR_TYPE void
! # endif
! # if defined(__cplusplus) || defined(__STDC__)
! #  define YYPARSE_PARAM_ARG YYPARSE_PARAM_PTR_TYPE *YYPARSE_PARAM
  #  define YYPARSE_PARAM_DECL
! # else /* !__cplusplus  && !__STDC__ */
  #  define YYPARSE_PARAM_ARG YYPARSE_PARAM
! #  define YYPARSE_PARAM_DECL YYPARSE_PARAM_PTR_TYPE *YYPARSE_PARAM;
! # endif /* !__cplusplus && !__STDC__ */
  #else /* !YYPARSE_PARAM */
! # if defined(__cplusplus) || defined(__STDC__)
! #  define YYPARSE_PARAM_ARG void
! # else
! #  define YYPARSE_PARAM_ARG
! # endif
  # define YYPARSE_PARAM_DECL
  #endif /* !YYPARSE_PARAM */
  
  /* Prevent warning if -Wstrict-prototypes.  */
  #ifdef __GNUC__
  # ifdef YYPARSE_PARAM
! int yyparse (YYPARSE_PARAM_PTR_TYPE *);
  # else
! int yyparse (YYPARSE_PARAM_ARG);
  # endif
  #endif
  
***************
*** 407,419 ****
    YY_DECL_VARIABLES
  #endif  /* !YYPURE */
  
!   register int yystate;
!   register int yyn;
    int yyresult;
    /* Number of tokens to shift before error messages enabled.  */
    int yyerrstatus;
    /* Lookahead token as an internal (translated) token number.  */
!   int yychar1 = 0;
  
    /* Three stacks and their tools:
       `yyss': related to states,
--- 410,422 ----
    YY_DECL_VARIABLES
  #endif  /* !YYPURE */
  
!   register int yystate;       /* {short|char} -> int promotion on addition */
!   register int yyn;   /* {short|char} -> int promotion on addition */
    int yyresult;
    /* Number of tokens to shift before error messages enabled.  */
    int yyerrstatus;
    /* Lookahead token as an internal (translated) token number.  */
!   YYSTACK_TYPE yychar1 = 0;
  
    /* Three stacks and their tools:
       `yyss': related to states,
***************
*** 424,432 ****
       to reallocate them elsewhere.  */
  
    /* The state stack. */
!   short       yyssa[YYINITDEPTH];
!   short *yyss = yyssa;
!   register short *yyssp;
  
    /* The semantic value stack.  */
    YYSTYPE yyvsa[YYINITDEPTH];
--- 427,435 ----
       to reallocate them elsewhere.  */
  
    /* The state stack. */
!   YYSTACK_TYPE        yyssa[YYINITDEPTH];
!   YYSTACK_TYPE *yyss = yyssa;
!   register YYSTACK_TYPE *yyssp;
  
    /* The semantic value stack.  */
    YYSTYPE yyvsa[YYINITDEPTH];
***************
*** 489,495 ****
    yyssp++;
  
   yysetstate:
!   *yyssp = yystate;
  
    if (yyssp >= yyss + yystacksize - 1)
      {
--- 492,498 ----
    yyssp++;
  
   yysetstate:
!   *yyssp = (YYSTACK_TYPE)yystate;
  
    if (yyssp >= yyss + yystacksize - 1)
      {
*** src/output.c.orig   Thu Feb 21 23:38:52 2002
--- src/output.c        Thu Feb 21 23:57:16 2002
***************
*** 293,300 ****
  \n\
  /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */\n");
  
    obstack_fgrow2 (&table_obstack,
!       "#define YYTRANSLATE(x) ((unsigned)(x) <= %d ? yytranslate[x] : %d)\
  \n\
  \n",
                  max_user_token_number, nsyms);
--- 293,301 ----
  \n\
  /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */\n");
  
+   obstack_fgrow1 (&table_obstack, "#define YYSTACK_TYPE %s\n", ntokens < 127 
? "char" : "short");
    obstack_fgrow2 (&table_obstack,
!       "#define YYTRANSLATE(x) (YYSTACK_TYPE)((unsigned)(x) <= %dU ? 
yytranslate[x] : %d)\
  \n\
  \n",
                  max_user_token_number, nsyms);

reply via email to

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