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