Article View: gnu.g++
Article #307Re: Use of yacc/bison and g++
From: Travis Lee Winfrey
Date: Mon, 29 Aug 1988 17:32
Date: Mon, 29 Aug 1988 17:32
45 lines
2725 bytes
2725 bytes
In article <8808240932.AA08805@prep.ai.mit.edu> gordon%stats.ucl.ac.uk@NSS.CS.UCL.AC.UK writes:
>Should it be possible to include C++ statements in a
>yacc file, "compile" with yacc (or better bison?) and compile the
>result with g++?
Yes, it *should* be possible. I've been doing that all summer with Yacc/CC. I
haven't used bison/g++, only because of the bugs and general flakiness of g++.
(spare me the flames, I'm sure it will become a fine compiler.) The action
statements in yacc are only translated, with $$, $1, etc., being rewritten
appropriately. Getting the typing right can be a mild problem. Generally, it
works exactly as you would expect it to.
The biggest problems I had were with CC, not with g++, and they both involved
static initializers:
1) when I used the default main() in liby.a, main() wasn't compiled by CC, so
_main() wasn't called from main(), so any static initializers of variables were
*not* called. This causes subtle bugs in your programs if you don't use
streams IO, and immediate core dumps if you do.
2) peripherally related to YACC, I had problems with an initial yylex() which
used cin, didn't use cout, and dumped core immediately on trying to read a
character. This is easy to repeat, as
#include <stream.h>
main()
{ char ch;
cin >> ch ;
}
dumps core with our streams library. If any reference to cout is made, even if
it can never be called (e.g., "if ( x && ! x ) cout.put(x);"), then the program
doesn't dump core. CC always failed, but g++ handled it correctly.
I tracked this down to the tied_to field of the cin structure, which contains
the address of cout. cout wasn't initialized because it was never called. I
didn't follow the bug into the cout routines, because I could patch it here:
since tied_to was not called if it was null, the fix was just to add "(void)
cin.tie(0);" to the program. This bug has probably been fixed in later
versions of streams, but it's a pretty special case.
t
Arpa: travis@mojo.cs.columbia.edu Bitnet: travis@cu20b
Usenet: rutgers!columbia!travis Dragnet: "just the facts, ma'am"
USMail: 483 Mudd, Columbia Univ., NYC 10025 Phone: 212-280-8091
Technical Details
Message-ID:
<5850@columbia.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!uunet!tut.cis.ohio-state.edu!mailrus!rutgers!columbia!mojo.columbia.edu!travisReferences:
<8808240932.AA08805@prep.ai.mit.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!uunet!tut.cis.ohio-state.edu!mailrus!rutgers!columbia!mojo.columbia.edu!travis From: travis@mojo.columbia.edu (Travis Lee Winfrey) Newsgroups: gnu.g++,comp.lang.c++ Subject: Re: Use of yacc/bison and g++ Message-ID: <5850@columbia.edu> Date: 29 Aug 88 17:32:50 GMT References: <8808240932.AA08805@prep.ai.mit.edu> Sender: news@columbia.edu Reply-To: travis@mojo.cs.columbia.edu Distribution: gnu Organization: Columbia University Department of Computer Science Lines: 45