home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / bison / simple.bsn < prev    next >
Text File  |  1990-07-01  |  15KB  |  588 lines

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