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