[5143] in Athena Bugs
ANSI C changes to lex and yacc
daemon@ATHENA.MIT.EDU (John Carr)
Sun Jun 10 22:34:28 1990
To: bugs@ATHENA.MIT.EDU
Date: Sun, 10 Jun 90 22:34:12 EDT
From: John Carr <jfc@ATHENA.MIT.EDU>
Here are changes to lex and yacc to use ANSI C "const" declarations
where appropriate. In addition to error checking, these declarations
have the effect of reducing data segment size by making the large
arrays used by lex and yacc read-only.
You must reinstall /usr/lib/lex/ncform to use lex with this change.
lex changes:
*** ref/header.c Tue Jun 23 11:58:13 1987
--- header.c Sun Jun 10 22:26:48 1990
***************
*** 39,48 ****
fprintf(fout,"int yytchar;\n");
fprintf(fout,"FILE *yyin ={stdin}, *yyout ={stdout};\n");
fprintf(fout,"extern int yylineno;\n");
fprintf(fout,"struct yysvf { \n");
! fprintf(fout,"\tstruct yywork *yystoff;\n");
fprintf(fout,"\tstruct yysvf *yyother;\n");
! fprintf(fout,"\tint *yystops;};\n");
fprintf(fout,"struct yysvf *yyestate;\n");
fprintf(fout,"extern struct yysvf yysvec[], *yybgin;\n");
}
--- 39,49 ----
fprintf(fout,"int yytchar;\n");
fprintf(fout,"FILE *yyin ={stdin}, *yyout ={stdout};\n");
fprintf(fout,"extern int yylineno;\n");
+ fprintf(fout,"#ifdef __STDC__\n#define _Const const\n#else\n#define _const\n#endif\n");
fprintf(fout,"struct yysvf { \n");
! fprintf(fout,"\t_Const struct yywork *yystoff;\n");
fprintf(fout,"\tstruct yysvf *yyother;\n");
! fprintf(fout,"\t_Const int *yystops;};\n");
fprintf(fout,"struct yysvf *yyestate;\n");
fprintf(fout,"extern struct yysvf yysvec[], *yybgin;\n");
}
*** ref/ncform Tue Mar 8 18:55:43 1988
--- ncform Sun Jun 10 22:12:51 1990
***************
*** 7,21 ****
struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
char yysbuf[YYLMAX];
char *yysptr = yysbuf;
! int *yyfnd;
extern struct yysvf *yyestate;
int yyprevious = YYNEWLINE;
yylook(){
register struct yysvf *yystate, **lsp;
! register struct yywork *yyt;
struct yysvf *yyz;
int yych;
! struct yywork *yyr;
# ifdef LEXDEBUG
int debug;
# endif
--- 7,21 ----
struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
char yysbuf[YYLMAX];
char *yysptr = yysbuf;
! _Const int *yyfnd;
extern struct yysvf *yyestate;
int yyprevious = YYNEWLINE;
yylook(){
register struct yysvf *yystate, **lsp;
! register _Const struct yywork *yyt;
struct yysvf *yyz;
int yych;
! _Const struct yywork *yyr;
# ifdef LEXDEBUG
int debug;
# endif
***************
*** 157,163 ****
}
}
yyback(p, m)
! int *p;
{
if (p==0) return(0);
while (*p)
--- 157,163 ----
}
}
yyback(p, m)
! _Const int *p;
{
if (p==0) return(0);
while (*p)
*** ref/sub2.c Wed Jun 24 01:23:43 1987
--- sub2.c Sun Jun 10 22:12:52 1990
***************
*** 216,222 ****
fprintf(fout,"define Svstop %d\n",nstates+1);
fprintf(fout,"integer vstop(Svstop)\n");
}
! else fprintf(fout,"int yyvstop[] ={\n0,\n");
while(stnum < 2 || stnum/2 < sptr){
for(i = 0; i<tptr; i++) tmpstat[i] = 0;
count = 0;
--- 216,222 ----
fprintf(fout,"define Svstop %d\n",nstates+1);
fprintf(fout,"integer vstop(Svstop)\n");
}
! else fprintf(fout,"_Const int yyvstop[] ={\n0,\n");
while(stnum < 2 || stnum/2 < sptr){
for(i = 0; i<tptr; i++) tmpstat[i] = 0;
count = 0;
***************
*** 804,810 ****
return;
}
fprintf(fout,"# define YYTYPE %s\n",stnum+1 > NCH ? "int" : "char");
! fprintf(fout,"struct yywork { YYTYPE verify, advance; } yycrank[] ={\n");
for(i=0;i<=yytop;i+=4){
for(j=0;j<4;j++){
k = i+j;
--- 804,810 ----
return;
}
fprintf(fout,"# define YYTYPE %s\n",stnum+1 > NCH ? "int" : "char");
! fprintf(fout,"_Const struct yywork { YYTYPE verify, advance; } yycrank[] ={\n");
for(i=0;i<=yytop;i+=4){
for(j=0;j<4;j++){
k = i+j;
***************
*** 839,845 ****
/* put out yymatch */
! fprintf(fout,"struct yywork *yytop = yycrank+%d;\n",yytop);
fprintf(fout,"struct yysvf *yybgin = yysvec+1;\n");
if(optim){
fprintf(fout,"char yymatch[] ={\n");
--- 839,845 ----
/* put out yymatch */
! fprintf(fout,"_Const struct yywork *yytop = yycrank+%d;\n",yytop);
fprintf(fout,"struct yysvf *yybgin = yysvec+1;\n");
if(optim){
fprintf(fout,"char yymatch[] ={\n");
yacc changes:
*** ref/y2.c Sun Apr 19 18:10:31 1987
--- y2.c Sun Jun 10 20:57:56 1990
***************
*** 265,270 ****
--- 265,271 ----
fprintf( ftable, "#define yyerrok yyerrflag = 0\n" );
fprintf( ftable, "extern int yychar;\nextern short yyerrflag;\n" );
fprintf( ftable, "#ifndef YYMAXDEPTH\n#define YYMAXDEPTH 150\n#endif\n" );
+ fprintf( ftable, "#ifdef __STDC__\n#define _Const const\n#else\n#define _Const\n#endif\n");
if( !ntypes ) fprintf( ftable, "#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n" );
fprintf( ftable, "YYSTYPE yylval, yyval;\n" );
*** ref/y3.c Fri Feb 11 18:25:44 1983
--- y3.c Sun Jun 10 19:07:55 1990
***************
*** 13,19 ****
int i, k, c;
register struct wset *u, *v;
! fprintf( ftable, "short yyexca[] ={\n" );
SLOOP(i) { /* output the stuff for state i */
nolook = !(tystate[i]==MUSTLOOKAHEAD);
--- 13,19 ----
int i, k, c;
register struct wset *u, *v;
! fprintf( ftable, "_Const short yyexca[] ={\n" );
SLOOP(i) { /* output the stuff for state i */
nolook = !(tystate[i]==MUSTLOOKAHEAD);
***************
*** 375,381 ****
register i;
! fprintf( ftable, "short %s[]={\n", s );
for( i=0; i<n; ){
if( i%10 == 0 ) fprintf( ftable, "\n" );
fprintf( ftable, "%4d", v[i] );
--- 375,381 ----
register i;
! fprintf( ftable, "_Const short %s[]={\n", s );
for( i=0; i<n; ){
if( i%10 == 0 ) fprintf( ftable, "\n" );
fprintf( ftable, "%4d", v[i] );
*** ref/y4.c Fri Feb 11 18:25:48 1983
--- y4.c Sun Jun 10 20:58:47 1990
***************
*** 293,299 ****
register i;
! fprintf( ftable, "short %s[]={\n", s );
for( i=0; i<n; ){
if( i%10 == 0 ) fprintf( ftable, "\n" );
fprintf( ftable, "%4d", v[i] );
--- 293,299 ----
register i;
! fprintf( ftable, "_Const short %s[]={\n", s );
for( i=0; i<n; ){
if( i%10 == 0 ) fprintf( ftable, "\n" );
fprintf( ftable, "%4d", v[i] );