OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [lcc/] [tst/] [yacc.c] - Blame information for rev 215

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 hellwig
# define ID 257
2
# define CON 258
3
# define UNARYMINUS 259
4
#define yyclearin yychar = -1
5
#define yyerrok yyerrflag = 0
6
extern int yychar;
7
extern short yyerrflag;
8
#ifndef YYMAXDEPTH
9
#define YYMAXDEPTH 150
10
#endif
11
#ifndef YYSTYPE
12
#define YYSTYPE int
13
#endif
14
YYSTYPE yylval, yyval;
15
# define YYERRCODE 256
16
 
17
 
18
 
19
#include <stdio.h>
20
 
21
# define U(x) x
22
# define NLSTATE yyprevious=YYNEWLINE
23
# define BEGIN yybgin = yysvec + 1 +
24
# define INITIAL 0
25
# define YYLERR yysvec
26
# define YYSTATE (yyestate-yysvec-1)
27
# define YYOPTIM 1
28
# define YYLMAX 200
29
# define output(c) (void)putc(c,yyout)
30
# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
31
# define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
32
# define yymore() (yymorfg=1)
33
# define ECHO fprintf(yyout, "%s",yytext)
34
# define REJECT { nstr = yyreject(); goto yyfussy;}
35
int yyleng; extern char yytext[];
36
int yymorfg;
37
extern char *yysptr, yysbuf[];
38
int yytchar;
39
FILE *yyin = NULL, *yyout = NULL;
40
extern int yylineno;
41
struct yysvf {
42
        struct yywork *yystoff;
43
        struct yysvf *yyother;
44
        int *yystops;};
45
struct yysvf *yyestate;
46
extern struct yysvf yysvec[], *yybgin;
47
# define YYNEWLINE 10
48
yylex(){
49
int nstr; extern int yyprevious;
50
while((nstr = yylook()) >= 0)
51
yyfussy: switch(nstr){
52
case 0:
53
if(yywrap()) return(0); break;
54
case 1:
55
 return ID;
56
break;
57
case 2:
58
                 return CON;
59
break;
60
case 3:
61
                  ;
62
break;
63
case 4:
64
                   return yytext[0];
65
break;
66
case -1:
67
break;
68
default:
69
fprintf(yyout,"bad switch yylook %d",nstr);
70
} return(0); }
71
/* end of yylex */
72
int yyvstop[] ={
73
0,
74
 
75
4,
76
0,
77
 
78
3,
79
4,
80
0,
81
 
82
2,
83
4,
84
0,
85
 
86
1,
87
4,
88
0,
89
 
90
2,
91
0,
92
 
93
1,
94
0,
95
0};
96
# define YYTYPE char
97
struct yywork { YYTYPE verify, advance; } yycrank[] ={
98
0,0,      0,0,      1,3,    0,0,
99
0,0,      0,0,      0,0,      0,0,
100
0,0,      0,0,      1,4,    1,3,
101
0,0,      0,0,      0,0,      0,0,
102
0,0,      0,0,      0,0,      0,0,
103
0,0,      0,0,      0,0,      0,0,
104
0,0,      0,0,      0,0,      0,0,
105
0,0,      0,0,      0,0,      0,0,
106
0,0,      0,0,      0,0,      0,0,
107
0,0,      0,0,      0,0,      0,0,
108
0,0,      0,0,      0,0,      0,0,
109
0,0,      0,0,      0,0,      0,0,
110
0,0,      1,5,    5,7,    5,7,
111
5,7,    5,7,    5,7,    5,7,
112
5,7,    5,7,    5,7,    5,7,
113
0,0,      0,0,      0,0,      0,0,
114
0,0,      0,0,      1,6,    6,8,
115
6,8,    6,8,    6,8,    6,8,
116
6,8,    6,8,    6,8,    6,8,
117
6,8,    0,0,      0,0,      0,0,
118
0,0,      0,0,      0,0,      0,0,
119
6,8,    6,8,    6,8,    6,8,
120
6,8,    6,8,    6,8,    6,8,
121
6,8,    6,8,    6,8,    6,8,
122
6,8,    6,8,    6,8,    6,8,
123
6,8,    6,8,    6,8,    6,8,
124
6,8,    6,8,    6,8,    6,8,
125
6,8,    6,8,    0,0,      0,0,
126
0,0,      0,0,      6,8,    0,0,
127
6,8,    6,8,    6,8,    6,8,
128
6,8,    6,8,    6,8,    6,8,
129
6,8,    6,8,    6,8,    6,8,
130
6,8,    6,8,    6,8,    6,8,
131
6,8,    6,8,    6,8,    6,8,
132
6,8,    6,8,    6,8,    6,8,
133
6,8,    6,8,    0,0,      0,0,
134
0,0};
135
struct yysvf yysvec[] ={
136
0,       0,       0,
137
yycrank+-1,     0,               0,
138
yycrank+0,       yysvec+1,       0,
139
yycrank+0,       0,               yyvstop+1,
140
yycrank+0,       0,               yyvstop+3,
141
yycrank+2,      0,               yyvstop+6,
142
yycrank+19,     0,               yyvstop+9,
143
yycrank+0,       yysvec+5,       yyvstop+12,
144
yycrank+0,       yysvec+6,       yyvstop+14,
145
0,       0,       0};
146
struct yywork *yytop = yycrank+141;
147
struct yysvf *yybgin = yysvec+1;
148
char yymatch[] ={
149
00  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
150
01  ,011 ,012 ,01  ,01  ,01  ,01  ,01  ,
151
01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
152
01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
153
011 ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
154
01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
155
'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,
156
'0' ,'0' ,01  ,01  ,01  ,01  ,01  ,01  ,
157
01  ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
158
'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
159
'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
160
'A' ,'A' ,'A' ,01  ,01  ,01  ,01  ,'A' ,
161
01  ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
162
'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
163
'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
164
'A' ,'A' ,'A' ,01  ,01  ,01  ,01  ,01  ,
165
0};
166
char yyextra[] ={
167
0,0,0,0,0,0,0,0,
168
0};
169
/*      ncform  4.1     83/08/11        */
170
 
