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