delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/16/12:10:08

Sender: crough45 AT amc DOT de
Date: Wed, 16 Apr 1997 16:44:36 +0100
From: Chris Croughton <crough45 AT amc DOT de>
Mime-Version: 1.0
To: grbhat AT unigoa DOT ernet DOT in
Cc: djgpp AT delorie DOT com
Subject: Re: advice on bison required
Message-Id: <97Apr16.174214gmt+0100.21895@internet01.amc.de>

Gurunandan R. Bhat wrote:

#define YYSTYPE double 

>at the beginning of the bison source. on doing this and 
>compiling with -d, bison generates a header file which is 
>expected to contain all type information required by the 

Not quite.  Anything in the explicit source code between
%{ and %} is just passed straight through to the output,
without bison looking at it.  So bison doesn't 'know' that
you've redefined YYSTYPE and doesn't generate the changed
definition in the header file it produces.

However, it does allow you to redefine the type.  Look again 
at the definition in the header file:

  #ifndef YYSTYPE
  #define YYSTYPE int
  #endif

That means that if you define YYSTYPE before including the 
header file it will use your definition instead of the
default 'int'.  In general it's best to have a common
header file which is included by both the bison and the
flex source, so in the .y file would be:

  %{
  #include "common_defs.h"
  ...
  %}

and in the .l would be:

  %{
  #include "common_defs.h"
  #include "program_tab.h"
  ...
  %}
  
(Or whatever the DOS bison produces as the .h file, I'm
on Unix at the moment and don't remember the DOS version 
of the file name, it's file.tab.h under Unix.)

The file "common_defs.h" (oops, that's not a DOS filename 
either but you know what I mean!) would contain:

  #define YYSTYPE double

If it's not clear, drop me an email and I'll try to do
better...

Chris

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019