171
int yylineno =1;
172
# define YYU(x) x
173
# define NLSTATE yyprevious=YYNEWLINE
174
char yytext[YYLMAX];
175
struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
176
char yysbuf[YYLMAX];
177
char *yysptr = yysbuf;
178
int *yyfnd;
179
extern struct yysvf *yyestate;
180
int yyprevious = YYNEWLINE;
181
yylook(){
182
        register struct yysvf *yystate, **lsp;
183
        register struct yywork *yyt;
184
        struct yysvf *yyz;
185
        int yych;
186
        struct yywork *yyr;
187
# ifdef LEXDEBUG
188
        int debug;
189
# endif
190
        char *yylastch;
191
        /* start off machines */
192
# ifdef LEXDEBUG
193
        debug = 0;
194
# endif
195
        if (!yymorfg)
196
                yylastch = yytext;
197
        else {
198
                yymorfg=0;
199
                yylastch = yytext+yyleng;
200
                }
201
        for(;;){
202
                lsp = yylstate;
203
                yyestate = yystate = yybgin;
204
                if (yyprevious==YYNEWLINE) yystate++;
205
                for (;;){
206
# ifdef LEXDEBUG
207
                        if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
208
# endif
209
                        yyt = yystate->yystoff;
210
                        if(yyt == yycrank){             /* may not be any transitions */
211
                                yyz = yystate->yyother;
212
                                if(yyz == 0)break;
213
                                if(yyz->yystoff == yycrank)break;
214
                                }
215
                        *yylastch++ = yych = input();
216
                tryagain:
217
# ifdef LEXDEBUG
218
                        if(debug){
219
                                fprintf(yyout,"char ");
220
                                allprint(yych);
221
                                putchar('\n');
222
                                }
223
# endif
224
                        yyr = yyt;
225
                        if ( yyt > yycrank){
226
                                yyt = yyr + yych;
227
                                if (yyt <= yytop && yyt->verify+yysvec == yystate){
228
                                        if(yyt->advance+yysvec == YYLERR)       /* error transitions */
229
                                                {unput(*--yylastch);break;}
230
                                        *lsp++ = yystate = yyt->advance+yysvec;
231
                                        goto contin;
232
                                        }
233
                                }
234
# ifdef YYOPTIM
235
                        else if(yyt < yycrank) {                /* r < yycrank */
236
                                yyt = yyr = yycrank+(yycrank-yyt);
237
# ifdef LEXDEBUG
238
                                if(debug)fprintf(yyout,"compressed state\n");
239
# endif
240
                                yyt = yyt + yych;
241
                                if(yyt <= yytop && yyt->verify+yysvec == yystate){
242
                                        if(yyt->advance+yysvec == YYLERR)       /* error transitions */
243
                                                {unput(*--yylastch);break;}
244
                                        *lsp++ = yystate = yyt->advance+yysvec;
245
                                        goto contin;
246
                                        }
247
                                yyt = yyr + YYU(yymatch[yych]);
248
# ifdef LEXDEBUG
249
                                if(debug){
250
                                        fprintf(yyout,"try fall back character ");
251
                                        allprint(YYU(yymatch[yych]));
252
                                        putchar('\n');
253
                                        }
254
# endif
255
                                if(yyt <= yytop && yyt->verify+yysvec == yystate){
256
                                        if(yyt->advance+yysvec == YYLERR)       /* error transition */
257
                                                {unput(*--yylastch);break;}
258
                                        *lsp++ = yystate = yyt->advance+yysvec;
259
                                        goto contin;
260
                                        }
261
                                }
262
                        if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
263
# ifdef LEXDEBUG
264
                                if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
265
# endif
266
                                goto tryagain;
267
                                }
268
# endif
269
                        else
270
                                {unput(*--yylastch);break;}
271
                contin:
272
# ifdef LEXDEBUG
273
                        if(debug){
274
                                fprintf(yyout,"state %d char ",yystate-yysvec-1);
275
                                allprint(yych);
276
                                putchar('\n');
277
                                }
278
# endif
279
                        ;
280
                        }
281
# ifdef LEXDEBUG
282
                if(debug){
283
                        fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
284
                        allprint(yych);
285
                        putchar('\n');
286
                        }
287
# endif
288
                while (lsp-- > yylstate){
289
                        *yylastch-- = 0;
290
                        if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
291
                                yyolsp = lsp;
292
                                if(yyextra[*yyfnd]){            /* must backup */
293
                                        while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
294
                                                lsp--;
295
                                                unput(*yylastch--);
296
                                                }
297
                                        }
298
                                yyprevious = YYU(*yylastch);
299
                                yylsp = lsp;
300
                                yyleng = yylastch-yytext+1;
301
                                yytext[yyleng] = 0;
302
# ifdef LEXDEBUG
303
                                if(debug){
304
                                        fprintf(yyout,"\nmatch ");
305
                                        sprint(yytext);
306
                                        fprintf(yyout," action %d\n",*yyfnd);
307
                                        }
308
# endif
309
                                return(*yyfnd++);
310
                                }
