Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

yacc.c

Go to the documentation of this file.
00001 # define ID 257
00002 # define CON 258
00003 # define UNARYMINUS 259
00004 #define yyclearin yychar = -1
00005 #define yyerrok yyerrflag = 0
00006 extern int yychar;
00007 extern short yyerrflag;
00008 #ifndef YYMAXDEPTH
00009 #define YYMAXDEPTH 150
00010 #endif
00011 #ifndef YYSTYPE
00012 #define YYSTYPE int
00013 #endif
00014 YYSTYPE yylval, yyval;
00015 # define YYERRCODE 256
00016 
00017 
00018 
00019 #include <stdio.h>
00020 
00021 # define U(x) x
00022 # define NLSTATE yyprevious=YYNEWLINE
00023 # define BEGIN yybgin = yysvec + 1 +
00024 # define INITIAL 0
00025 # define YYLERR yysvec
00026 # define YYSTATE (yyestate-yysvec-1)
00027 # define YYOPTIM 1
00028 # define YYLMAX 200
00029 # define output(c) (void)putc(c,yyout)
00030 # define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
00031 # define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
00032 # define yymore() (yymorfg=1)
00033 # define ECHO fprintf(yyout, "%s",yytext)
00034 # define REJECT { nstr = yyreject(); goto yyfussy;}
00035 int yyleng; extern char yytext[];
00036 int yymorfg;
00037 extern char *yysptr, yysbuf[];
00038 int yytchar;
00039 FILE *yyin ={stdin}, *yyout ={stdout};
00040 extern int yylineno;
00041 struct yysvf { 
00042     struct yywork *yystoff;
00043     struct yysvf *yyother;
00044     int *yystops;};
00045 struct yysvf *yyestate;
00046 extern struct yysvf yysvec[], *yybgin;
00047 # define YYNEWLINE 10
00048 yylex(){
00049 int nstr; extern int yyprevious;
00050 while((nstr = yylook()) >= 0)
00051 yyfussy: switch(nstr){
00052 case 0:
00053 if(yywrap()) return(0); break;
00054 case 1:
00055  return ID;
00056 break;
00057 case 2:
00058                  return CON;
00059 break;
00060 case 3:
00061                   ;
00062 break;
00063 case 4:
00064                    return yytext[0];
00065 break;
00066 case -1:
00067 break;
00068 default:
00069 fprintf(yyout,"bad switch yylook %d",nstr);
00070 } return(0); }
00071 /* end of yylex */
00072 int yyvstop[] ={
00073 0,
00074 
00075 4,
00076 0,
00077 
00078 3,
00079 4,
00080 0,
00081 
00082 2,
00083 4,
00084 0,
00085 
00086 1,
00087 4,
00088 0,
00089 
00090 2,
00091 0,
00092 
00093 1,
00094 0,
00095 0};
00096 # define YYTYPE char
00097 struct yywork { YYTYPE verify, advance; } yycrank[] ={
00098 0,0,    0,0,    1,3,    0,0,    
00099 0,0,    0,0,    0,0,    0,0,    
00100 0,0,    0,0,    1,4,    1,3,    
00101 0,0,    0,0,    0,0,    0,0,    
00102 0,0,    0,0,    0,0,    0,0,    
00103 0,0,    0,0,    0,0,    0,0,    
00104 0,0,    0,0,    0,0,    0,0,    
00105 0,0,    0,0,    0,0,    0,0,    
00106 0,0,    0,0,    0,0,    0,0,    
00107 0,0,    0,0,    0,0,    0,0,    
00108 0,0,    0,0,    0,0,    0,0,    
00109 0,0,    0,0,    0,0,    0,0,    
00110 0,0,    1,5,    5,7,    5,7,    
00111 5,7,    5,7,    5,7,    5,7,    
00112 5,7,    5,7,    5,7,    5,7,    
00113 0,0,    0,0,    0,0,    0,0,    
00114 0,0,    0,0,    1,6,    6,8,    
00115 6,8,    6,8,    6,8,    6,8,    
00116 6,8,    6,8,    6,8,    6,8,    
00117 6,8,    0,0,    0,0,    0,0,    
00118 0,0,    0,0,    0,0,    0,0,    
00119 6,8,    6,8,    6,8,    6,8,    
00120 6,8,    6,8,    6,8,    6,8,    
00121 6,8,    6,8,    6,8,    6,8,    
00122 6,8,    6,8,    6,8,    6,8,    
00123 6,8,    6,8,    6,8,    6,8,    
00124 6,8,    6,8,    6,8,    6,8,    
00125 6,8,    6,8,    0,0,    0,0,    
00126 0,0,    0,0,    6,8,    0,0,    
00127 6,8,    6,8,    6,8,    6,8,    
00128 6,8,    6,8,    6,8,    6,8,    
00129 6,8,    6,8,    6,8,    6,8,    
00130 6,8,    6,8,    6,8,    6,8,    
00131 6,8,    6,8,    6,8,    6,8,    
00132 6,8,    6,8,    6,8,    6,8,    
00133 6,8,    6,8,    0,0,    0,0,    
00134 0,0};
00135 struct yysvf yysvec[] ={
00136 0,  0,  0,
00137 yycrank+-1, 0,      0,  
00138 yycrank+0,  yysvec+1,   0,  
00139 yycrank+0,  0,      yyvstop+1,
00140 yycrank+0,  0,      yyvstop+3,
00141 yycrank+2,  0,      yyvstop+6,
00142 yycrank+19, 0,      yyvstop+9,
00143 yycrank+0,  yysvec+5,   yyvstop+12,
00144 yycrank+0,  yysvec+6,   yyvstop+14,
00145 0,  0,  0};
00146 struct yywork *yytop = yycrank+141;
00147 struct yysvf *yybgin = yysvec+1;
00148 char yymatch[] ={
00149 00  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
00150 01  ,011 ,012 ,01  ,01  ,01  ,01  ,01  ,
00151 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
00152 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
00153 011 ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
00154 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
00155 '0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,
00156 '0' ,'0' ,01  ,01  ,01  ,01  ,01  ,01  ,
00157 01  ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
00158 'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
00159 'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
00160 'A' ,'A' ,'A' ,01  ,01  ,01  ,01  ,'A' ,
00161 01  ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
00162 'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
00163 'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
00164 'A' ,'A' ,'A' ,01  ,01  ,01  ,01  ,01  ,
00165 0};
00166 char yyextra[] ={
00167 0,0,0,0,0,0,0,0,
00168 0};
00169 /*  ncform  4.1 83/08/11    */
00170 
00171 int yylineno =1;
00172 # define YYU(x) x
00173 # define NLSTATE yyprevious=YYNEWLINE
00174 char yytext[YYLMAX];
00175 struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
00176 char yysbuf[YYLMAX];
00177 char *yysptr = yysbuf;
00178 int *yyfnd;
00179 extern struct yysvf *yyestate;
00180 int yyprevious = YYNEWLINE;
00181 yylook(){
00182     register struct yysvf *yystate, **lsp;
00183     register struct yywork *yyt;
00184     struct yysvf *yyz;
00185     int yych;
00186     struct yywork *yyr;
00187 # ifdef LEXDEBUG
00188     int debug;
00189 # endif
00190     char *yylastch;
00191     /* start off machines */
00192 # ifdef LEXDEBUG
00193     debug = 0;
00194 # endif
00195     if (!yymorfg)
00196         yylastch = yytext;
00197     else {
00198         yymorfg=0;
00199         yylastch = yytext+yyleng;
00200         }
00201     for(;;){
00202         lsp = yylstate;
00203         yyestate = yystate = yybgin;
00204         if (yyprevious==YYNEWLINE) yystate++;
00205         for (;;){
00206 # ifdef LEXDEBUG
00207             if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
00208 # endif
00209             yyt = yystate->yystoff;
00210             if(yyt == yycrank){     /* may not be any transitions */
00211                 yyz = yystate->yyother;
00212                 if(yyz == 0)break;
00213                 if(yyz->yystoff == yycrank)break;
00214                 }
00215             *yylastch++ = yych = input();
00216         tryagain:
00217 # ifdef LEXDEBUG
00218             if(debug){
00219                 fprintf(yyout,"char ");
00220                 allprint(yych);
00221                 putchar('\n');
00222                 }
00223 # endif
00224             yyr = yyt;
00225             if ( yyt > yycrank){
00226                 yyt = yyr + yych;
00227                 if (yyt <= yytop && yyt->verify+yysvec == yystate){
00228                     if(yyt->advance+yysvec == YYLERR)   /* error transitions */
00229                         {unput(*--yylastch);break;}
00230                     *lsp++ = yystate = yyt->advance+yysvec;
00231                     goto contin;
00232                     }
00233                 }
00234 # ifdef YYOPTIM
00235             else if(yyt < yycrank) {        /* r < yycrank */
00236                 yyt = yyr = yycrank+(yycrank-yyt);
00237 # ifdef LEXDEBUG
00238                 if(debug)fprintf(yyout,"compressed state\n");
00239 # endif
00240                 yyt = yyt + yych;
00241                 if(yyt <= yytop && yyt->verify+yysvec == yystate){
00242                     if(yyt->advance+yysvec == YYLERR)   /* error transitions */
00243                         {unput(*--yylastch);break;}
00244                     *lsp++ = yystate = yyt->advance+yysvec;
00245                     goto contin;
00246                     }
00247                 yyt = yyr + YYU(yymatch[yych]);
00248 # ifdef LEXDEBUG
00249                 if(debug){
00250                     fprintf(yyout,"try fall back character ");
00251                     allprint(YYU(yymatch[yych]));
00252                     putchar('\n');
00253                     }
00254 # endif
00255                 if(yyt <= yytop && yyt->verify+yysvec == yystate){
00256                     if(yyt->advance+yysvec == YYLERR)   /* error transition */
00257                         {unput(*--yylastch);break;}
00258                     *lsp++ = yystate = yyt->advance+yysvec;
00259                     goto contin;
00260                     }
00261                 }
00262             if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
00263 # ifdef LEXDEBUG
00264                 if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
00265 # endif
00266                 goto tryagain;
00267                 }
00268 # endif
00269             else
00270                 {unput(*--yylastch);break;}
00271         contin:
00272 # ifdef LEXDEBUG
00273             if(debug){
00274                 fprintf(yyout,"state %d char ",yystate-yysvec-1);
00275                 allprint(yych);
00276                 putchar('\n');
00277                 }
00278 # endif
00279             ;
00280             }
00281 # ifdef LEXDEBUG
00282         if(debug){
00283             fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
00284             allprint(yych);
00285             putchar('\n');
00286             }
00287 # endif
00288         while (lsp-- > yylstate){
00289             *yylastch-- = 0;
00290             if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
00291                 yyolsp = lsp;
00292                 if(yyextra[*yyfnd]){        /* must backup */
00293                     while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
00294                         lsp--;
00295                         unput(*yylastch--);
00296                         }
00297                     }
00298                 yyprevious = YYU(*yylastch);
00299                 yylsp = lsp;
00300                 yyleng = yylastch-yytext+1;
00301                 yytext[yyleng] = 0;
00302 # ifdef LEXDEBUG
00303                 if(debug){
00304                     fprintf(yyout,"\nmatch ");
00305                     sprint(yytext);
00306                     fprintf(yyout," action %d\n",*yyfnd);
00307                     }
00308 # endif
00309                 return(*yyfnd++);
00310                 }
00311             unput(*yylastch);
00312             }
00313         if (yytext[0] == 0  /* && feof(yyin) */)
00314             {
00315             yysptr=yysbuf;
00316             return(0);
00317             }
00318         yyprevious = yytext[0] = input();
00319         if (yyprevious>0)
00320             output(yyprevious);
00321         yylastch=yytext;
00322 # ifdef LEXDEBUG
00323         if(debug)putchar('\n');
00324 # endif
00325         }
00326     }
00327 yyback(p, m)
00328     int *p;
00329 {
00330 if (p==0) return(0);
00331 while (*p)
00332     {
00333     if (*p++ == m)
00334         return(1);
00335     }
00336 return(0);
00337 }
00338     /* the following are only used in the lex library */
00339 yyinput(){
00340     return(input());
00341     }
00342 yyoutput(c)
00343   int c; {
00344     output(c);
00345     }
00346 yyunput(c)
00347    int c; {
00348     unput(c);
00349     }
00350 
00351 main() {
00352         yyparse();
00353     return 0;
00354 }
00355 
00356 /* yyerror - issue error message */
00357 yyerror(s) char *s; {
00358         printf("%s\n", s);
00359 }
00360 short yyexca[] ={
00361 -1, 1,
00362     0, -1,
00363     -2, 0,
00364     };
00365 # define YYNPROD 15
00366 # define YYLAST 249
00367 short yyact[]={
00368 
00369   12,   2,   9,   8,  17,  11,  25,  17,  15,  18,
00370   16,  10,  18,  17,  15,   7,  16,  13,  18,   5,
00371    3,   1,   0,  19,  20,   0,   0,  21,  22,  23,
00372   24,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00373    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00374    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00375    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00376    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00377    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00378    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00379    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00380    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00381    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00382    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00383    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00384    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00385    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00386    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00387    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00388    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00389    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00390    0,   0,   0,   0,   0,   0,   0,   6,  14,   0,
00391    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00392    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00393    0,   0,   0,   0,   0,   0,   0,   4,   6 };
00394 short yypact[]={
00395 
00396 -1000,  -9,-1000,   5,  -7, -59,-1000,-1000,-1000, -40,
00397  -29, -40, -40,-1000,-1000, -40, -40, -40, -40, -38,
00398  -35, -38, -38,-1000,-1000,-1000 };
00399 short yypgo[]={
00400 
00401    0,  21,  20,  17,  11 };
00402 short yyr1[]={
00403 
00404    0,   1,   1,   1,   1,   2,   4,   4,   4,   4,
00405    4,   4,   4,   4,   3 };
00406 short yyr2[]={
00407 
00408    0,   0,   2,   3,   3,   3,   3,   3,   3,   3,
00409    2,   3,   1,   1,   1 };
00410 short yychk[]={
00411 
00412 -1000,  -1,  10,  -2, 256,  -3, 257,  10,  10,  61,
00413   -4,  45,  40,  -3, 258,  43,  45,  42,  47,  -4,
00414   -4,  -4,  -4,  -4,  -4,  41 };
00415 short yydef[]={
00416 
00417    1,  -2,   2,   0,   0,   0,  14,   3,   4,   0,
00418    5,   0,   0,  12,  13,   0,   0,   0,   0,  10,
00419    0,   6,   7,   8,   9,  11 };
00420 #ifndef lint
00421 #endif
00422 
00423 # define YYFLAG -1000
00424 # define YYERROR goto yyerrlab
00425 # define YYACCEPT return(0)
00426 # define YYABORT return(1)
00427 
00428 /*  parser for yacc output  */
00429 
00430 #ifdef YYDEBUG
00431 int yydebug = 0; /* 1 for debugging */
00432 #endif
00433 YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
00434 int yychar = -1; /* current input token number */
00435 int yynerrs = 0;  /* number of errors */
00436 short yyerrflag = 0;  /* error recovery flag */
00437 
00438 yyparse() {
00439 
00440     short yys[YYMAXDEPTH];
00441     short yyj, yym;
00442     register YYSTYPE *yypvt;
00443     register short yystate, *yyps, yyn;
00444     register YYSTYPE *yypv;
00445     register short *yyxi;
00446 
00447     yystate = 0;
00448     yychar = -1;
00449     yynerrs = 0;
00450     yyerrflag = 0;
00451     yyps= &yys[-1];
00452     yypv= &yyv[-1];
00453 
00454  yystack:    /* put a state and value onto the stack */
00455 
00456 #ifdef YYDEBUG
00457     if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
00458 #endif
00459         if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
00460         *yyps = yystate;
00461         ++yypv;
00462         *yypv = yyval;
00463 
00464  yynewstate:
00465 
00466     yyn = yypact[yystate];
00467 
00468     if( yyn<= YYFLAG ) goto yydefault; /* simple state */
00469 
00470     if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
00471     if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
00472 
00473     if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
00474         yychar = -1;
00475         yyval = yylval;
00476         yystate = yyn;
00477         if( yyerrflag > 0 ) --yyerrflag;
00478         goto yystack;
00479         }
00480 
00481  yydefault:
00482     /* default state action */
00483 
00484     if( (yyn=yydef[yystate]) == -2 ) {
00485         if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
00486         /* look through exception table */
00487 
00488         for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
00489 
00490         while( *(yyxi+=2) >= 0 ){
00491             if( *yyxi == yychar ) break;
00492             }
00493         if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
00494         }
00495 
00496     if( yyn == 0 ){ /* error */
00497         /* error ... attempt to resume parsing */
00498 
00499         switch( yyerrflag ){
00500 
00501         case 0:   /* brand new error */
00502 
00503             yyerror( "syntax error" );
00504         yyerrlab:
00505             ++yynerrs;
00506 
00507         case 1:
00508         case 2: /* incompletely recovered error ... try again */
00509 
00510             yyerrflag = 3;
00511 
00512             /* find a state where "error" is a legal shift action */
00513 
00514             while ( yyps >= yys ) {
00515                yyn = yypact[*yyps] + YYERRCODE;
00516                if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
00517                   yystate = yyact[yyn];  /* simulate a shift of "error" */
00518                   goto yystack;
00519                   }
00520                yyn = yypact[*yyps];
00521 
00522                /* the current yyps has no shift onn "error", pop stack */
00523 
00524 #ifdef YYDEBUG
00525                if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
00526 #endif
00527                --yyps;
00528                --yypv;
00529                }
00530 
00531             /* there is no state on the stack with an error shift ... abort */
00532 
00533     yyabort:
00534             return(1);
00535 
00536 
00537         case 3:  /* no shift yet; clobber input char */
00538 
00539 #ifdef YYDEBUG
00540             if( yydebug ) printf( "error recovery discards char %d\n", yychar );
00541 #endif
00542 
00543             if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
00544             yychar = -1;
00545             goto yynewstate;   /* try again in the same state */
00546 
00547             }
00548 
00549         }
00550 
00551     /* reduction by production yyn */
00552 
00553 #ifdef YYDEBUG
00554         if( yydebug ) printf("reduce %d\n",yyn);
00555 #endif
00556         yyps -= yyr2[yyn];
00557         yypvt = yypv;
00558         yypv -= yyr2[yyn];
00559         yyval = yypv[1];
00560         yym=yyn;
00561             /* consult goto table to find next state */
00562         yyn = yyr1[yyn];
00563         yyj = yypgo[yyn] + *yyps + 1;
00564         if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
00565         switch(yym){
00566             
00567 case 4:
00568 { yyerrok; } break;
00569 case 5:
00570 { printf("store\n"); } break;
00571 case 6:
00572 { printf("add\n"); } break;
00573 case 7:
00574 { printf("negate\nadd\n"); } break;
00575 case 8:
00576 { printf("multiply\n"); } break;
00577 case 9:
00578 { printf("divide\n"); } break;
00579 case 10:
00580 { printf("negate\n"); } break;
00581 case 12:
00582 { printf("load\n"); } break;
00583 case 13:
00584 { printf("push %s\n", yytext); } break;
00585 case 14:
00586 { printf("%s\n", yytext); } break;
00587         }
00588         goto yystack;  /* stack new state and value */
00589 
00590     }
00591 int yywrap() { return 1; }

Generated on Thu Aug 25 12:38:17 2005 for Quake III Arena by  doxygen 1.3.9.1