home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / itc / cpp / cexp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-30  |  33.0 KB  |  1,244 lines

  1.  
  2. /*  A Bison parser, made from cexp.y  */
  3.  
  4. #define    INT    258
  5. #define    CHAR    259
  6. #define    NAME    260
  7. #define    ERROR    261
  8. #define    OR    262
  9. #define    AND    263
  10. #define    EQUAL    264
  11. #define    NOTEQUAL    265
  12. #define    LEQ    266
  13. #define    GEQ    267
  14. #define    LSH    268
  15. #define    RSH    269
  16. #define    UNARY    270
  17.  
  18. #line 109 "cexp.y"
  19.  
  20. #include "config.h"
  21. #include <setjmp.h>
  22. #include "alloca.h"
  23. /* #define YYDEBUG 1 */
  24.  
  25.   int yylex ();
  26.   void yyerror ();
  27.   int expression_value;
  28.  
  29.   static jmp_buf parse_return_error;
  30.  
  31.   /* some external tables of character types */
  32.   extern unsigned char is_idstart[], is_idchar[];
  33.  
  34.  
  35. #line 125 "cexp.y"
  36. typedef union {
  37.   long lval;
  38.   int voidval;
  39.   char *sval;
  40. } YYSTYPE;
  41.  
  42. #ifndef YYLTYPE
  43. typedef
  44.   struct yyltype
  45.     {
  46.       int timestamp;
  47.       int first_line;
  48.       int first_column;
  49.       int last_line;
  50.       int last_column;
  51.       char *text;
  52.    }
  53.   yyltype;
  54.  
  55. #define YYLTYPE yyltype
  56. #endif
  57.  
  58. #define    YYACCEPT    return(0)
  59. #define    YYABORT    return(1)
  60. #define    YYERROR    return(1)
  61. #include <stdio.h>
  62.  
  63. #ifndef __STDC__
  64. #define const
  65. #endif
  66.  
  67.  
  68.  
  69. #define    YYFINAL        59
  70. #define    YYFLAG        -32768
  71. #define    YYNTBASE    33
  72.  
  73. #define YYTRANSLATE(x) ((unsigned)(x) <= 270 ? yytranslate[x] : 36)
  74.  
  75. static const char yytranslate[] = {     0,
  76.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  77.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  78.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  79.      2,     2,    29,     2,     2,     2,    27,    14,     2,    31,
  80.     32,    25,    23,     9,    24,     2,    26,     2,     2,     2,
  81.      2,     2,     2,     2,     2,     2,     2,     8,     2,    17,
  82.      2,    18,     7,     2,     2,     2,     2,     2,     2,     2,
  83.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  84.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  85.      2,     2,     2,    13,     2,     2,     2,     2,     2,     2,
  86.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  87.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  88.      2,     2,     2,    12,     2,    30,     2,     2,     2,     2,
  89.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  90.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  91.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  92.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  93.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  94.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  95.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  96.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  97.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  98.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  99.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  100.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  101.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  102.      6,    10,    11,    15,    16,    19,    20,    21,    22,    28
  103. };
  104.  
  105. static const short yyrline[] = {     0,
  106.    154,   159,   160,   165,   167,   169,   171,   176,   178,   180,
  107.    182,   184,   186,   188,   190,   192,   194,   196,   198,   200,
  108.    202,   204,   206,   208,   210,   212,   214,   216,   218
  109. };
  110.  
  111. static const char * const yytname[] = {     0,
  112. "error","$illegal.","INT","CHAR","NAME","ERROR","'?'","':'","','","OR",
  113. "AND","'|'","'^'","'&'","EQUAL","NOTEQUAL","'<'","'>'","LEQ","GEQ",
  114. "LSH","RSH","'+'","'-'","'*'","'/'","'%'","UNARY","'!'","'~'",
  115. "'('","')'","start"
  116. };
  117.  
  118. static const short yyr1[] = {     0,
  119.     33,    34,    34,    35,    35,    35,    35,    35,    35,    35,
  120.     35,    35,    35,    35,    35,    35,    35,    35,    35,    35,
  121.     35,    35,    35,    35,    35,    35,    35,    35,    35
  122. };
  123.  
  124. static const short yyr2[] = {     0,
  125.      1,     1,     3,     2,     2,     2,     3,     3,     3,     3,
  126.      3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
  127.      3,     3,     3,     3,     3,     5,     1,     1,     1
  128. };
  129.  
  130. static const short yydefact[] = {     0,
  131.     27,    28,    29,     0,     0,     0,     0,     1,     2,     4,
  132.      5,     6,     0,     0,     0,     0,     0,     0,     0,     0,
  133.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  134.      0,     0,     0,     7,     3,     0,    25,    24,    23,    22,
  135.     21,    15,    16,    19,    20,    17,    18,    13,    14,    11,
  136.     12,     8,     9,    10,     0,    26,     0,     0,     0
  137. };
  138.  
  139. static const short yydefgoto[] = {    57,
  140.      8,     9
  141. };
  142.  
  143. static const short yypact[] = {    28,
  144. -32768,-32768,-32768,    28,    28,    28,    28,    -3,    74,-32768,
  145. -32768,-32768,    -2,    28,    28,    28,    28,    28,    28,    28,
  146.     28,    28,    28,    28,    28,    28,    28,    28,    28,    28,
  147.     28,    28,    28,-32768,    74,    53,    23,    90,   105,   119,
  148.    132,   143,   143,   150,   150,   150,   150,   155,   155,   -22,
  149.    -22,-32768,-32768,-32768,    28,    74,     8,     9,-32768
  150. };
  151.  
  152. static const short yypgoto[] = {-32768,
  153.     46,    -4
  154. };
  155.  
  156.  
  157. #define    YYLAST        182
  158.  
  159.  
  160. static const short yytable[] = {    10,
  161.     11,    12,    31,    32,    33,    14,    14,    58,    59,    35,
  162.     36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
  163.     46,    47,    48,    49,    50,    51,    52,    53,    54,    34,
  164.      1,     2,     3,    17,    18,    19,    20,    21,    22,    23,
  165.     24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
  166.     56,     4,    13,     0,     0,     0,     5,     6,     7,    15,
  167.     55,     0,    16,    17,    18,    19,    20,    21,    22,    23,
  168.     24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
  169.     15,     0,     0,    16,    17,    18,    19,    20,    21,    22,
  170.     23,    24,    25,    26,    27,    28,    29,    30,    31,    32,
  171.     33,    18,    19,    20,    21,    22,    23,    24,    25,    26,
  172.     27,    28,    29,    30,    31,    32,    33,    19,    20,    21,
  173.     22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
  174.     32,    33,    20,    21,    22,    23,    24,    25,    26,    27,
  175.     28,    29,    30,    31,    32,    33,    21,    22,    23,    24,
  176.     25,    26,    27,    28,    29,    30,    31,    32,    33,    23,
  177.     24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
  178.     27,    28,    29,    30,    31,    32,    33,    29,    30,    31,
  179.     32,    33
  180. };
  181.  
  182. static const short yycheck[] = {     4,
  183.      5,     6,    25,    26,    27,     9,     9,     0,     0,    14,
  184.     15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
  185.     25,    26,    27,    28,    29,    30,    31,    32,    33,    32,
  186.      3,     4,     5,    11,    12,    13,    14,    15,    16,    17,
  187.     18,    19,    20,    21,    22,    23,    24,    25,    26,    27,
  188.     55,    24,     7,    -1,    -1,    -1,    29,    30,    31,     7,
  189.      8,    -1,    10,    11,    12,    13,    14,    15,    16,    17,
  190.     18,    19,    20,    21,    22,    23,    24,    25,    26,    27,
  191.      7,    -1,    -1,    10,    11,    12,    13,    14,    15,    16,
  192.     17,    18,    19,    20,    21,    22,    23,    24,    25,    26,
  193.     27,    12,    13,    14,    15,    16,    17,    18,    19,    20,
  194.     21,    22,    23,    24,    25,    26,    27,    13,    14,    15,
  195.     16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
  196.     26,    27,    14,    15,    16,    17,    18,    19,    20,    21,
  197.     22,    23,    24,    25,    26,    27,    15,    16,    17,    18,
  198.     19,    20,    21,    22,    23,    24,    25,    26,    27,    17,
  199.     18,    19,    20,    21,    22,    23,    24,    25,    26,    27,
  200.     21,    22,    23,    24,    25,    26,    27,    23,    24,    25,
  201.     26,    27
  202. };
  203. #define YYPURE 1
  204.  
  205. #line 2 "bison.simple"
  206.  
  207. /* Skeleton output parser for bison,
  208.    copyright (C) 1984 Bob Corbett and Richard Stallman
  209.  
  210.                NO WARRANTY
  211.  
  212.   BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  213. NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
  214. WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
  215. RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
  216. WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  217. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  218. FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
  219. AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
  220. DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  221. CORRECTION.
  222.  
  223.  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  224. STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
  225. WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
  226. LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  227. OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  228. USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  229. DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
  230. A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
  231. PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  232. DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  233.  
  234.         GENERAL PUBLIC LICENSE TO COPY
  235.  
  236.   1. You may copy and distribute verbatim copies of this source file
  237. as you receive it, in any medium, provided that you conspicuously and
  238. appropriately publish on each copy a valid copyright notice "Copyright
  239. (C) 1985 Free Software Foundation, Inc."; and include following the
  240. copyright notice a verbatim copy of the above disclaimer of warranty
  241. and of this License.  You may charge a distribution fee for the
  242. physical act of transferring a copy.
  243.  
  244.   2. You may modify your copy or copies of this source file or
  245. any portion of it, and copy and distribute such modifications under
  246. the terms of Paragraph 1 above, provided that you also do the following:
  247.  
  248.     a) cause the modified files to carry prominent notices stating
  249.     that you changed the files and the date of any change; and
  250.  
  251.     b) cause the whole of any work that you distribute or publish,
  252.     that in whole or in part contains or is a derivative of this
  253.     program or any part thereof, to be licensed at no charge to all
  254.     third parties on terms identical to those contained in this
  255.     License Agreement (except that you may choose to grant more extensive
  256.     warranty protection to some or all third parties, at your option).
  257.  
  258.     c) You may charge a distribution fee for the physical act of
  259.     transferring a copy, and you may at your option offer warranty
  260.     protection in exchange for a fee.
  261.  
  262. Mere aggregation of another unrelated program with this program (or its
  263. derivative) on a volume of a storage or distribution medium does not bring
  264. the other program under the scope of these terms.
  265.  
  266.   3. You may copy and distribute this program (or a portion or derivative
  267. of it, under Paragraph 2) in object code or executable form under the terms
  268. of Paragraphs 1 and 2 above provided that you also do one of the following:
  269.  
  270.     a) accompany it with the complete corresponding machine-readable
  271.     source code, which must be distributed under the terms of
  272.     Paragraphs 1 and 2 above; or,
  273.  
  274.     b) accompany it with a written offer, valid for at least three
  275.     years, to give any third party free (except for a nominal
  276.     shipping charge) a complete machine-readable copy of the
  277.     corresponding source code, to be distributed under the terms of
  278.     Paragraphs 1 and 2 above; or,
  279.  
  280.     c) accompany it with the information you received as to where the
  281.     corresponding source code may be obtained.  (This alternative is
  282.     allowed only for noncommercial distribution and only if you
  283.     received the program in object code or executable form alone.)
  284.  
  285. For an executable file, complete source code means all the source code for
  286. all modules it contains; but, as a special exception, it need not include
  287. source code for modules which are standard libraries that accompany the
  288. operating system on which the executable file runs.
  289.  
  290.   4. You may not copy, sublicense, distribute or transfer this program
  291. except as expressly provided under this License Agreement.  Any attempt
  292. otherwise to copy, sublicense, distribute or transfer this program is void and
  293. your rights to use the program under this License agreement shall be
  294. automatically terminated.  However, parties who have received computer
  295. software programs from you with this License Agreement will not have
  296. their licenses terminated so long as such parties remain in full compliance.
  297.  
  298.   5. If you wish to incorporate parts of this program into other free
  299. programs whose distribution conditions are different, write to the Free
  300. Software Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
  301. worked out a simple rule that can be stated here, but we will often permit
  302. this.  We will be guided by the two goals of preserving the free status of
  303. all derivatives of our free software and of promoting the sharing and reuse of
  304. software.
  305.  
  306.  
  307. In other words, you are welcome to use, share and improve this program.
  308. You are forbidden to forbid anyone else to use, share and improve
  309. what you give them.   Help stamp out software-hoarding!  */
  310.  
  311. /* This is the parser code that is written into each bison parser
  312.   when the %semantic_parser declaration is not specified in the grammar.
  313.   It was written by Richard Stallman by simplifying the hairy parser
  314.   used when %semantic_parser is specified.  */
  315.  
  316. /* Note: there must be only one dollar sign in this file.
  317.    It is replaced by the list of actions, each action
  318.    as one case of the switch.  */
  319.  
  320. #define yyerrok        (yyerrstatus = 0)
  321. #define yyclearin    (yychar = YYEMPTY)
  322. #define YYEMPTY        -2
  323. #define YYEOF        0
  324. #define YYFAIL        goto yyerrlab;
  325.  
  326. #define YYTERROR    1
  327.  
  328. #ifndef YYIMPURE
  329. #define YYLEX        yylex()
  330. #endif
  331.  
  332. #ifndef YYPURE
  333. #define YYLEX        yylex(&yylval, &yylloc)
  334. #endif
  335.  
  336. /* If nonreentrant, generate the variables here */
  337.  
  338. #ifndef YYIMPURE
  339.  
  340. int    yychar;            /*  the lookahead symbol        */
  341. YYSTYPE    yylval;            /*  the semantic value of the        */
  342.                 /*  lookahead symbol            */
  343.  
  344. YYLTYPE yylloc;            /*  location data for the lookahead    */
  345.                 /*  symbol                */
  346.  
  347. #ifdef YYDEBUG
  348. int yydebug = 0;        /*  nonzero means print parse trace    */
  349. #endif
  350.  
  351. #endif  /* YYIMPURE */
  352.  
  353.  
  354. /*  YYMAXDEPTH indicates the initial size of the parser's stacks    */
  355.  
  356. #ifndef    YYMAXDEPTH
  357. #define YYMAXDEPTH 200
  358. #endif
  359.  
  360. /*  YYMAXLIMIT is the maximum size the stacks can grow to
  361.     (effective only if the built-in stack extension method is used).  */
  362.  
  363. #ifndef YYMAXLIMIT
  364. #define YYMAXLIMIT 10000
  365. #endif
  366.  
  367.  
  368. #line 87 "bison.simple"
  369. int
  370. yyparse()
  371. {
  372.   register int yystate;
  373.   register int yyn;
  374.   register short *yyssp;
  375.   register YYSTYPE *yyvsp;
  376.   YYLTYPE *yylsp;
  377.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  378.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  379.  
  380.   short    yyssa[YYMAXDEPTH];    /*  the state stack            */
  381.   YYSTYPE yyvsa[YYMAXDEPTH];    /*  the semantic value stack        */
  382.   YYLTYPE yylsa[YYMAXDEPTH];    /*  the location stack            */
  383.  
  384.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  385.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  386.   YYLTYPE *yyls = yylsa;
  387.  
  388.   int yymaxdepth = YYMAXDEPTH;
  389.  
  390. #ifndef YYPURE
  391.  
  392.   int yychar;
  393.   YYSTYPE yylval;
  394.   YYLTYPE yylloc;
  395.  
  396. #ifdef YYDEBUG
  397.   extern int yydebug;
  398. #endif
  399.  
  400. #endif
  401.  
  402.  
  403.   YYSTYPE yyval;        /*  the variable used to return        */
  404.                 /*  semantic values from the action    */
  405.                 /*  routines                */
  406.  
  407.   int yylen;
  408.  
  409. #ifdef YYDEBUG
  410.   if (yydebug)
  411.     fprintf(stderr, "Starting parse\n");
  412. #endif
  413.  
  414.   yystate = 0;
  415.   yyerrstatus = 0;
  416.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  417.  
  418.   /* Initialize stack pointers.
  419.      Waste one element of value and location stack
  420.      so that they stay on the same level as the state stack.  */
  421.  
  422.   yyssp = yyss - 1;
  423.   yyvsp = yyvs;
  424.   yylsp = yyls;
  425.  
  426. /* Push a new state, which is found in  yystate  .  */
  427. /* In all cases, when you get here, the value and location stacks
  428.    have just been pushed. so pushing a state here evens the stacks.  */
  429. yynewstate:
  430.  
  431.   *++yyssp = yystate;
  432.  
  433.   if (yyssp >= yyss + yymaxdepth - 1)
  434.     {
  435.       /* Give user a chance to reallocate the stack */
  436.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  437.       YYSTYPE *yyvs1 = yyvs;
  438.       YYLTYPE *yyls1 = yyls;
  439.       short *yyss1 = yyss;
  440.  
  441.       /* Get the current used size of the three stacks, in elements.  */
  442.       int size = yyssp - yyss + 1;
  443.  
  444. #ifdef yyoverflow
  445.       /* Each stack pointer address is followed by the size of
  446.      the data in use in that stack, in bytes.  */
  447.       yyoverflow("parser stack overflow",
  448.          &yyss1, size * sizeof (*yyssp),
  449.          &yyvs1, size * sizeof (*yyvsp),
  450.          &yyls1, size * sizeof (*yylsp),
  451.          &yymaxdepth);
  452.  
  453.       yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
  454. #else /* no yyoverflow */
  455.       /* Extend the stack our own way.  */
  456.       if (yymaxdepth >= YYMAXLIMIT)
  457.     yyerror("parser stack overflow");
  458.       yymaxdepth *= 2;
  459.       if (yymaxdepth > YYMAXLIMIT)
  460.     yymaxdepth = YYMAXLIMIT;
  461.       yyss = (short *) alloca (yymaxdepth * sizeof (*yyssp));
  462.       bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  463.       yyls = (YYLTYPE *) alloca (yymaxdepth * sizeof (*yylsp));
  464.       bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  465.       yyvs = (YYSTYPE *) alloca (yymaxdepth * sizeof (*yyvsp));
  466.       bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  467. #endif /* no yyoverflow */
  468.  
  469.       yyssp = yyss + size - 1;
  470.       yylsp = yyls + size - 1;
  471.       yyvsp = yyvs + size - 1;
  472.  
  473. #ifdef YYDEBUG
  474.       if (yydebug)
  475.     fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
  476. #endif
  477.  
  478.       if (yyssp >= yyss + yymaxdepth - 1)
  479.     YYERROR;
  480.     }
  481.  
  482. #ifdef YYDEBUG
  483.   if (yydebug)
  484.     fprintf(stderr, "Entering state %d\n", yystate);
  485. #endif
  486.  
  487. /* Do appropriate processing given the current state.  */
  488. /* Read a lookahead token if we need one and don't already have one.  */
  489. yyresume:
  490.  
  491.   /* First try to decide what to do without reference to lookahead token.  */
  492.  
  493.   yyn = yypact[yystate];
  494.   if (yyn == YYFLAG)
  495.     goto yydefault;
  496.  
  497.   /* Not known => get a lookahead token if don't already have one.  */
  498.  
  499.   /* yychar is either YYEMPTY or YYEOF
  500.      or a valid token in external form.  */
  501.  
  502.   if (yychar == YYEMPTY)
  503.     {
  504. #ifdef YYDEBUG
  505.       if (yydebug)
  506.     fprintf(stderr, "Reading a token: ");
  507. #endif
  508.       yychar = YYLEX;
  509.     }
  510.  
  511.   /* Convert token to internal form (in yychar1) for indexing tables with */
  512.  
  513.   if (yychar <= 0)        /* This means end of input. */
  514.     {
  515.       yychar1 = 0;
  516.       yychar = YYEOF;        /* Don't call YYLEX any more */
  517.  
  518. #ifdef YYDEBUG
  519.       if (yydebug)
  520.     fprintf(stderr, "Now at end of input.\n");
  521. #endif
  522.     }
  523.   else
  524.     {
  525.       yychar1 = YYTRANSLATE(yychar);
  526.  
  527. #ifdef YYDEBUG
  528.       if (yydebug)
  529.     fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
  530. #endif
  531.     }
  532.  
  533.   yyn += yychar1;
  534.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  535.     goto yydefault;
  536.  
  537.   yyn = yytable[yyn];
  538.  
  539.   /* yyn is what to do for this token type in this state.
  540.      Negative => reduce, -yyn is rule number.
  541.      Positive => shift, yyn is new state.
  542.        New state is final state => don't bother to shift,
  543.        just return success.
  544.      0, or most negative number => error.  */
  545.  
  546.   if (yyn < 0)
  547.     {
  548.       if (yyn == YYFLAG)
  549.     goto yyerrlab;
  550.       yyn = -yyn;
  551.       goto yyreduce;
  552.     }
  553.   else if (yyn == 0)
  554.     goto yyerrlab;
  555.  
  556.   if (yyn == YYFINAL)
  557.     YYACCEPT;
  558.  
  559.   /* Shift the lookahead token.  */
  560.  
  561. #ifdef YYDEBUG
  562.   if (yydebug)
  563.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  564. #endif
  565.  
  566.   /* Discard the token being shifted unless it is eof.  */
  567.   if (yychar != YYEOF)
  568.     yychar = YYEMPTY;
  569.  
  570.   *++yyvsp = yylval;
  571.   *++yylsp = yylloc;
  572.  
  573.   /* count tokens shifted since error; after three, turn off error status.  */
  574.   if (yyerrstatus) yyerrstatus--;
  575.  
  576.   yystate = yyn;
  577.   goto yynewstate;
  578.  
  579. /* Do the default action for the current state.  */
  580. yydefault:
  581.  
  582.   yyn = yydefact[yystate];
  583.   if (yyn == 0)
  584.     goto yyerrlab;
  585.  
  586. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  587. yyreduce:
  588.   yylen = yyr2[yyn];
  589.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  590.  
  591. #ifdef YYDEBUG
  592.   if (yydebug)
  593.     {
  594.       if (yylen == 1)
  595.     fprintf (stderr, "Reducing 1 value via line %d, ",
  596.          yyrline[yyn]);
  597.       else
  598.     fprintf (stderr, "Reducing %d values via line %d, ",
  599.          yylen, yyrline[yyn]);
  600.     }
  601. #endif
  602.  
  603.  
  604.   switch (yyn) {
  605.  
  606. case 1:
  607. #line 155 "cexp.y"
  608. { expression_value = yyvsp[0].lval; ;
  609.     break;}
  610. case 3:
  611. #line 161 "cexp.y"
  612. { yyval.lval = yyvsp[0].lval; ;
  613.     break;}
  614. case 4:
  615. #line 166 "cexp.y"
  616. { yyval.lval = - yyvsp[0].lval; ;
  617.     break;}
  618. case 5:
  619. #line 168 "cexp.y"
  620. { yyval.lval = ! yyvsp[0].lval; ;
  621.     break;}
  622. case 6:
  623. #line 170 "cexp.y"
  624. { yyval.lval = ~ yyvsp[0].lval; ;
  625.     break;}
  626. case 7:
  627. #line 172 "cexp.y"
  628. { yyval.lval = yyvsp[-1].lval; ;
  629.     break;}
  630. case 8:
  631. #line 177 "cexp.y"
  632. { yyval.lval = yyvsp[-2].lval * yyvsp[0].lval; ;
  633.     break;}
  634. case 9:
  635. #line 179 "cexp.y"
  636. { yyval.lval = yyvsp[-2].lval / yyvsp[0].lval; ;
  637.     break;}
  638. case 10:
  639. #line 181 "cexp.y"
  640. { yyval.lval = yyvsp[-2].lval % yyvsp[0].lval; ;
  641.     break;}
  642. case 11:
  643. #line 183 "cexp.y"
  644. { yyval.lval = yyvsp[-2].lval + yyvsp[0].lval; ;
  645.     break;}
  646. case 12:
  647. #line 185 "cexp.y"
  648. { yyval.lval = yyvsp[-2].lval - yyvsp[0].lval; ;
  649.     break;}
  650. case 13:
  651. #line 187 "cexp.y"
  652. { yyval.lval = yyvsp[-2].lval << yyvsp[0].lval; ;
  653.     break;}
  654. case 14:
  655. #line 189 "cexp.y"
  656. { yyval.lval = yyvsp[-2].lval >> yyvsp[0].lval; ;
  657.     break;}
  658. case 15:
  659. #line 191 "cexp.y"
  660. { yyval.lval = (yyvsp[-2].lval == yyvsp[0].lval); ;
  661.     break;}
  662. case 16:
  663. #line 193 "cexp.y"
  664. { yyval.lval = (yyvsp[-2].lval != yyvsp[0].lval); ;
  665.     break;}
  666. case 17:
  667. #line 195 "cexp.y"
  668. { yyval.lval = (yyvsp[-2].lval <= yyvsp[0].lval); ;
  669.     break;}
  670. case 18:
  671. #line 197 "cexp.y"
  672. { yyval.lval = (yyvsp[-2].lval >= yyvsp[0].lval); ;
  673.     break;}
  674. case 19:
  675. #line 199 "cexp.y"
  676. { yyval.lval = (yyvsp[-2].lval < yyvsp[0].lval); ;
  677.     break;}
  678. case 20:
  679. #line 201 "cexp.y"
  680. { yyval.lval = (yyvsp[-2].lval > yyvsp[0].lval); ;
  681.     break;}
  682. case 21:
  683. #line 203 "cexp.y"
  684. { yyval.lval = (yyvsp[-2].lval & yyvsp[0].lval); ;
  685.     break;}
  686. case 22:
  687. #line 205 "cexp.y"
  688. { yyval.lval = (yyvsp[-2].lval ^ yyvsp[0].lval); ;
  689.     break;}
  690. case 23:
  691. #line 207 "cexp.y"
  692. { yyval.lval = (yyvsp[-2].lval | yyvsp[0].lval); ;
  693.     break;}
  694. case 24:
  695. #line 209 "cexp.y"
  696. { yyval.lval = (yyvsp[-2].lval && yyvsp[0].lval); ;
  697.     break;}
  698. case 25:
  699. #line 211 "cexp.y"
  700. { yyval.lval = (yyvsp[-2].lval || yyvsp[0].lval); ;
  701.     break;}
  702. case 26:
  703. #line 213 "cexp.y"
  704. { yyval.lval = yyvsp[-4].lval ? yyvsp[-2].lval : yyvsp[0].lval; ;
  705.     break;}
  706. case 27:
  707. #line 215 "cexp.y"
  708. { yyval.lval = yylval.lval; ;
  709.     break;}
  710. case 28:
  711. #line 217 "cexp.y"
  712. { yyval.lval = yylval.lval; ;
  713.     break;}
  714. case 29:
  715. #line 219 "cexp.y"
  716. { yyval.lval = 0; ;
  717.     break;}
  718. }
  719.    /* the action file gets copied in in place of this dollarsign */
  720. #line 303 "bison.simple"
  721.  
  722.   yyvsp -= yylen;
  723.   yylsp -= yylen;
  724.   yyssp -= yylen;
  725.  
  726. #ifdef YYDEBUG
  727.   if (yydebug)
  728.     {
  729.       short *ssp1 = yyss - 1;
  730.       fprintf (stderr, "state stack now", yyssp-yyss);
  731.       while (ssp1 != yyssp)
  732.     fprintf (stderr, " %d", *++ssp1);
  733.       fprintf (stderr, "\n");
  734.     }
  735. #endif
  736.  
  737.   *++yyvsp = yyval;
  738.  
  739.   yylsp++;
  740.   if (yylen == 0)
  741.     {
  742.       yylsp->first_line = yylloc.first_line;
  743.       yylsp->first_column = yylloc.first_column;
  744.       yylsp->last_line = (yylsp-1)->last_line;
  745.       yylsp->last_column = (yylsp-1)->last_column;
  746.       yylsp->text = 0;
  747.     }
  748.   else
  749.     {
  750.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  751.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  752.     }
  753.  
  754.   /* Now "shift" the result of the reduction.
  755.      Determine what state that goes to,
  756.      based on the state we popped back to
  757.      and the rule number reduced by.  */
  758.  
  759.   yyn = yyr1[yyn];
  760.  
  761.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  762.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  763.     yystate = yytable[yystate];
  764.   else
  765.     yystate = yydefgoto[yyn - YYNTBASE];
  766.  
  767.   goto yynewstate;
  768.  
  769. yyerrlab:   /* here on detecting error */
  770.  
  771.   if (! yyerrstatus)
  772.     /* If not already recovering from an error, report this error.  */
  773.     {
  774.       yyerror("parse error");
  775.     }
  776.  
  777.   if (yyerrstatus == 3)
  778.     {
  779.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  780.  
  781.       /* return failure if at end of input */
  782.       if (yychar == YYEOF)
  783.     YYERROR;
  784.  
  785. #ifdef YYDEBUG
  786.       if (yydebug)
  787.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  788. #endif
  789.  
  790.       yychar = YYEMPTY;
  791.     }
  792.  
  793.   /* Else will try to reuse lookahead token
  794.      after shifting the error token.  */
  795.  
  796.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  797.  
  798.   goto yyerrhandle;
  799.  
  800. yyerrdefault:  /* current state does not do anything special for the error token. */
  801.  
  802. #if 0
  803.   /* This is wrong; only states that explicitly want error tokens
  804.      should shift them.  */
  805.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  806.   if (yyn) goto yydefault;
  807. #endif
  808.  
  809. yyerrpop:   /* pop the current state because it cannot handle the error token */
  810.  
  811.   if (yyssp == yyss) YYERROR;
  812.   yyvsp--;
  813.   yylsp--;
  814.   yystate = *--yyssp;
  815.  
  816. #ifdef YYDEBUG
  817.   if (yydebug)
  818.     {
  819.       short *ssp1 = yyss - 1;
  820.       fprintf (stderr, "Error: state stack now", yyssp-yyss);
  821.       while (ssp1 != yyssp)
  822.     fprintf (stderr, " %d", *++ssp1);
  823.       fprintf (stderr, "\n");
  824.     }
  825. #endif
  826.  
  827. yyerrhandle:
  828.  
  829.   yyn = yypact[yystate];
  830.   if (yyn == YYFLAG)
  831.     goto yyerrdefault;
  832.  
  833.   yyn += YYTERROR;
  834.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  835.     goto yyerrdefault;
  836.  
  837.   yyn = yytable[yyn];
  838.   if (yyn < 0)
  839.     {
  840.       if (yyn == YYFLAG)
  841.     goto yyerrpop;
  842.       yyn = -yyn;
  843.       goto yyreduce;
  844.     }
  845.   else if (yyn == 0)
  846.     goto yyerrpop;
  847.  
  848.   if (yyn == YYFINAL)
  849.     YYACCEPT;
  850.  
  851. #ifdef YYDEBUG
  852.   if (yydebug)
  853.     fprintf(stderr, "Shifting error token, ");
  854. #endif
  855.  
  856.   *++yyvsp = yylval;
  857.   *++yylsp = yylloc;
  858.  
  859.   yystate = yyn;
  860.   goto yynewstate;
  861. }
  862. #line 221 "cexp.y"
  863.  
  864.  
  865. /* During parsing of a C expression, the pointer to the next character
  866.    is in this variable.  */
  867.  
  868. static char *lexptr;
  869.  
  870. /* Take care of parsing a number (anything that starts with a digit).
  871.    Set yylval and return the token type; update lexptr.
  872.    LEN is the number of characters in it.  */
  873.  
  874. /* maybe needs to actually deal with floating point numbers */
  875.  
  876. int
  877. parse_number (olen)
  878.      int olen;
  879. {
  880.   register char *p = lexptr;
  881.   register long n = 0;
  882.   register int c;
  883.   register int base = 10;
  884.   register len = olen;
  885.   char *err_copy;
  886.  
  887.   extern double atof ();
  888.  
  889.   for (c = 0; c < len; c++)
  890.     if (p[c] == '.') {
  891.       /* It's a float since it contains a point.  */
  892.       yyerror ("floating point numbers not allowed in #if expressions");
  893.       return ERROR;
  894.       
  895. /* ****************
  896.      yylval.dval = atof (p);
  897.      lexptr += len;
  898.      return FLOAT;
  899.          ****************  */
  900.     }
  901.   
  902.   if (len >= 3 && (!strncmp (p, "0x", 2) || !strncmp (p, "0X", 2))) {
  903.     p += 2;
  904.     base = 16;
  905.     len -= 2;
  906.   }
  907.   else if (*p == '0')
  908.     base = 8;
  909.   
  910.   while (len-- > 0) {
  911.     c = *p++;
  912.     n *= base;
  913.     if (c >= '0' && c <= '9')
  914.       n += c - '0';
  915.     else {
  916.       if (c >= 'A' && c <= 'Z') c += 'a' - 'A';
  917.       if (base == 16 && c >= 'a' && c <= 'f')
  918.     n += c - 'a' + 10;
  919.       else if (len == 0 && c == 'l')
  920.     ;
  921.       else {
  922.     yyerror ("Invalid number in #if expression");
  923.     return ERROR;
  924.       }
  925.     }
  926.   }
  927.  
  928.   lexptr = p;
  929.   yylval.lval = n;
  930.   return INT;
  931. }
  932.  
  933. struct token {
  934.   char *operator;
  935.   int token;
  936. };
  937.  
  938. #define NULL 0
  939.  
  940. static struct token tokentab2[] = {
  941.   {"&&", AND},
  942.   {"||", OR},
  943.   {"<<", LSH},
  944.   {">>", RSH},
  945.   {"==", EQUAL},
  946.   {"!=", NOTEQUAL},
  947.   {"<=", LEQ},
  948.   {">=", GEQ},
  949.   {NULL, ERROR}
  950. };
  951.  
  952. /* Read one token, getting characters through lexptr.  */
  953.  
  954. int
  955. yylex ()
  956. {
  957.   register int c;
  958.   register int namelen;
  959.   register char *tokstart;
  960.   register struct token *toktab;
  961.  
  962.  retry:
  963.  
  964.   tokstart = lexptr;
  965.   c = *tokstart;
  966.   /* See if it is a special token of length 2.  */
  967.   for (toktab = tokentab2; toktab->operator != NULL; toktab++)
  968.     if (c == *toktab->operator && tokstart[1] == toktab->operator[1]) {
  969.       lexptr += 2;
  970.       return toktab->token;
  971.     }
  972.  
  973.   switch (c) {
  974.   case 0:
  975.     return 0;
  976.     
  977.   case ' ':
  978.   case '\t':
  979.   case '\n':
  980.     lexptr++;
  981.     goto retry;
  982.     
  983.   case '\'':
  984.     lexptr++;
  985.     c = *lexptr++;
  986.     if (c == '\\')
  987.       c = parse_escape (&lexptr);
  988.     yylval.lval = c;
  989.     c = *lexptr++;
  990.     if (c != '\'') {
  991.       yyerror ("Invalid character constant in #if");
  992.       return ERROR;
  993.     }
  994.     
  995.     return CHAR;
  996.  
  997.     /* some of these chars are invalid in constant expressions;
  998.        maybe do something about them later */
  999.   case '/':
  1000.   case '+':
  1001.   case '-':
  1002.   case '*':
  1003.   case '%':
  1004.   case '|':
  1005.   case '&':
  1006.   case '^':
  1007.   case '~':
  1008.   case '!':
  1009.   case '@':
  1010.   case '<':
  1011.   case '>':
  1012.   case '(':
  1013.   case ')':
  1014.   case '[':
  1015.   case ']':
  1016.   case '.':
  1017.   case '?':
  1018.   case ':':
  1019.   case '=':
  1020.   case '{':
  1021.   case '}':
  1022.   case ',':
  1023.     lexptr++;
  1024.     return c;
  1025.     
  1026.   case '"':
  1027.     yyerror ("double quoted strings not allowed in #if expressions");
  1028.     return ERROR;
  1029.   }
  1030.   if (c >= '0' && c <= '9') {
  1031.     /* It's a number */
  1032.     for (namelen = 0;
  1033.      c = tokstart[namelen], is_idchar[c] || c == '.'; 
  1034.      namelen++)
  1035.       ;
  1036.     return parse_number (namelen);
  1037.   }
  1038.   
  1039.   if (!is_idstart[c]) {
  1040.     yyerror ("Invalid token in expression");
  1041.     return ERROR;
  1042.   }
  1043.   
  1044.   /* It is a name.  See how long it is.  */
  1045.   
  1046.   for (namelen = 0; is_idchar[tokstart[namelen]]; namelen++)
  1047.     ;
  1048.   
  1049.   lexptr += namelen;
  1050.   return NAME;
  1051. }
  1052.  
  1053.  
  1054. /* Parse a C escape sequence.  STRING_PTR points to a variable
  1055.    containing a pointer to the string to parse.  That pointer
  1056.    is updated past the characters we use.  The value of the
  1057.    escape sequence is returned.
  1058.  
  1059.    A negative value means the sequence \ newline was seen,
  1060.    which is supposed to be equivalent to nothing at all.
  1061.  
  1062.    If \ is followed by a null character, we return a negative
  1063.    value and leave the string pointer pointing at the null character.
  1064.  
  1065.    If \ is followed by 000, we return 0 and leave the string pointer
  1066.    after the zeros.  A value of 0 does not mean end of string.  */
  1067.  
  1068. int
  1069. parse_escape (string_ptr)
  1070.      char **string_ptr;
  1071. {
  1072.   register int c = *(*string_ptr)++;
  1073.   switch (c)
  1074.     {
  1075.     case 'a':
  1076.       return '\a';
  1077.     case 'b':
  1078.       return '\b';
  1079.     case 'e':
  1080.       return 033;
  1081.     case 'f':
  1082.       return '\f';
  1083.     case 'n':
  1084.       return '\n';
  1085.     case 'r':
  1086.       return '\r';
  1087.     case 't':
  1088.       return '\t';
  1089.     case 'v':
  1090.       return '\v';
  1091.     case '\n':
  1092.       return -2;
  1093.     case 0:
  1094.       (*string_ptr)--;
  1095.       return 0;
  1096.     case '^':
  1097.       c = *(*string_ptr)++;
  1098.       if (c == '\\')
  1099.     c = parse_escape (string_ptr);
  1100.       if (c == '?')
  1101.     return 0177;
  1102.       return (c & 0200) | (c & 037);
  1103.       
  1104.     case '0':
  1105.     case '1':
  1106.     case '2':
  1107.     case '3':
  1108.     case '4':
  1109.     case '5':
  1110.     case '6':
  1111.     case '7':
  1112.       {
  1113.     register int i = c - '0';
  1114.     register int count = 0;
  1115.     while (++count < 3)
  1116.       {
  1117.         if ((c = *(*string_ptr)++) >= '0' && c <= '7')
  1118.           {
  1119.         i *= 8;
  1120.         i += c - '0';
  1121.           }
  1122.         else
  1123.           {
  1124.         (*string_ptr)--;
  1125.         break;
  1126.           }
  1127.       }
  1128.     return i;
  1129.       }
  1130.     default:
  1131.       return c;
  1132.     }
  1133. }
  1134.  
  1135. void
  1136. yyerror (s)
  1137.      char *s;
  1138. {
  1139.   error (s);
  1140.   longjmp (parse_return_error, 1);
  1141. }
  1142.  
  1143. /* This page contains the entry point to this file.  */
  1144.  
  1145. /* Parse STRING as an expression, and complain if this fails
  1146.    to use up all of the contents of STRING.  */
  1147. /* We do not support C comments.  They should be removed before
  1148.    this function is called.  */
  1149.  
  1150. int
  1151. parse_c_expression (string)
  1152.      char *string;
  1153. {
  1154.   lexptr = string;
  1155.   
  1156.   if (lexptr == 0 || *lexptr == 0) {
  1157.     error ("empty #if expression");
  1158.     return 0;            /* don't include the #if group */
  1159.   }
  1160.  
  1161.   /* if there is some sort of scanning error, just return 0 and assume
  1162.      the parsing routine has printed an error message somewhere.
  1163.      there is surely a better thing to do than this.     */
  1164.   if (setjmp(parse_return_error))
  1165.     return 0;
  1166.  
  1167.   if (yyparse ())
  1168.     return 0;            /* actually this is never reached
  1169.                    the way things stand. */
  1170.   if (*lexptr)
  1171.     error ("Junk after end of expression.");
  1172.  
  1173.   return expression_value;    /* set by yyparse() */
  1174. }
  1175.  
  1176. #ifdef TEST_EXP_READER
  1177. /* main program, for testing purposes. */
  1178. main()
  1179. {
  1180.   int n;
  1181.   char buf[1024];
  1182.   extern int yydebug;
  1183. /*
  1184.   yydebug = 1;
  1185. */
  1186.   initialize_random_junk ();
  1187.  
  1188.   for (;;) {
  1189.     printf("enter expression: ");
  1190.     n = 0;
  1191.     while ((buf[n] = getchar()) != '\n')
  1192.       n++;
  1193.     buf[n] = '\0';
  1194.     printf("parser returned %d\n", parse_c_expression(buf));
  1195.   }
  1196. }
  1197.  
  1198. /* table to tell if char can be part of a C identifier. */
  1199. char is_idchar[256];
  1200. /* table to tell if char can be first char of a c identifier. */
  1201. char is_idstart[256];
  1202. /* table to tell if c is horizontal space.  isspace() thinks that
  1203.    newline is space; this is not a good idea for this program. */
  1204. char is_hor_space[256];
  1205.  
  1206. /*
  1207.  * initialize random junk in the hash table and maybe other places
  1208.  */
  1209. initialize_random_junk()
  1210. {
  1211.   register int i;
  1212.  
  1213.   /*
  1214.    * Set up is_idchar and is_idstart tables.  These should be
  1215.    * faster than saying (is_alpha(c) || c == '_'), etc.
  1216.    * Must do set up these things before calling any routines tthat
  1217.    * refer to them.
  1218.    */
  1219.   for (i = 'a'; i <= 'z'; i++) {
  1220.     ++is_idchar[i - 'a' + 'A'];
  1221.     ++is_idchar[i];
  1222.     ++is_idstart[i - 'a' + 'A'];
  1223.     ++is_idstart[i];
  1224.   }
  1225.   for (i = '0'; i <= '9'; i++)
  1226.     ++is_idchar[i];
  1227.   ++is_idchar['_'];
  1228.   ++is_idstart['_'];
  1229. #ifdef DOLLARS_IN_IDENTIFIERS
  1230.   ++is_idchar['$'];
  1231.   ++is_idstart['$'];
  1232. #endif
  1233.  
  1234.   /* horizontal space table */
  1235.   ++is_hor_space[' '];
  1236.   ++is_hor_space['\t'];
  1237. }
  1238.  
  1239. error (msg)
  1240. {
  1241.   printf("error: %s\n", msg);
  1242. }
  1243. #endif
  1244.