home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 4.ddi / BISON.ZIP / BISON.SIM < prev    next >
Encoding:
Text File  |  1990-06-10  |  12.1 KB  |  483 lines

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