311
                        unput(*yylastch);
312
                        }
313
                if (yytext[0] == 0  /* && feof(yyin) */)
314
                        {
315
                        yysptr=yysbuf;
316
                        return(0);
317
                        }
318
                yyprevious = yytext[0] = input();
319
                if (yyprevious>0)
320
                        output(yyprevious);
321
                yylastch=yytext;
322
# ifdef LEXDEBUG
323
                if(debug)putchar('\n');
324
# endif
325
                }
326
        }
327
yyback(p, m)
328
        int *p;
329
{
330
if (p==0) return(0);
331
while (*p)
332
        {
333
        if (*p++ == m)
334
                return(1);
335
        }
336
return(0);
337
}
338
        /* the following are only used in the lex library */
339
yyinput(){
340
        return(input());
341
        }
342
yyoutput(c)
343
  int c; {
344
        output(c);
345
        }
346
yyunput(c)
347
   int c; {
348
        unput(c);
349
        }
350
 
351
main() {
352
        yyin = stdin; yyout = stdout;
353
        yyparse();
354
        return 0;
355
}
356
 
357
/* yyerror - issue error message */
358
yyerror(s) char *s; {
359
        printf("%s\n", s);
360
}
361
short yyexca[] ={
362
-1, 1,
363
        0, -1,
364
        -2, 0,
365
        };
