home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / TOP / USR / SRC / scpp.t.Z / scpp.t / parse.c < prev    next >
Text File  |  2009-11-06  |  23KB  |  870 lines

  1.  
  2. # line 74 "parse.y"
  3. typedef union  {
  4.     int intval;        /* yacc stack entries    */
  5.     struct anode *lexval;    /* everything in this file    */
  6. } YYSTYPE;
  7. # define MUL 257
  8. # define DIV 258
  9. # define MOD 259
  10. # define PLUS 260
  11. # define MINUS 261
  12. # define LS 262
  13. # define RS 263
  14. # define AND 264
  15. # define OR 265
  16. # define ER 266
  17. # define LT 267
  18. # define LE 268
  19. # define GT 269
  20. # define GE 270
  21. # define EQ 271
  22. # define NE 272
  23. # define ANDAND 273
  24. # define OROR 274
  25. # define CM 275
  26. # define QUEST 276
  27. # define COLON 277
  28. # define NOT 278
  29. # define COMPL 279
  30. # define LP 280
  31. # define RP 281
  32. # define INT 282
  33. # define FLOAT 283
  34. # define IDENT 284
  35. # define QUOTE 285
  36. # define DQUOTE 286
  37. # define BACKS 287
  38. # define OPENC 288
  39. # define CLOSEC 289
  40. # define WHITE 290
  41. # define NL 291
  42. # define QNL 292
  43. # define COMMENT 293
  44. # define OTHER 294
  45. # define STRING 295
  46. # define CHARS 296
  47. # define POUNDLINE 297
  48. # define DEFMAC 298
  49.  
  50. # line 86 "parse.y"
  51. # include "scpp.h"
  52.  
  53. /*
  54.  * struct anode - the structure used to pass strings.
  55.  *  Allocated by mknode();
  56.  *  Deallocated by freenode().
  57.  * The string described will be in pend[] and is NOT NULL-TERMINATED.
  58.  */
  59.  
  60. struct anode {
  61.     int an_val;    /*
  62.              * lexical (token) value of this string.
  63.              * A value of 0 == this node is free.
  64.              */
  65.     int an_ifval;    /* integer result of this expression */
  66. };
  67.  
  68. # define NODESIZ 100    /* max number of nodes in a #if expresssion    */
  69. struct anode nodepool[NODESIZ];
  70.  
  71. struct anode *mknode();
  72.  
  73. # define NIL ((struct anode *) 0)
  74. #define yyclearin yychar = -1
  75. #define yyerrok yyerrflag = 0
  76. extern int yychar;
  77. extern int yyerrflag;
  78. #ifndef YYMAXDEPTH
  79. #define YYMAXDEPTH 150
  80. #endif
  81. YYSTYPE yylval, yyval;
  82. typedef int yytabelem;
  83. # define YYERRCODE 256
  84.  
  85. # line 289 "parse.y"
  86.  
  87.  
  88. yyerror(s)
  89. char *s;
  90. {
  91.     struct anode *anp;
  92.  
  93.     /* free all nodes */
  94.  
  95.     for (anp = &nodepool[0]; anp < &nodepool[NODESIZ]; anp++) {
  96.         anp->an_val = 0;
  97.     }
  98.     warnf("syntax error in #if");
  99. }
  100.  
  101. /*
  102.  * yylex() - the lexical analyzer for #if statements.
  103.  *  yylex() reads from the stream of interpreted macros, skipping
  104.  *  insignificant tokens, then sets yylval appropriately and returns
  105.  *  the token number of the token.
  106.  */
  107.  
  108. int
  109. yylex()
  110. {
  111.     int tok;
  112.  
  113.  
  114.     /*
  115.      * Skip whitespace, quoted newlines, and interpreted preprocessor
  116.      * directives;
  117.      * End-of-file or an unquoted newline marks the end of the parse;
  118.      * calculate the value of integers and character constants.
  119.      */
  120.  
  121.     if (!(yylval.lexval = mknode())) {
  122.         return(0);
  123.     }
  124.  
  125.     while ((tok = gintok()) == WHITE || tok == COMMENT || tok == QNL)
  126.         ;
  127.  
  128.     if (tok == 0 || tok == NL) {
  129.         freenode(yylval.lexval);
  130.         yylval.lexval = NIL;
  131.         return(0);
  132.     }
  133.  
  134.     yylval.lexval->an_val = tok;
  135.     if (tok == INT) {
  136.         yylval.lexval->an_ifval = inttok(curtext, nxtout);
  137.     } else if (tok == CHARS) {
  138.         yylval.lexval->an_val = INT;
  139.         yylval.lexval->an_ifval = chartok(curtext, nxtout);
  140.     }
  141.     return(yylval.lexval->an_val);
  142. }
  143.  
  144. /*
  145.  * inttok - convert integer token.
  146.  *  Given the bounds of a token of type INT, return the value of that integer.
  147.  */
  148.  
  149. int
  150. inttok(s, e)
  151. char *s, *e;
  152. {
  153.     char *str;    /* points to a (dynamically alloc'ed) copy of the tok */
  154.     char *cp;
  155.     int base;    /* the radix of this integer            */
  156.     int value;    /* the value to return                */
  157.     int digit;    /* the value of the current digit        */
  158.  
  159.     /*
  160.      * get a copy of the token (to remove ATTN bytes and null-terminate
  161.      *  the string), and find out what the number base is.
  162.      */
  163.  
  164.     str = savtok(s, e);
  165.     cp = str;
  166.     if (*cp != '0') {
  167.         base = 10;
  168.     } else {
  169.         if (*cp && (*++cp == 'x' || *cp == 'X')) {
  170.             ++cp;
  171.             base = 16;
  172.         } else {
  173.             base = 8;
  174.         }
  175.     }
  176.  
  177.     /*
  178.      * convert the string
  179.      */
  180.  
  181.     value = 0;
  182.     for (;*cp; ++cp) {
  183.         if (*cp >= '0' && *cp <= '7') {
  184.             digit = (int)(*cp - '0');
  185.         } else if (*cp >= '8' && *cp <= '9' && base >= 10) {
  186.             digit = (int)(*cp - '0');
  187.         } else if (*cp >= 'a' && *cp <= 'f' && base == 16) {
  188.             digit = (int)(*cp - 'a') + 10;
  189.         } else if (*cp >= 'A' && *cp <= 'F' && base == 16) {
  190.             digit = (int)(*cp - 'A') + 10;
  191.         } else {
  192.             break;
  193.         }
  194.         value = value * base + digit;
  195.     }
  196.  
  197.     free(str);
  198.     return(value);
  199. }
  200.  
  201. /*
  202.  * chartok() - convert a character constant token.
  203.  *  given the bounds of a character constant, return the integer value
  204.  *   of that character constant.
  205.  */
  206.  
  207. int
  208. chartok(s, e)
  209. char *s, *e;
  210. {
  211.     char *str;    /* (dynamically alloc'ed) copy of the token    */
  212.     char *cp;
  213.     int value;    /* value to return                */
  214.     int cnt;
  215.  
  216.  
  217.     str = savtok(s, e);
  218.  
  219.     cp = str + 1;
  220.     if (*cp != '\\') {
  221.         value = (int) *cp;
  222.     } else if (*++cp == 'n') {
  223.         value = (int) '\n';
  224.     } else if (*cp == 't') {
  225.         value = (int) '\t';
  226.     } else if (*cp == 'b') {
  227.         value = (int) '\b';
  228. /*--read the book to find out the other chars supported--*/
  229.     } else if (*cp >= '0' && *cp <= '7') {
  230.         for (value = 0, cnt = 3; cnt >= 1 && *cp >= '0' && *cp <= '7';
  231.           --cnt, ++cp) {
  232.             value = value * 8 + (int)(*cp - '0');
  233.         }
  234.     } else {
  235.         value = (int) *cp;
  236.     }
  237.  
  238.     free(str);
  239.     return(value);
  240. }
  241.  
  242. struct anode *
  243. mknode()
  244. {
  245.     struct anode *anp;
  246.  
  247.     for (anp = &nodepool[0];
  248.       anp < &nodepool[NODESIZ] && anp->an_val != 0; anp++)
  249.         ;
  250.     if (anp >= &nodepool[NODESIZ]) {
  251.         warnf("#if expression too complex");
  252.         return(NIL);
  253.     }
  254.     anp->an_val = OTHER;
  255.     return(anp);
  256. }
  257.  
  258. freenode(n)
  259. struct anode *n;
  260. {
  261.     n->an_val = 0;
  262. }
  263. yytabelem yyexca[] ={
  264. -1, 1,
  265.     0, -1,
  266.     -2, 0,
  267.     };
  268. # define YYNPROD 30
  269. #define YYLAST 246
  270. yytabelem yyact[]={
  271.  
  272.      2,    11,    12,    13,    14,    15,    16,    17,    34,    11,
  273.     12,    13,    35,    36,    37,    38,    39,    40,    41,    42,
  274.     43,    44,    45,    46,    47,    48,    49,    50,    51,    52,
  275.     53,    54,    11,    12,    13,    14,    15,    16,    17,    24,
  276.     26,    25,    18,    20,    19,    21,    22,    23,    27,    28,
  277.     30,    29,     4,     3,     1,     0,    55,    57,    31,    32,
  278.     33,    11,    12,    13,    14,    15,     0,     0,     0,     5,
  279.      6,     7,     0,     8,     0,     9,     0,     0,     0,     0,
  280.      0,     0,     0,     0,     0,     0,     0,     0,     0,    10,
  281.     11,    12,    13,    14,    15,    16,    17,    24,    26,    25,
  282.     18,    20,    19,    21,    22,    23,    27,    28,    30,    29,
  283.     56,    11,    12,    13,    14,    15,    16,    17,    24,    26,
  284.     25,    18,    20,    19,    21,    22,    23,    27,    28,    30,
  285.     29,    11,    12,    13,    14,    15,    16,    17,    24,    26,
  286.     25,    18,    20,    19,    21,    22,    23,    27,    28,     0,
  287.     29,    11,    12,    13,    14,    15,    16,    17,    24,    26,
  288.     25,    18,    20,    19,    21,    22,    23,    27,    11,    12,
  289.     13,    14,    15,    16,    17,    24,    26,    25,    18,    20,
  290.     19,    21,    22,    23,    11,    12,    13,    14,    15,    16,
  291.     17,    24,     0,    25,    18,    20,    19,    21,    22,    23,
  292.     11,    12,    13,    14,    15,    16,    17,    24,     0,     0,
  293.     18,    20,    19,    21,    22,    23,    11,    12,    13,    14,
  294.     15,    16,    17,     0,     0,     0,    18,    20,    19,    21,
  295.     22,    23,    11,    12,    13,    14,    15,    16,    17,     0,
  296.      0,     0,    18,    20,    19,    21 };
  297. yytabelem yypact[]={
  298.  
  299.   -209, -1000,  -146, -1000,  -209,  -209,  -209,  -209, -1000, -1000,
  300.  -1000,  -209,  -209,  -209,  -209,  -209,  -209,  -209,  -209,  -209,
  301.   -209,  -209,  -209,  -209,  -209,  -209,  -209,  -209,  -209,  -209,
  302.   -209, -1000, -1000, -1000,  -225, -1000, -1000, -1000,  -248,  -248,
  303.   -196,  -196,  -256,  -256,  -256,  -256,   -25,   -25,   -41,   -57,
  304.    -73,   -89,  -106,  -167,  -126, -1000,  -209,  -126 };
  305. yytabelem yypgo[]={
  306.  
  307.      0,    54,     0,    53 };
  308. yytabelem yyr1[]={
  309.  
  310.      0,     1,     2,     2,     2,     2,     2,     2,     2,     2,
  311.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  312.      2,     2,     2,     3,     3,     3,     3,     3,     3,     3 };
  313. yytabelem yyr2[]={
  314.  
  315.      0,     3,     7,     7,     7,     7,     7,     7,     7,     7,
  316.      7,     7,     7,     7,     7,     7,     7,     7,     7,     7,
  317.     11,     7,     3,     5,     5,     5,     7,     3,     3,     3 };
  318. yytabelem yychk[]={
  319.  
  320.  -1000,    -1,    -2,    -3,   261,   278,   279,   280,   282,   284,
  321.    298,   257,   258,   259,   260,   261,   262,   263,   267,   269,
  322.    268,   270,   271,   272,   264,   266,   265,   273,   274,   276,
  323.    275,    -3,    -3,    -3,    -2,    -2,    -2,    -2,    -2,    -2,
  324.     -2,    -2,    -2,    -2,    -2,    -2,    -2,    -2,    -2,    -2,
  325.     -2,    -2,    -2,    -2,    -2,   281,   277,    -2 };
  326. yytabelem yydef[]={
  327.  
  328.      0,    -2,     1,    22,     0,     0,     0,     0,    27,    28,
  329.     29,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  330.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  331.      0,    23,    24,    25,     0,     2,     3,     4,     5,     6,
  332.      7,     8,     9,    10,    11,    12,    13,    14,    15,    16,
  333.     17,    18,    19,     0,    21,    26,     0,    20 };
  334. typedef struct { char *t_name; int t_val; } yytoktype;
  335. #ifndef YYDEBUG
  336. #define YYDEBUG    0    /* don't allow debugging */
  337. #endif
  338.  
  339. #ifdef YYDEBUG
  340.  
  341. yytoktype yytoks[] =
  342. {
  343.     "MUL",    257,
  344.     "DIV",    258,
  345.     "MOD",    259,
  346.     "PLUS",    260,
  347.     "MINUS",    261,
  348.     "LS",    262,
  349.     "RS",    263,
  350.     "AND",    264,
  351.     "OR",    265,
  352.     "ER",    266,
  353.     "LT",    267,
  354.     "LE",    268,
  355.     "GT",    269,
  356.     "GE",    270,
  357.     "EQ",    271,
  358.     "NE",    272,
  359.     "ANDAND",    273,
  360.     "OROR",    274,
  361.     "CM",    275,
  362.     "QUEST",    276,
  363.     "COLON",    277,
  364.     "NOT",    278,
  365.     "COMPL",    279,
  366.     "LP",    280,
  367.     "RP",    281,
  368.     "INT",    282,
  369.     "FLOAT",    283,
  370.     "IDENT",    284,
  371.     "QUOTE",    285,
  372.     "DQUOTE",    286,
  373.     "BACKS",    287,
  374.     "OPENC",    288,
  375.     "CLOSEC",    289,
  376.     "WHITE",    290,
  377.     "NL",    291,
  378.     "QNL",    292,
  379.     "COMMENT",    293,
  380.     "OTHER",    294,
  381.     "STRING",    295,
  382.     "CHARS",    296,
  383.     "POUNDLINE",    297,
  384.     "DEFMAC",    298,
  385.     "-unknown-",    -1    /* ends search */
  386. };
  387.  
  388. char * yyreds[] =
  389. {
  390.     "-no such reduction-",
  391.       "exp : e",
  392.       "e : e MUL e",
  393.       "e : e DIV e",
  394.       "e : e MOD e",
  395.       "e : e PLUS e",
  396.       "e : e MINUS e",
  397.       "e : e LS e",
  398.       "e : e RS e",
  399.       "e : e LT e",
  400.       "e : e GT e",
  401.       "e : e LE e",
  402.       "e : e GE e",
  403.       "e : e EQ e",
  404.       "e : e NE e",
  405.       "e : e AND e",
  406.       "e : e ER e",
  407.       "e : e OR e",
  408.       "e : e ANDAND e",
  409.       "e : e OROR e",
  410.       "e : e QUEST e COLON e",
  411.       "e : e CM e",
  412.       "e : term",
  413.       "term : MINUS term",
  414.       "term : NOT term",
  415.       "term : COMPL term",
  416.       "term : LP e RP",
  417.       "term : INT",
  418.       "term : IDENT",
  419.       "term : DEFMAC",
  420. };
  421. #endif /* YYDEBUG */
  422. #define YYERROR         goto yyerrlab
  423. #define YYACCEPT        return(0)
  424. #define YYABORT         return(1)
  425. #define YYBACKUP( newtoken, newvalue )\
  426. {   if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\
  427.         {yyerror( "syntax error - cannot backup" ); goto yyerrlab;}\
  428.     yychar = newtoken; yystate = *yyps; yylval = newvalue; goto yynewstate;\
  429. }
  430. #define YYRECOVERING()  (!!yyerrflag)
  431. #ifndef YYDEBUG
  432. #define YYDEBUG  1
  433. #endif
  434.  
  435. int yydebug;
  436.  
  437. #define YYFLAG          (-1000)
  438.  
  439. YYSTYPE yyv[ YYMAXDEPTH ];
  440. int yys[ YYMAXDEPTH ];
  441.  
  442. YYSTYPE *yypv;
  443. int *yyps;
  444.  
  445. int yystate;
  446. int yytmp;
  447.  
  448. int yynerrs;
  449. int yyerrflag;
  450. int yychar;
  451.  
  452. int
  453. yyparse()
  454. {
  455.   register YYSTYPE *yypvt;
  456.  
  457.   yypv = &yyv[-1];
  458.   yyps = &yys[-1];
  459.   yystate = 0;
  460.   yytmp = 0;
  461.   yynerrs = 0;
  462.   yyerrflag = 0;
  463.   yychar = -1;
  464.  
  465.   goto yystack;
  466.   {
  467.     register YYSTYPE *yy_pv;
  468.     register int *yy_ps;
  469.     register int yy_state;
  470.     register int  yy_n;
  471.  
  472.   yynewstate:
  473.     yy_pv = yypv;
  474.     yy_ps = yyps;
  475.     yy_state = yystate;
  476.     goto yy_newstate;
  477.  
  478.   yystack:
  479.     yy_pv = yypv;
  480.     yy_ps = yyps;
  481.     yy_state = yystate;
  482.  
  483.   yy_stack:
  484.  
  485. #ifdef YYDEBUG
  486.     if ( yydebug ){
  487.       register int yy_i;
  488.  
  489.       printf( "State %d, token ", yy_state );
  490.       if ( yychar == 0 )
  491.         printf( "end-of-file\n" );
  492.       else if ( yychar < 0 )
  493.         printf( "-none-\n" );
  494.       else {
  495.         for(yy_i = 0; yytoks[yy_i].t_val >= 0;yy_i++){
  496.           if ( yytoks[yy_i].t_val == yychar ) break;
  497.         }
  498.         printf( "%s\n", yytoks[yy_i].t_name );
  499.       }
  500.     }
  501. #endif /* YYDEBUG */
  502.     if ( ++yy_ps >= &yys[ YYMAXDEPTH ] ){
  503.       yyerror( "yacc stack overflow" );
  504.       YYABORT;
  505.     }
  506.     *yy_ps = yy_state;
  507.     _strass(++yy_pv, &yyval, sizeof(yyval));
  508.  
  509.   yy_newstate:
  510.     if ( ( yy_n = yypact[ yy_state ] ) <= YYFLAG )
  511.       goto yydefault;
  512. #ifdef YYDEBUG
  513.     yytmp = yychar < 0;
  514. #endif
  515.     if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
  516.       yychar = 0;
  517. #ifdef YYDEBUG
  518.     if ( yydebug && yytmp ){
  519.       register int yy_i;
  520.  
  521.       printf( "Received token " );
  522.       if ( yychar == 0 )
  523.         printf( "end-of-file\n" );
  524.       else if ( yychar < 0 )
  525.         printf( "-none-\n" );
  526.       else {
  527.         for ( yy_i = 0; yytoks[yy_i].t_val >= 0;yy_i++){
  528.           if ( yytoks[yy_i].t_val == yychar ) break;
  529.         }
  530.         printf( "%s\n", yytoks[yy_i].t_name );
  531.       }
  532.     }
  533. #endif /* YYDEBUG */
  534.     if ( ( ( yy_n += yychar ) < 0 ) || ( yy_n >= YYLAST ) )
  535.       goto yydefault;
  536.     if ( yychk[ yy_n = yyact[ yy_n ] ] == yychar ){
  537.       yychar = -1;
  538.       _strass(&yyval, &yylval, sizeof(yyval));
  539.       yy_state = yy_n;
  540.       if ( yyerrflag > 0 )
  541.         yyerrflag--;
  542.       goto yy_stack;
  543.     }
  544.   yydefault:
  545.     if ( ( yy_n = yydef[ yy_state ] ) == -2 ){
  546. #ifdef YYDEBUG
  547.       yytmp = yychar < 0;
  548. #endif
  549.       if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
  550.         yychar = 0;
  551. #ifdef YYDEBUG
  552.       if ( yydebug && yytmp ){
  553.         register int yy_i;
  554.  
  555.         printf( "Received token " );
  556.         if ( yychar == 0 )
  557.           printf( "end-of-file\n" );
  558.         else if ( yychar < 0 )
  559.           printf( "-none-\n" );
  560.         else {
  561.           for (yy_i = 0;yytoks[yy_i].t_val >=0;yy_i++){
  562.             if ( yytoks[yy_i].t_val == yychar) break;
  563.           }
  564.           printf( "%s\n", yytoks[yy_i].t_name );
  565.         }
  566.       }
  567. #endif /* YYDEBUG */
  568.       {
  569.         register int *yyxi = yyexca;
  570.  
  571.         while ( ( *yyxi != -1 ) || ( yyxi[1] != yy_state )){
  572.           yyxi += 2;
  573.         }
  574.         while ( ( *(yyxi += 2) >= 0 ) && ( *yyxi != yychar));
  575.         if ( ( yy_n = yyxi[1] ) < 0 ) YYACCEPT;
  576.       }
  577.     }
  578.     if ( yy_n == 0 ){
  579.       switch ( yyerrflag ) {
  580.         case 0:
  581.           yyerror( "syntax error" );
  582.           goto skip_init;
  583.         yyerrlab:
  584.           yy_pv = yypv;
  585.           yy_ps = yyps;
  586.           yy_state = yystate;
  587.           yynerrs++;
  588.         skip_init:
  589.         case 1:
  590.         case 2:
  591.           yyerrflag = 3;
  592.           while ( yy_ps >= yys ){
  593.             yy_n = yypact[ *yy_ps ] + YYERRCODE;
  594.             if ( yy_n >= 0 && yy_n < YYLAST &&
  595.                  yychk[yyact[yy_n]] == YYERRCODE){
  596.               yy_state = yyact[ yy_n ];
  597.               goto yy_stack;
  598.             }
  599. #ifdef YYDEBUG
  600. #       define _POP_ "Error recovery pops state %d, uncovers state %d\n"
  601.             if ( yydebug )
  602.               printf( _POP_, *yy_ps,yy_ps[-1]);
  603. #       undef _POP_
  604. #endif
  605.             yy_ps--;
  606.             yy_pv--;
  607.           }
  608.           YYABORT;
  609.         case 3:
  610. #ifdef YYDEBUG
  611.           if ( yydebug ){
  612.             register int yy_i;
  613.  
  614.             printf( "Error recovery discards " );
  615.             if ( yychar == 0 )
  616.               printf( "token end-of-file\n" );
  617.             else if ( yychar < 0 )
  618.               printf( "token -none-\n" );
  619.             else {
  620.               for ( yy_i = 0;yytoks[yy_i].t_val >=0;yy_i++){
  621.                 if ( yytoks[yy_i].t_val == yychar) break;
  622.               }
  623.               printf( "token %s\n",yytoks[yy_i].t_name);
  624.             }
  625.           }
  626. #endif /* YYDEBUG */
  627.           if ( yychar == 0 ) YYABORT;
  628.           yychar = -1;
  629.           goto yy_newstate;
  630.       }
  631.     }/* end if ( yy_n == 0 ) */
  632. #ifdef YYDEBUG
  633.     if ( yydebug )
  634.       printf( "Reduce by (%d) \"%s\"\n",yy_n,yyreds[yy_n]);
  635. #endif
  636.     yytmp = yy_n;
  637.     yypvt = yy_pv;
  638.     {
  639.       register int yy_len = yyr2[ yy_n ];
  640.  
  641.       if ( !( yy_len & 01 ) ){
  642.         yy_len >>= 1;
  643.         _strass(&yyval, &(( yy_pv -= yy_len )[1]), sizeof(yyval));
  644.         yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
  645.                    *( yy_ps -= yy_len ) + 1;
  646.         if ( yy_state >= YYLAST || yychk[yy_state = yyact[yy_state]] != -yy_n){
  647.           yy_state = yyact[ yypgo[ yy_n ] ];
  648.         }
  649.         goto yy_stack;
  650.       }
  651.       yy_len >>= 1;
  652.       _strass(&yyval, &(( yy_pv -= yy_len )[1]), sizeof(yyval));
  653.       yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
  654.                  *( yy_ps -= yy_len ) + 1;
  655.       if(yy_state >= YYLAST || yychk[yy_state = yyact[yy_state]] != -yy_n){
  656.         yy_state = yyact[ yypgo[ yy_n ] ];
  657.       }
  658.     }
  659.     yystate = yy_state;
  660.     yyps = yy_ps;
  661.     yypv = yy_pv;
  662.   }
  663.   switch( yytmp ){
  664.     
  665. case 1:
  666. # line 114 "parse.y"
  667. {
  668.             /*
  669.              * If the expression can be evaluated, set the result
  670.              */
  671.  
  672.             if (yypvt[-0].lexval->an_val == INT) {
  673.                 *curif |= yypvt[-0].lexval->an_ifval != 0 ?
  674.                   IF_TRUE : IF_FALSE;
  675.             }
  676.             freenode(yypvt[-0].lexval);
  677.         } break;
  678. case 2:
  679. # line 127 "parse.y"
  680. {
  681.             yypvt[-2].lexval->an_ifval = yypvt[-2].lexval->an_ifval * yypvt[-0].lexval->an_ifval;
  682.         binop:
  683.             yyval.lexval = yypvt[-2].lexval;
  684.             if (yypvt[-2].lexval->an_val == INT && yypvt[-0].lexval->an_val == INT) {
  685.                 yyval.lexval->an_val == INT;
  686.             } else {
  687.                 yyval.lexval->an_val = OTHER;
  688.             }
  689.             freenode(yypvt[-1].lexval);
  690.             freenode(yypvt[-0].lexval);
  691.         } break;
  692. case 3:
  693. # line 140 "parse.y"
  694. {
  695.           if (yypvt[-0].lexval->an_ifval == 0 && yypvt[-0].lexval->an_val == INT) {
  696.             yypvt[-0].lexval->an_val = OTHER;
  697.             warnf("division by zero in #if");
  698.           } else {
  699.             yypvt[-2].lexval->an_ifval = yypvt[-2].lexval->an_ifval / yypvt[-0].lexval->an_ifval;
  700.           }
  701.           goto binop;
  702.         } break;
  703. case 4:
  704. # line 150 "parse.y"
  705. {
  706.           if (yypvt[-0].lexval->an_ifval == 0 && yypvt[-0].lexval->an_val == INT) {
  707.             yypvt[-0].lexval->an_val = OTHER;
  708.             warnf("mod by zero in #if");
  709.           } else {
  710.             yypvt[-2].lexval->an_ifval = yypvt[-2].lexval->an_ifval % yypvt[-0].lexval->an_ifval;
  711.           }
  712.           goto binop;
  713.         } break;
  714. case 5:
  715. # line 160 "parse.y"
  716. {yypvt[-2].lexval->an_ifval = yypvt[-2].lexval->an_ifval + yypvt[-0].lexval->an_ifval; goto binop;} break;
  717. case 6:
  718. # line 162 "parse.y"
  719. {yypvt[-2].lexval->an_ifval = yypvt[-2].lexval->an_ifval - yypvt[-0].lexval->an_ifval; goto binop;} break;
  720. case 7:
  721. # line 164 "parse.y"
  722. {yypvt[-2].lexval->an_ifval = yypvt[-2].lexval->an_ifval << yypvt[-0].lexval->an_ifval; goto binop;} break;
  723. case 8:
  724. # line 166 "parse.y"
  725. {yypvt[-2].lexval->an_ifval = yypvt[-2].lexval->an_ifval >> yypvt[-0].lexval->an_ifval; goto binop;} break;
  726. case 9:
  727. # line 168 "parse.y"
  728. {yypvt[-2].lexval->an_ifval = yypvt[-2].lexval->an_ifval < yypvt[-0].lexval->an_ifval; goto binop;} break;
  729. case 10:
  730. # line 170 "parse.y"
  731. {yypvt[-2].lexval->an_ifval = yypvt[-2].lexval->an_ifval > yypvt[-0].lexval->an_ifval; goto binop;} break;
  732. case 11:
  733. # line 172 "parse.y"
  734. {yypvt[-2].lexval->an_ifval = yypvt[-2].lexval->an_ifval <= yypvt[-0].lexval->an_ifval; goto binop;} break;
  735. case 12:
  736. # line 174 "parse.y"
  737. {yypvt[-2].lexval->an_ifval = yypvt[-2].lexval->an_ifval >= yypvt[-0].lexval->an_ifval; goto binop;} break;
  738. case 13:
  739. # line 176 "parse.y"
  740. {yypvt[-2].lexval->an_ifval = yypvt[-2].lexval->an_ifval == yypvt[-0].lexval->an_ifval; goto binop;} break;
  741. case 14:
  742. # line 178 "parse.y"
  743. {yypvt[-2].lexval->an_ifval = yypvt[-2].lexval->an_ifval != yypvt[-0].lexval->an_ifval; goto binop;} break;
  744. case 15:
  745. # line 180 "parse.y"
  746. {yypvt[-2].lexval->an_ifval = yypvt[-2].lexval->an_ifval & yypvt[-0].lexval->an_ifval; goto binop;} break;
  747. case 16:
  748. # line 182 "parse.y"
  749. {yypvt[-2].lexval->an_ifval = yypvt[-2].lexval->an_ifval ^ yypvt[-0].lexval->an_ifval; goto binop;} break;
  750. case 17:
  751. # line 184 "parse.y"
  752. {yypvt[-2].lexval->an_ifval = yypvt[-2].lexval->an_ifval | yypvt[-0].lexval->an_ifval; goto binop;} break;
  753. case 18:
  754. # line 186 "parse.y"
  755. {
  756.             /*
  757.              * since this is a logical AND, its value
  758.              *  is known if either subexpression is false.
  759.              */
  760.  
  761.             yyval.lexval = yypvt[-2].lexval;
  762.             if (yypvt[-2].lexval->an_val == INT && yypvt[-0].lexval->an_val == INT) {
  763.                 /* both subexpressions are known */
  764.                 yyval.lexval->an_ifval = yypvt[-2].lexval->an_ifval && yypvt[-0].lexval->an_ifval;
  765.             } else {
  766.                 if ((yypvt[-2].lexval->an_val == INT && !yypvt[-2].lexval->an_ifval) ||
  767.                     (yypvt[-0].lexval->an_val == INT && !yypvt[-0].lexval->an_ifval)) {
  768.                     yyval.lexval->an_val = INT;
  769.                     yyval.lexval->an_ifval = FALSE;
  770.                 } else {
  771.                     yyval.lexval->an_val = OTHER;
  772.                 }
  773.             }
  774.             freenode(yypvt[-1].lexval); freenode(yypvt[-0].lexval);
  775.         } break;
  776. case 19:
  777. # line 208 "parse.y"
  778. {
  779.             /*
  780.              * since this is a logical OR, its value
  781.              *  is known if either subexpression is true.
  782.              */
  783.  
  784.             yyval.lexval = yypvt[-2].lexval;
  785.             if (yypvt[-2].lexval->an_val == INT && yypvt[-0].lexval->an_val == INT) {
  786.                 /* both subexpressions are known */
  787.                 yyval.lexval->an_ifval = yypvt[-2].lexval->an_ifval || yypvt[-0].lexval->an_ifval;
  788.             } else {
  789.                 if ((yypvt[-2].lexval->an_val == INT && yypvt[-2].lexval->an_ifval) ||
  790.                     (yypvt[-0].lexval->an_val == INT && yypvt[-0].lexval->an_ifval)) {
  791.                     yyval.lexval->an_val = INT;
  792.                     yyval.lexval->an_ifval = TRUE;
  793.                 } else {
  794.                     yyval.lexval->an_val = OTHER;
  795.                 }
  796.             }
  797.             freenode(yypvt[-1].lexval); freenode(yypvt[-0].lexval);
  798.         } break;
  799. case 20:
  800. # line 230 "parse.y"
  801. {
  802.             /*
  803.              * since this is an IF-ELSE, its value is known
  804.              * in some cases even if one subexpression is unknown.
  805.              */
  806.  
  807.             yyval.lexval = yypvt[-4].lexval;
  808.             if (yypvt[-4].lexval->an_val == INT) {
  809.                 if (yypvt[-4].lexval->an_ifval) {
  810.                     yyval.lexval->an_val = yypvt[-2].lexval->an_val;
  811.                     yyval.lexval->an_ifval = yypvt[-2].lexval->an_ifval;
  812.                 } else {
  813.                     yyval.lexval->an_val = yypvt[-0].lexval->an_val;
  814.                     yyval.lexval->an_ifval = yypvt[-0].lexval->an_ifval;
  815.                 }
  816.             } else {
  817.                 yyval.lexval->an_val = OTHER;
  818.             }
  819.             freenode(yypvt[-3].lexval); freenode(yypvt[-2].lexval); freenode(yypvt[-1].lexval);
  820.             freenode(yypvt[-0].lexval);
  821.         } break;
  822. case 21:
  823. # line 252 "parse.y"
  824. {
  825.             /*
  826.              * since this is a comma operator, the value of
  827.              * the first expression is irrelevant.
  828.              */
  829.  
  830.             yyval.lexval = yypvt[-0].lexval;
  831.             freenode(yypvt[-2].lexval);
  832.             freenode(yypvt[-1].lexval);
  833.         } break;
  834. case 22:
  835. # line 263 "parse.y"
  836. {yyval.lexval = yypvt[-0].lexval;} break;
  837. case 23:
  838. # line 267 "parse.y"
  839. {
  840.             yypvt[-0].lexval->an_ifval = -(yypvt[-0].lexval->an_ifval);
  841.         unop:
  842.             yyval.lexval = yypvt[-0].lexval;
  843.             freenode(yypvt[-1].lexval);
  844.         } break;
  845. case 24:
  846. # line 274 "parse.y"
  847. {yypvt[-0].lexval->an_ifval = !(yypvt[-0].lexval->an_ifval); goto unop;} break;
  848. case 25:
  849. # line 276 "parse.y"
  850. {yypvt[-0].lexval->an_ifval = ~(yypvt[-0].lexval->an_ifval); goto unop;} break;
  851. case 26:
  852. # line 278 "parse.y"
  853. {
  854.             yyval.lexval = yypvt[-1].lexval;
  855.             freenode(yypvt[-2].lexval); freenode(yypvt[-0].lexval);
  856.         } break;
  857. case 27:
  858. # line 283 "parse.y"
  859. {yyval.lexval= yypvt[-0].lexval;} break;
  860. case 28:
  861. # line 285 "parse.y"
  862. {/* an uninterpreted macro */ yyval.lexval = yypvt[-0].lexval;} break;
  863. case 29:
  864. # line 287 "parse.y"
  865. {/* an uninterpreted 'defined(x)' invocation */ yyval.lexval = yypvt[-0].lexval;} break;
  866.   }
  867.   goto yystack;
  868. }
  869.  
  870.