275 lines
5.0 KiB
Plaintext
275 lines
5.0 KiB
Plaintext
|
#define YYFLAG -1000
|
||
|
#define YYERROR goto yyerrlab
|
||
|
#define YYACCEPT return(0)
|
||
|
#define YYABORT return(1)
|
||
|
#define yyclearin yychar = -1
|
||
|
#define yyerrok yyerrflag = 0
|
||
|
|
||
|
#ifdef yydebug
|
||
|
#include "y.debug"
|
||
|
#else
|
||
|
#define yydebug 0
|
||
|
static const char* yytoknames[1]; /* for debugging */
|
||
|
static const char* yystates[1]; /* for debugging */
|
||
|
#endif
|
||
|
|
||
|
/* parser for yacc output */
|
||
|
#ifdef YYARG
|
||
|
#define yynerrs yyarg->yynerrs
|
||
|
#define yyerrflag yyarg->yyerrflag
|
||
|
#define yyval yyarg->yyval
|
||
|
#define yylval yyarg->yylval
|
||
|
#else
|
||
|
int yynerrs = 0; /* number of errors */
|
||
|
int yyerrflag = 0; /* error recovery flag */
|
||
|
#endif
|
||
|
|
||
|
static const char*
|
||
|
yytokname(int yyc)
|
||
|
{
|
||
|
static char x[10];
|
||
|
|
||
|
if(yyc > 0 && yyc <= sizeof(yytoknames)/sizeof(yytoknames[0]))
|
||
|
if(yytoknames[yyc-1])
|
||
|
return yytoknames[yyc-1];
|
||
|
sprintf(x, "<%d>", yyc);
|
||
|
return x;
|
||
|
}
|
||
|
|
||
|
static const char*
|
||
|
yystatname(int yys)
|
||
|
{
|
||
|
static char x[10];
|
||
|
|
||
|
if(yys >= 0 && yys < sizeof(yystates)/sizeof(yystates[0]))
|
||
|
if(yystates[yys])
|
||
|
return yystates[yys];
|
||
|
sprintf(x, "<%d>\n", yys);
|
||
|
return x;
|
||
|
}
|
||
|
|
||
|
static long
|
||
|
#ifdef YYARG
|
||
|
yylex1(struct Yyarg *yyarg)
|
||
|
#else
|
||
|
yylex1(void)
|
||
|
#endif
|
||
|
{
|
||
|
long yychar;
|
||
|
const long *t3p;
|
||
|
int c;
|
||
|
|
||
|
#ifdef YYARG
|
||
|
yychar = yylex(yyarg);
|
||
|
#else
|
||
|
yychar = yylex();
|
||
|
#endif
|
||
|
if(yychar <= 0) {
|
||
|
c = yytok1[0];
|
||
|
goto out;
|
||
|
}
|
||
|
if(yychar < sizeof(yytok1)/sizeof(yytok1[0])) {
|
||
|
c = yytok1[yychar];
|
||
|
goto out;
|
||
|
}
|
||
|
if(yychar >= YYPRIVATE)
|
||
|
if(yychar < YYPRIVATE+sizeof(yytok2)/sizeof(yytok2[0])) {
|
||
|
c = yytok2[yychar-YYPRIVATE];
|
||
|
goto out;
|
||
|
}
|
||
|
for(t3p=yytok3;; t3p+=2) {
|
||
|
c = t3p[0];
|
||
|
if(c == yychar) {
|
||
|
c = t3p[1];
|
||
|
goto out;
|
||
|
}
|
||
|
if(c == 0)
|
||
|
break;
|
||
|
}
|
||
|
c = 0;
|
||
|
|
||
|
out:
|
||
|
if(c == 0)
|
||
|
c = yytok2[1]; /* unknown char */
|
||
|
if(yydebug >= 3)
|
||
|
printf("lex %.4lX %s\n", yychar, yytokname(c));
|
||
|
return c;
|
||
|
}
|
||
|
|
||
|
int
|
||
|
#ifdef YYARG
|
||
|
yyparse(struct Yyarg *yyarg)
|
||
|
#else
|
||
|
yyparse(void)
|
||
|
#endif
|
||
|
{
|
||
|
struct
|
||
|
{
|
||
|
YYSTYPE yyv;
|
||
|
int yys;
|
||
|
} yys[YYMAXDEPTH], *yyp, *yypt;
|
||
|
const short *yyxi;
|
||
|
int yyj, yym, yystate, yyn, yyg;
|
||
|
long yychar;
|
||
|
#ifndef YYARG
|
||
|
YYSTYPE save1, save2;
|
||
|
int save3, save4;
|
||
|
|
||
|
save1 = yylval;
|
||
|
save2 = yyval;
|
||
|
save3 = yynerrs;
|
||
|
save4 = yyerrflag;
|
||
|
#endif
|
||
|
|
||
|
yystate = 0;
|
||
|
yychar = -1;
|
||
|
yynerrs = 0;
|
||
|
yyerrflag = 0;
|
||
|
yyp = &yys[0];
|
||
|
yyp--;
|
||
|
goto yystack;
|
||
|
|
||
|
ret0:
|
||
|
yyn = 0;
|
||
|
goto ret;
|
||
|
|
||
|
ret1:
|
||
|
yyn = 1;
|
||
|
goto ret;
|
||
|
|
||
|
ret:
|
||
|
#ifndef YYARG
|
||
|
yylval = save1;
|
||
|
yyval = save2;
|
||
|
yynerrs = save3;
|
||
|
yyerrflag = save4;
|
||
|
#endif
|
||
|
return yyn;
|
||
|
|
||
|
yystack:
|
||
|
/* put a state and value onto the stack */
|
||
|
if(yydebug >= 4)
|
||
|
printf("char %s in %s", yytokname(yychar), yystatname(yystate));
|
||
|
|
||
|
yyp++;
|
||
|
if(yyp >= &yys[YYMAXDEPTH]) {
|
||
|
yyerror("yacc stack overflow");
|
||
|
goto ret1;
|
||
|
}
|
||
|
yyp->yys = yystate;
|
||
|
yyp->yyv = yyval;
|
||
|
|
||
|
yynewstate:
|
||
|
yyn = yypact[yystate];
|
||
|
if(yyn <= YYFLAG)
|
||
|
goto yydefault; /* simple state */
|
||
|
if(yychar < 0)
|
||
|
#ifdef YYARG
|
||
|
yychar = yylex1(yyarg);
|
||
|
#else
|
||
|
yychar = yylex1();
|
||
|
#endif
|
||
|
yyn += yychar;
|
||
|
if(yyn < 0 || yyn >= YYLAST)
|
||
|
goto yydefault;
|
||
|
yyn = yyact[yyn];
|
||
|
if(yychk[yyn] == yychar) { /* valid shift */
|
||
|
yychar = -1;
|
||
|
yyval = yylval;
|
||
|
yystate = yyn;
|
||
|
if(yyerrflag > 0)
|
||
|
yyerrflag--;
|
||
|
goto yystack;
|
||
|
}
|
||
|
|
||
|
yydefault:
|
||
|
/* default state action */
|
||
|
yyn = yydef[yystate];
|
||
|
if(yyn == -2) {
|
||
|
if(yychar < 0)
|
||
|
#ifdef YYARG
|
||
|
yychar = yylex1(yyarg);
|
||
|
#else
|
||
|
yychar = yylex1();
|
||
|
#endif
|
||
|
|
||
|
/* look through exception table */
|
||
|
for(yyxi=yyexca;; yyxi+=2)
|
||
|
if(yyxi[0] == -1 && yyxi[1] == yystate)
|
||
|
break;
|
||
|
for(yyxi += 2;; yyxi += 2) {
|
||
|
yyn = yyxi[0];
|
||
|
if(yyn < 0 || yyn == yychar)
|
||
|
break;
|
||
|
}
|
||
|
yyn = yyxi[1];
|
||
|
if(yyn < 0)
|
||
|
goto ret0;
|
||
|
}
|
||
|
if(yyn == 0) {
|
||
|
/* error ... attempt to resume parsing */
|
||
|
switch(yyerrflag) {
|
||
|
case 0: /* brand new error */
|
||
|
yyerror("syntax error");
|
||
|
if(yydebug >= 1) {
|
||
|
printf("%s", yystatname(yystate));
|
||
|
printf("saw %s\n", yytokname(yychar));
|
||
|
}
|
||
|
goto yyerrlab;
|
||
|
yyerrlab:
|
||
|
yynerrs++;
|
||
|
|
||
|
case 1:
|
||
|
case 2: /* incompletely recovered error ... try again */
|
||
|
yyerrflag = 3;
|
||
|
|
||
|
/* find a state where "error" is a legal shift action */
|
||
|
while(yyp >= yys) {
|
||
|
yyn = yypact[yyp->yys] + YYERRCODE;
|
||
|
if(yyn >= 0 && yyn < YYLAST) {
|
||
|
yystate = yyact[yyn]; /* simulate a shift of "error" */
|
||
|
if(yychk[yystate] == YYERRCODE)
|
||
|
goto yystack;
|
||
|
}
|
||
|
|
||
|
/* the current yyp has no shift onn "error", pop stack */
|
||
|
if(yydebug >= 2)
|
||
|
printf("error recovery pops state %d, uncovers %d\n",
|
||
|
yyp->yys, (yyp-1)->yys );
|
||
|
yyp--;
|
||
|
}
|
||
|
/* there is no state on the stack with an error shift ... abort */
|
||
|
goto ret1;
|
||
|
|
||
|
case 3: /* no shift yet; clobber input char */
|
||
|
if(yydebug >= YYEOFCODE)
|
||
|
printf("error recovery discards %s\n", yytokname(yychar));
|
||
|
if(yychar == YYEOFCODE)
|
||
|
goto ret1;
|
||
|
yychar = -1;
|
||
|
goto yynewstate; /* try again in the same state */
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* reduction by production yyn */
|
||
|
if(yydebug >= 2)
|
||
|
printf("reduce %d in:\n\t%s", yyn, yystatname(yystate));
|
||
|
|
||
|
yypt = yyp;
|
||
|
yyp -= yyr2[yyn];
|
||
|
yyval = (yyp+1)->yyv;
|
||
|
yym = yyn;
|
||
|
|
||
|
/* consult goto table to find next state */
|
||
|
yyn = yyr1[yyn];
|
||
|
yyg = yypgo[yyn];
|
||
|
yyj = yyg + yyp->yys + 1;
|
||
|
|
||
|
if(yyj >= YYLAST || yychk[yystate=yyact[yyj]] != -yyn)
|
||
|
yystate = yyact[yyg];
|
||
|
switch(yym) {
|
||
|
$A
|
||
|
}
|
||
|
goto yystack; /* stack new state and value */
|
||
|
}
|