home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / online / source / c / compilers / Bison.sit.hqx / Bison / Bison.simple < prev    next >
Text File  |  1992-08-21  |  15KB  |  636 lines

  1. /* Mac/MPW version of the GNU Bison "simple" parser skeleton */
  2. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  3. #line 3 "bison.simple"
  4.  
  5. /* Skeleton output parser for bison,
  6.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  7.  
  8.    This program is free software; you can redistribute it and/or modify
  9.    it under the terms of the GNU General Public License as published by
  10.    the Free Software Foundation; either version 1, or (at your option)
  11.    any later version.
  12.  
  13.    This program is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    GNU General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with this program; if not, write to the Free Software
  20.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22.  
  23. #ifndef alloca
  24. #ifdef __GNUC__
  25. #define alloca __builtin_alloca
  26. #else /* not GNU C.  */
  27. #ifdef macintosh
  28. #define alloca malloc
  29. #else
  30. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  31. #include <alloca.h>
  32. #else /* not sparc */
  33. #if defined (MSDOS) && !defined (__TURBOC__)
  34. #include <malloc.h>
  35. #else /* not MSDOS, or __TURBOC__ */
  36. #if defined(_AIX)
  37. #include <malloc.h>
  38.  #pragma alloca
  39. #endif /* not _AIX */
  40. #endif /* not MSDOS, or __TURBOC__ */
  41. #endif /* not sparc.  */
  42. #endif /* not Macintosh */
  43. #endif /* not GNU C.  */
  44. #endif /* alloca not defined.  */
  45.  
  46. /* This is the parser code that is written into each bison parser
  47.   when the %semantic_parser declaration is not specified in the grammar.
  48.   It was written by Richard Stallman by simplifying the hairy parser
  49.   used when %semantic_parser is specified.  */
  50.  
  51. /* Note: there must be only one dollar sign in this file.
  52.    It is replaced by the list of actions, each action
  53.    as one case of the switch.  */
  54.  
  55. #define yyerrok        (yyerrstatus = 0)
  56. #define yyclearin    (yychar = YYEMPTY)
  57. #define YYEMPTY        -2
  58. #define YYEOF        0
  59. #define YYACCEPT    return(0)
  60. #define YYABORT     return(1)
  61. #define YYERROR        goto yyerrlab1
  62. /* Like YYERROR except do call yyerror.
  63.    This remains here temporarily to ease the
  64.    transition to the new meaning of YYERROR, for GCC.
  65.    Once GCC version 2 has supplanted version 1, this can go.  */
  66. #define YYFAIL        goto yyerrlab
  67. #define YYRECOVERING()  (!!yyerrstatus)
  68. #define YYBACKUP(token, value) \
  69. do                                \
  70.   if (yychar == YYEMPTY && yylen == 1)                \
  71.     { yychar = (token), yylval = (value);            \
  72.       yychar1 = YYTRANSLATE (yychar);                \
  73.       YYPOPSTACK;                        \
  74.       goto yybackup;                        \
  75.     }                                \
  76.   else                                \
  77.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  78. while (0)
  79.  
  80. #define YYTERROR    1
  81. #define YYERRCODE    256
  82.  
  83. #ifndef YYPURE
  84. #define YYLEX        yylex()
  85. #endif
  86.  
  87. #ifdef YYPURE
  88. #ifdef YYLSP_NEEDED
  89. #define YYLEX        yylex(&yylval, &yylloc)
  90. #else
  91. #define YYLEX        yylex(&yylval)
  92. #endif
  93. #endif
  94.  
  95. /* If nonreentrant, generate the variables here */
  96.  
  97. #ifndef YYPURE
  98.  
  99. int    yychar;            /*  the lookahead symbol        */
  100. YYSTYPE    yylval;            /*  the semantic value of the        */
  101.                 /*  lookahead symbol            */
  102.  
  103. #ifdef YYLSP_NEEDED
  104. YYLTYPE yylloc;            /*  location data for the lookahead    */
  105.                 /*  symbol                */
  106. #endif
  107.  
  108. int yynerrs;            /*  number of parse errors so far       */
  109. #endif  /* not YYPURE */
  110.  
  111. #if YYDEBUG != 0
  112. int yydebug;            /*  nonzero means print parse trace    */
  113. /* Since this is uninitialized, it does not stop multiple parsers
  114.    from coexisting.  */
  115. #endif
  116.  
  117. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  118.  
  119. #ifndef    YYINITDEPTH
  120. #define YYINITDEPTH 200
  121. #endif
  122.  
  123. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  124.     (effective only if the built-in stack extension method is used).  */
  125.  
  126. #if YYMAXDEPTH == 0
  127. #undef YYMAXDEPTH
  128. #endif
  129.  
  130. #ifndef YYMAXDEPTH
  131. #define YYMAXDEPTH 10000
  132. #endif
  133.  
  134. #if __GNUC__ > 1        /* GNU C and GNU C++ define this.  */
  135. #define __yy_bcopy(FROM,TO,COUNT)    __builtin_memcpy(TO,FROM,COUNT)
  136. #else                /* not GNU C or C++ */
  137. #ifndef __cplusplus
  138.  
  139. /* This is the most reliable way to avoid incompatibilities
  140.    in available built-in functions on various systems.  */
  141. static void
  142. __yy_bcopy (from, to, count)
  143.      char *from;
  144.      char *to;
  145.      int count;
  146. {
  147.   register char *f = from;
  148.   register char *t = to;
  149.   register int i = count;
  150.  
  151.   while (i-- > 0)
  152.     *t++ = *f++;
  153. }
  154.  
  155. #else /* __cplusplus */
  156.  
  157. /* This is the most reliable way to avoid incompatibilities
  158.    in available built-in functions on various systems.  */
  159. static void
  160. __yy_bcopy (char *from, char *to, int count)
  161. {
  162.   register char *f = from;
  163.   register char *t = to;
  164.   register int i = count;
  165.  
  166.   while (i-- > 0)
  167.     *t++ = *f++;
  168. }
  169.  
  170. #endif
  171. #endif
  172.  
  173. #line 173 "bison.simple"
  174. int
  175. yyparse()
  176. {
  177.   register int yystate;
  178.   register int yyn;
  179.   register short *yyssp;
  180.   register YYSTYPE *yyvsp;
  181.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  182.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  183.  
  184.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  185.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  186.  
  187.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  188.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  189.  
  190. #ifdef YYLSP_NEEDED
  191.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  192.   YYLTYPE *yyls = yylsa;
  193.   YYLTYPE *yylsp;
  194.  
  195. #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
  196. #else
  197. #define YYPOPSTACK   (yyvsp--, yyssp--)
  198. #endif
  199.  
  200.   int yystacksize = YYINITDEPTH;
  201.  
  202. #ifdef YYPURE
  203.   int yychar;
  204.   YYSTYPE yylval;
  205.   int yynerrs;
  206. #ifdef YYLSP_NEEDED
  207.   YYLTYPE yylloc;
  208. #endif
  209. #endif
  210.  
  211.   YYSTYPE yyval;        /*  the variable used to return        */
  212.                 /*  semantic values from the action    */
  213.                 /*  routines                */
  214.  
  215.   int yylen;
  216.  
  217. #if YYDEBUG != 0
  218.   if (yydebug)
  219.     fprintf(stderr, "Starting parse\n");
  220. #endif
  221.  
  222.   yystate = 0;
  223.   yyerrstatus = 0;
  224.   yynerrs = 0;
  225.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  226.  
  227.   /* Initialize stack pointers.
  228.      Waste one element of value and location stack
  229.      so that they stay on the same level as the state stack.  */
  230.  
  231.   yyssp = yyss - 1;
  232.   yyvsp = yyvs;
  233. #ifdef YYLSP_NEEDED
  234.   yylsp = yyls;
  235. #endif
  236.  
  237. /* Push a new state, which is found in  yystate  .  */
  238. /* In all cases, when you get here, the value and location stacks
  239.    have just been pushed. so pushing a state here evens the stacks.  */
  240. yynewstate:
  241.  
  242.   *++yyssp = yystate;
  243.  
  244.   if (yyssp >= yyss + yystacksize - 1)
  245.     {
  246.       /* Give user a chance to reallocate the stack */
  247.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  248.       YYSTYPE *yyvs1 = yyvs;
  249.       short *yyss1 = yyss;
  250. #ifdef YYLSP_NEEDED
  251.       YYLTYPE *yyls1 = yyls;
  252. #endif
  253.  
  254.       /* Get the current used size of the three stacks, in elements.  */
  255.       int size = yyssp - yyss + 1;
  256.  
  257. #ifdef yyoverflow
  258.       /* Each stack pointer address is followed by the size of
  259.      the data in use in that stack, in bytes.  */
  260.       yyoverflow("parser stack overflow",
  261.          &yyss1, size * sizeof (*yyssp),
  262.          &yyvs1, size * sizeof (*yyvsp),
  263. #ifdef YYLSP_NEEDED
  264.          &yyls1, size * sizeof (*yylsp),
  265. #endif
  266.          &yystacksize);
  267.  
  268.       yyss = yyss1; yyvs = yyvs1;
  269. #ifdef YYLSP_NEEDED
  270.       yyls = yyls1;
  271. #endif
  272. #else /* no yyoverflow */
  273.       /* Extend the stack our own way.  */
  274.       if (yystacksize >= YYMAXDEPTH)
  275.     {
  276.       yyerror("parser stack overflow");
  277.       return 2;
  278.     }
  279.       yystacksize *= 2;
  280.       if (yystacksize > YYMAXDEPTH)
  281.     yystacksize = YYMAXDEPTH;
  282.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  283.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  284.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  285.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  286. #ifdef YYLSP_NEEDED
  287.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  288.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  289. #endif
  290. #endif /* no yyoverflow */
  291.  
  292.       yyssp = yyss + size - 1;
  293.       yyvsp = yyvs + size - 1;
  294. #ifdef YYLSP_NEEDED
  295.       yylsp = yyls + size - 1;
  296. #endif
  297.  
  298. #if YYDEBUG != 0
  299.       if (yydebug)
  300.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  301. #endif
  302.  
  303.       if (yyssp >= yyss + yystacksize - 1)
  304.     YYABORT;
  305.     }
  306.  
  307. #if YYDEBUG != 0
  308.   if (yydebug)
  309.     fprintf(stderr, "Entering state %d\n", yystate);
  310. #endif
  311.  
  312.  yybackup:
  313.  
  314. /* Do appropriate processing given the current state.  */
  315. /* Read a lookahead token if we need one and don't already have one.  */
  316. /* yyresume: */
  317.  
  318.   /* First try to decide what to do without reference to lookahead token.  */
  319.  
  320.   yyn = yypact[yystate];
  321.   if (yyn == YYFLAG)
  322.     goto yydefault;
  323.  
  324.   /* Not known => get a lookahead token if don't already have one.  */
  325.  
  326.   /* yychar is either YYEMPTY or YYEOF
  327.      or a valid token in external form.  */
  328.  
  329.   if (yychar == YYEMPTY)
  330.     {
  331. #if YYDEBUG != 0
  332.       if (yydebug)
  333.     fprintf(stderr, "Reading a token: ");
  334. #endif
  335.       yychar = YYLEX;
  336.     }
  337.  
  338.   /* Convert token to internal form (in yychar1) for indexing tables with */
  339.  
  340.   if (yychar <= 0)        /* This means end of input. */
  341.     {
  342.       yychar1 = 0;
  343.       yychar = YYEOF;        /* Don't call YYLEX any more */
  344.  
  345. #if YYDEBUG != 0
  346.       if (yydebug)
  347.     fprintf(stderr, "Now at end of input.\n");
  348. #endif
  349.     }
  350.   else
  351.     {
  352.       yychar1 = YYTRANSLATE(yychar);
  353.  
  354. #if YYDEBUG != 0
  355.       if (yydebug)
  356.     {
  357.       fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
  358.       /* Give the individual parser a way to print the precise meaning
  359.          of a token, for further debugging info.  */
  360. #ifdef YYPRINT
  361.       YYPRINT (stderr, yychar, yylval);
  362. #endif
  363.       fprintf (stderr, ")\n");
  364.     }
  365. #endif
  366.     }
  367.  
  368.   yyn += yychar1;
  369.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  370.     goto yydefault;
  371.  
  372.   yyn = yytable[yyn];
  373.  
  374.   /* yyn is what to do for this token type in this state.
  375.      Negative => reduce, -yyn is rule number.
  376.      Positive => shift, yyn is new state.
  377.        New state is final state => don't bother to shift,
  378.        just return success.
  379.      0, or most negative number => error.  */
  380.  
  381.   if (yyn < 0)
  382.     {
  383.       if (yyn == YYFLAG)
  384.     goto yyerrlab;
  385.       yyn = -yyn;
  386.       goto yyreduce;
  387.     }
  388.   else if (yyn == 0)
  389.     goto yyerrlab;
  390.  
  391.   if (yyn == YYFINAL)
  392.     YYACCEPT;
  393.  
  394.   /* Shift the lookahead token.  */
  395.  
  396. #if YYDEBUG != 0
  397.   if (yydebug)
  398.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  399. #endif
  400.  
  401.   /* Discard the token being shifted unless it is eof.  */
  402.   if (yychar != YYEOF)
  403.     yychar = YYEMPTY;
  404.  
  405.   *++yyvsp = yylval;
  406. #ifdef YYLSP_NEEDED
  407.   *++yylsp = yylloc;
  408. #endif
  409.  
  410.   /* count tokens shifted since error; after three, turn off error status.  */
  411.   if (yyerrstatus) yyerrstatus--;
  412.  
  413.   yystate = yyn;
  414.   goto yynewstate;
  415.  
  416. /* Do the default action for the current state.  */
  417. yydefault:
  418.  
  419.   yyn = yydefact[yystate];
  420.   if (yyn == 0)
  421.     goto yyerrlab;
  422.  
  423. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  424. yyreduce:
  425.   yylen = yyr2[yyn];
  426.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  427.  
  428. #if YYDEBUG != 0
  429.   if (yydebug)
  430.     {
  431.       int i;
  432.  
  433.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  434.            yyn, yyrline[yyn]);
  435.  
  436.       /* Print the symboles being reduced, and their result.  */
  437.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  438.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  439.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  440.     }
  441. #endif
  442.  
  443. $   /* the action file gets copied in in place of this dollarsign */
  444. #line 443 "bison.simple"
  445.  
  446.   yyvsp -= yylen;
  447.   yyssp -= yylen;
  448. #ifdef YYLSP_NEEDED
  449.   yylsp -= yylen;
  450. #endif
  451.  
  452. #if YYDEBUG != 0
  453.   if (yydebug)
  454.     {
  455.       short *ssp1 = yyss - 1;
  456.       fprintf (stderr, "state stack now");
  457.       while (ssp1 != yyssp)
  458.     fprintf (stderr, " %d", *++ssp1);
  459.       fprintf (stderr, "\n");
  460.     }
  461. #endif
  462.  
  463.   *++yyvsp = yyval;
  464.  
  465. #ifdef YYLSP_NEEDED
  466.   yylsp++;
  467.   if (yylen == 0)
  468.     {
  469.       yylsp->first_line = yylloc.first_line;
  470.       yylsp->first_column = yylloc.first_column;
  471.       yylsp->last_line = (yylsp-1)->last_line;
  472.       yylsp->last_column = (yylsp-1)->last_column;
  473.       yylsp->text = 0;
  474.     }
  475.   else
  476.     {
  477.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  478.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  479.     }
  480. #endif
  481.  
  482.   /* Now "shift" the result of the reduction.
  483.      Determine what state that goes to,
  484.      based on the state we popped back to
  485.      and the rule number reduced by.  */
  486.  
  487.   yyn = yyr1[yyn];
  488.  
  489.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  490.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  491.     yystate = yytable[yystate];
  492.   else
  493.     yystate = yydefgoto[yyn - YYNTBASE];
  494.  
  495.   goto yynewstate;
  496.  
  497. yyerrlab:   /* here on detecting error */
  498.  
  499.   if (! yyerrstatus)
  500.     /* If not already recovering from an error, report this error.  */
  501.     {
  502.       ++yynerrs;
  503.  
  504. #ifdef YYERROR_VERBOSE
  505.       yyn = yypact[yystate];
  506.  
  507.       if (yyn > YYFLAG && yyn < YYLAST)
  508.     {
  509.       int size = 0;
  510.       char *msg;
  511.       int x, count;
  512.  
  513.       count = 0;
  514.       for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  515.         if (yycheck[x + yyn] == x)
  516.           size += strlen(yytname[x]) + 15, count++;
  517.       msg = (char *) malloc(size + 15);
  518.       if (msg != 0)
  519.         {
  520.           strcpy(msg, "parse error");
  521.  
  522.           if (count < 5)
  523.         {
  524.           count = 0;
  525.           for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  526.             if (yycheck[x + yyn] == x)
  527.               {
  528.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  529.             strcat(msg, yytname[x]);
  530.             strcat(msg, "'");
  531.             count++;
  532.               }
  533.         }
  534.           yyerror(msg);
  535.           free(msg);
  536.         }
  537.       else
  538.         yyerror ("parse error; also virtual memory exceeded");
  539.     }
  540.       else
  541. #endif /* YYERROR_VERBOSE */
  542.     yyerror("parse error");
  543.     }
  544.  
  545. yyerrlab1:   /* here on error raised explicitly by an action */
  546.  
  547.   if (yyerrstatus == 3)
  548.     {
  549.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  550.  
  551.       /* return failure if at end of input */
  552.       if (yychar == YYEOF)
  553.     YYABORT;
  554.  
  555. #if YYDEBUG != 0
  556.       if (yydebug)
  557.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  558. #endif
  559.  
  560.       yychar = YYEMPTY;
  561.     }
  562.  
  563.   /* Else will try to reuse lookahead token
  564.      after shifting the error token.  */
  565.  
  566.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  567.  
  568.   goto yyerrhandle;
  569.  
  570. yyerrdefault:  /* current state does not do anything special for the error token. */
  571.  
  572. #if 0
  573.   /* This is wrong; only states that explicitly want error tokens
  574.      should shift them.  */
  575.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  576.   if (yyn) goto yydefault;
  577. #endif
  578.  
  579. yyerrpop:   /* pop the current state because it cannot handle the error token */
  580.  
  581.   if (yyssp == yyss) YYABORT;
  582.   yyvsp--;
  583.   yystate = *--yyssp;
  584. #ifdef YYLSP_NEEDED
  585.   yylsp--;
  586. #endif
  587.  
  588. #if YYDEBUG != 0
  589.   if (yydebug)
  590.     {
  591.       short *ssp1 = yyss - 1;
  592.       fprintf (stderr, "Error: state stack now");
  593.       while (ssp1 != yyssp)
  594.     fprintf (stderr, " %d", *++ssp1);
  595.       fprintf (stderr, "\n");
  596.     }
  597. #endif
  598.  
  599. yyerrhandle:
  600.  
  601.   yyn = yypact[yystate];
  602.   if (yyn == YYFLAG)
  603.     goto yyerrdefault;
  604.  
  605.   yyn += YYTERROR;
  606.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  607.     goto yyerrdefault;
  608.  
  609.   yyn = yytable[yyn];
  610.   if (yyn < 0)
  611.     {
  612.       if (yyn == YYFLAG)
  613.     goto yyerrpop;
  614.       yyn = -yyn;
  615.       goto yyreduce;
  616.     }
  617.   else if (yyn == 0)
  618.     goto yyerrpop;
  619.  
  620.   if (yyn == YYFINAL)
  621.     YYACCEPT;
  622.  
  623. #if YYDEBUG != 0
  624.   if (yydebug)
  625.     fprintf(stderr, "Shifting error token, ");
  626. #endif
  627.  
  628.   *++yyvsp = yylval;
  629. #ifdef YYLSP_NEEDED
  630.   *++yylsp = yylloc;
  631. #endif
  632.  
  633.   yystate = yyn;
  634.   goto yynewstate;
  635. }
  636.