]> git.sur5r.net Git - cc65/blob - test/ref/yacc2.c
remote TABs in doc/ and test/
[cc65] / test / ref / yacc2.c
1 /*
2   !!DESCRIPTION!!
3   !!ORIGIN!!      testsuite
4   !!LICENCE!!     Public Domain
5   !!AUTHOR!!      Groepaz/Hitmen
6 */
7
8 #include <stdio.h>
9
10 # define YYTYPE char
11 struct yywork 
12
13         YYTYPE verify, advance; 
14 } yycrank[] =
15 {
16         {0,0},  {0,0},  {1,3},  {0,0},
17         {0,0},  {0,0},  {0,0},  {0,0},
18         {0,0},  {0,0},  {1,4},  {1,3},
19         {0,0},  {0,0},  {0,0},  {0,0},
20
21         {0,0},  {0,0},  {0,0},  {0,0},
22         {0,0},  {0,0},  {0,0},  {0,0},
23         {0,0},  {0,0},  {0,0},  {0,0},
24         {0,0},  {0,0},  {0,0},  {0,0},
25  
26         {0,0},  {0,0},  {0,0},  {0,0},
27         {0,0},  {0,0},  {0,0},  {0,0},
28         {0,0},  {0,0},  {0,0},  {0,0},
29         {0,0},  {0,0},  {0,0},  {0,0},
30  
31         {0,0},  {1,5},  {5,7},  {5,7},
32         {5,7},  {5,7},  {5,7},  {5,7},
33         {5,7},  {5,7},  {5,7},  {5,7},
34         {0,0},  {0,0},  {0,0},  {0,0},
35 /* 0x40 */
36         {0,0},  {0,0},  {1,6},  {6,8},
37         {6,8},  {6,8},  {6,8},  {6,8},
38         {6,8},  {6,8},  {6,8},  {6,8},
39         {6,8},  {0,0},  {0,0},  {0,0},
40  
41         {0,0},  {0,0},  {0,0},  {0,0},
42         {6,8},  {6,8},  {6,8},  {6,8},
43         {6,8},  {6,8},  {6,8},  {6,8},
44         {6,8},  {6,8},  {6,8},  {6,8},
45  
46         {6,8},  {6,8},  {6,8},  {6,8},
47         {6,8},  {6,8},  {6,8},  {6,8},
48         {6,8},  {6,8},  {6,8},  {6,8},
49         {6,8},  {6,8},  {0,0},  {0,0},
50  
51         {0,0},  {0,0},  {6,8},  {0,0},
52         {6,8},  {6,8},  {6,8},  {6,8},
53         {6,8},  {6,8},  {6,8},  {6,8},
54         {6,8},  {6,8},  {6,8},  {6,8},
55 /* 0x80 */
56         {6,8},  {6,8},  {6,8},  {6,8},
57         {6,8},  {6,8},  {6,8},  {6,8},
58         {6,8},  {6,8},  {6,8},  {6,8},
59         {6,8},  {6,8},  {0,0},  {0,0},
60
61 #ifdef CHARSETHACK
62         {0,0},  {0,0},  {0,0},  {0,0},
63         {0,0},  {0,0},  {0,0},  {0,0},
64         {0,0},  {0,0},  {0,0},  {0,0},
65         {0,0},  {0,0},  {0,0},  {0,0},
66
67         {0,0},  {0,0},  {0,0},  {0,0},
68         {0,0},  {0,0},  {0,0},  {0,0},
69         {0,0},  {0,0},  {0,0},  {0,0},
70         {0,0},  {0,0},  {0,0},  {0,0},
71
72         {0,0},  {0,0},  {0,0},  {0,0},
73         {0,0},  {0,0},  {0,0},  {0,0},
74         {0,0},  {0,0},  {0,0},  {0,0},
75         {0,0},  {0,0},  {0,0},  {0,0},
76
77 /* 0xc0 */
78         {0,0},  {0,0},  {1,6},  {6,8},
79         {6,8},  {6,8},  {6,8},  {6,8},
80         {6,8},  {6,8},  {6,8},  {6,8},
81         {6,8},  {0,0},  {0,0},  {0,0},
82 #endif
83         {0,0}
84 };
85
86 struct yywork *yytop = yycrank+255;
87
88 int yyvstop[] =
89 {
90         0,4,0,3,4,0,2,4,0,1,4,0,2,0,1,0,0
91 };
92
93 struct yysvf 
94 {
95         struct yywork *yystoff;
96         struct yysvf *yyother;
97         int *yystops;
98 };
99
100 struct yysvf yysvec[] =
101 {
102         {0,     0,      0},
103         {yycrank+-1,    0,              0},
104         {yycrank+0,     yysvec+1,       0},
105         {yycrank+0,     0,              yyvstop+1},
106         {yycrank+0,     0,              yyvstop+3},
107         {yycrank+2,     0,              yyvstop+6},
108         {yycrank+19,    0,              yyvstop+9},
109         {yycrank+0,     yysvec+5,       yyvstop+12},
110         {yycrank+0,     yysvec+6,       yyvstop+14},
111         {0,     0,      0}
112 };
113
114 #if 0
115 # define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):GETCHAR())==('\n')?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
116 // *yylastch++ = yych = input();
117 void subtest1(void)
118 {
119         *yylastch++ = yych = input();
120 }
121 #endif
122
123 // do some bogus operation to destroy all registers etc
124 static int bog=1234;
125 #if 0
126 void bogus(void)
127 {
128         bog*=0x1234;
129 }
130 #else
131 #define bogus() bog+=0x1234
132 #endif
133
134 #if 1
135 // yyt = yyt + yych;
136 void subtest2(void)
137 {
138         register struct yywork *yyt;
139         int yych;
140
141         yyt=yycrank;
142         yych=10;
143
144         bogus();
145         yyt = yyt + yych;
146
147         printf("yyt: %d %d\n",yyt->verify,yyt->advance);
148 }
149 #endif
150
151 #if 1
152 // if(yyt <= yytop && yyt->verify+yysvec == yystate)
153 void subtest3(void)
154 {
155         register struct yywork *yyt;
156         register struct yysvf *yystate;
157
158         yyt=yycrank;
159         yystate=yysvec;
160         
161         bogus();
162         if(yyt <= yytop && yyt->verify+yysvec == yystate)
163         {
164                 printf("if ok %d %d\n",yyt->verify,yyt->advance);
165         }
166         else
167         {
168                 printf("if not ok %d %d\n",yyt->verify,yyt->advance);
169         }
170 }
171 #endif
172
173 short yyr2[]=
174 {
175    0,   0,   2,   3,   3,   3,   3,   3,   3,   3,
176    2,   3,   1,   1,   1 
177 };
178
179 // yyps -= yyr2[yyn];
180 void subtest4(void)
181 {
182         register short *yyps, yyn;
183
184         yyps=0x8004;
185         yyn=0;
186
187         while(yyn<14)
188         {
189                 bogus();
190                 yyps -= yyr2[yyn];
191
192                 yyn++;
193         }
194         printf("yyps: %04x\n",yyps);
195 }
196
197 #if 1
198
199 int yylookret=10;
200 yylook()
201 {
202         yylookret--;
203         return yylookret;
204 }
205
206 // while((nstr = yylook()) >= 0)
207 void subtest5(void)
208 {
209         int nstr;
210
211         bogus();
212         while((nstr = yylook()) >= 0)
213         {
214                 printf("nstr: %04x\n",nstr);
215                 bogus();
216         }
217 }
218 #endif
219
220 int main(void)
221 {
222 //    subtest1();
223     subtest2();
224     subtest3();
225     subtest4();
226     subtest5();
227
228     return 0;
229 }