Related articles |
---|
bison/g++/catch exception stehmanaf@nswc.navy.mil (Alexandra) (1999-07-30) |
Solution: bison/g++/catch exception stehmanaf@nswc.navy.mil (Alexandra Stehman) (1999-08-04) |
From: | Alexandra <stehmanaf@nswc.navy.mil> |
Newsgroups: | comp.compilers |
Date: | 30 Jul 1999 22:20:04 -0400 |
Organization: | Compilers Central |
Keywords: | yacc, C++, question |
OPERATING SYSTEMS:
IRIX 6.4
Solaris 2.6
HPUX 10.20
COMPILERS, ETC.:
gnu g++ 2.8.1
bison 1.25
flex 2.5.4
SYMPTOMS:
In the grammar file, I've tried to put a few exceptions in the action
code. The only exceptions I've used are bad_alloc on any calls to "new"
the parser might make. It seems that on the Solaris and HP systems,
bison (or g++) can't handle the "catch" statement. The code compiles
and runs fine on irix. So this poses the questions: does
bison (or g++) not support catch block syntax, which would seem
ridiculous if true, and if false then what could possibly be causing the
trouble? (If the former is true, I'm thinking sgi modified the versions
available from their freeware site to handle exceptions.)
Here's a sampling of the error message, same on both troublesome
platforms (which results from running a makefile):
CONSOLE OUTPUT:
make libRMSpec.a
bison -d -y yaccfile.y
perl -p -i.bak -e 's/<yacc\.h>/"y.tab.h"/' y.tab.c
mv y.tab.c y.tab.cpp
g++ -c y.tab.cpp
yaccfile.y: In function `int yyparse(void *)':
yaccfile.y:227: parse error before `&'
yaccfile.y:236: parse error before `else'
yaccfile.y:240: parse error before `&'
yaccfile.y:247: confused by earlier errors, bailing out
*** Error code 1
make: Fatal error: Command failed for target `y.tab.o'
Current working directory /home/usr/astehman/latest/solaris
*** Error code 1
make: Fatal error: Command failed for target `lib'
It seems as though the error is from g++, but it's a parse error...
A highly simplified code snippet from the grammar file (class and
variable names have been modified, but the concept hasn't been altered):
CODE FROM GRAMMAR FILE (*.Y):
<snip>
top_level_block: block_head
IDENTIFIER
LEFT_CURLY {
nestLevel++;
string name = $2;
if (nestLevel > 1){
if (verbosity) cout <<"Not a top level block."
<<endl;
try {
current_block = new Block(name);
} catch (const bad_alloc &ba){
cout <<"From Parser: Cannot allocate
memory for a new Block object. " <<endl
<< "Name: " <<name <<endl
<< "Actual Exception: " <<ba.what()
<<endl;
}
Block::addBlock(current_block);
<snip>
(where IDENTIFIER has been defined conventionally as [a-zA-Z_0-9\.\:\-]+
and LEFT_CURLY as {)
Any thoughts on this?
TIA,
Alexandra F. Stehman
Computer Scientist
Naval Surface Warfare Center, Dahlgren Division
Dahlgren, VA
Return to the
comp.compilers page.
Search the
comp.compilers archives again.