Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Aug 2000 15:28:35 -0700
From:      Zack Weinberg <zack@wolery.cumb.org>
To:        freebsd-hackers@freebsd.org
Subject:   Portability and warnings tweaks for byacc(1)'s skeleton file
Message-ID:  <20000828152835.Z17776@wolery.cumb.org>

next in thread | raw e-mail | index | archive | help
I have noticed and corrected a number of portability problems with
byacc's generated parser, also adjusted things so that it does not
provoke a couple of gcc warnings that are not commonly requested but
that my project uses.

More specifically:

  - stdlib.h is not available in pre-C89 environments.  I made its
    inclusion conditional on __STDC__ || __cplusplus, which is not
    perfect but will do.  Otherwise, I declare malloc and realloc by
    hand. 

  - 'const' is not available either in K+R C.  #define it to nothing
    if neither __STDC__ nor __cplusplus is defined.

  - Change the declarations of yyname[] and yyrule[] placed in y.code.c
    in -r mode to match their actual definitions in y.tab.c.

  - gcc can be asked to issue warnings if a function definition is
    seen without a previous prototype - even if the definition is
    written in prototype form.  The project I'm using byacc with has
    this warning turned on.  I therefore added explicit prototypes for
    both yygrowstack and yyparse, conditioned on __STDC__ ||
    __cplusplus.

A patch is appended.  Also, I don't have a patch for this, but I have
to change the line in the Makefile reading

MAN1=yacc.1 yyfix.1

to use MAN= instead, or yyfix.1 is not installed.  This may be a
problem with my copy of pmake.

Please cc: me directly on any responses, I am not subscribed to this
list.

Thank you.
zw

--- byacc-1.9.1.orig/skeleton.c
+++ byacc-1.9.1/skeleton.c
@@ -54,11 +54,13 @@
 
 char *banner[] =
 {
+    "#if !(defined(__cplusplus) || __STDC__)",
+    "#define const",
+    "#endif",
     "#ifndef lint",
     "static char const ",
     "yyrcsid[] = \"$FreeBSD: src/usr.bin/yacc/skeleton.c,v 1.28 2000/01/17 02:04:06 bde Exp $\";",
     "#endif",
-    "#include <stdlib.h>",
     "#define YYBYACC 1",
     "#define YYMAJOR 1",
     "#define YYMINOR 9",
@@ -84,8 +86,8 @@
     "extern const short yytable[];",
     "extern const short yycheck[];",
     "#if YYDEBUG",
-    "extern char *yyname[];",
-    "extern char *yyrule[];",
+    "extern const char * const yyname[];",
+    "extern const char * const yyrule[];",
     "#endif",
     0
 };
@@ -127,6 +129,14 @@
 char *body[] =
 {
     "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
+    "#if defined(__cplusplus) || __STDC__",
+    "#include <stdlib.h>",
+    "static int yygrowstack(void);",
+    "#else",
+    "char *malloc();",
+    "char *realloc();",
+    "#endif",
+    "",
     "static int yygrowstack()",
     "{",
     "    int newsize, i;",
@@ -177,6 +187,7 @@
     "#if defined(__cplusplus) || __STDC__",
     "#define YYPARSE_PARAM_ARG YYPARSE_PARAM_TYPE YYPARSE_PARAM",
     "#define YYPARSE_PARAM_DECL",
+    "extern int yyparse (YYPARSE_PARAM_ARG);",
     "#else	/* ! ANSI-C/C++ */",
     "#define YYPARSE_PARAM_ARG YYPARSE_PARAM",
     "#define YYPARSE_PARAM_DECL YYPARSE_PARAM_TYPE YYPARSE_PARAM;",


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000828152835.Z17776>