home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Science / Science.zip / OS2SCALC.ZIP / GRAM.C < prev    next >
C/C++ Source or Header  |  1988-11-09  |  12KB  |  442 lines

  1.  
  2. # line 15 "gram.y"
  3. #include "sc.h"
  4.  
  5. # line 18 "gram.y"
  6. typedef union  {
  7.     int ival;
  8.     double fval;
  9.     struct ent *ent;
  10.     struct enode *enode;
  11.     char *sval;
  12. } YYSTYPE;
  13. # define STRING 257
  14. # define NUMBER 258
  15. # define FNUMBER 259
  16. # define WORD 260
  17. # define COL 261
  18. # define S_FORMAT 262
  19. # define S_LABEL 263
  20. # define S_LEFTSTRING 264
  21. # define S_RIGHTSTRING 265
  22. # define S_GET 266
  23. # define S_PUT 267
  24. # define S_MERGE 268
  25. # define S_LET 269
  26. # define S_WRITE 270
  27. # define S_TBL 271
  28. # define S_PROGLET 272
  29. # define S_COPY 273
  30. # define S_SHOW 274
  31. # define K_FIXED 275
  32. # define K_SUM 276
  33. # define K_PROD 277
  34. # define K_AVE 278
  35. #define yyclearin yychar = -1
  36. #define yyerrok yyerrflag = 0
  37. extern int yychar;
  38. extern short yyerrflag;
  39. #ifndef YYMAXDEPTH
  40. #define YYMAXDEPTH 150
  41. #endif
  42. YYSTYPE yylval, yyval;
  43. # define YYERRCODE 256
  44. short yyexca[] ={
  45. -1, 1,
  46.     0, -1,
  47.     -2, 0,
  48. -1, 83,
  49.     60, 0,
  50.     61, 0,
  51.     62, 0,
  52.     -2, 34,
  53. -1, 85,
  54.     60, 0,
  55.     61, 0,
  56.     62, 0,
  57.     -2, 35,
  58. -1, 86,
  59.     60, 0,
  60.     61, 0,
  61.     62, 0,
  62.     -2, 36,
  63. -1, 96,
  64.     60, 0,
  65.     61, 0,
  66.     62, 0,
  67.     -2, 39,
  68. -1, 97,
  69.     60, 0,
  70.     61, 0,
  71.     62, 0,
  72.     -2, 41,
  73. -1, 98,
  74.     60, 0,
  75.     61, 0,
  76.     62, 0,
  77.     -2, 40,
  78.     };
  79. # define YYNPROD 43
  80. # define YYLAST 267
  81. short yyact[]={
  82.  
  83.   14,  69,  70,  71,  16,  55,   6,   3,   4,   5,
  84.    7,   9,   8,   2,  10,  11,  49,  13,  12,  27,
  85.   49,  54,  26,  43,  49,  20,  44,  43,  45,  53,
  86.   44,  43,  45,  34,  44,  30,  45,  52,  51,  50,
  87.   25,  24,  23,  22,  87,  21,  90,  42,  84,  67,
  88.   33,  42, 105,  32,  65,  42,  31,  67,  59,  57,
  89.   29,  58,  65,  60, 104,  94,  59,  57, 103,  58,
  90.   56,  60,  36,  35,  95, 111,  62,  63,  64,  61,
  91.  110, 109,  93,  67,  62,  63,  64,  61,  65,  39,
  92.   67,  67,  59,  57,  92,  58,  65,  60,  38,  59,
  93.   59,  57,  91,  58,  60,  60,  67,   1,   0,  48,
  94.   62,  63,  64,  48,   0,   0,   0,  48,  62,  63,
  95.   64,  61,  40,   0,   0,  15,  17,  18,  19,   0,
  96.    0,  68,   0,   0,  73,  74,  28,   0,  75,  76,
  97.   66,   0,  72,   0,   0,   0,   0,   0,  66,   0,
  98.    0,  37,   0,   0,   0,   0,  78,  79,  80,  81,
  99.   82,  83,  85,  86,  88,  89,  67,   0,   0,   0,
  100.    0,   0,   0,   0,  66,  59,  57,   0,  58,  77,
  101.   60,   0,  66,  96,   0,   0,  97,   0,   0,  98,
  102.   67,   0,   0,   0, 102,  65,  67,   0,   0,  59,
  103.   57,   0,  58,   0,  60,  59,  57,   0,  58,   0,
  104.   60,   0,   0,   0,  99, 100, 101,  62,  63,  64,
  105.    0,   0,   0,  62,  63,  64, 106, 107, 108,   0,
  106.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  107.    0,  46,  47,   0,  16,  46,  47,   0,  16,  46,
  108.   47,   0,  16,   0,   0,   0,   0,   0,  41,   0,
  109.    0,   0,  41,   0,   0,   0,  41 };
  110. short yypact[]={
  111.  
  112. -256,-1000,-257,-257,-257,-257,-236,-212,-214,-215,
  113. -216,-217,-239,-257,-1000,  -1,-223,  -5,  -8, -11,
  114. -225,-1000,-1000,-1000,-1000,-1000,  15,  14,-257,  -9,
  115. -1000,-218,-219,-220,-229,-240,-253,  12,  58,-1000,
  116. -1000,  -9,-275,  -9,  -9,  -9,-1000,-1000,  -9,  -9,
  117. -1000,-1000,-1000,-1000,-1000,-1000,-257,  -9,  -9,  -9,
  118.   -9,  -9, -13,  -9, -17,  -9,  -9, -15,-1000,  62,
  119.   54,  42,  24,-1000,-1000,-1000,-1000,-1000,  57,  57,
  120.   73,  73,  16, 133,  -9, 133, 133,  -9, 163, 157,
  121.   -9,-257,-257,-257,-1000,  -9, 133, 133, 133,  10,
  122.    6,  -6,  50,-257,-257,-257,  40,  39,  34,-1000,
  123. -1000,-1000 };
  124. short yypgo[]={
  125.  
  126.    0, 122,  98,  89, 107 };
  127. short yyr1[]={
  128.  
  129.    0,   4,   4,   4,   4,   4,   4,   4,   4,   4,
  130.    4,   4,   4,   4,   4,   4,   3,   3,   3,   3,
  131.    3,   3,   3,   3,   3,   3,   3,   3,   2,   2,
  132.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  133.    2,   2,   1 };
  134. short yyr2[]={
  135.  
  136.    0,   4,   4,   4,   4,   4,   2,   2,   2,   2,
  137.    2,   4,   4,   5,   0,   1,   1,   2,   7,   7,
  138.    7,   3,   2,   2,   1,   1,   2,   2,   3,   3,
  139.    3,   3,   1,   5,   3,   3,   3,   3,   3,   4,
  140.    4,   4,   2 };
  141. short yychk[]={
  142.  
  143. -1000,  -4, 269, 263, 264, 265, 262, 266, 268, 267,
  144.  270, 271, 274, 273, 256,  -1, 261,  -1,  -1,  -1,
  145.  261, 257, 257, 257, 257, 257, 261, 258,  -1,  61,
  146.  258,  61,  61,  61, 258,  58,  58,  -1,  -2,  -3,
  147.   -1, 275,  64,  40,  43,  45, 258, 259, 126,  33,
  148.  257, 257, 257, 258, 261, 258,  58,  43,  45,  42,
  149.   47,  63,  60,  61,  62,  38, 124,  33,  -3, 276,
  150.  277, 278,  -2,  -3,  -3,  -3,  -3,  -1,  -2,  -2,
  151.   -2,  -2,  -2,  -2,  61,  -2,  -2,  61,  -2,  -2,
  152.   61,  40,  40,  40,  41,  58,  -2,  -2,  -2,  -1,
  153.   -1,  -1,  -2,  58,  58,  58,  -1,  -1,  -1,  41,
  154.   41,  41 };
  155. short yydef[]={
  156.  
  157.   14,  -2,   0,   0,   0,   0,   0,   0,   0,   0,
  158.    0,   0,   0,   0,  15,   0,   0,   0,   0,   0,
  159.    0,   6,   7,   8,   9,  10,   0,   0,   0,   0,
  160.   42,   0,   0,   0,   0,   0,   0,   0,   1,  32,
  161.   16,   0,   0,   0,   0,   0,  24,  25,   0,   0,
  162.    2,   3,   4,   5,  11,  12,   0,   0,   0,   0,
  163.    0,   0,   0,   0,   0,   0,   0,   0,  17,   0,
  164.    0,   0,   0,  22,  23,  26,  27,  13,  28,  29,
  165.   30,  31,   0,  -2,   0,  -2,  -2,   0,  37,  38,
  166.    0,   0,   0,   0,  21,   0,  -2,  -2,  -2,   0,
  167.    0,   0,  33,   0,   0,   0,   0,   0,   0,  18,
  168.   19,  20 };
  169. #ifndef lint
  170. static char yaccpar_sccsid[] = "@(#)yaccpar    4.1    (Berkeley)    2/11/83";
  171. #endif not lint
  172.  
  173. #
  174. # define YYFLAG -1000
  175. # define YYERROR goto yyerrlab
  176. # define YYACCEPT return(0)
  177. # define YYABORT return(1)
  178.  
  179. /*    parser for yacc output    */
  180.  
  181. #ifdef YYDEBUG
  182. int yydebug = 0; /* 1 for debugging */
  183. #endif
  184. YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
  185. int yychar = -1; /* current input token number */
  186. int yynerrs = 0;  /* number of errors */
  187. short yyerrflag = 0;  /* error recovery flag */
  188.  
  189. yyparse() {
  190.  
  191.     short yys[YYMAXDEPTH];
  192.     short yyj, yym;
  193.     register YYSTYPE *yypvt;
  194.     register short yystate, *yyps, yyn;
  195.     register YYSTYPE *yypv;
  196.     register short *yyxi;
  197.  
  198.     yystate = 0;
  199.     yychar = -1;
  200.     yynerrs = 0;
  201.     yyerrflag = 0;
  202.     yyps= &yys[-1];
  203.     yypv= &yyv[-1];
  204.  
  205.  yystack:    /* put a state and value onto the stack */
  206.  
  207. #ifdef YYDEBUG
  208.     if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
  209. #endif
  210.         if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
  211.         *yyps = yystate;
  212.         ++yypv;
  213.         *yypv = yyval;
  214.  
  215.  yynewstate:
  216.  
  217.     yyn = yypact[yystate];
  218.  
  219.     if( yyn<= YYFLAG ) goto yydefault; /* simple state */
  220.  
  221.     if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
  222.     if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
  223.  
  224.     if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
  225.         yychar = -1;
  226.         yyval = yylval;
  227.         yystate = yyn;
  228.         if( yyerrflag > 0 ) --yyerrflag;
  229.         goto yystack;
  230.         }
  231.  
  232.  yydefault:
  233.     /* default state action */
  234.  
  235.     if( (yyn=yydef[yystate]) == -2 ) {
  236.         if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
  237.         /* look through exception table */
  238.  
  239.         for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
  240.  
  241.         while( *(yyxi+=2) >= 0 ){
  242.             if( *yyxi == yychar ) break;
  243.             }
  244.         if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
  245.         }
  246.  
  247.     if( yyn == 0 ){ /* error */
  248.         /* error ... attempt to resume parsing */
  249.  
  250.         switch( yyerrflag ){
  251.  
  252.         case 0:   /* brand new error */
  253.  
  254.             yyerror( "syntax error" );
  255.         yyerrlab:
  256.             ++yynerrs;
  257.  
  258.         case 1:
  259.         case 2: /* incompletely recovered error ... try again */
  260.  
  261.             yyerrflag = 3;
  262.  
  263.             /* find a state where "error" is a legal shift action */
  264.  
  265.             while ( yyps >= yys ) {
  266.                yyn = yypact[*yyps] + YYERRCODE;
  267.                if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
  268.                   yystate = yyact[yyn];  /* simulate a shift of "error" */
  269.                   goto yystack;
  270.                   }
  271.                yyn = yypact[*yyps];
  272.  
  273.                /* the current yyps has no shift onn "error", pop stack */
  274.  
  275. #ifdef YYDEBUG
  276.                if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
  277. #endif
  278.                --yyps;
  279.                --yypv;
  280.                }
  281.  
  282.             /* there is no state on the stack with an error shift ... abort */
  283.  
  284.     yyabort:
  285.             return(1);
  286.  
  287.  
  288.         case 3:  /* no shift yet; clobber input char */
  289.  
  290. #ifdef YYDEBUG
  291.             if( yydebug ) printf( "error recovery discards char %d\n", yychar );
  292. #endif
  293.  
  294.             if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
  295.             yychar = -1;
  296.             goto yynewstate;   /* try again in the same state */
  297.  
  298.             }
  299.  
  300.         }
  301.  
  302.     /* reduction by production yyn */
  303.  
  304. #ifdef YYDEBUG
  305.         if( yydebug ) printf("reduce %d\n",yyn);
  306. #endif
  307.         yyps -= yyr2[yyn];
  308.         yypvt = yypv;
  309.         yypv -= yyr2[yyn];
  310.         yyval = yypv[1];
  311.         yym=yyn;
  312.             /* consult goto table to find next state */
  313.         yyn = yyr1[yyn];
  314.         yyj = yypgo[yyn] + *yyps + 1;
  315.         if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
  316.         switch(yym){
  317.  
  318. case 1:
  319. # line 59 "gram.y"
  320. { let (yypvt[-2].ent, yypvt[-0].enode); } break;
  321. case 2:
  322. # line 61 "gram.y"
  323. { label (yypvt[-2].ent, yypvt[-0].sval, 0); } break;
  324. case 3:
  325. # line 63 "gram.y"
  326. { label (yypvt[-2].ent, yypvt[-0].sval, -1); } break;
  327. case 4:
  328. # line 65 "gram.y"
  329. { label (yypvt[-2].ent, yypvt[-0].sval, 1); } break;
  330. case 5:
  331. # line 67 "gram.y"
  332. { fwidth[yypvt[-2].ival] = yypvt[-1].ival;
  333.                   FullUpdate++;
  334.                   modflg++;
  335.                   precision[yypvt[-2].ival] = yypvt[-0].ival; } break;
  336. case 6:
  337. # line 71 "gram.y"
  338. { readfile (yypvt[-0].sval,1); } break;
  339. case 7:
  340. # line 72 "gram.y"
  341. { readfile (yypvt[-0].sval,0); } break;
  342. case 8:
  343. # line 73 "gram.y"
  344. { writefile (yypvt[-0].sval); } break;
  345. case 9:
  346. # line 74 "gram.y"
  347. { printfile (yypvt[-0].sval); } break;
  348. case 10:
  349. # line 75 "gram.y"
  350. { tblprintfile (yypvt[-0].sval); } break;
  351. case 11:
  352. # line 76 "gram.y"
  353. { showcol( yypvt[-2].ival, yypvt[-0].ival); } break;
  354. case 12:
  355. # line 77 "gram.y"
  356. { showrow( yypvt[-2].ival, yypvt[-0].ival); } break;
  357. case 13:
  358. # line 79 "gram.y"
  359. { copy(yypvt[-3].ent, yypvt[-2].ent, yypvt[-0].ent); } break;
  360. case 16:
  361. # line 83 "gram.y"
  362. { yyval.enode = new ('v', yypvt[-0].ent); } break;
  363. case 17:
  364. # line 84 "gram.y"
  365. { yyval.enode = new ('f', 0L, yypvt[-0].enode); } break;
  366. case 18:
  367. # line 86 "gram.y"
  368. { yyval.enode = new (O_REDUCE('+'), yypvt[-3].ent, yypvt[-1].ent); } break;
  369. case 19:
  370. # line 88 "gram.y"
  371. { yyval.enode = new (O_REDUCE('*'), yypvt[-3].ent, yypvt[-1].ent); } break;
  372. case 20:
  373. # line 90 "gram.y"
  374. { yyval.enode = new (O_REDUCE('a'), yypvt[-3].ent, yypvt[-1].ent); } break;
  375. case 21:
  376. # line 91 "gram.y"
  377. { yyval.enode = yypvt[-1].enode; } break;
  378. case 22:
  379. # line 92 "gram.y"
  380. { yyval.enode = yypvt[-0].enode; } break;
  381. case 23:
  382. # line 93 "gram.y"
  383. { yyval.enode = new ('m', 0L, yypvt[-0].enode); } break;
  384. case 24:
  385. # line 94 "gram.y"
  386. { yyval.enode = new ('k', (double) yypvt[-0].ival); } break;
  387. case 25:
  388. # line 95 "gram.y"
  389. { yyval.enode = new ('k', yypvt[-0].fval); } break;
  390. case 26:
  391. # line 96 "gram.y"
  392. { yyval.enode = new ('~', 0L, yypvt[-0].enode); } break;
  393. case 27:
  394. # line 97 "gram.y"
  395. { yyval.enode = new ('~', 0L, yypvt[-0].enode); } break;
  396. case 28:
  397. # line 100 "gram.y"
  398. { yyval.enode = new ('+', yypvt[-2].enode, yypvt[-0].enode); } break;
  399. case 29:
  400. # line 101 "gram.y"
  401. { yyval.enode = new ('-', yypvt[-2].enode, yypvt[-0].enode); } break;
  402. case 30:
  403. # line 102 "gram.y"
  404. { yyval.enode = new ('*', yypvt[-2].enode, yypvt[-0].enode); } break;
  405. case 31:
  406. # line 103 "gram.y"
  407. { yyval.enode = new ('/', yypvt[-2].enode, yypvt[-0].enode); } break;
  408. case 33:
  409. # line 105 "gram.y"
  410. { yyval.enode = new ('?', yypvt[-4].enode, new(':', yypvt[-2].enode, yypvt[-0].enode)); } break;
  411. case 34:
  412. # line 106 "gram.y"
  413. { yyval.enode = new ('<', yypvt[-2].enode, yypvt[-0].enode); } break;
  414. case 35:
  415. # line 107 "gram.y"
  416. { yyval.enode = new ('=', yypvt[-2].enode, yypvt[-0].enode); } break;
  417. case 36:
  418. # line 108 "gram.y"
  419. { yyval.enode = new ('>', yypvt[-2].enode, yypvt[-0].enode); } break;
  420. case 37:
  421. # line 109 "gram.y"
  422. { yyval.enode = new ('&', yypvt[-2].enode, yypvt[-0].enode); } break;
  423. case 38:
  424. # line 110 "gram.y"
  425. { yyval.enode = new ('|', yypvt[-2].enode, yypvt[-0].enode); } break;
  426. case 39:
  427. # line 111 "gram.y"
  428. { yyval.enode = new ('~', 0L, new ('>', yypvt[-3].enode, yypvt[-0].enode)); } break;
  429. case 40:
  430. # line 112 "gram.y"
  431. { yyval.enode = new ('~', 0L, new ('=', yypvt[-3].enode, yypvt[-0].enode)); } break;
  432. case 41:
  433. # line 113 "gram.y"
  434. { yyval.enode = new ('~', 0L, new ('<', yypvt[-3].enode, yypvt[-0].enode)); } break;
  435. case 42:
  436. # line 116 "gram.y"
  437. { yyval.ent = lookat(yypvt[-0].ival , yypvt[-1].ival); } break;
  438.         }
  439.         goto yystack;  /* stack new state and value */
  440.  
  441.     }
  442.