- ENTER; /* force stack free before we return */
- SAVEVPTR(PL_yycharp);
- SAVEVPTR(PL_yylvalp);
- PL_yycharp = &yychar; /* so PL_yyerror() can access it */
- PL_yylvalp = &yylval; /* so various functions in toke.c can access it */
-
- yyss_sv = newSV(YYINITDEPTH * sizeof(short));
- yyvs_sv = newSV(YYINITDEPTH * sizeof(YYSTYPE));
- SAVEFREESV(yyss_sv);
- SAVEFREESV(yyvs_sv);
- yyss = (short *) SvPVX(yyss_sv);
- yyvs = (YYSTYPE *) SvPVX(yyvs_sv);
- /* note that elements zero of yyvs and yyns are not used */
- yyssp = yyss;
- yyvsp = yyvs;
-#ifdef DEBUGGING
- yyns_sv = newSV(YYINITDEPTH * sizeof(char *));
- SAVEFREESV(yyns_sv);
- /* XXX This seems strange to cast char * to char ** */
- yyns = (const char **) SvPVX(yyns_sv);
- yynsp = yyns;
-#endif
-
- yystate = 0;
- yyerrstatus = 0;
- yynerrs = 0;
- yychar = YYEMPTY; /* Cause a token to be read. */
-
- YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
-
- goto yysetstate;
-
-/*------------------------------------------------------------.
-| yynewstate -- Push a new state, which is found in yystate. |
-`------------------------------------------------------------*/
- yynewstate:
- /* In all cases, when you get here, the value and location stacks
- have just been pushed. so pushing a state here evens the stacks.
- */
- yyssp++;
-
- yysetstate:
- *yyssp = yystate;
-
- if (yyss + yystacksize - 1 <= yyssp) {
- /* Get the current used size of the three stacks, in elements. */
- const YYSIZE_T yysize = yyssp - yyss + 1;
-
- /* Extend the stack our own way. */
- if (YYMAXDEPTH <= yystacksize)
- goto yyoverflowlab;
- yystacksize *= 2;
- if (YYMAXDEPTH < yystacksize)
- yystacksize = YYMAXDEPTH;
-
- SvGROW(yyss_sv, yystacksize * sizeof(short));
- SvGROW(yyvs_sv, yystacksize * sizeof(YYSTYPE));
- yyss = (short *) SvPVX(yyss_sv);
- yyvs = (YYSTYPE *) SvPVX(yyvs_sv);
-#ifdef DEBUGGING
- SvGROW(yyns_sv, yystacksize * sizeof(char *));
- /* XXX This seems strange to cast char * to char ** */
- yyns = (const char **) SvPVX(yyns_sv);
- if (! yyns)
- goto yyoverflowlab;
- yynsp = yyns + yysize - 1;
-#endif
- if (!yyss || ! yyvs)
- goto yyoverflowlab;
-
- yyssp = yyss + yysize - 1;
- yyvsp = yyvs + yysize - 1;
-
-
- YYDPRINTF ((Perl_debug_log, "Stack size increased to %lu\n",
- (unsigned long int) yystacksize));
-
- if (yyss + yystacksize - 1 <= yyssp)
- YYABORT;
- }
-
- goto yybackup;
-
- /*-----------.
- | yybackup. |
- `-----------*/
- yybackup:
-
-/* Do appropriate processing given the current state. */
-/* Read a lookahead token if we need one and don't already have one. */
-/* yyresume: */
-
- /* First try to decide what to do without reference to lookahead token. */
-
- yyn = yypact[yystate];
- if (yyn == YYPACT_NINF)
- goto yydefault;
-
- /* Not known => get a lookahead token if don't already have one. */
-
- /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
- if (yychar == YYEMPTY) {
- YYDPRINTF ((Perl_debug_log, "Reading a token: "));
-#ifdef PERL_IN_MADLY_C
- yychar = PL_madskills ? madlex() : yylex();
-#else
- yychar = yylex();
-#endif
-
-# ifdef EBCDIC
- if (yychar >= 0 && yychar < 255) {
- yychar = NATIVE_TO_ASCII(yychar);
- }
-# endif
- }
-
- if (yychar <= YYEOF) {
- yychar = yytoken = YYEOF;
- YYDPRINTF ((Perl_debug_log, "Now at end of input.\n"));
- }
- else {
- yytoken = YYTRANSLATE (yychar);
- YYDSYMPRINTF ("Next token is", yytoken, &yylval);
- }
-
- /* If the proper action on seeing token YYTOKEN is to reduce or to
- detect an error, take that action. */
- yyn += yytoken;
- if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
- goto yydefault;
- yyn = yytable[yyn];
- if (yyn <= 0) {
- if (yyn == 0 || yyn == YYTABLE_NINF)
- goto yyerrlab;
- yyn = -yyn;
- goto yyreduce;
- }
-
- if (yyn == YYFINAL)
- YYACCEPT;
-
- /* Shift the lookahead token. */
- YYDPRINTF ((Perl_debug_log, "Shifting token %s, ", yytname[yytoken]));
-
- /* Discard the token being shifted unless it is eof. */
- if (yychar != YYEOF)
- yychar = YYEMPTY;
-
- *++yyvsp = yylval;
+ parser = PL_parser;
+
+ ENTER; /* force parser state cleanup/restoration before we return */
+ SAVEPPTR(parser->yylval.pval);
+ SAVEINT(parser->yychar);
+ SAVEINT(parser->yyerrstatus);
+ SAVEINT(parser->yylen);
+ SAVEVPTR(parser->stack);
+ SAVEVPTR(parser->stack_max1);
+ SAVEVPTR(parser->ps);
+
+ /* initialise state for this parse */
+ parser->yychar = gramtype;
+ yytoken = YYTRANSLATE(NATIVE_TO_UNI(parser->yychar));
+
+ parser->yyerrstatus = 0;
+ parser->yylen = 0;
+ Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
+ parser->stack_max1 = parser->stack + YYINITDEPTH - 1;
+ ps = parser->ps = parser->stack;
+ ps->state = 0;
+ SAVEDESTRUCTOR_X(S_clear_yystack, parser);
+
+ while (1) {
+ /* main loop: shift some tokens, then reduce when possible */
+
+ while (1) {
+ /* shift a token, or quit when it's possible to reduce */
+
+ yystate = ps->state;
+
+ YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
+
+ parser->yylen = 0;
+
+ /* Grow the stack? We always leave 1 spare slot, in case of a
+ * '' -> 'foo' reduction.
+ * Note that stack_max1 points to the (top-1)th allocated stack
+ * element to make this check faster */
+
+ if (ps >= parser->stack_max1) {
+ Size_t pos = ps - parser->stack;
+ Size_t newsize = 2 * (parser->stack_max1 + 2 - parser->stack);
+ /* this will croak on insufficient memory */
+ Renew(parser->stack, newsize, yy_stack_frame);
+ ps = parser->ps = parser->stack + pos;
+ parser->stack_max1 = parser->stack + newsize - 1;
+
+ YYDPRINTF((Perl_debug_log,
+ "parser stack size increased to %lu frames\n",
+ (unsigned long int)newsize));
+ }
+
+ /* Do appropriate processing given the current state. Read a
+ * lookahead token if we need one and don't already have one.
+ * */
+
+ /* First try to decide what to do without reference to
+ * lookahead token. */
+
+ yyn = yypact[yystate];
+ if (yyn == YYPACT_NINF)
+ goto yydefault;
+
+ /* Not known => get a lookahead token if don't already have
+ * one. YYCHAR is either YYEMPTY or YYEOF or a valid
+ * lookahead symbol. */
+
+ if (parser->yychar == YYEMPTY) {
+ YYDPRINTF ((Perl_debug_log, "Reading a token:\n"));
+ parser->yychar = yylex();
+ assert(parser->yychar >= 0);
+ if (parser->yychar == YYEOF) {
+ YYDPRINTF ((Perl_debug_log, "Now at end of input.\n"));
+ }
+ /* perly.tab is shipped based on an ASCII system, so need
+ * to index it with characters translated to ASCII.
+ * Although it's not designed for this purpose, we can use
+ * NATIVE_TO_UNI here. It returns its argument on ASCII
+ * platforms, and on EBCDIC translates native to ascii in
+ * the 0-255 range, leaving every other possible input
+ * unchanged. This jibes with yylex() returning some bare
+ * characters in that range, but all tokens it returns are
+ * either 0, or above 255. There could be a problem if NULs
+ * weren't 0, or were ever returned as raw chars by yylex() */
+ yytoken = YYTRANSLATE(NATIVE_TO_UNI(parser->yychar));
+ }
+
+ /* make sure no-ones changed yychar since the last call to yylex */
+ assert(yytoken == YYTRANSLATE(NATIVE_TO_UNI(parser->yychar)));
+ YYDSYMPRINTF("lookahead token is", yytoken, &parser->yylval);
+
+
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ * detect an error, take that action.
+ * Casting yyn to unsigned allows a >=0 test to be included as
+ * part of the <=YYLAST test for speed */
+ yyn += yytoken;
+ if ((unsigned int)yyn > YYLAST || yycheck[yyn] != yytoken) {
+ yydefault:
+ /* do the default action for the current state. */
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+ break; /* time to reduce */
+ }
+
+ yyn = yytable[yyn];
+ if (yyn <= 0) {
+ if (yyn == 0 || yyn == YYTABLE_NINF)
+ goto yyerrlab;
+ yyn = -yyn;
+ break; /* time to reduce */
+ }
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ /* Shift the lookahead token. */
+ YYDPRINTF ((Perl_debug_log, "Shifting token %s, ", yytname[yytoken]));
+
+ /* Discard the token being shifted unless it is eof. */
+ if (parser->yychar != YYEOF)
+ parser->yychar = YYEMPTY;
+
+ YYPUSHSTACK;
+ ps->state = yyn;
+ ps->val = parser->yylval;
+ ps->compcv = (CV*)SvREFCNT_inc(PL_compcv);
+ ps->savestack_ix = PL_savestack_ix;