home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / yacc / example.c < prev    next >
Encoding:
C/C++ Source or Header  |  1983-12-31  |  7.5 KB  |  368 lines

  1. /*
  2.  * Created by CSD YACC (IBM PC) from "example.Y" */
  3. # define ONE 257
  4. # define TWO 258
  5. # define THREE 259
  6. # define FOUR 260
  7. # define FIVE 261
  8. # define SIX 262
  9. # define SEVEN 263
  10. # define EIGHT 264
  11. # define NINE 265
  12. # define DOT 266
  13. #define yyclearin yychar = -1
  14. #define yyerrok yyerrflag = 0
  15. #ifndef YYMAXDEPTH
  16. #define YYMAXDEPTH 150
  17. #endif
  18. #ifndef YYSTYPE
  19. #define YYSTYPE int
  20. #endif
  21. extern YYSTYPE yylval;  /*CSD & DECUS LEX */
  22. YYSTYPE yyval;          /*CSD & DECUS LEX */
  23. # define YYERRCODE 256
  24.  
  25. #line 108
  26.  
  27.  
  28.  
  29.  
  30. #ifndef ATT_SIZE
  31. #define ATT_SIZE     150
  32. #endif
  33.  
  34. union _attr_elem {
  35.   float  _t0;
  36.   int  _t1;
  37. } _attr_stack [ATT_SIZE];
  38. union _attr_elem *_ap =      &_attr_stack [ATT_SIZE - 1];
  39.  
  40.  /* processed by a YACC preprocessor */ 
  41. short yyexca[] ={
  42. -1, 1,
  43.     0, -1,
  44.     -2, 0,
  45. -1, 15,
  46.     0, 2,
  47.     -2, 9,
  48.     };
  49. # define YYNPROD 19
  50. # define YYLAST 38
  51. short yyact[]={
  52.  
  53.    4,   5,   6,   7,   8,   9,  10,  11,  12,  13,
  54.    4,   5,   6,   7,   8,   9,  10,  11,  12,  18,
  55.   19,   3,  17,  14,  16,  15,   2,   1,   0,   0,
  56.    0,   0,   0,   0,   0,   0,   0,  20 };
  57. short yypact[]={
  58.  
  59. -247,-1000,-257,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
  60. -1000,-1000,-1000,-1000,-1000,-1000,-247,-247,-1000,-1000,
  61. -1000 };
  62. short yypgo[]={
  63.  
  64.    0,  27,  26,  25,  20,  24,  19,  22 };
  65. short yyr1[]={
  66.  
  67.    0,   1,   1,   2,   2,   3,   3,   6,   5,   7,
  68.    4,   4,   4,   4,   4,   4,   4,   4,   4 };
  69. short yyr2[]={
  70.  
  71.    0,   1,   3,   1,   2,   2,   3,   1,   0,   0,
  72.    1,   1,   1,   1,   1,   1,   1,   1,   1 };
  73. short yychk[]={
  74.  
  75. -1000,  -1,  -2,  -4, 257, 258, 259, 260, 261, 262,
  76.  263, 264, 265, 266,  -4,  -3,  -5,  -7,  -6,  -4,
  77.   -6 };
  78. short yydef[]={
  79.  
  80.    0,  -2,   1,   3,  10,  11,  12,  13,  14,  15,
  81.   16,  17,  18,   8,   4,  -2,   0,   0,   5,   7,
  82.    6 };
  83. # define YYFLAG -1000
  84. # define YYERROR goto yyerrlab
  85. # define YYACCEPT return(0)
  86. # define YYABORT return(1)
  87.  
  88. /*      parser for yacc output  */
  89.  
  90. int yydebug = 0; /* 1 for debugging */
  91. YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
  92. int yychar = -1; /* current input token number */
  93. int yynerrs = 0;  /* number of errors */
  94. short yyerrflag = 0;  /* error recovery flag */
  95.  
  96. yyparse()
  97.    {
  98.  
  99.    short yys[YYMAXDEPTH];
  100.    short yyj, yym;
  101.    register YYSTYPE *yypvt;
  102.    register short yystate, *yyps, yyn;
  103.    register YYSTYPE *yypv;
  104.    register short *yyxi;
  105.  
  106.    yystate = 0;
  107.    yychar = -1;
  108.    yynerrs = 0;
  109.    yyerrflag = 0;
  110.    yyps= &yys[-1];
  111.    yypv= &yyv[-1];
  112.  
  113. yystack:    /* put a state and value onto the stack */
  114.  
  115.    if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
  116.    if( ++yyps> &yys[YYMAXDEPTH] )
  117.       {
  118.       yyerror( "yacc stack overflow" );
  119.       return(1);
  120.       }
  121.    *yyps = yystate;
  122.    ++yypv;
  123. #ifdef UNION
  124.    yyunion(yypv, &yyval);
  125. #else
  126.    *yypv = yyval;
  127. #endif
  128. yynewstate:
  129.  
  130.    yyn = yypact[yystate];
  131.  
  132.    if( yyn<= YYFLAG ) goto yydefault; /* simple state */
  133.  
  134.    if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
  135.    if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
  136.  
  137.    if( yychk[ yyn=yyact[ yyn ] ] == yychar )
  138.       {
  139.       /* valid shift */
  140.       yychar = -1;
  141. #ifdef UNION
  142.       yyunion(&yyval, &yylval);
  143. #else
  144.       yyval = yylval;
  145. #endif
  146.       yystate = yyn;
  147.       if( yyerrflag > 0 ) --yyerrflag;
  148.       goto yystack;
  149.       }
  150. yydefault:
  151.    /* default state action */
  152.  
  153.    if( (yyn=yydef[yystate]) == -2 )
  154.       {
  155.       if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
  156.       /* look through exception table */
  157.  
  158.       for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
  159.  
  160.       for(yyxi+=2; *yyxi >= 0; yyxi+=2)
  161.          {
  162.          if( *yyxi == yychar ) break;
  163.          }
  164.       if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
  165.       }
  166.  
  167.    if( yyn == 0 )
  168.       {
  169.       /* error */
  170.       /* error ... attempt to resume parsing */
  171.  
  172.       switch( yyerrflag )
  173.          {
  174.  
  175.       case 0:   /* brand new error */
  176.  
  177.          yyerror( "syntax error" );
  178. yyerrlab:
  179.          ++yynerrs;
  180.  
  181.       case 1:
  182.       case 2: /* incompletely recovered error ... try again */
  183.  
  184.          yyerrflag = 3;
  185.  
  186.          /* find a state where "error" is a legal shift action */
  187.  
  188.          while ( yyps >= yys )
  189.             {
  190.             yyn = yypact[*yyps] + YYERRCODE;
  191.             if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE )
  192.                {
  193.                yystate = yyact[yyn];  /* simulate a shift of "error" */
  194.                goto yystack;
  195.                }
  196.             yyn = yypact[*yyps];
  197.  
  198.             /* the current yyps has no shift onn "error", pop stack */
  199.  
  200.             if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
  201.             --yyps;
  202.             --yypv;
  203.             }
  204.  
  205.          /* there is no state on the stack with an error shift ... abort */
  206.  
  207. yyabort:
  208.          return(1);
  209.  
  210.  
  211.       case 3:  /* no shift yet; clobber input char */
  212.  
  213.          if( yydebug ) printf( "error recovery discards char %d\n", yychar );
  214.  
  215.          if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
  216.          yychar = -1;
  217.          goto yynewstate;   /* try again in the same state */
  218.  
  219.          }
  220.  
  221.       }
  222.  
  223.    /* reduction by production yyn */
  224.  
  225.    if( yydebug ) printf("reduce %d\n",yyn);
  226.    yyps -= yyr2[yyn];
  227.    yypvt = yypv;
  228.    yypv -= yyr2[yyn];
  229. #ifdef UNION
  230.    yyunion(&yyval, &yypv[1]);
  231. #else
  232.    yyval = yypv[1];
  233. #endif
  234.    yym=yyn;
  235.    /* consult goto table to find next state */
  236.    yyn = yyr1[yyn];
  237.    yyj = yypgo[yyn] + *yyps + 1;
  238.    if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
  239.    switch(yym)
  240.       {
  241.       
  242. case 1:
  243. # line 13
  244.  
  245. {       float _L1L_;
  246. { _L1L_ = (float) _ap [0]._t1;
  247.  
  248.                     _ap += 1; 
  249. --_ap; _ap[0]._t0 = _L1L_;
  250.   }
  251. } break;
  252. case 2:
  253. # line 20
  254.  
  255. {       float _L1L_;
  256. { _L1L_ = (float) _ap [2]._t1 + _ap [0]._t0;
  257.  
  258.                     _ap += 3; 
  259. --_ap; _ap[0]._t0 = _L1L_;
  260.   }
  261. } break;
  262. case 4:
  263. # line 28
  264.  
  265. {       int _L1L_;
  266. { _L1L_ = 10 * _ap [1]._t1 + _ap [0]._t1;
  267.  
  268.                     _ap += 2; 
  269. --_ap; _ap[0]._t1 = _L1L_;
  270.   }
  271. } break;
  272. case 6:
  273. # line 36
  274.  
  275. {       int _L1L_;
  276.        float _L2L_;
  277. { _L2L_ = _ap [2]._t0 + _ap [0]._t0;
  278.  
  279.                     _ap += 4; 
  280. --_ap; _ap[0]._t1 = _L1L_;
  281. --_ap; _ap[0]._t0 = _L2L_;
  282.   }
  283. } break;
  284. case 7:
  285. # line 45
  286.  
  287. {       float _L1L_;
  288. { _L1L_ = ( (float) _ap [0]._t1) / (power (10, _ap [1]._t1));
  289.  
  290.                     _ap += 1; 
  291. --_ap; _ap[0]._t0 = _L1L_;
  292.   }
  293. } break;
  294. case 8:
  295. # line 52
  296.  
  297. {     _ap -= 1;
  298. { _ap [0]._t1 = 1;
  299.  
  300.                 }
  301. } break;
  302. case 9:
  303. # line 57
  304.  
  305. {     _ap -= 1;
  306. { _ap [0]._t1 = _ap [2]._t1 + 1;
  307.  
  308.                 }
  309. } break;
  310. case 10:
  311. # line 62
  312.  
  313. {     _ap -= 1;
  314. { _ap [0]._t1 = 1;
  315.  
  316.                 }
  317. } break;
  318. case 11:
  319. # line 67
  320.  
  321. {     _ap -= 1;
  322. { _ap [0]._t1 = 2;
  323.  
  324.                 }
  325. } break;
  326. case 12:
  327. # line 72
  328.  
  329. {     _ap -= 1;
  330. { _ap [0]._t1 = 3;
  331.  
  332.                 }
  333. } break;
  334. case 13:
  335. # line 77
  336.  
  337. {     _ap -= 1;
  338. { _ap [0]._t1 = 4;
  339.  
  340.                 }
  341. } break;
  342. case 14:
  343. # line 82
  344.  
  345. {     _ap -= 1;
  346. { _ap [0]._t1 = 5;
  347.  
  348.                 }
  349. } break;
  350. case 15:
  351. # line 87
  352.  
  353. {     _ap -= 1;
  354. { _ap [0]._t1 = 6;
  355.  
  356.                 }
  357. } break;
  358. case 16:
  359. # line 92
  360.  
  361. {     _ap -= 1;
  362. { _ap [0]._t1 = 7;
  363.  
  364.                 }
  365. } break;
  366. case 17:
  367. # line 97
  368.  
  369. {     _ap -= 1;
  370. { _ap [0]._t1 = 8;
  371.  
  372.                 }
  373. } break;
  374. case 18:
  375. # line 102
  376.  
  377. {     _ap -= 1;
  378. { _ap [0]._t1 = 9;
  379.  
  380.                 }
  381. } break;/* End of actions */
  382.       }
  383.    goto yystack;  /* stack new state and value */
  384.  
  385.    }
  386.