Re: Section 3.1.2 has what appears to be a bug
slipbits <[email protected]> Mon, 20 Jun 2022 13:08:19 -0700
| Newsgroups | gmane.comp.parsers.bison.bugs |
|---|---|
| Message-ID | <[email protected]> |
Hi Kaz;
I''ll have to think about this some more. The quick take is that only
%code import is available for use in D and Java. The remaining tags are
for C/C++. If this is not correct then please correct me (sigh, having a
dialog with someone who knows what he's talking about is such a humbling
experience), and the User's Manual.
Here is my table of reason, which I hope is reasonable.
%code tag
C/C++
D/Java
Description
%code
•
Placed after all declarations
%code import
•
•
Placed in an importable class
%code provides
•
Placed after YYSTAB, YYLTYPE declaration
%code requires
•
Placed before YYSTAB, YYLTYPE declaration
%code top
•
Placed after Bison prologue and before %code require
art
On 6/19/2022 9:06 AM, Kaz Kylheku wrote:
> On 2022-06-17 10:26, slipbits wrote:
>> 3.1.2 Prologue Alternatives, pg. 50
>> “and the new YYLTYPE definition before the Bison-generated YYSTYPE
>> and YYLTYPE definitions in both the parser implementation file and
>> the parser header file”.
>>
>> This position causes, in this case, YYLTYPE to be doubly defined in the same scope.
>>
> [ elided ]
>> Is this a bug?
> There are ways in which both the header file and the parser source file
> can independently provide a definition such that they don't clash:
>
> /* paste freely wherever you want, however many times you want */
> #ifndef FOO_DEFINED
> struct foo { int x; };
> #define FOO_DEFINED
> #endif
>
> The text refers to an example, and in that example this appears:
>
> #define YYLTYPE YYLTYPE
> typedef struct YYLTYPE
> { ...
>
> in all likelihood, the Bison-generated skeleton code is checking for
> the presence of the preprocessor symbol
>
> You should try the example; if that doesn't work, then there is a bug.
>
> I don't use YYLTYPE, but for YYSTYPE, Bison clearly generates
> code like:
>
> if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
> typedef union YYSTYPE
> {
>
> Not sure about Java and other supported languages that don't have
> preprocessing.