Article View: gnu.utils.bug
Article #206crashes in bison generated grammars: rearrangement fixes, but....
From: Steve Murphy
Date: Thu, 06 Aug 1992 16:30
Date: Thu, 06 Aug 1992 16:30
138 lines
7075 bytes
7075 bytes
This is to let you know that all is not perfectly well with bison
generated grammars. I'm using 1.18, on a sparcstation 2, running
4.1.1.
I have a grammar that looks something like this:
%{
#ifndef LINT
static char rcs_edifmapb_id[] = "$Id: edif_map.b,v 1.10 1992/05/15 20:56:37 murf Exp $";
#endif
#include <stdio.h>
#include "structure.h"
#include "edif_rp_struct.h"
#if defined(EDI) || defined(BERK)
#include "form_edif_interface.h"
#endif
char *re_comp();
struct map *reading,*writing,**current;
#define Calloc(x) (x *)calloc(sizeof (x),1)
extern double edif_grid_divisor;
extern int page_spacing;
struct path *pptr;
extern struct namefilter *netfilt, *instfilt;
%}
%union {
struct map *mapstructptr;
struct position pos;
struct placement place;
char string[100];
double dval;
int orientation;
struct pathlist *plist;
struct path *pathptr;
struct userwindow userwindow;
}
%token ON READING WRITING MAP CELL TO SYMBOL MODULE PARAM FORGET SET COMMA SEMI HAS VIA BUNVIA GRIDRES R0 R90 R180 R270 MX MY MYR90 MXR90 OFFSET
%token BUNINPIN BUNOUTPIN BUNIOPIN INPIN OUTPIN IOPIN PICBUNINPIN PICBUNOUTPIN PICBUNIOPIN PICINPIN PICOUTPIN PICIOPIN WIRE FROM DIRMAG WINDOW
%token DIRLESSPINS PAGESPACING EXTRACT EXTRACTNUMBER NET SCHEM FILTER NETNAMES INSTNAMES XSCALE YSCALE
%token <string> STRING
%token <dval> NUM
%type <pos> offset
%type <place> xform
%type <orientation> orient
%type <mapstructptr> readmaplist writemaplist readmapitem writemapitem readmapintro
writemapintro paramlist paramobject object paramitem value
%type <pathptr> path
%type <plist> pathlist
%type <userwindow> window
%%
file : statlist {}
;
statlist : statitem {}
| statlist statitem {}
;
statitem : reading {}
| writing {}
;
reading: ON READING COMMA {/*current = &reading;*/} readmaplist {}
;
readmaplist : readmapitem {reading=$1;} /* Will crash here ---v */
| readmaplist readmapitem {struct map *x; x=$2; if( $2) {$2->next = $1; reading = $2;
$$ = $2;} else $$ = $1;}
;
readmapitem : readmapintro SEMI {$$ = $1;}
| paramlist SEMI {$$ = $1;}
| readmapintro pathlist xform SEMI { $$=$1; $$->place = $3; $$->pathlist = $2; }
| readmapintro xform pathlist SEMI { $$=$1; $$->place = $2; $$->pathlist = $3; }
| readmapintro pathlist xform COMMA window SEMI { $$=$1; $$->place = $3; $$->pathlist = $2; $$->win = $5; }
| readmapintro pathlist xform COMMA paramlist SEMI {$$=$1; $$->parammaplist = $5; $$->pathlist = $2; $$->place = $3; }
| readmapintro pathlist xform COMMA window COMMA paramlist SEMI {$$=$1; $$->parammaplist = $7; $$->pathlist = $2; $$->place = $3; $$->win = $5; }
| readmapintro xform pathlist COMMA window COMMA paramlist SEMI {$$=$1; $$->parammaplist = $7; $$->pathlist = $3; $$->place = $2; $$->win = $5; }
| readmapintro xform pathlist COMMA paramlist SEMI {$$=$1; $$->parammaplist = $5; $$->pathlist = $3; $$->place = $2; }
| readmapintro xform pathlist COMMA window SEMI { $$=$1; $$->place = $2; $$->pathlist = $3; $$->win = $5;}
| readmapintro pathlist COMMA window COMMA paramlist SEMI {$$=$1; $$->parammaplist = $6; $$->pathlist = $2; $$->win = $4; }
| readmapintro pathlist COMMA paramlist SEMI {$$=$1; $$->parammaplist = $4; $$->pathlist = $2; }
| readmapintro xform COMMA window COMMA paramlist SEMI {$$=$1; $$->parammaplist = $6; $$->place = $2; $$->win = $4; }
| readmapintro xform COMMA paramlist SEMI {$$=$1; $$->parammaplist = $4; $$->place = $2; }
| readmapintro xform SEMI {$$=$1; $$->place = $2; }
| readmapintro pathlist SEMI {$$=$1; $$->pathlist = $2; }
| readmapintro paramlist SEMI {$$=$1; $$->parammaplist = $2;}
| readmapintro window SEMI {$$=$1; $$->win = $2; }
| readmapintro window COMMA paramlist SEMI {$$=$1; $$->parammaplist = $4; $$->win = $2;}
| MAP paramobject paramlist SEMI {$$ = $2; $$->parammaplist = $3;}
| SET GRIDRES TO NUM SEMI {edif_grid_divisor = $4; $$=0;
edif_print(1,"<<edif_grid_divisor = %f>>\n",edif_grid_divisor);}
| SET DIRLESSPINS SEMI { setDirlessPins(1); $$=0; }
| SET XSCALE TO NUM SEMI {set_x_scale_factor($4); $$=0;}
| SET YSCALE TO NUM SEMI {set_y_scale_factor($4); $$=0;}
| SET PAGESPACING TO NUM SEMI {page_spacing = $4; $$=0;
edif_print(1,"<<page_spacing = %d>>\n",page_spacing);}
| FILTER NETNAMES STRING TO STRING SEMI
{struct namefilter *x,*y; x = (struct namefilter *)calloc(sizeof(struct namefilter),1);
$$=0;strcpy(x->from,$3); strcpy(x->to,$5);
if( !netfilt ) netfilt =x;
else{ y=netfilt; while( y->next) y = y->next; y->next = x; }}
| FILTER INSTNAMES STRING TO STRING SEMI
{struct namefilter *x,*y; x = (struct namefilter *)calloc(sizeof(struct namefilter),1);
$$=0;strcpy(x->from,$3); strcpy(x->to,$5);
if( !instfilt ) instfilt =x;
else{ y=instfilt; while( y->next) y = y->next; y->next = x; }}
;
anyway, if I move the actions in before the SEMI, especially the ones
that zero out $$, I will often get crashes when I try to evaluate the
second rule of readmaplist. $2 is garbage, and results in a segment
fault. We've been fixing this by moving around where the actions are,
for instance, last time I compiled (probably under 1.16), this seemed
to make things work better:
| readmapintro window SEMI {$$=$1; $$->win = $2; }
| readmapintro window COMMA paramlist SEMI {$$=$1; $$->parammaplist = $4; $$->win = $2;}
| MAP paramobject paramlist SEMI {$$ = $2; $$->parammaplist = $3;}
| SET GRIDRES TO NUM {edif_grid_divisor = $4; $$=0;
edif_print(1,"<<edif_grid_divisor = %f>>\n",edif_grid_divisor);} SEMI
| SET DIRLESSPINS { setDirlessPins(1); $$=0; } SEMI
| SET XSCALE TO NUM {set_x_scale_factor($4); $$=0;} SEMI
| SET YSCALE TO NUM {set_y_scale_factor($4); $$=0;} SEMI
| SET PAGESPACING TO NUM {page_spacing = $4; $$=0;
edif_print(1,"<<page_spacing = %d>>\n",page_spacing);} SEMI
| FILTER NETNAMES STRING TO STRING SEMI
Now it doesn't. If this kind of clue doesn't help you, perhaps I can
rip out some example files and the complete source to this chunk, and
you can quickly construct a test executable. The yyvsp stack seems to
be getting mixed up.
murf
Technical Details
Message-ID:
<9208061630.AA02905@murphy.sps.mot.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!murphy.sps.mot.COM!murfShow Full Headers
Complete Article Headers
Newsgroups: gnu.utils.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!murphy.sps.mot.COM!murf From: murf@murphy.sps.mot.COM (Steve Murphy) Subject: crashes in bison generated grammars: rearrangement fixes, but.... Message-ID: <9208061630.AA02905@murphy.sps.mot.com> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Thu, 6 Aug 1992 16:30:50 GMT Approved: bug-gnu-utils@prep.ai.mit.edu Lines: 139