366
# define YYNPROD 15
367
# define YYLAST 249
368
short yyact[]={
369
 
370
  12,   2,   9,   8,  17,  11,  25,  17,  15,  18,
371
  16,  10,  18,  17,  15,   7,  16,  13,  18,   5,
372
   3,   1,   0,  19,  20,   0,   0,  21,  22,  23,
373
  24,   0,   0,   0,   0,   0,   0,   0,   0,   0,
374
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
375
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
376
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
377
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
378
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
379
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
380
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
381
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
382
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
383
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
384
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
385
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
386
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
387
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
388
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
389
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
390
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
391
   0,   0,   0,   0,   0,   0,   0,   6,  14,   0,
392
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
393
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
394
   0,   0,   0,   0,   0,   0,   0,   4,   6 };
395
short yypact[]={
396
 
397
-1000,  -9,-1000,   5,  -7, -59,-1000,-1000,-1000, -40,
398
 -29, -40, -40,-1000,-1000, -40, -40, -40, -40, -38,
399
 -35, -38, -38,-1000,-1000,-1000 };
400
short yypgo[]={
401
 
402
   0,  21,  20,  17,  11 };
403
short yyr1[]={
404
 
405
   0,   1,   1,   1,   1,   2,   4,   4,   4,   4,
406
   4,   4,   4,   4,   3 };
407
short yyr2[]={
408
 
409
   0,   0,   2,   3,   3,   3,   3,   3,   3,   3,
410
   2,   3,   1,   1,   1 };
411
short yychk[]={
412
 
413
-1000,  -1,  10,  -2, 256,  -3, 257,  10,  10,  61,
414
  -4,  45,  40,  -3, 258,  43,  45,  42,  47,  -4,
415
  -4,  -4,  -4,  -4,  -4,  41 };
416
short yydef[]={
417
 
418
   1,  -2,   2,   0,   0,   0,  14,   3,   4,   0,
419
   5,   0,   0,  12,  13,   0,   0,   0,   0,  10,
420
   0,   6,   7,   8,   9,  11 };
421
#ifndef lint
422
#endif
423
 
424
# define YYFLAG -1000
425
# define YYERROR goto yyerrlab
426
# define YYACCEPT return(0)
427
# define YYABORT return(1)
428
 
429
/*      parser for yacc output  */
430
 
431
#ifdef YYDEBUG
432
int yydebug = 0; /* 1 for debugging */
433
#endif
434
YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
435
int yychar = -1; /* current input token number */
436
int yynerrs = 0;  /* number of errors */
437
short yyerrflag = 0;  /* error recovery flag */
438
 
