help-bison
[Top][All Lists]
Advanced

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

Re: Error with bison 2.6.X and ftnchek


From: Akim Demaille
Subject: Re: Error with bison 2.6.X and ftnchek
Date: Sat, 3 Nov 2012 08:37:25 +0100

Hi Orion,

Le 2 nov. 2012 à 17:24, Orion Poplawski a écrit :

> I'm trying to compile a very old program (ftnchek) with bison 2.6.X and 
> getting the following error:
> 
> y.tab.c:1285:3: warning: implicit declaration of function 'YY' 
> [-Wimplicit-function-declaration]
> y.tab.c:1286:1: error: initializer element is not constant
> y.tab.c:1286:1: error: (near initialization for 'yytname[422]')
> 
> # 1181 "y.tab.c"
> static const char *const yytname[] =
> {
> .....
>  "nonneg unsigned int const", "pre label", "label", YY ((void *)0)
> };
> 
> This seems to be what is triggering it.
> 
> It compiles fine with 2.5, and with that the last element above is simply 
> "0".  Any idea what is wrong?  I'm afraid I know nothing about using bison so 
> don't know whether this is a bug in bison or an error in how it is being used.

Well, the Makefile for ftncheck reads:

# N.B. tokdefs.h is copy of y.tab.h used to avoid remaking stuff when
# grammar changes but not tokens.  If the parser is made by bison,
# it is edited to make token names in "parse error" messages more readable.
# Also concatenate backslash-continued #if lines, which some older
# compilers don't like.
# The following copies y.tab.h to tokdefs.h if changed, then aborts make,
# since dependencies may have changed.
fortran.c: fortran.y
        $(YACC) $(YFLAGS) fortran.y
        @if test "$(YACC_NAME)" = "bison$(EXE)" ; \
        then \
          $(SED) -e '/yytname\[] =/,/^};/s/tok_//g' \
                 -e '/yytname\[] =/,/^};/s/_/ /g' \
                 -e '/yytname\[] =/,/^};/s/EOS/end of statement/g' \
                 -e  ':CAT'  -e '/^# *if.*\\$$/N' -e 's/\\\n//' -e tCAT \
                y.tab.c > fortran.c ; \
          $(RM) y.tab.c ; \
        else \
          $(MV) y.tab.c fortran.c ; \
        fi
        @if $(CMP) -s y.tab.h tokdefs.h ; then true ; else \
                echo; echo tokdefs.h changed -- repeat make ; \
                $(CP) y.tab.h tokdefs.h; \
                false ; \
        fi

There's a whole section about Bison's yytname:

          $(SED) -e '/yytname\[] =/,/^};/s/tok_//g' \
                 -e '/yytname\[] =/,/^};/s/_/ /g' \
                 -e '/yytname\[] =/,/^};/s/EOS/end of statement/g' \

that thinks it's ok to 's/_/ /g;'.  But Bison was recently changed
to use YY_NULL instead of NULL to end its yytname list.  So the sed
snippet splits it in YY and NULL, which results in your bug report.

The point is to have better error messages, see the following
diff snippet:

 static const char *const yytname[] =
 {
-  "$end", "error", "$undefined", "tok_identifier", "tok_array_identifier",
-  "tok_label", "tok_integer_const", "tok_real_const", "tok_dp_const",
-  "tok_quad_const", "tok_complex_const", "tok_dcomplex_const",
+  "$end", "error", "$undefined", "identifier", "array identifier",
+  "label", "integer const", "real const", "dp const",
+  "quad const", "complex const", "dcomplex const",

which ends with:

-  "construct_name", "data_constant", "nonzero_unsigned_int_const",
-  "nonneg_unsigned_int_const", "pre_label", "label", YY_NULL
+  "construct name", "data constant", "nonzero unsigned int const",
+  "nonneg unsigned int const", "pre label", "label", YY NULL
 };
 #endif

For some reason it also removes the \- continuation and fuses the
lines (I must say that I am very surprised that sed accepts s/\\\n//).

The bottom line is Bison not guilty imho.  ftnchk needs to be updated.
Actually it could benefit from some more recent features of Bison,
I would ping its maintainers to know if they are interested.  The
simplest workaround for you is certainly to add -DYY to the compiler
command line to nuke the resulting YY.

Cheers.




reply via email to

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