1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-23 19:29:37 +00:00
cc65/test/ref/yacc2.c

230 lines
4.9 KiB
C
Raw Normal View History

2014-09-24 14:45:10 +00:00
/*
!!DESCRIPTION!!
!!ORIGIN!! testsuite
!!LICENCE!! Public Domain
!!AUTHOR!! Groepaz/Hitmen
*/
#include <stdio.h>
2014-09-24 14:45:10 +00:00
# define YYTYPE char
struct yywork
{
2019-02-12 21:50:49 +00:00
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},
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}, {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},
2014-09-24 14:45:10 +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},
2014-09-24 14:45:10 +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},
2014-09-24 14:45:10 +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
};
struct yywork *yytop = yycrank+255;
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
};
struct yysvf
{
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
};
#if 0
# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):GETCHAR())==('\n')?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
// *yylastch++ = yych = input();
void subtest1(void)
{
2019-02-12 21:50:49 +00:00
*yylastch++ = yych = input();
2014-09-24 14:45:10 +00:00
}
#endif
// do some bogus operation to destroy all registers etc
static int bog=1234;
#if 0
void bogus(void)
{
2019-02-12 21:50:49 +00:00
bog*=0x1234;
2014-09-24 14:45:10 +00:00
}
#else
2019-02-12 21:50:49 +00:00
#define bogus() bog+=0x1234
2014-09-24 14:45:10 +00:00
#endif
#if 1
// yyt = yyt + yych;
void subtest2(void)
{
2019-02-12 21:50:49 +00:00
register struct yywork *yyt;
int yych;
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
yyt=yycrank;
yych=10;
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
bogus();
yyt = yyt + yych;
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
printf("yyt: %d %d\n",yyt->verify,yyt->advance);
2014-09-24 14:45:10 +00:00
}
#endif
#if 1
// if(yyt <= yytop && yyt->verify+yysvec == yystate)
void subtest3(void)
{
2019-02-12 21:50:49 +00:00
register struct yywork *yyt;
register struct yysvf *yystate;
yyt=yycrank;
yystate=yysvec;
bogus();
if(yyt <= yytop && yyt->verify+yysvec == yystate)
{
printf("if ok %d %d\n",yyt->verify,yyt->advance);
}
else
{
printf("if not ok %d %d\n",yyt->verify,yyt->advance);
}
2014-09-24 14:45:10 +00:00
}
#endif
short yyr2[]=
{
0, 0, 2, 3, 3, 3, 3, 3, 3, 3,
2, 3, 1, 1, 1
};
// yyps -= yyr2[yyn];
void subtest4(void)
{
2019-02-12 21:50:49 +00:00
register short *yyps, yyn;
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
yyps=0x8004;
yyn=0;
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
while(yyn<14)
{
bogus();
yyps -= yyr2[yyn];
2014-09-24 14:45:10 +00:00
2019-02-12 21:50:49 +00:00
yyn++;
}
printf("yyps: %04x\n",yyps);
2014-09-24 14:45:10 +00:00
}
#if 1
int yylookret=10;
yylook()
{
2019-02-12 21:50:49 +00:00
yylookret--;
return yylookret;
2014-09-24 14:45:10 +00:00
}
// while((nstr = yylook()) >= 0)
void subtest5(void)
{
2019-02-12 21:50:49 +00:00
int nstr;
bogus();
while((nstr = yylook()) >= 0)
{
printf("nstr: %04x\n",nstr);
bogus();
}
2014-09-24 14:45:10 +00:00
}
#endif
int main(void)
{
// subtest1();
subtest2();
subtest3();
subtest4();
subtest5();
return 0;
}