1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-28 22:30:12 +00:00
cc65/test/ref/yacc.c

1007 lines
28 KiB
C
Raw Normal View History

2014-09-24 14:45:10 +00:00
/*
!!DESCRIPTION!!
!!ORIGIN!! LCC 4.1 Testsuite
!!LICENCE!! own, freely distributeable for non-profit. read CPYRIGHT.LCC
*/
/*#define STANDALONE*/
#include "common.h"
2014-09-24 14:45:10 +00:00
#ifndef YACCDBG
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
/*
#define LEXDEBUG
#define YYDEBUG
*/
#endif
FILE *infile, *outfile;
#define getchar() fgetc(infile)
2014-09-24 14:45:10 +00:00
/* hack the original tables to work with both petscii and ascii */
#define CHARSETHACK
# define ID 257
# define CON 258
# define UNARYMINUS 259
#define yyclearin yychar = -1
#define yyerrok yyerrflag = 0
extern int yychar;
extern short yyerrflag;
#ifndef YYMAXDEPTH
/*#define YYMAXDEPTH 150*/
#define YYMAXDEPTH 50
#endif
#ifndef YYSTYPE
#define YYSTYPE int
#endif
YYSTYPE yylval, yyval;
# define YYERRCODE 256
# define U(x) x
# define NLSTATE yyprevious=YYNEWLINE
# define BEGIN yybgin = yysvec + 1 +
# define INITIAL 0
# define YYLERR yysvec
# define YYSTATE (yyestate-yysvec-1)
# define YYOPTIM 1
# define YYLMAX 200
# define output(c) (void)putc(c,yyout)
/* # define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar) */
# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getchar())==('\n')?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
# define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
# define yymore() (yymorfg=1)
# define ECHO fprintf(yyout, "%s",yytext)
# define REJECT { nstr = yyreject(); goto yyfussy;}
int yyleng; extern char yytext[];
int yymorfg;
extern char *yysptr, yysbuf[];
int yytchar;
#define yyin infile
#define yyout outfile
extern int yylineno;
2022-04-17 14:07:52 +00:00
struct yysvf
2014-09-24 14:45:10 +00:00
{
2019-02-12 21:50:49 +00:00
struct yywork *yystoff;
struct yysvf *yyother;
int *yystops;
2014-09-24 14:45:10 +00:00
};
struct yysvf *yyestate;
extern struct yysvf yysvec[], *yybgin;
/*# define YYNEWLINE 10 */
# define YYNEWLINE ('\n')
#ifdef NO_IMPLICIT_FUNC_PROTOTYPES
yylook();
int yywrap();
yyparse();
yyerror(char *s);
yyunput(int c);
yyoutput(int c);
yyinput();
yyback(int *p,int m);
#endif
#ifdef YYDEBUG
void printchar(char *name,int ch)
{
2019-02-12 21:50:49 +00:00
if((ch==YYNEWLINE))
{
fprintf(yyout," %s=YYNEWLINE\n",name);
}
else if((ch<0)||(ch>0xf0)||(!isprint(ch)))
{
fprintf(yyout," %s=%04x\n",name,ch &0xffff);
}
else
{
fprintf(yyout," %s='%c'\n",name,ch);
}
2014-09-24 14:45:10 +00:00
}
#endif
yylex()
{
int nstr;
extern int yyprevious;
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylex()\n");
2014-09-24 14:45:10 +00:00
#endif
2019-02-12 21:50:49 +00:00
while((nstr = yylook()) >= 0)
{
2014-09-24 14:45:10 +00:00
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylex: nstr=%d\n",nstr);
2014-09-24 14:45:10 +00:00
#endif
yyfussy:
2019-02-12 21:50:49 +00:00
switch(nstr)
{
case 0:
if(yywrap()) return(0);
break;
case 1:
return ID;
break;
case 2:
return CON;
break;
case 3:
;
break;
case 4:
return yytext[0];
break;
case -1:
break;
default:
fprintf(yyout,"yylex: bad switch yylook %d\n",nstr);
}
}
2022-04-17 14:07:52 +00:00
2014-09-24 14:45:10 +00:00
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylex: return 0\n");
2014-09-24 14:45:10 +00:00
#endif
2019-02-12 21:50:49 +00:00
return(0);
2014-09-24 14:45:10 +00:00
}
/* end of yylex */
int yyvstop[] =
{
2019-02-12 21:50:49 +00:00
0,4,0,3,4,0,2,4,0,1,4,0,2,0,1,0,0
2014-09-24 14:45:10 +00:00
};
# define YYTYPE char
2022-04-17 14:07:52 +00:00
struct yywork
{
YYTYPE verify, advance;
2014-09-24 14:45:10 +00:00
} yycrank[] =
{
2019-02-12 21:50:49 +00:00
{0,0}, {0,0}, {1,3}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {1,4}, {1,3},
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
{0,0}, {1,5}, {5,7}, {5,7},
{5,7}, {5,7}, {5,7}, {5,7},
{5,7}, {5,7}, {5,7}, {5,7},
{0,0}, {0,0}, {0,0}, {0,0},
2014-09-24 14:45:10 +00:00
/* 0x40 */
2019-02-12 21:50:49 +00:00
{0,0}, {0,0}, {1,6}, {6,8},
{6,8}, {6,8}, {6,8}, {6,8},
{6,8}, {6,8}, {6,8}, {6,8},
{6,8}, {0,0}, {0,0}, {0,0},
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
{0,0}, {0,0}, {0,0}, {0,0},
{6,8}, {6,8}, {6,8}, {6,8},
{6,8}, {6,8}, {6,8}, {6,8},
{6,8}, {6,8}, {6,8}, {6,8},
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
{6,8}, {6,8}, {6,8}, {6,8},
{6,8}, {6,8}, {6,8}, {6,8},
{6,8}, {6,8}, {6,8}, {6,8},
{6,8}, {6,8}, {0,0}, {0,0},
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
{0,0}, {0,0}, {6,8}, {0,0},
{6,8}, {6,8}, {6,8}, {6,8},
{6,8}, {6,8}, {6,8}, {6,8},
{6,8}, {6,8}, {6,8}, {6,8},
2014-09-24 14:45:10 +00:00
/* 0x80 */
2019-02-12 21:50:49 +00:00
{6,8}, {6,8}, {6,8}, {6,8},
{6,8}, {6,8}, {6,8}, {6,8},
{6,8}, {6,8}, {6,8}, {6,8},
{6,8}, {6,8}, {0,0}, {0,0},
2014-09-24 14:45:10 +00:00
#ifdef CHARSETHACK
2019-02-12 21:50:49 +00:00
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0},
2014-09-24 14:45:10 +00:00
/* 0xc0 */
2019-02-12 21:50:49 +00:00
{0,0}, {0,0}, {1,6}, {6,8},
{6,8}, {6,8}, {6,8}, {6,8},
{6,8}, {6,8}, {6,8}, {6,8},
{6,8}, {0,0}, {0,0}, {0,0},
2014-09-24 14:45:10 +00:00
#endif
2019-02-12 21:50:49 +00:00
{0,0}
2014-09-24 14:45:10 +00:00
};
/*
2022-04-17 14:07:52 +00:00
struct yysvf
2014-09-24 14:45:10 +00:00
{
2019-02-12 21:50:49 +00:00
struct yywork *yystoff;
struct yysvf *yyother;
int *yystops;
2014-09-24 14:45:10 +00:00
};
*/
struct yysvf yysvec[] =
{
2019-02-12 21:50:49 +00:00
{0, 0, 0},
{yycrank+-1, 0, 0},
{yycrank+0, yysvec+1, 0},
{yycrank+0, 0, yyvstop+1},
{yycrank+0, 0, yyvstop+3},
{yycrank+2, 0, yyvstop+6},
{yycrank+19, 0, yyvstop+9},
{yycrank+0, yysvec+5, yyvstop+12},
{yycrank+0, yysvec+6, yyvstop+14},
{0, 0, 0}
2014-09-24 14:45:10 +00:00
};
/* 0x8d */
/* struct yywork *yytop = yycrank+141; */
/* 0xff */
struct yywork *yytop = yycrank+255;
struct yysvf *yybgin = yysvec+1;
/*
2019-02-12 21:50:49 +00:00
WARNING: this table contains one entry per character
in the execution character set and must match it.
2014-09-24 14:45:10 +00:00
*/
char yymatch[] =
{
2019-02-12 21:50:49 +00:00
00 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
2014-09-24 14:45:10 +00:00
#ifdef CHARSETHACK
2019-02-12 21:50:49 +00:00
01 ,011 ,012 ,01 ,01 ,012 ,01 ,01 ,
2014-09-24 14:45:10 +00:00
#else
2019-02-12 21:50:49 +00:00
01 ,011 ,012 ,01 ,01 ,01 ,01 ,01 ,
2014-09-24 14:45:10 +00:00
#endif
2019-02-12 21:50:49 +00:00
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
011 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,
'0' ,'0' ,01 ,01 ,01 ,01 ,01 ,01 ,
2022-04-17 14:07:52 +00:00
2014-09-24 14:45:10 +00:00
/* 0x40 (ascii) @A... (petscii) @a... */
2019-02-12 21:50:49 +00:00
01 ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
'A' ,'A' ,'A' ,01 ,01 ,01 ,01 ,'A' ,
2022-04-17 14:07:52 +00:00
2014-09-24 14:45:10 +00:00
/* 0x60 (ascii) @a... */
2019-02-12 21:50:49 +00:00
01 ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
'A' ,'A' ,'A' ,01 ,01 ,01 ,01 ,01 ,
2022-04-17 14:07:52 +00:00
2014-09-24 14:45:10 +00:00
#ifdef CHARSETHACK
/* 0x80 */
2019-02-12 21:50:49 +00:00
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
2014-09-24 14:45:10 +00:00
/* 0xc0 (petcii) @A... */
2019-02-12 21:50:49 +00:00
01 ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
'A' ,'A' ,'A' ,01 ,01 ,01 ,01 ,01 ,
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
2014-09-24 14:45:10 +00:00
#endif
2019-02-12 21:50:49 +00:00
0
2014-09-24 14:45:10 +00:00
};
char yyextra[] =
{
2019-02-12 21:50:49 +00:00
0,0,0,0,0,0,0,0,0
2014-09-24 14:45:10 +00:00
};
2019-02-12 21:50:49 +00:00
/* ncform 4.1 83/08/11 */
2014-09-24 14:45:10 +00:00
int yylineno =1;
# define YYU(x) x
# define NLSTATE yyprevious=YYNEWLINE
char yytext[YYLMAX];
struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
char yysbuf[YYLMAX];
char *yysptr = yysbuf;
int *yyfnd;
extern struct yysvf *yyestate;
int yyprevious = YYNEWLINE;
unsigned char testbreak=0;
yylook()
{
2019-02-12 21:50:49 +00:00
register struct yysvf *yystate, **lsp;
register struct yywork *yyt;
struct yysvf *yyz;
int yych;
struct yywork *yyr;
2014-09-24 14:45:10 +00:00
/*
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
int debug;
2014-09-24 14:45:10 +00:00
# endif
*/
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
char *yylastch;
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
/* start off machines */
2014-09-24 14:45:10 +00:00
/*
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
debug = 1;
2014-09-24 14:45:10 +00:00
# else
2019-02-12 21:50:49 +00:00
debug = 0;
2014-09-24 14:45:10 +00:00
# endif
*/
# ifdef LEXDEBUG
#define debug 1
# else
#define debug 0
#endif
2022-04-17 14:07:52 +00:00
2014-09-24 14:45:10 +00:00
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook()\n");
# endif
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
if (!yymorfg)
yylastch = yytext;
else
{
yymorfg=0;
yylastch = yytext+yyleng;
}
2014-09-24 14:45:10 +00:00
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: yymorfg=%d\n",yymorfg);
2014-09-24 14:45:10 +00:00
# endif
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
for(;;)
{
2014-09-24 14:45:10 +00:00
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: (outer loop)");
printchar("yyprevious",yyprevious);
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
lsp = yylstate;
yyestate = yystate = yybgin;
if (yyprevious==YYNEWLINE) yystate++;
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
testbreak=0;
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
for (;;)
{
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: (inner loop) state %d\n",yystate-yysvec-1);
# endif
if(testbreak==5)
{
fprintf(yyout,"yylook: error, aborted after 5 loops\n");
2019-11-12 10:23:23 +00:00
exit(EXIT_FAILURE);
2019-02-12 21:50:49 +00:00
}
testbreak++;
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
yyt = yystate->yystoff;
/* fprintf(yyout,"yylook: yyt offs: %02x\n",yyt-yycrank); */
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
if(yyt == yycrank)
{ /* may not be any transitions */
yyz = yystate->yyother;
if(yyz == 0)break;
if(yyz->yystoff == yycrank)break;
}
*yylastch++ = yych = input();
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: input ");
printchar("yych",yych);
2014-09-24 14:45:10 +00:00
# endif
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
tryagain:
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
/* fprintf(yyout,"yylook: yych=%02x yymatch[yych]=%02x\n",yych,yymatch[yych]); */
fprintf(yyout,"yylook: tryagain\n");
# endif
yyr = yyt;
/* fprintf(yyout,"yylook: yyr offs: %02x\n",yyr-yycrank); */
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
if ( yyt > yycrank)
{
yyt = yyr + yych;
if (yyt <= yytop && yyt->verify+yysvec == yystate)
{
if(yyt->advance+yysvec == YYLERR) /* error transitions */
{
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: unput (1) ");
printchar("*yylastch",*yylastch);
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
unput(*--yylastch);
break;
}
*lsp++ = yystate = yyt->advance+yysvec;
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: continue (1)\n");
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
goto contin;
}
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: ( yyt > yycrank)\n");
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
}
2014-09-24 14:45:10 +00:00
# ifdef YYOPTIM
2019-02-12 21:50:49 +00:00
else if(yyt < yycrank) /* r < yycrank */
2022-04-17 14:07:52 +00:00
{
2019-02-12 21:50:49 +00:00
yyt = yyr = yycrank+(yycrank-yyt);
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: compressed state\n");
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
yyt = yyt + yych;
if(yyt <= yytop && yyt->verify+yysvec == yystate)
{
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: (1)\n");
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
if(yyt->advance+yysvec == YYLERR) /* error transitions */
{
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: unput (2) ");
printchar("*yylastch",*yylastch);
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
unput(*--yylastch);
break;
}
*lsp++ = yystate = yyt->advance+yysvec;
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: continue (2)\n");
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
goto contin;
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
}
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
/*
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: yych=%02x yymatch[yych]=%02x\n",yych,yymatch[yych]);
fprintf(yyout,"yylook: yyt offs: %02x\n",yyt-yycrank);
fprintf(yyout,"yylook: yyr offs: %02x\n",yyr-yycrank);
2014-09-24 14:45:10 +00:00
*/
# endif
2019-02-12 21:50:49 +00:00
yyt = yyr + YYU(yymatch[yych]);
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
/*
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: yyt offs: %02x <= yytop offs: %02x\n",yyt-yycrank,yytop-yycrank);
fprintf(yyout,"yylook: yyt->verify=%04x yysvec=%04x (yyt->verify+yysvec)=%04x == yystate=%04x\n",yyt->verify,yysvec,(yyt->verify+yysvec),yystate);
2014-09-24 14:45:10 +00:00
*/
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: try fall back character\n");
2014-09-24 14:45:10 +00:00
# endif
2022-04-17 14:07:52 +00:00
if(yyt <= yytop && yyt->verify+yysvec == yystate)
2019-02-12 21:50:49 +00:00
{
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: (2a)\n");
2014-09-24 14:45:10 +00:00
# endif
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
if(yyt->advance+yysvec == YYLERR) /* error transition */
{
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
/* cc65 compiles this ?! fprintf(yyout,"yylook: unput (3) ",); */
fprintf(yyout,"yylook: unput (3) ");
printchar("*yylastch",*yylastch);
# endif
unput(*--yylastch);
break;
}
*lsp++ = yystate = yyt->advance+yysvec;
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
/* fprintf(yyout,"yylook: yyt offs: %02x yyt->advance=%d\n",yyt-yycrank,yyt->advance); */
fprintf(yyout,"yylook: continue (3)\n");
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
goto contin;
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
}
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: (2)\n");
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
}
if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank)
{
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: fall back to state %d\n",yystate-yysvec-1);
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
goto tryagain;
}
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
else
{
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: unput (4) ");
printchar("*yylastch",*yylastch);
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
unput(*--yylastch);
break;
}
contin:
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: contin state=%d\n",yystate-yysvec-1);
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
;
}
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
if (lsp == yylstate)
{
fprintf(yyout,"yylook: stopped (end)\n");
}
else
{
fprintf(yyout,"yylook: stopped at %d with:\n",*(lsp-1)-(yysvec+1));
}
# endif
while (lsp-- > yylstate)
{
*yylastch-- = 0;
if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0)
{
yyolsp = lsp;
if(yyextra[*yyfnd]) /* must backup */
2022-04-17 14:07:52 +00:00
{
2019-02-12 21:50:49 +00:00
while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate)
{
lsp--;
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: unput (5) ");
printchar("*yylastch",*yylastch);
# endif
unput(*yylastch--);
}
}
yyprevious = YYU(*yylastch);
yylsp = lsp;
yyleng = yylastch-yytext+1;
yytext[yyleng] = 0;
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: match action %d\n",*yyfnd);
fprintf(yyout,"yylook: done loops: %d\n",testbreak);
# endif
return(*yyfnd++);
}
unput(*yylastch);
}
if (yytext[0] == 0 /* && feof(yyin) */)
{
yysptr=yysbuf;
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: done loops: %d\n",testbreak);
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
return(0);
}
yyprevious = yytext[0] = input();
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: input ");
printchar("yyprevious",yyprevious);
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
if (yyprevious>0)
output(yyprevious);
yylastch=yytext;
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
/* if(debug)putchar('\n'); */
2014-09-24 14:45:10 +00:00
# endif
2019-02-12 21:50:49 +00:00
}
2014-09-24 14:45:10 +00:00
# ifdef LEXDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: done loops: %d\n",testbreak);
fprintf(yyout,"yylook: return <void>\n");
2014-09-24 14:45:10 +00:00
# endif
}
2022-04-17 14:07:52 +00:00
2014-09-24 14:45:10 +00:00
yyback(p, m)
2019-02-12 21:50:49 +00:00
int *p;
2014-09-24 14:45:10 +00:00
{
2019-02-12 21:50:49 +00:00
if (p==0) return(0);
while (*p)
{
if (*p++ == m)
{
return(1);
}
}
return(0);
2014-09-24 14:45:10 +00:00
}
2019-02-12 21:50:49 +00:00
/* the following are only used in the lex library */
2014-09-24 14:45:10 +00:00
yyinput()
{
2019-02-12 21:50:49 +00:00
int out=input();
2022-04-17 14:07:52 +00:00
2014-09-24 14:45:10 +00:00
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
fprintf(yyout,"yylook: input ");
printchar("out",out);
2022-04-17 14:07:52 +00:00
#endif
2019-02-12 21:50:49 +00:00
return(out);
2014-09-24 14:45:10 +00:00
}
yyoutput(c)
2022-04-17 14:07:52 +00:00
int c;
2014-09-24 14:45:10 +00:00
{
2019-02-12 21:50:49 +00:00
output(c);
2014-09-24 14:45:10 +00:00
}
yyunput(c)
2022-04-17 14:07:52 +00:00
int c;
2014-09-24 14:45:10 +00:00
{
2019-02-12 21:50:49 +00:00
unput(c);
2014-09-24 14:45:10 +00:00
}
2022-04-17 14:07:52 +00:00
main()
2014-09-24 14:45:10 +00:00
{
printf("main start\n");
infile = fopen("yacc.in","rb");
if (infile == NULL) {
return EXIT_FAILURE;
}
outfile = stdout;
2014-09-24 14:45:10 +00:00
yyparse();
fclose(infile);
2014-09-24 14:45:10 +00:00
printf("main end\n");
return 0;
}
/* yyerror - issue error message */
2022-04-17 14:07:52 +00:00
yyerror(s)
char *s;
2014-09-24 14:45:10 +00:00
{
printf("[%s]\n", s);
}
short yyexca[] =
{
-1, 1,
2019-02-12 21:50:49 +00:00
0, -1,
-2, 0,
2014-09-24 14:45:10 +00:00
};
# define YYNPROD 15
# define YYLAST 249
short yyact[]=
{
12, 2, 9, 8, 17, 11, 25, 17, 15, 18,
16, 10, 18, 17, 15, 7, 16, 13, 18, 5,
3, 1, 0, 19, 20, 0, 0, 21, 22, 23,
24, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 6, 14, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2022-04-17 14:07:52 +00:00
0, 0, 0, 0, 0, 0, 0, 4, 6
2014-09-24 14:45:10 +00:00
};
short yypact[]=
{
-1000, -9,-1000, 5, -7, -59,-1000,-1000,-1000, -40,
-29, -40, -40,-1000,-1000, -40, -40, -40, -40, -38,
2022-04-17 14:07:52 +00:00
-35, -38, -38,-1000,-1000,-1000
2014-09-24 14:45:10 +00:00
};
short yypgo[]=
{
2022-04-17 14:07:52 +00:00
0, 21, 20, 17, 11
2014-09-24 14:45:10 +00:00
};
short yyr1[]=
{
0, 1, 1, 1, 1, 2, 4, 4, 4, 4,
2022-04-17 14:07:52 +00:00
4, 4, 4, 4, 3
2014-09-24 14:45:10 +00:00
};
short yyr2[]=
{
0, 0, 2, 3, 3, 3, 3, 3, 3, 3,
2022-04-17 14:07:52 +00:00
2, 3, 1, 1, 1
2014-09-24 14:45:10 +00:00
};
short yychk[]=
{
-1000, -1, 10, -2, 256, -3, 257, 10, 10, 61,
-4, 45, 40, -3, 258, 43, 45, 42, 47, -4,
2022-04-17 14:07:52 +00:00
-4, -4, -4, -4, -4, 41
2014-09-24 14:45:10 +00:00
};
short yydef[]=
{
1, -2, 2, 0, 0, 0, 14, 3, 4, 0,
5, 0, 0, 12, 13, 0, 0, 0, 0, 10,
2022-04-17 14:07:52 +00:00
0, 6, 7, 8, 9, 11
2014-09-24 14:45:10 +00:00
};
# define YYFLAG -1000
# define YYERROR goto yyerrlab
# define YYACCEPT return(0)
# define YYABORT return(1)
2019-02-12 21:50:49 +00:00
/* parser for yacc output */
2014-09-24 14:45:10 +00:00
#ifdef YYDEBUG
int yydebug = 1; /* 1 for debugging */
#else
int yydebug = 0; /* 1 for debugging */
#endif
YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
int yychar = -1; /* current input token number */
int yynerrs = 0; /* number of errors */
short yyerrflag = 0; /* error recovery flag */
2022-04-17 14:07:52 +00:00
yyparse()
2014-09-24 14:45:10 +00:00
{
2019-02-12 21:50:49 +00:00
short yys[YYMAXDEPTH];
short yyj, yym;
register YYSTYPE *yypvt;
register short yystate, *yyps, yyn;
register YYSTYPE *yypv;
register short *yyxi;
yystate = 0;
yychar = -1;
yynerrs = 0;
yyerrflag = 0;
yyps= &yys[-1];
yypv= &yyv[-1];
2014-09-24 14:45:10 +00:00
yystack: /* put a state and value onto the stack */
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
printf("yyparse: yystack\n");
2014-09-24 14:45:10 +00:00
#endif
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
printf("yyparse: yystate=%d, ", yystate);
printchar("yychar",yychar);
2014-09-24 14:45:10 +00:00
#endif
2019-02-12 21:50:49 +00:00
if( ++yyps> &yys[YYMAXDEPTH] )
{
yyerror( "yyparse: yacc stack overflow" );
return(1);
}
*yyps = yystate;
++yypv;
*yypv = yyval;
2014-09-24 14:45:10 +00:00
yynewstate:
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
printf("yyparse: yynewstate\n");
2014-09-24 14:45:10 +00:00
#endif
2019-02-12 21:50:49 +00:00
yyn = yypact[yystate];
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
if( yyn<= YYFLAG ) goto yydefault; /* simple state */
2014-09-24 14:45:10 +00:00
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
printf("yyparse: yynewstate (1)\n");
2014-09-24 14:45:10 +00:00
#endif
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
2014-09-24 14:45:10 +00:00
#ifdef YYDEBUG
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
printf("yyparse: yynewstate yyn=%d ",yyn);
printchar("yychar",yychar);
2014-09-24 14:45:10 +00:00
#endif
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
2014-09-24 14:45:10 +00:00
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
printf("yyparse: yynewstate (2)\n");
2014-09-24 14:45:10 +00:00
#endif
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
if( yychk[ yyn=yyact[ yyn ] ] == yychar ) /* valid shift */
2022-04-17 14:07:52 +00:00
{
2019-02-12 21:50:49 +00:00
yychar = -1;
yyval = yylval;
yystate = yyn;
2014-09-24 14:45:10 +00:00
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
printf("yyparse: yynewstate (3)\n");
2014-09-24 14:45:10 +00:00
#endif
2019-02-12 21:50:49 +00:00
if( yyerrflag > 0 ) --yyerrflag;
goto yystack;
}
2014-09-24 14:45:10 +00:00
yydefault:
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
printf("yyparse: yydefault yystate=%d\n",yystate);
2014-09-24 14:45:10 +00:00
#endif
2019-02-12 21:50:49 +00:00
/* default state action */
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
if( (yyn=yydef[yystate]) == -2 )
{
if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
/* look through exception table */
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
while( *(yyxi+=2) >= 0 )
{
if( *yyxi == yychar ) break;
}
if( (yyn = yyxi[1]) < 0 ) return(0); /* accept */
}
2014-09-24 14:45:10 +00:00
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
printf("yyparse: yyn=%d yyerrflag=%d\n",yyn,yyerrflag);
2014-09-24 14:45:10 +00:00
#endif
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
if( yyn == 0 ) /* error */
2022-04-17 14:07:52 +00:00
{
2019-02-12 21:50:49 +00:00
/* error ... attempt to resume parsing */
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
switch( yyerrflag ){
case 0: /* brand new error */
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
yyerror( "yyparse: syntax error" );
yyerrlab:
++yynerrs;
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
case 1:
case 2: /* incompletely recovered error ... try again */
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
yyerrflag = 3;
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
/* find a state where "error" is a legal shift action */
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
while ( yyps >= yys ) {
yyn = yypact[*yyps] + YYERRCODE;
if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
yystate = yyact[yyn]; /* simulate a shift of "error" */
goto yystack;
}
yyn = yypact[*yyps];
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
/* the current yyps has no shift onn "error", pop stack */
2014-09-24 14:45:10 +00:00
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
printf("yyparse: error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
2014-09-24 14:45:10 +00:00
#endif
2019-02-12 21:50:49 +00:00
--yyps;
--yypv;
}
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
/* there is no state on the stack with an error shift ... abort */
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
yyabort:
return(1);
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
case 3: /* no shift yet; clobber input char */
2014-09-24 14:45:10 +00:00
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
printf("yyparse: error recovery discards char ");
printchar("yychar",yychar);
2014-09-24 14:45:10 +00:00
#endif
2019-02-12 21:50:49 +00:00
if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
yychar = -1;
goto yynewstate; /* try again in the same state */
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
}
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
}
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
/* reduction by production yyn */
2014-09-24 14:45:10 +00:00
#ifdef YYDEBUG
2019-02-12 21:50:49 +00:00
printf("yyparse: reduce %d\n",yyn);
2014-09-24 14:45:10 +00:00
#endif
2019-02-12 21:50:49 +00:00
yyps -= yyr2[yyn];
yypvt = yypv;
yypv -= yyr2[yyn];
yyval = yypv[1];
yym=yyn;
/* consult goto table to find next state */
yyn = yyr1[yyn];
yyj = yypgo[yyn] + *yyps + 1;
if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
switch(yym)
{
case 4:
2022-04-17 14:07:52 +00:00
{
yyerrok;
2019-02-12 21:50:49 +00:00
}
break;
case 5:
2022-04-17 14:07:52 +00:00
{
2019-02-12 21:50:49 +00:00
printf("[STORE]\n");
2022-04-17 14:07:52 +00:00
}
2019-02-12 21:50:49 +00:00
break;
case 6:
2022-04-17 14:07:52 +00:00
{
2019-02-12 21:50:49 +00:00
printf("[ADD]\n");
2022-04-17 14:07:52 +00:00
}
2019-02-12 21:50:49 +00:00
break;
case 7:
2022-04-17 14:07:52 +00:00
{
2019-02-12 21:50:49 +00:00
printf("[NEG]\n[ADD]\n");
2022-04-17 14:07:52 +00:00
}
2019-02-12 21:50:49 +00:00
break;
case 8:
2022-04-17 14:07:52 +00:00
{
2019-02-12 21:50:49 +00:00
printf("[MUL]\n");
2022-04-17 14:07:52 +00:00
}
2019-02-12 21:50:49 +00:00
break;
case 9:
2022-04-17 14:07:52 +00:00
{
2019-02-12 21:50:49 +00:00
printf("[DIV]\n");
2022-04-17 14:07:52 +00:00
}
2019-02-12 21:50:49 +00:00
break;
case 10:
2022-04-17 14:07:52 +00:00
{
printf("[NEG]\n");
}
2019-02-12 21:50:49 +00:00
break;
case 12:
2022-04-17 14:07:52 +00:00
{
printf("[LOAD]\n");
}
2019-02-12 21:50:49 +00:00
break;
case 13:
2022-04-17 14:07:52 +00:00
{
2019-02-12 21:50:49 +00:00
printf("[PUSH %s]\n", yytext);
2022-04-17 14:07:52 +00:00
}
2019-02-12 21:50:49 +00:00
break;
case 14:
2022-04-17 14:07:52 +00:00
{
2019-02-12 21:50:49 +00:00
printf("[%s]\n", yytext);
2022-04-17 14:07:52 +00:00
}
2019-02-12 21:50:49 +00:00
break;
}
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
goto yystack; /* stack new state and value */
2014-09-24 14:45:10 +00:00
}
2022-04-17 14:07:52 +00:00
int yywrap()
{
return 1;
2014-09-24 14:45:10 +00:00
}