439
yyparse() {
440
 
441
        short yys[YYMAXDEPTH];
442
        short yyj, yym;
443
        register YYSTYPE *yypvt;
444
        register short yystate, *yyps, yyn;
445
        register YYSTYPE *yypv;
446
        register short *yyxi;
447
 
448
        yystate = 0;
449
        yychar = -1;
450
        yynerrs = 0;
451
        yyerrflag = 0;
452
        yyps= &yys[-1];
453
        yypv= &yyv[-1];
454
 
455
 yystack:    /* put a state and value onto the stack */
456
 
457
#ifdef YYDEBUG
458
        if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
459
#endif
460
                if( ++yyps> &yys[YYMAXDEPTH-1] ) { yyerror( "yacc stack overflow" ); return(1); }
461
                *yyps = yystate;
462
                ++yypv;
463
                *yypv = yyval;
464
 
465
 yynewstate:
466
 
467
        yyn = yypact[yystate];
468
 
469
        if( yyn<= YYFLAG ) goto yydefault; /* simple state */
470
 
471
        if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
472
        if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
473
 
474
        if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
475
                yychar = -1;
476
                yyval = yylval;
477
                yystate = yyn;
478
                if( yyerrflag > 0 ) --yyerrflag;
479
                goto yystack;
480
                }
481
 
482
 yydefault:
483
        /* default state action */
484
 
485
        if( (yyn=yydef[yystate]) == -2 ) {
486
                if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
487
                /* look through exception table */
488
 
489
                for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
490
 
491
                while( *(yyxi+=2) >= 0 ){
492
                        if( *yyxi == yychar ) break;
493
                        }
494
                if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
495
                }
496
 
497
        if( yyn == 0 ){ /* error */
498
                /* error ... attempt to resume parsing */
499
 
500
                switch( yyerrflag ){
501
 
502
                case 0:   /* brand new error */
503
 
504
                        yyerror( "syntax error" );
505
                yyerrlab:
506
                        ++yynerrs;
507
 
508
                case 1:
509
                case 2: /* incompletely recovered error ... try again */
510
 
511
                        yyerrflag = 3;
512
 
513
                        /* find a state where "error" is a legal shift action */
514
 
515
                        while ( yyps >= yys ) {
516
                           yyn = yypact[*yyps] + YYERRCODE;
517
                           if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
518
                              yystate = yyact[yyn];  /* simulate a shift of "error" */
519
                              goto yystack;
520
                              }
521
                           yyn = yypact[*yyps];
522
 
523
                           /* the current yyps has no shift onn "error", pop stack */
524
 
525
#ifdef YYDEBUG
526
                           if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
527
#endif
528
                           --yyps;
529
                           --yypv;
530
                           }
531
 
532
                        /* there is no state on the stack with an error shift ... abort */
533
 
534
        yyabort:
535
                        return(1);
536
 
537
 
538
                case 3:  /* no shift yet; clobber input char */
539
 
540
#ifdef YYDEBUG
541
                        if( yydebug ) printf( "error recovery discards char %d\n", yychar );
542
#endif
543
 
544
                        if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
545
                        yychar = -1;
546
                        goto yynewstate;   /* try again in the same state */
547
 
548
                        }
549
 
550
                }
551
 
552
        /* reduction by production yyn */
553
 
554
#ifdef YYDEBUG
555
                if( yydebug ) printf("reduce %d\n",yyn);
556
#endif
557
                yyps -= yyr2[yyn];
558
                yypvt = yypv;
559
                yypv -= yyr2[yyn];
560
                yyval = yypv[1];
561
                yym=yyn;
562
                        /* consult goto table to find next state */
563
                yyn = yyr1[yyn];
564
                yyj = yypgo[yyn] + *yyps + 1;
565
                if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
566
                switch(yym){
567
 
568
case 4:
569
{ yyerrok; } break;
570
case 5:
571
{ printf("store\n"); } break;
572
case 6:
573
{ printf("add\n"); } break;
574
case 7:
575
{ printf("negate\nadd\n"); } break;
576
case 8:
577
{ printf("multiply\n"); } break;
578
case 9:
579
{ printf("divide\n"); } break;
580
case 10:
581
{ printf("negate\n"); } break;
582
case 12:
583
{ printf("load\n"); } break;
584
case 13:
585
{ printf("push %s\n", yytext); } break;
586
case 14:
587
{ printf("%s\n", yytext); } break;
588
                }
589
                goto yystack;  /* stack new state and value */
590
 
591
        }
592
int yywrap() { return 1; }

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.