home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / debug / fsdb / expr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-10  |  29.9 KB  |  1,135 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2.  
  3. /*  A Bison parser, made from expr.y with Bison version GNU Bison version 1.22
  4.   */
  5.  
  6. #define YYBISON 1  /* Identify Bison output.  */
  7.  
  8. #define    NUM    258
  9. #define    OP_LOR    259
  10. #define    OP_LAND    260
  11. #define    OP_EQ    261
  12. #define    OP_NE    262
  13. #define    OP_LE    263
  14. #define    OP_GE    264
  15. #define    OP_SHL    265
  16. #define    OP_SHR    266
  17. #define    OP_NEG    267
  18. #define    OP_LNOT    268
  19. #define    OP_NOT    269
  20.  
  21. #line 1 "expr.y"
  22.  
  23.  
  24. #include <ctype.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #ifndef TEST
  28. #include "ed.h"
  29. #include <debug/syms.h>
  30. #endif
  31. #define YYSTYPE long
  32.  
  33.  
  34. #ifdef TEST
  35. unsigned long syms_name2val (char *);
  36. int main (int, char **);
  37. int undefined_symbol = 0;
  38. #define valid_addr(x,y) 0
  39. #define read_child (void)
  40. #endif
  41. int evaluate (char *, long *, char **);
  42. static int yylex ();
  43. static void yyerror (char *);
  44.  
  45. static long result;
  46. static char *input;
  47. static char *error;
  48.  
  49.  
  50. #ifndef YYLTYPE
  51. typedef
  52.   struct yyltype
  53.     {
  54.       int timestamp;
  55.       int first_line;
  56.       int first_column;
  57.       int last_line;
  58.       int last_column;
  59.       char *text;
  60.    }
  61.   yyltype;
  62.  
  63. #define YYLTYPE yyltype
  64. #endif
  65.  
  66. #ifndef YYSTYPE
  67. #define YYSTYPE int
  68. #endif
  69. #include <stdio.h>
  70.  
  71. #ifndef __cplusplus
  72. #ifndef __STDC__
  73. #define const
  74. #endif
  75. #endif
  76.  
  77.  
  78.  
  79. #define    YYFINAL        55
  80. #define    YYFLAG        -32768
  81. #define    YYNTBASE    32
  82.  
  83. #define YYTRANSLATE(x) ((unsigned)(x) <= 269 ? yytranslate[x] : 34)
  84.  
  85. static const char yytranslate[] = {     0,
  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,     2,     2,     2,     2,     2,     2,     2,
  89.      2,     2,    26,     2,     2,     2,    21,     8,     2,    28,
  90.     29,    19,    17,     2,    18,     2,    20,     2,     2,     2,
  91.      2,     2,     2,     2,     2,     2,     2,    22,     2,    10,
  92.      2,    11,     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.     30,     2,    31,     6,     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,     5,     2,    27,     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,     2,     2,     2,     2,     2,
  102.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  103.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  104.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  105.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  106.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  107.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  108.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  109.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  110.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  111.      2,     2,     2,     2,     2,     1,     2,     3,     4,     7,
  112.      9,    12,    13,    14,    15,    16,    23,    24,    25
  113. };
  114.  
  115. #if YYDEBUG != 0
  116. static const short yyprhs[] = {     0,
  117.      0,     2,     4,     8,    12,    16,    20,    24,    28,    32,
  118.     36,    40,    44,    48,    52,    56,    60,    64,    68,    72,
  119.     76,    79,    82,    85,    89,    93
  120. };
  121.  
  122. static const short yyrhs[] = {    33,
  123.      0,     3,     0,    33,     4,    33,     0,    33,     7,    33,
  124.      0,    33,     5,    33,     0,    33,     8,    33,     0,    33,
  125.      6,    33,     0,    33,     9,    33,     0,    33,    11,    33,
  126.      0,    33,    10,    33,     0,    33,    14,    33,     0,    33,
  127.     13,    33,     0,    33,    12,    33,     0,    33,    15,    33,
  128.      0,    33,    16,    33,     0,    33,    17,    33,     0,    33,
  129.     18,    33,     0,    33,    19,    33,     0,    33,    20,    33,
  130.      0,    33,    21,    33,     0,    18,    33,     0,    26,    33,
  131.      0,    27,    33,     0,    28,    33,    29,     0,    30,    33,
  132.     31,     0,    33,    22,     3,     0
  133. };
  134.  
  135. #endif
  136.  
  137. #if YYDEBUG != 0
  138. static const short yyrline[] = { 0,
  139.     46,    49,    50,    51,    52,    53,    54,    55,    56,    57,
  140.     58,    59,    60,    61,    62,    63,    64,    65,    66,    68,
  141.     70,    71,    72,    73,    74,    80
  142. };
  143.  
  144. static const char * const yytname[] = {   "$","error","$illegal.","NUM","OP_LOR",
  145. "'|'","'^'","OP_LAND","'&'","OP_EQ","'<'","'>'","OP_NE","OP_LE","OP_GE","OP_SHL",
  146. "OP_SHR","'+'","'-'","'*'","'/'","'%'","':'","OP_NEG","OP_LNOT","OP_NOT","'!'",
  147. "'~'","'('","')'","'['","']'","main","expr",""
  148. };
  149. #endif
  150.  
  151. static const short yyr1[] = {     0,
  152.     32,    33,    33,    33,    33,    33,    33,    33,    33,    33,
  153.     33,    33,    33,    33,    33,    33,    33,    33,    33,    33,
  154.     33,    33,    33,    33,    33,    33
  155. };
  156.  
  157. static const short yyr2[] = {     0,
  158.      1,     1,     3,     3,     3,     3,     3,     3,     3,     3,
  159.      3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
  160.      2,     2,     2,     3,     3,     3
  161. };
  162.  
  163. static const short yydefact[] = {     0,
  164.      2,     0,     0,     0,     0,     0,     1,    21,    22,    23,
  165.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  166.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  167.      0,    24,    25,     3,     5,     7,     4,     6,     8,    10,
  168.      9,    13,    12,    11,    14,    15,    16,    17,    18,    19,
  169.     20,    26,     0,     0,     0
  170. };
  171.  
  172. static const short yydefgoto[] = {    53,
  173.      7
  174. };
  175.  
  176. static const short yypact[] = {    45,
  177. -32768,    45,    45,    45,    45,    45,    98,-32768,-32768,-32768,
  178.     72,    25,    45,    45,    45,    45,    45,    45,    45,    45,
  179.     45,    45,    45,    45,    45,    45,    45,    45,    45,    45,
  180.     50,-32768,-32768,   114,   114,   114,   128,   128,   142,   142,
  181.    142,   142,   142,   142,   -12,   -12,    30,    30,    32,    32,
  182.     32,-32768,    55,    57,-32768
  183. };
  184.  
  185. static const short yypgoto[] = {-32768,
  186.     -2
  187. };
  188.  
  189.  
  190. #define    YYLAST        164
  191.  
  192.  
  193. static const short yytable[] = {     8,
  194.      9,    10,    11,    12,    26,    27,    28,    29,    30,    31,
  195.     34,    35,    36,    37,    38,    39,    40,    41,    42,    43,
  196.     44,    45,    46,    47,    48,    49,    50,    51,    13,    14,
  197.     15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
  198.     25,    26,    27,    28,    29,    30,    31,     1,    28,    29,
  199.     30,    31,    52,    31,    54,    33,    55,     0,     0,     0,
  200.      0,     0,     2,     0,     0,     0,     0,     0,     0,     0,
  201.      3,     4,     5,     0,     6,    13,    14,    15,    16,    17,
  202.     18,    19,    20,    21,    22,    23,    24,    25,    26,    27,
  203.     28,    29,    30,    31,     0,     0,     0,     0,     0,     0,
  204.     32,    13,    14,    15,    16,    17,    18,    19,    20,    21,
  205.     22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
  206.     16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
  207.     26,    27,    28,    29,    30,    31,    18,    19,    20,    21,
  208.     22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
  209. -32768,-32768,-32768,-32768,-32768,-32768,    24,    25,    26,    27,
  210.     28,    29,    30,    31
  211. };
  212.  
  213. static const short yycheck[] = {     2,
  214.      3,     4,     5,     6,    17,    18,    19,    20,    21,    22,
  215.     13,    14,    15,    16,    17,    18,    19,    20,    21,    22,
  216.     23,    24,    25,    26,    27,    28,    29,    30,     4,     5,
  217.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
  218.     16,    17,    18,    19,    20,    21,    22,     3,    19,    20,
  219.     21,    22,     3,    22,     0,    31,     0,    -1,    -1,    -1,
  220.     -1,    -1,    18,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  221.     26,    27,    28,    -1,    30,     4,     5,     6,     7,     8,
  222.      9,    10,    11,    12,    13,    14,    15,    16,    17,    18,
  223.     19,    20,    21,    22,    -1,    -1,    -1,    -1,    -1,    -1,
  224.     29,     4,     5,     6,     7,     8,     9,    10,    11,    12,
  225.     13,    14,    15,    16,    17,    18,    19,    20,    21,    22,
  226.      7,     8,     9,    10,    11,    12,    13,    14,    15,    16,
  227.     17,    18,    19,    20,    21,    22,     9,    10,    11,    12,
  228.     13,    14,    15,    16,    17,    18,    19,    20,    21,    22,
  229.      9,    10,    11,    12,    13,    14,    15,    16,    17,    18,
  230.     19,    20,    21,    22
  231. };
  232. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  233. #line 3 "bison.simple"
  234.  
  235. /* Skeleton output parser for bison,
  236.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  237.  
  238.    This program is free software; you can redistribute it and/or modify
  239.    it under the terms of the GNU General Public License as published by
  240.    the Free Software Foundation; either version 1, or (at your option)
  241.    any later version.
  242.  
  243.    This program is distributed in the hope that it will be useful,
  244.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  245.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  246.    GNU General Public License for more details.
  247.  
  248.    You should have received a copy of the GNU General Public License
  249.    along with this program; if not, write to the Free Software
  250.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  251.  
  252.  
  253. #ifndef alloca
  254. #ifdef __GNUC__
  255. #define alloca __builtin_alloca
  256. #else /* not GNU C.  */
  257. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
  258. #include <alloca.h>
  259. #else /* not sparc */
  260. #if defined (MSDOS) && !defined (__TURBOC__)
  261. #include <malloc.h>
  262. #else /* not MSDOS, or __TURBOC__ */
  263. #if defined(_AIX)
  264. #include <malloc.h>
  265.  #pragma alloca
  266. #else /* not MSDOS, __TURBOC__, or _AIX */
  267. #ifdef __hpux
  268. #ifdef __cplusplus
  269. extern "C" {
  270. void *alloca (unsigned int);
  271. };
  272. #else /* not __cplusplus */
  273. void *alloca ();
  274. #endif /* not __cplusplus */
  275. #endif /* __hpux */
  276. #endif /* not _AIX */
  277. #endif /* not MSDOS, or __TURBOC__ */
  278. #endif /* not sparc.  */
  279. #endif /* not GNU C.  */
  280. #endif /* alloca not defined.  */
  281.  
  282. /* This is the parser code that is written into each bison parser
  283.   when the %semantic_parser declaration is not specified in the grammar.
  284.   It was written by Richard Stallman by simplifying the hairy parser
  285.   used when %semantic_parser is specified.  */
  286.  
  287. /* Note: there must be only one dollar sign in this file.
  288.    It is replaced by the list of actions, each action
  289.    as one case of the switch.  */
  290.  
  291. #define yyerrok        (yyerrstatus = 0)
  292. #define yyclearin    (yychar = YYEMPTY)
  293. #define YYEMPTY        -2
  294. #define YYEOF        0
  295. #define YYACCEPT    return(0)
  296. #define YYABORT     return(1)
  297. #define YYERROR        goto yyerrlab1
  298. /* Like YYERROR except do call yyerror.
  299.    This remains here temporarily to ease the
  300.    transition to the new meaning of YYERROR, for GCC.
  301.    Once GCC version 2 has supplanted version 1, this can go.  */
  302. #define YYFAIL        goto yyerrlab
  303. #define YYRECOVERING()  (!!yyerrstatus)
  304. #define YYBACKUP(token, value) \
  305. do                                \
  306.   if (yychar == YYEMPTY && yylen == 1)                \
  307.     { yychar = (token), yylval = (value);            \
  308.       yychar1 = YYTRANSLATE (yychar);                \
  309.       YYPOPSTACK;                        \
  310.       goto yybackup;                        \
  311.     }                                \
  312.   else                                \
  313.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  314. while (0)
  315.  
  316. #define YYTERROR    1
  317. #define YYERRCODE    256
  318.  
  319. #ifndef YYPURE
  320. #define YYLEX        yylex()
  321. #endif
  322.  
  323. #ifdef YYPURE
  324. #ifdef YYLSP_NEEDED
  325. #define YYLEX        yylex(&yylval, &yylloc)
  326. #else
  327. #define YYLEX        yylex(&yylval)
  328. #endif
  329. #endif
  330.  
  331. /* If nonreentrant, generate the variables here */
  332.  
  333. #ifndef YYPURE
  334.  
  335. int    yychar;            /*  the lookahead symbol        */
  336. YYSTYPE    yylval;            /*  the semantic value of the        */
  337.                 /*  lookahead symbol            */
  338.  
  339. #ifdef YYLSP_NEEDED
  340. YYLTYPE yylloc;            /*  location data for the lookahead    */
  341.                 /*  symbol                */
  342. #endif
  343.  
  344. int yynerrs;            /*  number of parse errors so far       */
  345. #endif  /* not YYPURE */
  346.  
  347. #if YYDEBUG != 0
  348. int yydebug;            /*  nonzero means print parse trace    */
  349. /* Since this is uninitialized, it does not stop multiple parsers
  350.    from coexisting.  */
  351. #endif
  352.  
  353. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  354.  
  355. #ifndef    YYINITDEPTH
  356. #define YYINITDEPTH 200
  357. #endif
  358.  
  359. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  360.     (effective only if the built-in stack extension method is used).  */
  361.  
  362. #if YYMAXDEPTH == 0
  363. #undef YYMAXDEPTH
  364. #endif
  365.  
  366. #ifndef YYMAXDEPTH
  367. #define YYMAXDEPTH 10000
  368. #endif
  369.  
  370. /* Prevent warning if -Wstrict-prototypes.  */
  371. #ifdef __GNUC__
  372. int yyparse (void);
  373. #endif
  374.  
  375. #if __GNUC__ > 1        /* GNU C and GNU C++ define this.  */
  376. #define __yy_bcopy(FROM,TO,COUNT)    __builtin_memcpy(TO,FROM,COUNT)
  377. #else                /* not GNU C or C++ */
  378. #ifndef __cplusplus
  379.  
  380. /* This is the most reliable way to avoid incompatibilities
  381.    in available built-in functions on various systems.  */
  382. static void
  383. __yy_bcopy (from, to, count)
  384.      char *from;
  385.      char *to;
  386.      int count;
  387. {
  388.   register char *f = from;
  389.   register char *t = to;
  390.   register int i = count;
  391.  
  392.   while (i-- > 0)
  393.     *t++ = *f++;
  394. }
  395.  
  396. #else /* __cplusplus */
  397.  
  398. /* This is the most reliable way to avoid incompatibilities
  399.    in available built-in functions on various systems.  */
  400. static void
  401. __yy_bcopy (char *from, char *to, int count)
  402. {
  403.   register char *f = from;
  404.   register char *t = to;
  405.   register int i = count;
  406.  
  407.   while (i-- > 0)
  408.     *t++ = *f++;
  409. }
  410.  
  411. #endif
  412. #endif
  413.  
  414. #line 184 "bison.simple"
  415. int
  416. yyparse()
  417. {
  418.   register int yystate;
  419.   register int yyn;
  420.   register short *yyssp;
  421.   register YYSTYPE *yyvsp;
  422.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  423.   int yychar1 = 0;        /*  lookahead token as an internal (translated) token number */
  424.  
  425.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  426.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  427.  
  428.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  429.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  430.  
  431. #ifdef YYLSP_NEEDED
  432.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  433.   YYLTYPE *yyls = yylsa;
  434.   YYLTYPE *yylsp;
  435.  
  436. #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
  437. #else
  438. #define YYPOPSTACK   (yyvsp--, yyssp--)
  439. #endif
  440.  
  441.   int yystacksize = YYINITDEPTH;
  442.  
  443. #ifdef YYPURE
  444.   int yychar;
  445.   YYSTYPE yylval;
  446.   int yynerrs;
  447. #ifdef YYLSP_NEEDED
  448.   YYLTYPE yylloc;
  449. #endif
  450. #endif
  451.  
  452.   YYSTYPE yyval;        /*  the variable used to return        */
  453.                 /*  semantic values from the action    */
  454.                 /*  routines                */
  455.  
  456.   int yylen;
  457.  
  458. #if YYDEBUG != 0
  459.   if (yydebug)
  460.     fprintf(stderr, "Starting parse\n");
  461. #endif
  462.  
  463.   yystate = 0;
  464.   yyerrstatus = 0;
  465.   yynerrs = 0;
  466.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  467.  
  468.   /* Initialize stack pointers.
  469.      Waste one element of value and location stack
  470.      so that they stay on the same level as the state stack.
  471.      The wasted elements are never initialized.  */
  472.  
  473.   yyssp = yyss - 1;
  474.   yyvsp = yyvs;
  475. #ifdef YYLSP_NEEDED
  476.   yylsp = yyls;
  477. #endif
  478.  
  479. /* Push a new state, which is found in  yystate  .  */
  480. /* In all cases, when you get here, the value and location stacks
  481.    have just been pushed. so pushing a state here evens the stacks.  */
  482. yynewstate:
  483.  
  484.   *++yyssp = yystate;
  485.  
  486.   if (yyssp >= yyss + yystacksize - 1)
  487.     {
  488.       /* Give user a chance to reallocate the stack */
  489.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  490.       YYSTYPE *yyvs1 = yyvs;
  491.       short *yyss1 = yyss;
  492. #ifdef YYLSP_NEEDED
  493.       YYLTYPE *yyls1 = yyls;
  494. #endif
  495.  
  496.       /* Get the current used size of the three stacks, in elements.  */
  497.       int size = yyssp - yyss + 1;
  498.  
  499. #ifdef yyoverflow
  500.       /* Each stack pointer address is followed by the size of
  501.      the data in use in that stack, in bytes.  */
  502. #ifdef YYLSP_NEEDED
  503.       /* This used to be a conditional around just the two extra args,
  504.      but that might be undefined if yyoverflow is a macro.  */
  505.       yyoverflow("parser stack overflow",
  506.          &yyss1, size * sizeof (*yyssp),
  507.          &yyvs1, size * sizeof (*yyvsp),
  508.          &yyls1, size * sizeof (*yylsp),
  509.          &yystacksize);
  510. #else
  511.       yyoverflow("parser stack overflow",
  512.          &yyss1, size * sizeof (*yyssp),
  513.          &yyvs1, size * sizeof (*yyvsp),
  514.          &yystacksize);
  515. #endif
  516.  
  517.       yyss = yyss1; yyvs = yyvs1;
  518. #ifdef YYLSP_NEEDED
  519.       yyls = yyls1;
  520. #endif
  521. #else /* no yyoverflow */
  522.       /* Extend the stack our own way.  */
  523.       if (yystacksize >= YYMAXDEPTH)
  524.     {
  525.       yyerror("parser stack overflow");
  526.       return 2;
  527.     }
  528.       yystacksize *= 2;
  529.       if (yystacksize > YYMAXDEPTH)
  530.     yystacksize = YYMAXDEPTH;
  531.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  532.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  533.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  534.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  535. #ifdef YYLSP_NEEDED
  536.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  537.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  538. #endif
  539. #endif /* no yyoverflow */
  540.  
  541.       yyssp = yyss + size - 1;
  542.       yyvsp = yyvs + size - 1;
  543. #ifdef YYLSP_NEEDED
  544.       yylsp = yyls + size - 1;
  545. #endif
  546.  
  547. #if YYDEBUG != 0
  548.       if (yydebug)
  549.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  550. #endif
  551.  
  552.       if (yyssp >= yyss + yystacksize - 1)
  553.     YYABORT;
  554.     }
  555.  
  556. #if YYDEBUG != 0
  557.   if (yydebug)
  558.     fprintf(stderr, "Entering state %d\n", yystate);
  559. #endif
  560.  
  561.   goto yybackup;
  562.  yybackup:
  563.  
  564. /* Do appropriate processing given the current state.  */
  565. /* Read a lookahead token if we need one and don't already have one.  */
  566. /* yyresume: */
  567.  
  568.   /* First try to decide what to do without reference to lookahead token.  */
  569.  
  570.   yyn = yypact[yystate];
  571.   if (yyn == YYFLAG)
  572.     goto yydefault;
  573.  
  574.   /* Not known => get a lookahead token if don't already have one.  */
  575.  
  576.   /* yychar is either YYEMPTY or YYEOF
  577.      or a valid token in external form.  */
  578.  
  579.   if (yychar == YYEMPTY)
  580.     {
  581. #if YYDEBUG != 0
  582.       if (yydebug)
  583.     fprintf(stderr, "Reading a token: ");
  584. #endif
  585.       yychar = YYLEX;
  586.     }
  587.  
  588.   /* Convert token to internal form (in yychar1) for indexing tables with */
  589.  
  590.   if (yychar <= 0)        /* This means end of input. */
  591.     {
  592.       yychar1 = 0;
  593.       yychar = YYEOF;        /* Don't call YYLEX any more */
  594.  
  595. #if YYDEBUG != 0
  596.       if (yydebug)
  597.     fprintf(stderr, "Now at end of input.\n");
  598. #endif
  599.     }
  600.   else
  601.     {
  602.       yychar1 = YYTRANSLATE(yychar);
  603.  
  604. #if YYDEBUG != 0
  605.       if (yydebug)
  606.     {
  607.       fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
  608.       /* Give the individual parser a way to print the precise meaning
  609.          of a token, for further debugging info.  */
  610. #ifdef YYPRINT
  611.       YYPRINT (stderr, yychar, yylval);
  612. #endif
  613.       fprintf (stderr, ")\n");
  614.     }
  615. #endif
  616.     }
  617.  
  618.   yyn += yychar1;
  619.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  620.     goto yydefault;
  621.  
  622.   yyn = yytable[yyn];
  623.  
  624.   /* yyn is what to do for this token type in this state.
  625.      Negative => reduce, -yyn is rule number.
  626.      Positive => shift, yyn is new state.
  627.        New state is final state => don't bother to shift,
  628.        just return success.
  629.      0, or most negative number => error.  */
  630.  
  631.   if (yyn < 0)
  632.     {
  633.       if (yyn == YYFLAG)
  634.     goto yyerrlab;
  635.       yyn = -yyn;
  636.       goto yyreduce;
  637.     }
  638.   else if (yyn == 0)
  639.     goto yyerrlab;
  640.  
  641.   if (yyn == YYFINAL)
  642.     YYACCEPT;
  643.  
  644.   /* Shift the lookahead token.  */
  645.  
  646. #if YYDEBUG != 0
  647.   if (yydebug)
  648.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  649. #endif
  650.  
  651.   /* Discard the token being shifted unless it is eof.  */
  652.   if (yychar != YYEOF)
  653.     yychar = YYEMPTY;
  654.  
  655.   *++yyvsp = yylval;
  656. #ifdef YYLSP_NEEDED
  657.   *++yylsp = yylloc;
  658. #endif
  659.  
  660.   /* count tokens shifted since error; after three, turn off error status.  */
  661.   if (yyerrstatus) yyerrstatus--;
  662.  
  663.   yystate = yyn;
  664.   goto yynewstate;
  665.  
  666. /* Do the default action for the current state.  */
  667. yydefault:
  668.  
  669.   yyn = yydefact[yystate];
  670.   if (yyn == 0)
  671.     goto yyerrlab;
  672.  
  673. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  674. yyreduce:
  675.   yylen = yyr2[yyn];
  676.   if (yylen > 0)
  677.     yyval = yyvsp[1-yylen]; /* implement default value of the action */
  678.  
  679. #if YYDEBUG != 0
  680.   if (yydebug)
  681.     {
  682.       int i;
  683.  
  684.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  685.            yyn, yyrline[yyn]);
  686.  
  687.       /* Print the symbols being reduced, and their result.  */
  688.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  689.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  690.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  691.     }
  692. #endif
  693.  
  694.  
  695.   switch (yyn) {
  696.  
  697. case 1:
  698. #line 46 "expr.y"
  699. { result = yyvsp[0]; ;
  700.     break;}
  701. case 2:
  702. #line 49 "expr.y"
  703. { yyval = yyvsp[0]; ;
  704.     break;}
  705. case 3:
  706. #line 50 "expr.y"
  707. { yyval = yyvsp[-2] || yyvsp[0]; ;
  708.     break;}
  709. case 4:
  710. #line 51 "expr.y"
  711. { yyval = yyvsp[-2] && yyvsp[0]; ;
  712.     break;}
  713. case 5:
  714. #line 52 "expr.y"
  715. { yyval = yyvsp[-2] | yyvsp[0]; ;
  716.     break;}
  717. case 6:
  718. #line 53 "expr.y"
  719. { yyval = yyvsp[-2] & yyvsp[0]; ;
  720.     break;}
  721. case 7:
  722. #line 54 "expr.y"
  723. { yyval = yyvsp[-2] ^ yyvsp[0]; ;
  724.     break;}
  725. case 8:
  726. #line 55 "expr.y"
  727. { yyval = yyvsp[-2] == yyvsp[0]; ;
  728.     break;}
  729. case 9:
  730. #line 56 "expr.y"
  731. { yyval = yyvsp[-2] > yyvsp[0]; ;
  732.     break;}
  733. case 10:
  734. #line 57 "expr.y"
  735. { yyval = yyvsp[-2] < yyvsp[0]; ;
  736.     break;}
  737. case 11:
  738. #line 58 "expr.y"
  739. { yyval = yyvsp[-2] >= yyvsp[0]; ;
  740.     break;}
  741. case 12:
  742. #line 59 "expr.y"
  743. { yyval = yyvsp[-2] <= yyvsp[0]; ;
  744.     break;}
  745. case 13:
  746. #line 60 "expr.y"
  747. { yyval = yyvsp[-2] != yyvsp[0]; ;
  748.     break;}
  749. case 14:
  750. #line 61 "expr.y"
  751. { yyval = (unsigned)yyvsp[-2] << yyvsp[0]; ;
  752.     break;}
  753. case 15:
  754. #line 62 "expr.y"
  755. { yyval = (unsigned)yyvsp[-2] >> yyvsp[0]; ;
  756.     break;}
  757. case 16:
  758. #line 63 "expr.y"
  759. { yyval = yyvsp[-2] + yyvsp[0]; ;
  760.     break;}
  761. case 17:
  762. #line 64 "expr.y"
  763. { yyval = yyvsp[-2] - yyvsp[0]; ;
  764.     break;}
  765. case 18:
  766. #line 65 "expr.y"
  767. { yyval = yyvsp[-2] * yyvsp[0]; ;
  768.     break;}
  769. case 19:
  770. #line 67 "expr.y"
  771. { if (yyvsp[0]) yyval = yyvsp[-2] / yyvsp[0]; else yyerror ("Division by zero"); ;
  772.     break;}
  773. case 20:
  774. #line 69 "expr.y"
  775. { if (yyvsp[0]) yyval = yyvsp[-2] % yyvsp[0]; else yyerror ("Division by zero"); ;
  776.     break;}
  777. case 21:
  778. #line 70 "expr.y"
  779. { yyval = -yyvsp[0]; ;
  780.     break;}
  781. case 22:
  782. #line 71 "expr.y"
  783. { yyval = !yyvsp[0]; ;
  784.     break;}
  785. case 23:
  786. #line 72 "expr.y"
  787. { yyval = ~yyvsp[0]; ;
  788.     break;}
  789. case 24:
  790. #line 73 "expr.y"
  791. { yyval = yyvsp[-1]; ;
  792.     break;}
  793. case 25:
  794. #line 75 "expr.y"
  795. { if (valid_addr (yyvsp[-1], 4))
  796.           { long l; read_child (yyvsp[-1], &l, 4); yyval = l; }
  797.         else
  798.           yyerror ("Error reading child");
  799.       ;
  800.     break;}
  801. case 26:
  802. #line 81 "expr.y"
  803. { switch (yyvsp[0]) {
  804.       case 1: yyval = (yyvsp[-2] & 0xff); break;
  805.       case 2: yyval = (yyvsp[-2] & 0xffff); break;
  806.       case 4: yyval = (yyvsp[-2] & 0xffffffff); break;
  807.       default: yyerror ("Invalid resizing");
  808.       };
  809.     break;}
  810. }
  811.    /* the action file gets copied in in place of this dollarsign */
  812. #line 465 "bison.simple"
  813.  
  814.   yyvsp -= yylen;
  815.   yyssp -= yylen;
  816. #ifdef YYLSP_NEEDED
  817.   yylsp -= yylen;
  818. #endif
  819.  
  820. #if YYDEBUG != 0
  821.   if (yydebug)
  822.     {
  823.       short *ssp1 = yyss - 1;
  824.       fprintf (stderr, "state stack now");
  825.       while (ssp1 != yyssp)
  826.     fprintf (stderr, " %d", *++ssp1);
  827.       fprintf (stderr, "\n");
  828.     }
  829. #endif
  830.  
  831.   *++yyvsp = yyval;
  832.  
  833. #ifdef YYLSP_NEEDED
  834.   yylsp++;
  835.   if (yylen == 0)
  836.     {
  837.       yylsp->first_line = yylloc.first_line;
  838.       yylsp->first_column = yylloc.first_column;
  839.       yylsp->last_line = (yylsp-1)->last_line;
  840.       yylsp->last_column = (yylsp-1)->last_column;
  841.       yylsp->text = 0;
  842.     }
  843.   else
  844.     {
  845.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  846.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  847.     }
  848. #endif
  849.  
  850.   /* Now "shift" the result of the reduction.
  851.      Determine what state that goes to,
  852.      based on the state we popped back to
  853.      and the rule number reduced by.  */
  854.  
  855.   yyn = yyr1[yyn];
  856.  
  857.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  858.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  859.     yystate = yytable[yystate];
  860.   else
  861.     yystate = yydefgoto[yyn - YYNTBASE];
  862.  
  863.   goto yynewstate;
  864.  
  865. yyerrlab:   /* here on detecting error */
  866.  
  867.   if (! yyerrstatus)
  868.     /* If not already recovering from an error, report this error.  */
  869.     {
  870.       ++yynerrs;
  871.  
  872. #ifdef YYERROR_VERBOSE
  873.       yyn = yypact[yystate];
  874.  
  875.       if (yyn > YYFLAG && yyn < YYLAST)
  876.     {
  877.       int size = 0;
  878.       char *msg;
  879.       int x, count;
  880.  
  881.       count = 0;
  882.       /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */
  883.       for (x = (yyn < 0 ? -yyn : 0);
  884.            x < (sizeof(yytname) / sizeof(char *)); x++)
  885.         if (yycheck[x + yyn] == x)
  886.           size += strlen(yytname[x]) + 15, count++;
  887.       msg = (char *) malloc(size + 15);
  888.       if (msg != 0)
  889.         {
  890.           strcpy(msg, "parse error");
  891.  
  892.           if (count < 5)
  893.         {
  894.           count = 0;
  895.           for (x = (yyn < 0 ? -yyn : 0);
  896.                x < (sizeof(yytname) / sizeof(char *)); x++)
  897.             if (yycheck[x + yyn] == x)
  898.               {
  899.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  900.             strcat(msg, yytname[x]);
  901.             strcat(msg, "'");
  902.             count++;
  903.               }
  904.         }
  905.           yyerror(msg);
  906.           free(msg);
  907.         }
  908.       else
  909.         yyerror ("parse error; also virtual memory exceeded");
  910.     }
  911.       else
  912. #endif /* YYERROR_VERBOSE */
  913.     yyerror("parse error");
  914.     }
  915.  
  916.   goto yyerrlab1;
  917. yyerrlab1:   /* here on error raised explicitly by an action */
  918.  
  919.   if (yyerrstatus == 3)
  920.     {
  921.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  922.  
  923.       /* return failure if at end of input */
  924.       if (yychar == YYEOF)
  925.     YYABORT;
  926.  
  927. #if YYDEBUG != 0
  928.       if (yydebug)
  929.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  930. #endif
  931.  
  932.       yychar = YYEMPTY;
  933.     }
  934.  
  935.   /* Else will try to reuse lookahead token
  936.      after shifting the error token.  */
  937.  
  938.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  939.  
  940.   goto yyerrhandle;
  941.  
  942. yyerrdefault:  /* current state does not do anything special for the error token. */
  943.  
  944. #if 0
  945.   /* This is wrong; only states that explicitly want error tokens
  946.      should shift them.  */
  947.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  948.   if (yyn) goto yydefault;
  949. #endif
  950.  
  951. yyerrpop:   /* pop the current state because it cannot handle the error token */
  952.  
  953.   if (yyssp == yyss) YYABORT;
  954.   yyvsp--;
  955.   yystate = *--yyssp;
  956. #ifdef YYLSP_NEEDED
  957.   yylsp--;
  958. #endif
  959.  
  960. #if YYDEBUG != 0
  961.   if (yydebug)
  962.     {
  963.       short *ssp1 = yyss - 1;
  964.       fprintf (stderr, "Error: state stack now");
  965.       while (ssp1 != yyssp)
  966.     fprintf (stderr, " %d", *++ssp1);
  967.       fprintf (stderr, "\n");
  968.     }
  969. #endif
  970.  
  971. yyerrhandle:
  972.  
  973.   yyn = yypact[yystate];
  974.   if (yyn == YYFLAG)
  975.     goto yyerrdefault;
  976.  
  977.   yyn += YYTERROR;
  978.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  979.     goto yyerrdefault;
  980.  
  981.   yyn = yytable[yyn];
  982.   if (yyn < 0)
  983.     {
  984.       if (yyn == YYFLAG)
  985.     goto yyerrpop;
  986.       yyn = -yyn;
  987.       goto yyreduce;
  988.     }
  989.   else if (yyn == 0)
  990.     goto yyerrpop;
  991.  
  992.   if (yyn == YYFINAL)
  993.     YYACCEPT;
  994.  
  995. #if YYDEBUG != 0
  996.   if (yydebug)
  997.     fprintf(stderr, "Shifting error token, ");
  998. #endif
  999.  
  1000.   *++yyvsp = yylval;
  1001. #ifdef YYLSP_NEEDED
  1002.   *++yylsp = yylloc;
  1003. #endif
  1004.  
  1005.   yystate = yyn;
  1006.   goto yynewstate;
  1007. }
  1008. #line 89 "expr.y"
  1009.  
  1010.  
  1011. static int
  1012. yylex ()
  1013. {
  1014.   char *p, save;
  1015.   int i;
  1016.   static struct {
  1017.     char c1, c2;
  1018.     int token;
  1019.   } twochars[] = {
  1020.     { '=', '=', OP_EQ },
  1021.     { '>', '=', OP_GE },
  1022.     { '<', '=', OP_LE },
  1023.     { '!', '=', OP_NE },
  1024.     { '&', '&', OP_LAND},
  1025.     { '|', '|', OP_LOR },
  1026.     { '<', '<', OP_SHL},
  1027.     { '>', '>', OP_SHR}};
  1028.  
  1029.   while (isspace (*input)) input++;
  1030.   switch (*input)
  1031.     {
  1032.     case '0' ... '9':
  1033.     case 'a' ... 'z':
  1034.     case 'A' ... 'Z':
  1035.     case '%':
  1036.     case '_':
  1037.     case '#':
  1038.     case '.':
  1039.       p = input++;
  1040.       while (isalnum (*input)
  1041.          || *input == '_' || *input == '#' || *input == '.')
  1042.     input++;
  1043.       save = *input;
  1044.       *input = 0;
  1045.       yylval = (long) syms_name2val (p);
  1046.       if (undefined_symbol)
  1047.     {
  1048.       static char buf[80];
  1049.       sprintf (buf, "Undefined symbol `%s'", p);
  1050.       yyerror (buf);
  1051.     }
  1052.       *input = save;
  1053.       return NUM;
  1054.     case '\'':
  1055.       if (input[1] == '\\' && input[2] && input[3] == '\'')
  1056.     {
  1057.       static char escaped[] = "e\et\tb\bn\nr\r\\\\''";
  1058.       for (i = 0; escaped[i]; i += 2)
  1059.         if (input[2] == escaped[i])
  1060.           {
  1061.         input += 4;
  1062.         yylval = escaped[i + 1];
  1063.         return NUM;
  1064.           }
  1065.       yyerror ("Unrecognized escaped character");
  1066.     }
  1067.       else if (input[1] && input[2] == '\'')
  1068.     {
  1069.       yylval = input[1];
  1070.       input += 3;
  1071.     }
  1072.       else
  1073.     yyerror ("Unterminated character constant");
  1074.       return NUM;
  1075.     case 0:
  1076.       return 0;
  1077.     default:
  1078.       for (i = 0; i < sizeof (twochars) / sizeof (twochars[0]); i++)
  1079.     if (*input == twochars[i].c1 && input[1] == twochars[i].c2)
  1080.       {
  1081.         input += 2;
  1082.         return twochars[i].token;
  1083.       }
  1084.       return *input++;
  1085.     }
  1086. }
  1087.  
  1088. int
  1089. evaluate (char *exp, long *res, char **errtxt)
  1090. {
  1091.   int err;
  1092.  
  1093.   input = exp;
  1094.   error = 0;
  1095.   err = yyparse ();
  1096.   *res = result;
  1097.   *errtxt = error;
  1098.   undefined_symbol = 0;
  1099.   return err || error;
  1100. }
  1101.  
  1102. static void
  1103. yyerror (char *s)
  1104. {
  1105.   if (!error) error = s;
  1106. }
  1107.  
  1108.  
  1109. #ifdef TEST
  1110.  
  1111. unsigned long
  1112. syms_name2val (char *p)
  1113. {
  1114.   return strtoul(p, 0, 0);
  1115. }
  1116.  
  1117. int
  1118. main (int argc, char **argv)
  1119. {
  1120.   long res;
  1121.   int i, err;
  1122.   char *errtxt;
  1123.  
  1124.   for (i = 1; i < argc; i++)
  1125.     {
  1126.       err = evaluate (argv[i], &res, &errtxt);
  1127.       if (err)
  1128.     printf ("`%s' -> %s\n", argv[i], errtxt);
  1129.       else
  1130.     printf ("`%s' -> %ld\n", argv[i], res);
  1131.     }
  1132.   return 0;
  1133. }
  1134. #endif
  1135.