-char rcsid[] = "$Header: perly.c,v 2.0 88/06/05 00:09:56 root Exp $";
-/*
- * $Log: perly.c,v $
- * Revision 2.0 88/06/05 00:09:56 root
- * Baseline version 2.0.
+/* perly.c
+ *
+ * Copyright (c) 2004, 2005, 2006, 2007, 2008 by Larry Wall and others
+ *
+ * You may distribute under the terms of either the GNU General Public
+ * License or the Artistic License, as specified in the README file.
*
+ * Note that this file was originally generated as an output from
+ * GNU bison version 1.875, but now the code is statically maintained
+ * and edited; the bits that are dependent on perly.y are now
+ * #included from the files perly.tab and perly.act.
+ *
+ * Here is an important copyright statement from the original, generated
+ * file:
+ *
+ * As a special exception, when this file is copied by Bison into a
+ * Bison output file, you may use that output file without
+ * restriction. This special exception was added by the Free
+ * Software Foundation in version 1.24 of Bison.
+ *
+ * Note that this file is also #included in madly.c, to allow compilation
+ * of a second parser, Perl_madparse, that is identical to Perl_yyparse,
+ * but which includes extra code for dumping the parse tree.
+ * This is controlled by the PERL_IN_MADLY_C define.
*/
#include "EXTERN.h"
+#define PERL_IN_PERLY_C
#include "perl.h"
-#include "perly.h"
-
-extern char *tokename[];
-extern int yychar;
-static int cmd_tosave();
-static int arg_tosave();
-static int spat_tosave();
+typedef unsigned char yytype_uint8;
+typedef signed char yytype_int8;
+typedef unsigned short int yytype_uint16;
+typedef short int yytype_int16;
+typedef signed char yysigned_char;
-main(argc,argv,env)
-register int argc;
-register char **argv;
-register char **env;
-{
- register STR *str;
- register char *s;
- char *index(), *strcpy(), *getenv();
- bool dosearch = FALSE;
-
- uid = (int)getuid();
- euid = (int)geteuid();
- linestr = str_new(80);
- str_nset(linestr,"",0);
- str = str_make(""); /* first used for -I flags */
- incstab = aadd(stabent("INC",TRUE));
- for (argc--,argv++; argc; argc--,argv++) {
- if (argv[0][0] != '-' || !argv[0][1])
- break;
- reswitch:
- switch (argv[0][1]) {
- case 'a':
- minus_a = TRUE;
- strcpy(argv[0], argv[0]+1);
- goto reswitch;
-#ifdef DEBUGGING
- case 'D':
- debug = atoi(argv[0]+2);
-#ifdef YYDEBUG
- yydebug = (debug & 1);
-#endif
- break;
-#endif
- case 'e':
- if (!e_fp) {
- e_tmpname = strcpy(safemalloc(sizeof(TMPPATH)),TMPPATH);
- mktemp(e_tmpname);
- e_fp = fopen(e_tmpname,"w");
- }
- if (argv[1])
- fputs(argv[1],e_fp);
- putc('\n', e_fp);
- argc--,argv++;
- break;
- case 'i':
- inplace = savestr(argv[0]+2);
- argvoutstab = stabent("ARGVOUT",TRUE);
- break;
- case 'I':
- str_cat(str,argv[0]);
- str_cat(str," ");
- if (argv[0][2]) {
- apush(incstab->stab_array,str_make(argv[0]+2));
- }
- else {
- apush(incstab->stab_array,str_make(argv[1]));
- str_cat(str,argv[1]);
- argc--,argv++;
- str_cat(str," ");
- }
- break;
- case 'n':
- minus_n = TRUE;
- strcpy(argv[0], argv[0]+1);
- goto reswitch;
- case 'p':
- minus_p = TRUE;
- strcpy(argv[0], argv[0]+1);
- goto reswitch;
- case 'P':
- preprocess = TRUE;
- strcpy(argv[0], argv[0]+1);
- goto reswitch;
- case 's':
- doswitches = TRUE;
- strcpy(argv[0], argv[0]+1);
- goto reswitch;
- case 'S':
- dosearch = TRUE;
- strcpy(argv[0], argv[0]+1);
- goto reswitch;
- case 'U':
- unsafe = TRUE;
- strcpy(argv[0], argv[0]+1);
- goto reswitch;
- case 'v':
- version();
- exit(0);
- case 'w':
- dowarn = TRUE;
- strcpy(argv[0], argv[0]+1);
- goto reswitch;
- case '-':
- argc--,argv++;
- goto switch_end;
- case 0:
- break;
- default:
- fatal("Unrecognized switch: %s",argv[0]);
- }
- }
- switch_end:
- if (e_fp) {
- fclose(e_fp);
- argc++,argv--;
- argv[0] = e_tmpname;
- }
-#ifndef PRIVLIB
-#define PRIVLIB "/usr/local/lib/perl"
-#endif
- apush(incstab->stab_array,str_make(PRIVLIB));
-
- str_set(&str_no,No);
- str_set(&str_yes,Yes);
- init_eval();
-
- /* open script */
-
- if (argv[0] == Nullch)
- argv[0] = "-";
- if (dosearch && argv[0][0] != '/' && (s = getenv("PATH"))) {
- char *xfound = Nullch, *xfailed = Nullch;
-
- while (*s) {
- s = cpytill(tokenbuf,s,':');
- if (*s)
- s++;
- if (tokenbuf[0])
- strcat(tokenbuf,"/");
- strcat(tokenbuf,argv[0]);
#ifdef DEBUGGING
- if (debug & 1)
- fprintf(stderr,"Looking for %s\n",tokenbuf);
+# define YYDEBUG 1
+#else
+# define YYDEBUG 0
#endif
- if (stat(tokenbuf,&statbuf) < 0) /* not there? */
- continue;
- if ((statbuf.st_mode & S_IFMT) == S_IFREG
- && cando(S_IREAD,TRUE) && cando(S_IEXEC,TRUE)) {
- xfound = tokenbuf; /* bingo! */
- break;
- }
- if (!xfailed)
- xfailed = savestr(tokenbuf);
- }
- if (!xfound)
- fatal("Can't execute %s", xfailed);
- if (xfailed)
- safefree(xfailed);
- argv[0] = savestr(xfound);
- }
- filename = savestr(argv[0]);
- origfilename = savestr(filename);
- if (strEQ(filename,"-"))
- argv[0] = "";
- if (preprocess) {
- str_cat(str,"-I");
- str_cat(str,PRIVLIB);
- sprintf(buf, "\
-/bin/sed -e '/^[^#]/b' \
- -e '/^#[ ]*include[ ]/b' \
- -e '/^#[ ]*define[ ]/b' \
- -e '/^#[ ]*if[ ]/b' \
- -e '/^#[ ]*ifdef[ ]/b' \
- -e '/^#[ ]*ifndef[ ]/b' \
- -e '/^#[ ]*else/b' \
- -e '/^#[ ]*endif/b' \
- -e 's/^#.*//' \
- %s | %s -C %s %s",
- argv[0], CPPSTDIN, str_get(str), CPPMINUS);
- rsfp = popen(buf,"r");
- }
- else if (!*argv[0])
- rsfp = stdin;
- else
- rsfp = fopen(argv[0],"r");
- if (rsfp == Nullfp)
- fatal("Perl script \"%s\" doesn't seem to exist",filename);
- str_free(str); /* free -I directories */
- defstab = stabent("_",TRUE);
+/* contains all the parser state tables; auto-generated from perly.y */
+#include "perly.tab"
- /* init tokener */
+# define YYSIZE_T size_t
- bufptr = str_get(linestr);
+#define YYEOF 0
+#define YYTERROR 1
- /* now parse the report spec */
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrlab1
- if (yyparse())
- fatal("Execution aborted due to compilation errors.\n");
+/* Enable debugging if requested. */
+#ifdef DEBUGGING
- if (dowarn) {
- stab_check('A','Z');
- stab_check('a','z');
- }
+# define yydebug (DEBUG_p_TEST)
- preprocess = FALSE;
- if (e_fp) {
- e_fp = Nullfp;
- UNLINK(e_tmpname);
- }
- argc--,argv++; /* skip name of script */
- if (doswitches) {
- for (; argc > 0 && **argv == '-'; argc--,argv++) {
- if (argv[0][1] == '-') {
- argc--,argv++;
- break;
- }
- str_numset(stabent(argv[0]+1,TRUE)->stab_val,(double)1.0);
- }
- }
- if (argvstab = stabent("ARGV",allstabs)) {
- aadd(argvstab);
- for (; argc > 0; argc--,argv++) {
- apush(argvstab->stab_array,str_make(argv[0]));
- }
- }
- if (envstab = stabent("ENV",allstabs)) {
- hadd(envstab);
- for (; *env; env++) {
- if (!(s = index(*env,'=')))
- continue;
- *s++ = '\0';
- str = str_make(s);
- str->str_link.str_magic = envstab;
- hstore(envstab->stab_hash,*env,str);
- *--s = '=';
- }
- }
- if (sigstab = stabent("SIG",allstabs))
- hadd(sigstab);
+# define YYFPRINTF PerlIO_printf
- magicalize("!#?^~=-%0123456789.+&*()<>,\\/[|");
+# define YYDPRINTF(Args) \
+do { \
+ if (yydebug) \
+ YYFPRINTF Args; \
+} while (0)
- sawampersand = (stabent("&",FALSE) != Nullstab);
- if (tmpstab = stabent("0",allstabs))
- str_set(STAB_STR(tmpstab),origfilename);
- if (tmpstab = stabent("$",allstabs))
- str_numset(STAB_STR(tmpstab),(double)getpid());
+# define YYDSYMPRINTF(Title, Token, Value) \
+do { \
+ if (yydebug) { \
+ YYFPRINTF (Perl_debug_log, "%s ", Title); \
+ yysymprint (aTHX_ Perl_debug_log, Token, Value); \
+ YYFPRINTF (Perl_debug_log, "\n"); \
+ } \
+} while (0)
- tmpstab = stabent("stdin",TRUE);
- tmpstab->stab_io = stio_new();
- tmpstab->stab_io->fp = stdin;
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
- tmpstab = stabent("stdout",TRUE);
- tmpstab->stab_io = stio_new();
- tmpstab->stab_io->fp = stdout;
- defoutstab = tmpstab;
- curoutstab = tmpstab;
+static void
+yysymprint(pTHX_ PerlIO * const yyoutput, int yytype, const YYSTYPE * const yyvaluep)
+{
+ if (yytype < YYNTOKENS) {
+ YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
+# ifdef YYPRINT
+ YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+# else
+ YYFPRINTF (yyoutput, "0x%"UVxf, (UV)yyvaluep->ival);
+# endif
+ }
+ else
+ YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
- tmpstab = stabent("stderr",TRUE);
- tmpstab->stab_io = stio_new();
- tmpstab->stab_io->fp = stderr;
+ YYFPRINTF (yyoutput, ")");
+}
- savestack = anew(Nullstab); /* for saving non-local values */
- setjmp(top_env); /* sets goto_targ on longjump */
+/* yy_stack_print()
+ * print the top 8 items on the parse stack.
+ */
-#ifdef DEBUGGING
- if (debug & 1024)
- dump_cmd(main_root,Nullcmd);
- if (debug)
- fprintf(stderr,"\nEXECUTING...\n\n");
-#endif
+static void
+yy_stack_print (pTHX_ const yy_parser *parser)
+{
+ const yy_stack_frame *ps, *min;
- /* do it */
+ min = parser->ps - 8 + 1;
+ if (min <= parser->stack)
+ min = parser->stack + 1;
- (void) cmd_exec(main_root);
+ PerlIO_printf(Perl_debug_log, "\nindex:");
+ for (ps = min; ps <= parser->ps; ps++)
+ PerlIO_printf(Perl_debug_log, " %8d", (int)(ps - parser->stack));
- if (goto_targ)
- fatal("Can't find label \"%s\"--aborting",goto_targ);
- exit(0);
- /* NOTREACHED */
-}
+ PerlIO_printf(Perl_debug_log, "\nstate:");
+ for (ps = min; ps <= parser->ps; ps++)
+ PerlIO_printf(Perl_debug_log, " %8d", ps->state);
-magicalize(list)
-register char *list;
-{
- register STAB *stab;
- char sym[2];
-
- sym[1] = '\0';
- while (*sym = *list++) {
- if (stab = stabent(sym,allstabs)) {
- stab->stab_flags = SF_VMAGIC;
- stab->stab_val->str_link.str_magic = stab;
- }
- }
-}
-
-ARG *
-make_split(stab,arg)
-register STAB *stab;
-register ARG *arg;
-{
- register SPAT *spat = (SPAT *) safemalloc(sizeof (SPAT));
+ PerlIO_printf(Perl_debug_log, "\ntoken:");
+ for (ps = min; ps <= parser->ps; ps++)
+ PerlIO_printf(Perl_debug_log, " %8.8s", ps->name);
- if (arg->arg_type != O_MATCH) {
- spat = (SPAT *) safemalloc(sizeof (SPAT));
- bzero((char *)spat, sizeof(SPAT));
- spat->spat_next = spat_root; /* link into spat list */
- spat_root = spat;
+ PerlIO_printf(Perl_debug_log, "\nvalue:");
+ for (ps = min; ps <= parser->ps; ps++) {
+ switch (yy_type_tab[yystos[ps->state]]) {
+ case toketype_opval:
+ PerlIO_printf(Perl_debug_log, " %8.8s",
+ ps->val.opval
+ ? PL_op_name[ps->val.opval->op_type]
+ : "(Nullop)"
+ );
+ break;
+#ifndef PERL_IN_MADLY_C
+ case toketype_p_tkval:
+ PerlIO_printf(Perl_debug_log, " %8.8s",
+ ps->val.pval ? ps->val.pval : "(NULL)");
+ break;
- spat->spat_runtime = arg;
- arg = make_match(O_MATCH,stab2arg(A_STAB,defstab),spat);
- }
- arg->arg_type = O_SPLIT;
- spat = arg[2].arg_ptr.arg_spat;
- spat->spat_repl = stab2arg(A_STAB,aadd(stab));
- if (spat->spat_short) { /* exact match can bypass regexec() */
- if (!((spat->spat_flags & SPAT_SCANFIRST) &&
- (spat->spat_flags & SPAT_ALL) )) {
- str_free(spat->spat_short);
- spat->spat_short = Nullstr;
+ case toketype_i_tkval:
+#endif
+ case toketype_ival:
+ PerlIO_printf(Perl_debug_log, " %8"IVdf, (IV)ps->val.ival);
+ break;
+ default:
+ PerlIO_printf(Perl_debug_log, " %8"UVxf, (UV)ps->val.ival);
}
}
- return arg;
+ PerlIO_printf(Perl_debug_log, "\n\n");
}
-SUBR *
-make_sub(name,cmd)
-char *name;
-CMD *cmd;
-{
- register SUBR *sub = (SUBR *) safemalloc(sizeof (SUBR));
- STAB *stab = stabent(name,TRUE);
+# define YY_STACK_PRINT(parser) \
+do { \
+ if (yydebug && DEBUG_v_TEST) \
+ yy_stack_print (aTHX_ parser); \
+} while (0)
- if (stab->stab_sub) {
- if (dowarn) {
- line_t oldline = line;
- if (cmd)
- line = cmd->c_line;
- warn("Subroutine %s redefined",name);
- line = oldline;
- }
- cmd_free(stab->stab_sub->cmd);
- afree(stab->stab_sub->tosave);
- safefree((char*)stab->stab_sub);
- }
- bzero((char *)sub, sizeof(SUBR));
- sub->cmd = cmd;
- sub->filename = filename;
- tosave = anew(Nullstab);
- tosave->ary_fill = 0; /* make 1 based */
- cmd_tosave(cmd); /* this builds the tosave array */
- sub->tosave = tosave;
- stab->stab_sub = sub;
-}
+/*------------------------------------------------.
+| Report that the YYRULE is going to be reduced. |
+`------------------------------------------------*/
-CMD *
-block_head(tail)
-register CMD *tail;
+static void
+yy_reduce_print (pTHX_ int yyrule)
{
- if (tail == Nullcmd) {
- return tail;
- }
- return tail->c_head;
+ int yyi;
+ const unsigned int yylineno = yyrline[yyrule];
+ YYFPRINTF (Perl_debug_log, "Reducing stack by rule %d (line %u), ",
+ yyrule - 1, yylineno);
+ /* Print the symbols being reduced, and their result. */
+ for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
+ YYFPRINTF (Perl_debug_log, "%s ", yytname [yyrhs[yyi]]);
+ YYFPRINTF (Perl_debug_log, "-> %s\n", yytname [yyr1[yyrule]]);
}
-CMD *
-append_line(head,tail)
-register CMD *head;
-register CMD *tail;
-{
- if (tail == Nullcmd)
- return head;
- if (!tail->c_head) /* make sure tail is well formed */
- tail->c_head = tail;
- if (head != Nullcmd) {
- tail = tail->c_head; /* get to start of tail list */
- if (!head->c_head)
- head->c_head = head; /* start a new head list */
- while (head->c_next) {
- head->c_next->c_head = head->c_head;
- head = head->c_next; /* get to end of head list */
- }
- head->c_next = tail; /* link to end of old list */
- tail->c_head = head->c_head; /* propagate head pointer */
- }
- while (tail->c_next) {
- tail->c_next->c_head = tail->c_head;
- tail = tail->c_next;
- }
- return tail;
-}
+# define YY_REDUCE_PRINT(Rule) \
+do { \
+ if (yydebug) \
+ yy_reduce_print (aTHX_ Rule); \
+} while (0)
-CMD *
-make_acmd(type,stab,cond,arg)
-int type;
-STAB *stab;
-ARG *cond;
-ARG *arg;
-{
- register CMD *cmd = (CMD *) safemalloc(sizeof (CMD));
-
- bzero((char *)cmd, sizeof(CMD));
- cmd->c_type = type;
- cmd->ucmd.acmd.ac_stab = stab;
- cmd->ucmd.acmd.ac_expr = arg;
- cmd->c_expr = cond;
- if (cond) {
- opt_arg(cmd,1,1);
- cmd->c_flags |= CF_COND;
- }
- if (cmdline != NOLINE) {
- cmd->c_line = cmdline;
- cmdline = NOLINE;
- }
- cmd->c_file = filename;
- return cmd;
-}
+#else /* !DEBUGGING */
+# define YYDPRINTF(Args)
+# define YYDSYMPRINTF(Title, Token, Value)
+# define YY_STACK_PRINT(parser)
+# define YY_REDUCE_PRINT(Rule)
+#endif /* !DEBUGGING */
-CMD *
-make_ccmd(type,arg,cblock)
-int type;
-register ARG *arg;
-struct compcmd cblock;
-{
- register CMD *cmd = (CMD *) safemalloc(sizeof (CMD));
-
- bzero((char *)cmd, sizeof(CMD));
- cmd->c_type = type;
- cmd->c_expr = arg;
- cmd->ucmd.ccmd.cc_true = cblock.comp_true;
- cmd->ucmd.ccmd.cc_alt = cblock.comp_alt;
- if (arg) {
- opt_arg(cmd,1,0);
- cmd->c_flags |= CF_COND;
- }
- if (cmdline != NOLINE) {
- cmd->c_line = cmdline;
- cmdline = NOLINE;
- }
- return cmd;
-}
+/* called during cleanup (via SAVEDESTRUCTOR_X) to free any items on the
+ * parse stack, thus avoiding leaks if we die */
-void
-opt_arg(cmd,fliporflop,acmd)
-register CMD *cmd;
-int fliporflop;
-int acmd;
+static void
+S_clear_yystack(pTHX_ const yy_parser *parser)
{
- register ARG *arg;
- int opt = CFT_EVAL;
- int sure = 0;
- ARG *arg2;
- char *tmps; /* for True macro */
- int context = 0; /* 0 = normal, 1 = before &&, 2 = before || */
- int flp = fliporflop;
-
- if (!cmd)
- return;
- arg = cmd->c_expr;
-
- /* Can we turn && and || into if and unless? */
-
- if (acmd && !cmd->ucmd.acmd.ac_expr &&
- (arg->arg_type == O_AND || arg->arg_type == O_OR) ) {
- dehoist(arg,1);
- dehoist(arg,2);
- cmd->ucmd.acmd.ac_expr = arg[2].arg_ptr.arg_arg;
- cmd->c_expr = arg[1].arg_ptr.arg_arg;
- if (arg->arg_type == O_OR)
- cmd->c_flags ^= CF_INVERT; /* || is like unless */
- arg->arg_len = 0;
- arg_free(arg);
- arg = cmd->c_expr;
- }
-
- /* Turn "if (!expr)" into "unless (expr)" */
-
- while (arg->arg_type == O_NOT) {
- dehoist(arg,1);
- cmd->c_flags ^= CF_INVERT; /* flip sense of cmd */
- cmd->c_expr = arg[1].arg_ptr.arg_arg; /* hoist the rest of expr */
- free_arg(arg);
- arg = cmd->c_expr; /* here we go again */
- }
+ yy_stack_frame *ps = parser->ps;
+ int i = 0;
- if (!arg->arg_len) { /* sanity check */
- cmd->c_flags |= opt;
+ if (!parser->stack || ps == parser->stack)
return;
- }
-
- /* for "cond .. cond" we set up for the initial check */
- if (arg->arg_type == O_FLIP)
- context |= 4;
-
- /* for "cond && expr" and "cond || expr" we can ignore expr, sort of */
-
- if (arg->arg_type == O_AND)
- context |= 1;
- else if (arg->arg_type == O_OR)
- context |= 2;
- if (context && arg[flp].arg_type == A_EXPR) {
- arg = arg[flp].arg_ptr.arg_arg;
- flp = 1;
- }
-
- if (arg[flp].arg_flags & (AF_PRE|AF_POST)) {
- cmd->c_flags |= opt;
- return; /* side effect, can't optimize */
- }
-
- if (arg->arg_type == O_ITEM || arg->arg_type == O_FLIP ||
- arg->arg_type == O_AND || arg->arg_type == O_OR) {
- if (arg[flp].arg_type == A_SINGLE) {
- opt = (str_true(arg[flp].arg_ptr.arg_str) ? CFT_TRUE : CFT_FALSE);
- cmd->c_short = arg[flp].arg_ptr.arg_str;
- goto literal;
- }
- else if (arg[flp].arg_type == A_STAB || arg[flp].arg_type == A_LVAL) {
- cmd->c_stab = arg[flp].arg_ptr.arg_stab;
- opt = CFT_REG;
- literal:
- if (!context) { /* no && or ||? */
- free_arg(arg);
- cmd->c_expr = Nullarg;
- }
- if (!(context & 1))
- cmd->c_flags |= CF_EQSURE;
- if (!(context & 2))
- cmd->c_flags |= CF_NESURE;
- }
- }
- else if (arg->arg_type == O_MATCH || arg->arg_type == O_SUBST ||
- arg->arg_type == O_NMATCH || arg->arg_type == O_NSUBST) {
- if ((arg[1].arg_type == A_STAB || arg[1].arg_type == A_LVAL) &&
- arg[2].arg_type == A_SPAT &&
- arg[2].arg_ptr.arg_spat->spat_short ) {
- cmd->c_stab = arg[1].arg_ptr.arg_stab;
- cmd->c_short = arg[2].arg_ptr.arg_spat->spat_short;
- cmd->c_slen = arg[2].arg_ptr.arg_spat->spat_slen;
- if (arg[2].arg_ptr.arg_spat->spat_flags & SPAT_ALL &&
- !(arg[2].arg_ptr.arg_spat->spat_flags & SPAT_ONCE) &&
- (arg->arg_type == O_MATCH || arg->arg_type == O_NMATCH) )
- sure |= CF_EQSURE; /* (SUBST must be forced even */
- /* if we know it will work.) */
- arg[2].arg_ptr.arg_spat->spat_short = Nullstr;
- arg[2].arg_ptr.arg_spat->spat_slen = 0; /* only one chk */
- sure |= CF_NESURE; /* normally only sure if it fails */
- if (arg->arg_type == O_NMATCH || arg->arg_type == O_NSUBST)
- cmd->c_flags |= CF_FIRSTNEG;
- if (context & 1) { /* only sure if thing is false */
- if (cmd->c_flags & CF_FIRSTNEG)
- sure &= ~CF_NESURE;
- else
- sure &= ~CF_EQSURE;
- }
- else if (context & 2) { /* only sure if thing is true */
- if (cmd->c_flags & CF_FIRSTNEG)
- sure &= ~CF_EQSURE;
- else
- sure &= ~CF_NESURE;
- }
- if (sure & (CF_EQSURE|CF_NESURE)) { /* if we know anything*/
- if (arg[2].arg_ptr.arg_spat->spat_flags & SPAT_SCANFIRST)
- opt = CFT_SCAN;
- else
- opt = CFT_ANCHOR;
- if (sure == (CF_EQSURE|CF_NESURE) /* really sure? */
- && arg->arg_type == O_MATCH
- && context & 4
- && fliporflop == 1) {
- spat_free(arg[2].arg_ptr.arg_spat);
- arg[2].arg_ptr.arg_spat = Nullspat; /* don't do twice */
- }
- cmd->c_flags |= sure;
- }
- }
- }
- else if (arg->arg_type == O_SEQ || arg->arg_type == O_SNE ||
- arg->arg_type == O_SLT || arg->arg_type == O_SGT) {
- if (arg[1].arg_type == A_STAB || arg[1].arg_type == A_LVAL) {
- if (arg[2].arg_type == A_SINGLE) {
- cmd->c_stab = arg[1].arg_ptr.arg_stab;
- cmd->c_short = arg[2].arg_ptr.arg_str;
- cmd->c_slen = 30000;
- switch (arg->arg_type) {
- case O_SLT: case O_SGT:
- sure |= CF_EQSURE;
- cmd->c_flags |= CF_FIRSTNEG;
- break;
- case O_SNE:
- cmd->c_flags |= CF_FIRSTNEG;
- /* FALL THROUGH */
- case O_SEQ:
- sure |= CF_NESURE|CF_EQSURE;
- break;
- }
- if (context & 1) { /* only sure if thing is false */
- if (cmd->c_flags & CF_FIRSTNEG)
- sure &= ~CF_NESURE;
- else
- sure &= ~CF_EQSURE;
- }
- else if (context & 2) { /* only sure if thing is true */
- if (cmd->c_flags & CF_FIRSTNEG)
- sure &= ~CF_EQSURE;
- else
- sure &= ~CF_NESURE;
- }
- if (sure & (CF_EQSURE|CF_NESURE)) {
- opt = CFT_STROP;
- cmd->c_flags |= sure;
- }
- }
- }
- }
- else if (arg->arg_type == O_EQ || arg->arg_type == O_NE ||
- arg->arg_type == O_LE || arg->arg_type == O_GE ||
- arg->arg_type == O_LT || arg->arg_type == O_GT) {
- if (arg[1].arg_type == A_STAB || arg[1].arg_type == A_LVAL) {
- if (arg[2].arg_type == A_SINGLE) {
- cmd->c_stab = arg[1].arg_ptr.arg_stab;
- cmd->c_short = str_nmake(str_gnum(arg[2].arg_ptr.arg_str));
- cmd->c_slen = arg->arg_type;
- sure |= CF_NESURE|CF_EQSURE;
- if (context & 1) { /* only sure if thing is false */
- sure &= ~CF_EQSURE;
- }
- else if (context & 2) { /* only sure if thing is true */
- sure &= ~CF_NESURE;
- }
- if (sure & (CF_EQSURE|CF_NESURE)) {
- opt = CFT_NUMOP;
- cmd->c_flags |= sure;
+ YYDPRINTF ((Perl_debug_log, "clearing the parse stack\n"));
+
+ /* Freeing ops on the stack, and the op_latefree / op_latefreed /
+ * op_attached flags:
+ *
+ * When we pop tokens off the stack during error recovery, or when
+ * we pop all the tokens off the stack after a die during a shift or
+ * reduce (i.e. Perl_croak somewhere in yylex() or in one of the
+ * newFOO() functions), then it's possible that some of these tokens are
+ * of type opval, pointing to an OP. All these ops are orphans; each is
+ * its own miniature subtree that has not yet been attached to a
+ * larger tree. In this case, we should clearly free the op (making
+ * sure, for each op we free that we have PL_comppad pointing to the
+ * right place for freeing any SVs attached to the op in threaded
+ * builds.
+ *
+ * However, there is a particular problem if we die in newFOO() called
+ * by a reducing action; e.g.
+ *
+ * foo : bar baz boz
+ * { $$ = newFOO($1,$2,$3) }
+ *
+ * where
+ * OP *newFOO { ....; if (...) croak; .... }
+ *
+ * In this case, when we come to clean bar baz and boz off the stack,
+ * we don't know whether newFOO() has already:
+ * * freed them
+ * * left them as is
+ * * attached them to part of a larger tree
+ * * attached them to PL_compcv
+ * * attached them to PL_compcv then freed it (as in BEGIN {die } )
+ *
+ * To get round this problem, we set the flag op_latefree on every op
+ * that gets pushed onto the parser stack. If op_free() sees this
+ * flag, it clears the op and frees any children,, but *doesn't* free
+ * the op itself; instead it sets the op_latefreed flag. This means
+ * that we can safely call op_free() multiple times on each stack op.
+ * So, when clearing the stack, we first, for each op that was being
+ * reduced, call op_free with op_latefree=1. This ensures that all ops
+ * hanging off these op are freed, but the reducing ops themselces are
+ * just undefed. Then we set op_latefreed=0 on *all* ops on the stack
+ * and free them. A little thought should convince you that this
+ * two-part approach to the reducing ops should handle the first three
+ * cases above safely.
+ *
+ * In the case of attaching to PL_compcv (currently just newATTRSUB
+ * does this), then we set the op_attached flag on the op that has
+ * been so attached, then avoid doing the final op_free during
+ * cleanup, on the assumption that it will happen (or has already
+ * happened) when PL_compcv is freed.
+ *
+ * Note this is fairly fragile mechanism. A more robust approach
+ * would be to use two of these flag bits as 2-bit reference count
+ * field for each op, indicating whether it is pointed to from:
+ * * a parent op
+ * * the parser stack
+ * * a CV
+ * but this would involve reworking all code (core and external) that
+ * manipulate op trees.
+ *
+ * XXX DAPM 17/1/07 I've decided its too fragile for now, and so have
+ * disabled it */
+
+#define DISABLE_STACK_FREE
+
+
+#ifdef DISABLE_STACK_FREE
+ ps -= parser->yylen;
+ PERL_UNUSED_VAR(i);
+#else
+ /* clear any reducing ops (1st pass) */
+
+ for (i=0; i< parser->yylen; i++) {
+ LEAVE_SCOPE(ps[-i].savestack_ix);
+ if (yy_type_tab[yystos[ps[-i].state]] == toketype_opval
+ && ps[-i].val.opval) {
+ if ( ! (ps[-i].val.opval->op_attached
+ && !ps[-i].val.opval->op_latefreed))
+ {
+ if (ps[-i].comppad != PL_comppad) {
+ PAD_RESTORE_LOCAL(ps[-i].comppad);
}
+ op_free(ps[-i].val.opval);
}
}
}
- else if (arg->arg_type == O_ASSIGN &&
- (arg[1].arg_type == A_STAB || arg[1].arg_type == A_LVAL) &&
- arg[1].arg_ptr.arg_stab == defstab &&
- arg[2].arg_type == A_EXPR ) {
- arg2 = arg[2].arg_ptr.arg_arg;
- if (arg2->arg_type == O_ITEM && arg2[1].arg_type == A_READ) {
- opt = CFT_GETS;
- cmd->c_stab = arg2[1].arg_ptr.arg_stab;
- if (!(arg2[1].arg_ptr.arg_stab->stab_io->flags & IOF_ARGV)) {
- free_arg(arg2);
- free_arg(arg);
- cmd->c_expr = Nullarg;
- }
- }
- }
- else if (arg->arg_type == O_CHOP &&
- (arg[1].arg_type == A_STAB || arg[1].arg_type == A_LVAL) ) {
- opt = CFT_CHOP;
- cmd->c_stab = arg[1].arg_ptr.arg_stab;
- free_arg(arg);
- cmd->c_expr = Nullarg;
- }
- if (context & 4)
- opt |= CF_FLIP;
- cmd->c_flags |= opt;
-
- if (cmd->c_flags & CF_FLIP) {
- if (fliporflop == 1) {
- arg = cmd->c_expr; /* get back to O_FLIP arg */
- arg[3].arg_ptr.arg_cmd = (CMD*)safemalloc(sizeof(CMD));
- bcopy((char *)cmd, (char *)arg[3].arg_ptr.arg_cmd, sizeof(CMD));
- arg[4].arg_ptr.arg_cmd = (CMD*)safemalloc(sizeof(CMD));
- bcopy((char *)cmd, (char *)arg[4].arg_ptr.arg_cmd, sizeof(CMD));
- opt_arg(arg[4].arg_ptr.arg_cmd,2,acmd);
- arg->arg_len = 2; /* this is a lie */
- }
- else {
- if ((opt & CF_OPTIMIZE) == CFT_EVAL)
- cmd->c_flags = (cmd->c_flags & ~CF_OPTIMIZE) | CFT_UNFLIP;
- }
- }
-}
+#endif
-ARG *
-mod_match(type,left,pat)
-register ARG *left;
-register ARG *pat;
-{
+ /* now free whole the stack, including the just-reduced ops */
- register SPAT *spat;
- register ARG *newarg;
-
- if ((pat->arg_type == O_MATCH ||
- pat->arg_type == O_SUBST ||
- pat->arg_type == O_TRANS ||
- pat->arg_type == O_SPLIT
- ) &&
- pat[1].arg_ptr.arg_stab == defstab ) {
- switch (pat->arg_type) {
- case O_MATCH:
- newarg = make_op(type == O_MATCH ? O_MATCH : O_NMATCH,
- pat->arg_len,
- left,Nullarg,Nullarg,0);
- break;
- case O_SUBST:
- newarg = l(make_op(type == O_MATCH ? O_SUBST : O_NSUBST,
- pat->arg_len,
- left,Nullarg,Nullarg,0));
- break;
- case O_TRANS:
- newarg = l(make_op(type == O_MATCH ? O_TRANS : O_NTRANS,
- pat->arg_len,
- left,Nullarg,Nullarg,0));
- break;
- case O_SPLIT:
- newarg = make_op(type == O_MATCH ? O_SPLIT : O_SPLIT,
- pat->arg_len,
- left,Nullarg,Nullarg,0);
- break;
- }
- if (pat->arg_len >= 2) {
- newarg[2].arg_type = pat[2].arg_type;
- newarg[2].arg_ptr = pat[2].arg_ptr;
- newarg[2].arg_flags = pat[2].arg_flags;
- if (pat->arg_len >= 3) {
- newarg[3].arg_type = pat[3].arg_type;
- newarg[3].arg_ptr = pat[3].arg_ptr;
- newarg[3].arg_flags = pat[3].arg_flags;
+ while (ps > parser->stack) {
+ LEAVE_SCOPE(ps->savestack_ix);
+ if (yy_type_tab[yystos[ps->state]] == toketype_opval
+ && ps->val.opval)
+ {
+ if (ps->comppad != PL_comppad) {
+ PAD_RESTORE_LOCAL(ps->comppad);
}
+ YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
+#ifndef DISABLE_STACK_FREE
+ ps->val.opval->op_latefree = 0;
+ if (!(ps->val.opval->op_attached && !ps->val.opval->op_latefreed))
+#endif
+ op_free(ps->val.opval);
}
- safefree((char*)pat);
- }
- else {
- spat = (SPAT *) safemalloc(sizeof (SPAT));
- bzero((char *)spat, sizeof(SPAT));
- spat->spat_next = spat_root; /* link into spat list */
- spat_root = spat;
-
- spat->spat_runtime = pat;
- newarg = make_op(type,2,left,Nullarg,Nullarg,0);
- newarg[2].arg_type = A_SPAT;
- newarg[2].arg_ptr.arg_spat = spat;
- newarg[2].arg_flags = AF_SPECIAL;
+ ps--;
}
-
- return newarg;
}
-CMD *
-add_label(lbl,cmd)
-char *lbl;
-register CMD *cmd;
-{
- if (cmd)
- cmd->c_label = lbl;
- return cmd;
-}
-CMD *
-addcond(cmd, arg)
-register CMD *cmd;
-register ARG *arg;
-{
- cmd->c_expr = arg;
- opt_arg(cmd,1,0);
- cmd->c_flags |= CF_COND;
- return cmd;
-}
+/*----------.
+| yyparse. |
+`----------*/
-CMD *
-addloop(cmd, arg)
-register CMD *cmd;
-register ARG *arg;
+int
+#ifdef PERL_IN_MADLY_C
+Perl_madparse (pTHX)
+#else
+Perl_yyparse (pTHX)
+#endif
{
- cmd->c_expr = arg;
- opt_arg(cmd,1,0);
- cmd->c_flags |= CF_COND|CF_LOOP;
- if (cmd->c_type == C_BLOCK)
- cmd->c_flags &= ~CF_COND;
- else {
- arg = cmd->ucmd.acmd.ac_expr;
- if (arg && arg->arg_type == O_ITEM && arg[1].arg_type == A_CMD)
- cmd->c_flags &= ~CF_COND; /* "do {} while" happens at least once */
- if (arg && arg->arg_type == O_SUBR)
- cmd->c_flags &= ~CF_COND; /* likewise for "do subr() while" */
- }
- return cmd;
-}
+ dVAR;
+ register int yystate;
+ register int yyn;
+ int yyresult;
-CMD *
-invert(cmd)
-register CMD *cmd;
-{
- cmd->c_flags ^= CF_INVERT;
- return cmd;
-}
+ /* Lookahead token as an internal (translated) token number. */
+ int yytoken = 0;
-yyerror(s)
-char *s;
-{
- char tmpbuf[128];
- char *tname = tmpbuf;
-
- if (yychar > 256) {
- tname = tokename[yychar-256];
- if (strEQ(tname,"word"))
- strcpy(tname,tokenbuf);
- else if (strEQ(tname,"register"))
- sprintf(tname,"$%s",tokenbuf);
- else if (strEQ(tname,"array_length"))
- sprintf(tname,"$#%s",tokenbuf);
- }
- else if (!yychar)
- strcpy(tname,"EOF");
- else if (yychar < 32)
- sprintf(tname,"^%c",yychar+64);
- else if (yychar == 127)
- strcpy(tname,"^?");
- else
- sprintf(tname,"%c",yychar);
- sprintf(tokenbuf, "%s in file %s at line %d, next token \"%s\"\n",
- s,filename,line,tname);
- if (in_eval)
- str_set(stabent("@",TRUE)->stab_val,tokenbuf);
- else
- fputs(tokenbuf,stderr);
-}
+ register yy_parser *parser; /* the parser object */
+ register yy_stack_frame *ps; /* current parser stack frame */
-ARG *
-make_op(type,newlen,arg1,arg2,arg3,dolist)
-int type;
-int newlen;
-ARG *arg1;
-ARG *arg2;
-ARG *arg3;
-int dolist;
-{
- register ARG *arg;
- register ARG *chld;
- register int doarg;
-
- arg = op_new(newlen);
- arg->arg_type = type;
- doarg = opargs[type];
- if (chld = arg1) {
- if (!(doarg & 1))
- arg[1].arg_flags |= AF_SPECIAL;
- if (doarg & 16)
- arg[1].arg_flags |= AF_NUMERIC;
- if (chld->arg_type == O_ITEM &&
- (hoistable[chld[1].arg_type] || chld[1].arg_type == A_LVAL) ) {
- arg[1].arg_type = chld[1].arg_type;
- arg[1].arg_ptr = chld[1].arg_ptr;
- arg[1].arg_flags |= chld[1].arg_flags;
- free_arg(chld);
- }
- else {
- arg[1].arg_type = A_EXPR;
- arg[1].arg_ptr.arg_arg = chld;
- if (dolist & 1) {
- if (chld->arg_type == O_LIST) {
- if (newlen == 1) { /* we can hoist entire list */
- chld->arg_type = type;
- free_arg(arg);
- arg = chld;
- }
- else {
- arg[1].arg_flags |= AF_SPECIAL;
- }
- }
- else {
- switch (chld->arg_type) {
- case O_ARRAY:
- if (chld->arg_len == 1)
- arg[1].arg_flags |= AF_SPECIAL;
- break;
- case O_ITEM:
- if (chld[1].arg_type == A_READ ||
- chld[1].arg_type == A_INDREAD ||
- chld[1].arg_type == A_GLOB)
- arg[1].arg_flags |= AF_SPECIAL;
- break;
- case O_SPLIT:
- case O_TMS:
- case O_EACH:
- case O_VALUES:
- case O_KEYS:
- case O_SORT:
- arg[1].arg_flags |= AF_SPECIAL;
- break;
- }
- }
- }
- }
- }
- if (chld = arg2) {
- if (!(doarg & 2))
- arg[2].arg_flags |= AF_SPECIAL;
- if (doarg & 32)
- arg[2].arg_flags |= AF_NUMERIC;
- if (chld->arg_type == O_ITEM &&
- (hoistable[chld[1].arg_type] ||
- (type == O_ASSIGN &&
- ((chld[1].arg_type == A_READ && !(arg[1].arg_flags & AF_SPECIAL))
- ||
- (chld[1].arg_type == A_INDREAD && !(arg[1].arg_flags & AF_SPECIAL))
- ||
- (chld[1].arg_type == A_GLOB && !(arg[1].arg_flags & AF_SPECIAL))
- ||
- chld[1].arg_type == A_BACKTICK ) ) ) ) {
- arg[2].arg_type = chld[1].arg_type;
- arg[2].arg_ptr = chld[1].arg_ptr;
- free_arg(chld);
- }
- else {
- arg[2].arg_type = A_EXPR;
- arg[2].arg_ptr.arg_arg = chld;
- if ((dolist & 2) &&
- (chld->arg_type == O_LIST ||
- (chld->arg_type == O_ARRAY && chld->arg_len == 1) ))
- arg[2].arg_flags |= AF_SPECIAL;
- }
- }
- if (chld = arg3) {
- if (!(doarg & 4))
- arg[3].arg_flags |= AF_SPECIAL;
- if (doarg & 64)
- arg[3].arg_flags |= AF_NUMERIC;
- if (chld->arg_type == O_ITEM && hoistable[chld[1].arg_type]) {
- arg[3].arg_type = chld[1].arg_type;
- arg[3].arg_ptr = chld[1].arg_ptr;
- free_arg(chld);
- }
- else {
- arg[3].arg_type = A_EXPR;
- arg[3].arg_ptr.arg_arg = chld;
- if ((dolist & 4) &&
- (chld->arg_type == O_LIST ||
- (chld->arg_type == O_ARRAY && chld->arg_len == 1) ))
- arg[3].arg_flags |= AF_SPECIAL;
- }
- }
-#ifdef DEBUGGING
- if (debug & 16) {
- fprintf(stderr,"%lx <= make_op(%s",arg,opname[arg->arg_type]);
- if (arg1)
- fprintf(stderr,",%s=%lx",
- argname[arg[1].arg_type],arg[1].arg_ptr.arg_arg);
- if (arg2)
- fprintf(stderr,",%s=%lx",
- argname[arg[2].arg_type],arg[2].arg_ptr.arg_arg);
- if (arg3)
- fprintf(stderr,",%s=%lx",
- argname[arg[3].arg_type],arg[3].arg_ptr.arg_arg);
- fprintf(stderr,")\n");
- }
+#define YYPOPSTACK parser->ps = --ps
+#define YYPUSHSTACK parser->ps = ++ps
+
+ /* The variable used to return semantic value and location from the
+ action routines: ie $$. */
+ YYSTYPE yyval;
+
+#ifndef PERL_IN_MADLY_C
+# ifdef PERL_MAD
+ if (PL_madskills)
+ return madparse();
+# endif
#endif
- evalstatic(arg); /* see if we can consolidate anything */
- return arg;
-}
-/* turn 123 into 123 == $. */
+ YYDPRINTF ((Perl_debug_log, "Starting parse\n"));
-ARG *
-flipflip(arg)
-register ARG *arg;
-{
- if (arg && arg->arg_type == O_ITEM && arg[1].arg_type == A_SINGLE) {
- arg = (ARG*)saferealloc((char*)arg,3*sizeof(ARG));
- arg->arg_type = O_EQ;
- arg->arg_len = 2;
- arg[2].arg_type = A_STAB;
- arg[2].arg_flags = 0;
- arg[2].arg_ptr.arg_stab = stabent(".",TRUE);
- }
- return arg;
-}
+ parser = PL_parser;
+ ps = parser->ps;
-void
-evalstatic(arg)
-register ARG *arg;
-{
- register STR *str;
- register STR *s1;
- register STR *s2;
- double value; /* must not be register */
- register char *tmps;
- int i;
- unsigned long tmplong;
- double exp(), log(), sqrt(), modf();
- char *crypt();
-
- if (!arg || !arg->arg_len)
- return;
+ ENTER; /* force parser stack cleanup before we return */
+ SAVEDESTRUCTOR_X(S_clear_yystack, parser);
- if (arg[1].arg_type == A_SINGLE &&
- (arg->arg_len == 1 || arg[2].arg_type == A_SINGLE) ) {
- str = str_new(0);
- s1 = arg[1].arg_ptr.arg_str;
- if (arg->arg_len > 1)
- s2 = arg[2].arg_ptr.arg_str;
- else
- s2 = Nullstr;
- switch (arg->arg_type) {
- default:
- str_free(str);
- str = Nullstr; /* can't be evaluated yet */
- break;
- case O_CONCAT:
- str_sset(str,s1);
- str_scat(str,s2);
- break;
- case O_REPEAT:
- i = (int)str_gnum(s2);
- while (i-- > 0)
- str_scat(str,s1);
- break;
- case O_MULTIPLY:
- value = str_gnum(s1);
- str_numset(str,value * str_gnum(s2));
- break;
- case O_DIVIDE:
- value = str_gnum(s2);
- if (value == 0.0)
- fatal("Illegal division by constant zero");
- str_numset(str,str_gnum(s1) / value);
- break;
- case O_MODULO:
- tmplong = (unsigned long)str_gnum(s2);
- if (tmplong == 0L)
- fatal("Illegal modulus of constant zero");
- str_numset(str,(double)(((unsigned long)str_gnum(s1)) % tmplong));
- break;
- case O_ADD:
- value = str_gnum(s1);
- str_numset(str,value + str_gnum(s2));
- break;
- case O_SUBTRACT:
- value = str_gnum(s1);
- str_numset(str,value - str_gnum(s2));
- break;
- case O_LEFT_SHIFT:
- value = str_gnum(s1);
- i = (int)str_gnum(s2);
- str_numset(str,(double)(((unsigned long)value) << i));
- break;
- case O_RIGHT_SHIFT:
- value = str_gnum(s1);
- i = (int)str_gnum(s2);
- str_numset(str,(double)(((unsigned long)value) >> i));
- break;
- case O_LT:
- value = str_gnum(s1);
- str_numset(str,(double)(value < str_gnum(s2)));
- break;
- case O_GT:
- value = str_gnum(s1);
- str_numset(str,(double)(value > str_gnum(s2)));
- break;
- case O_LE:
- value = str_gnum(s1);
- str_numset(str,(double)(value <= str_gnum(s2)));
- break;
- case O_GE:
- value = str_gnum(s1);
- str_numset(str,(double)(value >= str_gnum(s2)));
- break;
- case O_EQ:
- value = str_gnum(s1);
- str_numset(str,(double)(value == str_gnum(s2)));
- break;
- case O_NE:
- value = str_gnum(s1);
- str_numset(str,(double)(value != str_gnum(s2)));
- break;
- case O_BIT_AND:
- value = str_gnum(s1);
- str_numset(str,(double)(((unsigned long)value) &
- ((unsigned long)str_gnum(s2))));
- break;
- case O_XOR:
- value = str_gnum(s1);
- str_numset(str,(double)(((unsigned long)value) ^
- ((unsigned long)str_gnum(s2))));
- break;
- case O_BIT_OR:
- value = str_gnum(s1);
- str_numset(str,(double)(((unsigned long)value) |
- ((unsigned long)str_gnum(s2))));
- break;
- case O_AND:
- if (str_true(s1))
- str = str_make(str_get(s2));
- else
- str = str_make(str_get(s1));
- break;
- case O_OR:
- if (str_true(s1))
- str = str_make(str_get(s1));
- else
- str = str_make(str_get(s2));
- break;
- case O_COND_EXPR:
- if (arg[3].arg_type != A_SINGLE) {
- str_free(str);
- str = Nullstr;
- }
- else {
- str = str_make(str_get(str_true(s1) ? s2 : arg[3].arg_ptr.arg_str));
- str_free(arg[3].arg_ptr.arg_str);
- }
- break;
- case O_NEGATE:
- str_numset(str,(double)(-str_gnum(s1)));
- break;
- case O_NOT:
- str_numset(str,(double)(!str_true(s1)));
- break;
- case O_COMPLEMENT:
- str_numset(str,(double)(~(long)str_gnum(s1)));
- break;
- case O_LENGTH:
- str_numset(str, (double)str_len(s1));
- break;
- case O_SUBSTR:
- if (arg[3].arg_type != A_SINGLE || stabent("[",allstabs)) {
- str_free(str); /* making the fallacious assumption */
- str = Nullstr; /* that any $[ occurs before substr()*/
- }
- else {
- char *beg;
- int len = (int)str_gnum(s2);
- int tmp;
-
- for (beg = str_get(s1); *beg && len > 0; beg++,len--) ;
- len = (int)str_gnum(arg[3].arg_ptr.arg_str);
- str_free(arg[3].arg_ptr.arg_str);
- if (len > (tmp = strlen(beg)))
- len = tmp;
- str_nset(str,beg,len);
- }
- break;
- case O_SLT:
- tmps = str_get(s1);
- str_numset(str,(double)(strLT(tmps,str_get(s2))));
- break;
- case O_SGT:
- tmps = str_get(s1);
- str_numset(str,(double)(strGT(tmps,str_get(s2))));
- break;
- case O_SLE:
- tmps = str_get(s1);
- str_numset(str,(double)(strLE(tmps,str_get(s2))));
- break;
- case O_SGE:
- tmps = str_get(s1);
- str_numset(str,(double)(strGE(tmps,str_get(s2))));
- break;
- case O_SEQ:
- tmps = str_get(s1);
- str_numset(str,(double)(strEQ(tmps,str_get(s2))));
- break;
- case O_SNE:
- tmps = str_get(s1);
- str_numset(str,(double)(strNE(tmps,str_get(s2))));
- break;
- case O_CRYPT:
-#ifdef CRYPT
- tmps = str_get(s1);
- str_set(str,crypt(tmps,str_get(s2)));
-#else
- fatal(
- "The crypt() function is unimplemented due to excessive paranoia.");
-#endif
- break;
- case O_EXP:
- str_numset(str,exp(str_gnum(s1)));
- break;
- case O_LOG:
- str_numset(str,log(str_gnum(s1)));
- break;
- case O_SQRT:
- str_numset(str,sqrt(str_gnum(s1)));
- break;
- case O_INT:
- value = str_gnum(s1);
- if (value >= 0.0)
- modf(value,&value);
- else {
- modf(-value,&value);
- value = -value;
- }
- str_numset(str,value);
- break;
- case O_ORD:
- str_numset(str,(double)(*str_get(s1)));
- break;
- }
- if (str) {
- arg->arg_type = O_ITEM; /* note arg1 type is already SINGLE */
- str_free(s1);
- str_free(s2);
- arg[1].arg_ptr.arg_str = str;
- }
- }
-}
+/*------------------------------------------------------------.
+| yynewstate -- Push a new state, which is found in yystate. |
+`------------------------------------------------------------*/
+ yynewstate:
-ARG *
-l(arg)
-register ARG *arg;
-{
- register int i;
- register ARG *arg1;
- ARG *tmparg;
+ yystate = ps->state;
- arg->arg_flags |= AF_COMMON; /* XXX should cross-match */
- /* this does unnecessary copying */
+ YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
- if (arg[1].arg_type == A_ARYLEN) {
- arg[1].arg_type = A_LARYLEN;
- return arg;
+#ifndef DISABLE_STACK_FREE
+ if (yy_type_tab[yystos[yystate]] == toketype_opval && ps->val.opval) {
+ ps->val.opval->op_latefree = 1;
+ ps->val.opval->op_latefreed = 0;
}
+#endif
- /* see if it's an array reference */
+ parser->yylen = 0;
- if (arg[1].arg_type == A_EXPR) {
- arg1 = arg[1].arg_ptr.arg_arg;
+ {
+ size_t size = ps - parser->stack + 1;
- if (arg1->arg_type == O_LIST && arg->arg_type != O_ITEM) {
- /* assign to list */
- arg[1].arg_flags |= AF_SPECIAL;
- dehoist(arg,2);
- arg[2].arg_flags |= AF_SPECIAL;
- for (i = arg1->arg_len; i >= 1; i--) {
- switch (arg1[i].arg_type) {
- case A_STAB: case A_LVAL:
- arg1[i].arg_type = A_LVAL;
- break;
- case A_EXPR: case A_LEXPR:
- arg1[i].arg_type = A_LEXPR;
- if (arg1[i].arg_ptr.arg_arg->arg_type == O_ARRAY)
- arg1[i].arg_ptr.arg_arg->arg_type = O_LARRAY;
- else if (arg1[i].arg_ptr.arg_arg->arg_type == O_HASH)
- arg1[i].arg_ptr.arg_arg->arg_type = O_LHASH;
- if (arg1[i].arg_ptr.arg_arg->arg_type == O_LARRAY)
- break;
- if (arg1[i].arg_ptr.arg_arg->arg_type == O_LHASH)
- break;
- /* FALL THROUGH */
- default:
- sprintf(tokenbuf,
- "Illegal item (%s) as lvalue",argname[arg1[i].arg_type]);
- yyerror(tokenbuf);
- }
- }
- }
- else if (arg1->arg_type == O_ARRAY) {
- if (arg1->arg_len == 1 && arg->arg_type != O_ITEM) {
- /* assign to array */
- arg[1].arg_flags |= AF_SPECIAL;
- dehoist(arg,2);
- arg[2].arg_flags |= AF_SPECIAL;
- }
- else
- arg1->arg_type = O_LARRAY; /* assign to array elem */
- }
- else if (arg1->arg_type == O_HASH)
- arg1->arg_type = O_LHASH;
- else if (arg1->arg_type != O_ASSIGN) {
- sprintf(tokenbuf,
- "Illegal expression (%s) as lvalue",opname[arg1->arg_type]);
- yyerror(tokenbuf);
- }
- arg[1].arg_type = A_LEXPR;
-#ifdef DEBUGGING
- if (debug & 16)
- fprintf(stderr,"lval LEXPR\n");
-#endif
- return arg;
- }
+ /* grow the stack? We always leave 1 spare slot,
+ * in case of a '' -> 'foo' reduction */
- /* not an array reference, should be a register name */
+ if (size >= (size_t)parser->stack_size - 1) {
+ /* this will croak on insufficient memory */
+ parser->stack_size *= 2;
+ Renew(parser->stack, parser->stack_size, yy_stack_frame);
+ ps = parser->ps = parser->stack + size -1;
- if (arg[1].arg_type != A_STAB && arg[1].arg_type != A_LVAL) {
- sprintf(tokenbuf,
- "Illegal item (%s) as lvalue",argname[arg[1].arg_type]);
- yyerror(tokenbuf);
+ YYDPRINTF((Perl_debug_log,
+ "parser stack size increased to %lu frames\n",
+ (unsigned long int)parser->stack_size));
+ }
}
- arg[1].arg_type = A_LVAL;
-#ifdef DEBUGGING
- if (debug & 16)
- fprintf(stderr,"lval LVAL\n");
-#endif
- return arg;
-}
-dehoist(arg,i)
-ARG *arg;
-{
- ARG *tmparg;
+/* Do appropriate processing given the current state. */
+/* Read a lookahead token if we need one and don't already have one. */
- if (arg[i].arg_type != A_EXPR) { /* dehoist */
- tmparg = make_op(O_ITEM,1,Nullarg,Nullarg,Nullarg,0);
- tmparg[1] = arg[i];
- arg[i].arg_ptr.arg_arg = tmparg;
- arg[i].arg_type = A_EXPR;
- }
-}
+ /* First try to decide what to do without reference to lookahead token. */
-ARG *
-addflags(i,flags,arg)
-register ARG *arg;
-{
- arg[i].arg_flags |= flags;
- return arg;
-}
+ yyn = yypact[yystate];
+ if (yyn == YYPACT_NINF)
+ goto yydefault;
-ARG *
-hide_ary(arg)
-ARG *arg;
-{
- if (arg->arg_type == O_ARRAY)
- return make_op(O_ITEM,1,arg,Nullarg,Nullarg,0);
- return arg;
-}
+ /* Not known => get a lookahead token if don't already have one. */
-ARG *
-make_list(arg)
-register ARG *arg;
-{
- register int i;
- register ARG *node;
- register ARG *nxtnode;
- register int j;
- STR *tmpstr;
-
- if (!arg) {
- arg = op_new(0);
- arg->arg_type = O_LIST;
- }
- if (arg->arg_type != O_COMMA) {
- arg->arg_flags |= AF_LISTISH; /* see listish() below */
- return arg;
- }
- for (i = 2, node = arg; ; i++) {
- if (node->arg_len < 2)
- break;
- if (node[2].arg_type != A_EXPR)
- break;
- node = node[2].arg_ptr.arg_arg;
- if (node->arg_type != O_COMMA)
- break;
- }
- if (i > 2) {
- node = arg;
- arg = op_new(i);
- tmpstr = arg->arg_ptr.arg_str;
- *arg = *node; /* copy everything except the STR */
- arg->arg_ptr.arg_str = tmpstr;
- for (j = 1; ; ) {
- arg[j] = node[1];
- ++j; /* Bug in Xenix compiler */
- if (j >= i) {
- arg[j] = node[2];
- free_arg(node);
- break;
- }
- nxtnode = node[2].arg_ptr.arg_arg;
- free_arg(node);
- node = nxtnode;
+ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
+ if (parser->yychar == YYEMPTY) {
+ YYDPRINTF ((Perl_debug_log, "Reading a token: "));
+#ifdef PERL_IN_MADLY_C
+ parser->yychar = PL_madskills ? madlex() : yylex();
+#else
+ parser->yychar = yylex();
+#endif
+
+# ifdef EBCDIC
+ if (parser->yychar >= 0 && parser->yychar < 255) {
+ parser->yychar = NATIVE_TO_ASCII(parser->yychar);
}
+# endif
}
- arg->arg_type = O_LIST;
- arg->arg_len = i;
- return arg;
-}
-/* turn a single item into a list */
-
-ARG *
-listish(arg)
-ARG *arg;
-{
- if (arg->arg_flags & AF_LISTISH) {
- arg = make_op(O_LIST,1,arg,Nullarg,Nullarg,0);
- arg[1].arg_flags &= ~AF_SPECIAL;
+ if (parser->yychar <= YYEOF) {
+ parser->yychar = yytoken = YYEOF;
+ YYDPRINTF ((Perl_debug_log, "Now at end of input.\n"));
}
- return arg;
-}
+ else {
+ yytoken = YYTRANSLATE (parser->yychar);
+ YYDSYMPRINTF ("Next token is", yytoken, &parser->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 (parser->yychar != YYEOF)
+ parser->yychar = YYEMPTY;
+
+ YYPUSHSTACK;
+ ps->state = yyn;
+ ps->val = parser->yylval;
+ ps->comppad = PL_comppad;
+ ps->savestack_ix = PL_savestack_ix;
+#ifdef DEBUGGING
+ ps->name = (const char *)(yytname[yytoken]);
+#endif
-/* mark list of local variables */
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (parser->yyerrstatus)
+ parser->yyerrstatus--;
-ARG *
-localize(arg)
-ARG *arg;
-{
- arg->arg_flags |= AF_LOCAL;
- return arg;
-}
+ goto yynewstate;
-ARG *
-stab2arg(atype,stab)
-int atype;
-register STAB *stab;
-{
- register ARG *arg;
- arg = op_new(1);
- arg->arg_type = O_ITEM;
- arg[1].arg_type = atype;
- arg[1].arg_ptr.arg_stab = stab;
- return arg;
-}
+ /*-----------------------------------------------------------.
+ | yydefault -- do the default action for the current state. |
+ `-----------------------------------------------------------*/
+ yydefault:
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
-ARG *
-cval_to_arg(cval)
-register char *cval;
-{
- register ARG *arg;
-
- arg = op_new(1);
- arg->arg_type = O_ITEM;
- arg[1].arg_type = A_SINGLE;
- arg[1].arg_ptr.arg_str = str_make(cval);
- safefree(cval);
- return arg;
-}
-ARG *
-op_new(numargs)
-int numargs;
-{
- register ARG *arg;
+ /*-----------------------------.
+ | yyreduce -- Do a reduction. |
+ `-----------------------------*/
+ yyreduce:
+ /* yyn is the number of a rule to reduce with. */
+ parser->yylen = yyr2[yyn];
- arg = (ARG*)safemalloc((numargs + 1) * sizeof (ARG));
- bzero((char *)arg, (numargs + 1) * sizeof (ARG));
- arg->arg_ptr.arg_str = str_new(0);
- arg->arg_len = numargs;
- return arg;
-}
+ /* If YYLEN is nonzero, implement the default value of the action:
+ "$$ = $1".
-void
-free_arg(arg)
-ARG *arg;
-{
- str_free(arg->arg_ptr.arg_str);
- safefree((char*)arg);
-}
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. Assigning to YYVAL
+ unconditionally makes the parser a bit smaller, and it avoids a
+ GCC warning that YYVAL may be used uninitialized. */
+ yyval = ps[1-parser->yylen].val;
-ARG *
-make_match(type,expr,spat)
-int type;
-ARG *expr;
-SPAT *spat;
-{
- register ARG *arg;
+ YY_STACK_PRINT(parser);
+ YY_REDUCE_PRINT (yyn);
- arg = make_op(type,2,expr,Nullarg,Nullarg,0);
+ switch (yyn) {
- arg[2].arg_type = A_SPAT;
- arg[2].arg_ptr.arg_spat = spat;
-#ifdef DEBUGGING
- if (debug & 16)
- fprintf(stderr,"make_match SPAT=%lx\n",(long)spat);
-#endif
- if (type == O_SUBST || type == O_NSUBST) {
- if (arg[1].arg_type != A_STAB)
- yyerror("Illegal lvalue");
- arg[1].arg_type = A_LVAL;
- }
- return arg;
-}
+#define dep() deprecate("\"do\" to call subroutines")
-ARG *
-cmd_to_arg(cmd)
-CMD *cmd;
-{
- register ARG *arg;
+#ifdef PERL_IN_MADLY_C
+# define IVAL(i) (i)->tk_lval.ival
+# define PVAL(p) (p)->tk_lval.pval
+# define TOKEN_GETMAD(a,b,c) token_getmad((a),(b),(c))
+# define TOKEN_FREE(a) token_free(a)
+# define OP_GETMAD(a,b,c) op_getmad((a),(b),(c))
+# define IF_MAD(a,b) (a)
+# define DO_MAD(a) a
+# define MAD
+#else
+# define IVAL(i) (i)
+# define PVAL(p) (p)
+# define TOKEN_GETMAD(a,b,c)
+# define TOKEN_FREE(a)
+# define OP_GETMAD(a,b,c)
+# define IF_MAD(a,b) (b)
+# define DO_MAD(a)
+# undef MAD
+#endif
- arg = op_new(1);
- arg->arg_type = O_ITEM;
- arg[1].arg_type = A_CMD;
- arg[1].arg_ptr.arg_cmd = cmd;
- return arg;
-}
+/* contains all the rule actions; auto-generated from perly.y */
+#include "perly.act"
-CMD *
-wopt(cmd)
-register CMD *cmd;
-{
- register CMD *tail;
- register ARG *arg = cmd->c_expr;
- STAB *asgnstab;
-
- /* hoist "while (<channel>)" up into command block */
-
- if (arg && arg->arg_type == O_ITEM && arg[1].arg_type == A_READ) {
- cmd->c_flags &= ~CF_OPTIMIZE; /* clear optimization type */
- cmd->c_flags |= CFT_GETS; /* and set it to do the input */
- cmd->c_stab = arg[1].arg_ptr.arg_stab;
- if (arg[1].arg_ptr.arg_stab->stab_io->flags & IOF_ARGV) {
- cmd->c_expr = l(make_op(O_ASSIGN, 2, /* fake up "$_ =" */
- stab2arg(A_LVAL,defstab), arg, Nullarg,1 ));
- }
- else {
- free_arg(arg);
- cmd->c_expr = Nullarg;
- }
- }
- else if (arg && arg->arg_type == O_ITEM && arg[1].arg_type == A_INDREAD) {
- cmd->c_flags &= ~CF_OPTIMIZE; /* clear optimization type */
- cmd->c_flags |= CFT_INDGETS; /* and set it to do the input */
- cmd->c_stab = arg[1].arg_ptr.arg_stab;
- free_arg(arg);
- cmd->c_expr = Nullarg;
- }
- else if (arg && arg->arg_type == O_ITEM && arg[1].arg_type == A_GLOB) {
- if ((cmd->c_flags & CF_OPTIMIZE) == CFT_ARRAY)
- asgnstab = cmd->c_stab;
- else
- asgnstab = defstab;
- cmd->c_expr = l(make_op(O_ASSIGN, 2, /* fake up "$foo =" */
- stab2arg(A_LVAL,asgnstab), arg, Nullarg,1 ));
- cmd->c_flags &= ~CF_OPTIMIZE; /* clear optimization type */
}
- /* First find the end of the true list */
+#ifndef DISABLE_STACK_FREE
+ /* any just-reduced ops with the op_latefreed flag cleared need to be
+ * freed; the rest need the flag resetting */
+ {
+ int i;
+ for (i=0; i< parser->yylen; i++) {
+ if (yy_type_tab[yystos[ps[-i].state]] == toketype_opval
+ && ps[-i].val.opval)
+ {
+ ps[-i].val.opval->op_latefree = 0;
+ if (ps[-i].val.opval->op_latefreed)
+ op_free(ps[-i].val.opval);
+ }
+ }
+ }
+#endif
- if (cmd->ucmd.ccmd.cc_true == Nullcmd)
- return cmd;
- for (tail = cmd->ucmd.ccmd.cc_true; tail->c_next; tail = tail->c_next) ;
+ parser->ps = ps -= (parser->yylen-1);
- /* if there's a continue block, link it to true block and find end */
+ /* Now shift the result of the reduction. Determine what state
+ that goes to, based on the state we popped back to and the rule
+ number reduced by. */
- if (cmd->ucmd.ccmd.cc_alt != Nullcmd) {
- tail->c_next = cmd->ucmd.ccmd.cc_alt;
- for ( ; tail->c_next; tail = tail->c_next) ;
- }
+ ps->val = yyval;
+ ps->comppad = PL_comppad;
+ ps->savestack_ix = PL_savestack_ix;
+#ifdef DEBUGGING
+ ps->name = (const char *)(yytname [yyr1[yyn]]);
+#endif
- /* Here's the real trick: link the end of the list back to the beginning,
- * inserting a "last" block to break out of the loop. This saves one or
- * two procedure calls every time through the loop, because of how cmd_exec
- * does tail recursion.
- */
-
- tail->c_next = (CMD *) safemalloc(sizeof (CMD));
- tail = tail->c_next;
- if (!cmd->ucmd.ccmd.cc_alt)
- cmd->ucmd.ccmd.cc_alt = tail; /* every loop has a continue now */
-
- bcopy((char *)cmd, (char *)tail, sizeof(CMD));
- tail->c_type = C_EXPR;
- tail->c_flags ^= CF_INVERT; /* turn into "last unless" */
- tail->c_next = tail->ucmd.ccmd.cc_true; /* loop directly back to top */
- tail->ucmd.acmd.ac_expr = make_op(O_LAST,0,Nullarg,Nullarg,Nullarg,0);
- tail->ucmd.acmd.ac_stab = Nullstab;
- return cmd;
-}
+ yyn = yyr1[yyn];
-CMD *
-over(eachstab,cmd)
-STAB *eachstab;
-register CMD *cmd;
-{
- /* hoist "for $foo (@bar)" up into command block */
+ yystate = yypgoto[yyn - YYNTOKENS] + ps[-1].state;
+ if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == ps[-1].state)
+ yystate = yytable[yystate];
+ else
+ yystate = yydefgoto[yyn - YYNTOKENS];
+ ps->state = yystate;
+
+ goto yynewstate;
+
+
+ /*------------------------------------.
+ | yyerrlab -- here on detecting error |
+ `------------------------------------*/
+ yyerrlab:
+ /* If not already recovering from an error, report this error. */
+ if (!parser->yyerrstatus) {
+ yyerror ("syntax error");
+ }
+
+
+ if (parser->yyerrstatus == 3) {
+ /* If just tried and failed to reuse lookahead token after an
+ error, discard it. */
+
+ /* Return failure if at end of input. */
+ if (parser->yychar == YYEOF) {
+ /* Pop the error token. */
+ YYPOPSTACK;
+ /* Pop the rest of the stack. */
+ while (ps > parser->stack) {
+ YYDSYMPRINTF ("Error: popping", yystos[ps->state], &ps->val);
+ LEAVE_SCOPE(ps->savestack_ix);
+ if (yy_type_tab[yystos[ps->state]] == toketype_opval
+ && ps->val.opval)
+ {
+ YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
+ if (ps->comppad != PL_comppad) {
+ PAD_RESTORE_LOCAL(ps->comppad);
+ }
+ ps->val.opval->op_latefree = 0;
+ op_free(ps->val.opval);
+ }
+ YYPOPSTACK;
+ }
+ YYABORT;
+ }
- cmd->c_flags &= ~CF_OPTIMIZE; /* clear optimization type */
- cmd->c_flags |= CFT_ARRAY; /* and set it to do the iteration */
- cmd->c_stab = eachstab;
+ YYDSYMPRINTF ("Error: discarding", yytoken, &parser->yylval);
+ parser->yychar = YYEMPTY;
- return cmd;
-}
+ }
-static int gensym = 0;
+ /* Else will try to reuse lookahead token after shifting the error
+ token. */
+ goto yyerrlab1;
-STAB *
-genstab()
-{
- sprintf(tokenbuf,"_GEN_%d",gensym++);
- return stabent(tokenbuf,TRUE);
-}
-/* this routine is in perly.c by virtue of being sort of an alternate main() */
+ /*----------------------------------------------------.
+ | yyerrlab1 -- error raised explicitly by an action. |
+ `----------------------------------------------------*/
+ yyerrlab1:
+ parser->yyerrstatus = 3; /* Each real token shifted decrements this. */
-STR *
-do_eval(str,optype)
-STR *str;
-int optype;
-{
- int retval;
- CMD *myroot;
- ARRAY *ar;
- int i;
- char *oldfile = filename;
- line_t oldline = line;
- int oldtmps_base = tmps_base;
- int oldsave = savestack->ary_fill;
-
- tmps_base = tmps_max;
- str_set(stabent("@",TRUE)->stab_val,"");
- if (optype != O_DOFILE) { /* normal eval */
- filename = "(eval)";
- line = 1;
- str_sset(linestr,str);
- }
- else {
- filename = savestr(str_get(str)); /* can't free this easily */
- str_set(linestr,"");
- rsfp = fopen(filename,"r");
- ar = incstab->stab_array;
- if (!rsfp && *filename != '/') {
- for (i = 0; i <= ar->ary_fill; i++) {
- sprintf(tokenbuf,"%s/%s",str_get(afetch(ar,i)),filename);
- rsfp = fopen(tokenbuf,"r");
- if (rsfp) {
- free(filename);
- filename = savestr(tokenbuf);
+ for (;;) {
+ yyn = yypact[yystate];
+ if (yyn != YYPACT_NINF) {
+ yyn += YYTERROR;
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) {
+ yyn = yytable[yyn];
+ if (0 < yyn)
break;
- }
}
}
- if (!rsfp) {
- filename = oldfile;
- tmps_base = oldtmps_base;
- return &str_no;
- }
- line = 0;
- }
- in_eval++;
- bufptr = str_get(linestr);
- if (setjmp(eval_env))
- retval = 1;
- else
- retval = yyparse();
- myroot = eval_root; /* in case cmd_exec does another eval! */
- if (retval)
- str = &str_no;
- else {
- str = str_static(cmd_exec(eval_root));
- /* if we don't save str, free zaps it */
- cmd_free(myroot); /* can't free on error, for some reason */
- }
- in_eval--;
- filename = oldfile;
- line = oldline;
- tmps_base = oldtmps_base;
- if (savestack->ary_fill > oldsave) /* let them use local() */
- restorelist(oldsave);
- return str;
-}
-
-cmd_free(cmd)
-register CMD *cmd;
-{
- register CMD *tofree;
- register CMD *head = cmd;
-
- while (cmd) {
- if (cmd->c_type != C_WHILE) { /* WHILE block is duplicated */
- if (cmd->c_label)
- safefree(cmd->c_label);
- if (cmd->c_short)
- str_free(cmd->c_short);
- if (cmd->c_spat)
- spat_free(cmd->c_spat);
- if (cmd->c_expr)
- arg_free(cmd->c_expr);
- }
- switch (cmd->c_type) {
- case C_WHILE:
- case C_BLOCK:
- case C_IF:
- if (cmd->ucmd.ccmd.cc_true)
- cmd_free(cmd->ucmd.ccmd.cc_true);
- if (cmd->c_type == C_IF && cmd->ucmd.ccmd.cc_alt)
- cmd_free(cmd->ucmd.ccmd.cc_alt);
- break;
- case C_EXPR:
- if (cmd->ucmd.acmd.ac_expr)
- arg_free(cmd->ucmd.acmd.ac_expr);
- break;
- }
- tofree = cmd;
- cmd = cmd->c_next;
- safefree((char*)tofree);
- if (cmd && cmd == head) /* reached end of while loop */
- break;
- }
-}
-arg_free(arg)
-register ARG *arg;
-{
- register int i;
+ /* Pop the current state because it cannot handle the error token. */
+ if (ps == parser->stack)
+ YYABORT;
- for (i = 1; i <= arg->arg_len; i++) {
- switch (arg[i].arg_type) {
- case A_NULL:
- break;
- case A_LEXPR:
- case A_EXPR:
- arg_free(arg[i].arg_ptr.arg_arg);
- break;
- case A_CMD:
- cmd_free(arg[i].arg_ptr.arg_cmd);
- break;
- case A_WORD:
- case A_STAB:
- case A_LVAL:
- case A_READ:
- case A_GLOB:
- case A_ARYLEN:
- break;
- case A_SINGLE:
- case A_DOUBLE:
- case A_BACKTICK:
- str_free(arg[i].arg_ptr.arg_str);
- break;
- case A_SPAT:
- spat_free(arg[i].arg_ptr.arg_spat);
- break;
- case A_NUMBER:
- break;
+ YYDSYMPRINTF ("Error: popping", yystos[ps->state], &ps->val);
+ LEAVE_SCOPE(ps->savestack_ix);
+ if (yy_type_tab[yystos[ps->state]] == toketype_opval && ps->val.opval) {
+ YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
+ if (ps->comppad != PL_comppad) {
+ PAD_RESTORE_LOCAL(ps->comppad);
+ }
+ ps->val.opval->op_latefree = 0;
+ op_free(ps->val.opval);
}
- }
- free_arg(arg);
-}
+ YYPOPSTACK;
+ yystate = ps->state;
-spat_free(spat)
-register SPAT *spat;
-{
- register SPAT *sp;
-
- if (spat->spat_runtime)
- arg_free(spat->spat_runtime);
- if (spat->spat_repl) {
- arg_free(spat->spat_repl);
- }
- if (spat->spat_short) {
- str_free(spat->spat_short);
- }
- if (spat->spat_regexp) {
- regfree(spat->spat_regexp);
+ YY_STACK_PRINT(parser);
}
- /* now unlink from spat list */
- if (spat_root == spat)
- spat_root = spat->spat_next;
- else {
- for (sp = spat_root; sp->spat_next != spat; sp = sp->spat_next) ;
- sp->spat_next = spat->spat_next;
- }
+ if (yyn == YYFINAL)
+ YYACCEPT;
- safefree((char*)spat);
-}
-
-/* Recursively descend a command sequence and push the address of any string
- * that needs saving on recursion onto the tosave array.
- */
+ YYDPRINTF ((Perl_debug_log, "Shifting error token, "));
-static int
-cmd_tosave(cmd)
-register CMD *cmd;
-{
- register CMD *head = cmd;
-
- while (cmd) {
- if (cmd->c_spat)
- spat_tosave(cmd->c_spat);
- if (cmd->c_expr)
- arg_tosave(cmd->c_expr);
- switch (cmd->c_type) {
- case C_WHILE:
- case C_BLOCK:
- case C_IF:
- if (cmd->ucmd.ccmd.cc_true)
- cmd_tosave(cmd->ucmd.ccmd.cc_true);
- if (cmd->c_type == C_IF && cmd->ucmd.ccmd.cc_alt)
- cmd_tosave(cmd->ucmd.ccmd.cc_alt);
- break;
- case C_EXPR:
- if (cmd->ucmd.acmd.ac_expr)
- arg_tosave(cmd->ucmd.acmd.ac_expr);
- break;
- }
- cmd = cmd->c_next;
- if (cmd && cmd == head) /* reached end of while loop */
- break;
- }
-}
+ YYPUSHSTACK;
+ ps->state = yyn;
+ ps->val = parser->yylval;
+ ps->comppad = PL_comppad;
+ ps->savestack_ix = PL_savestack_ix;
+#ifdef DEBUGGING
+ ps->name ="<err>";
+#endif
-static int
-arg_tosave(arg)
-register ARG *arg;
-{
- register int i;
- int saving = FALSE;
+ goto yynewstate;
- for (i = 1; i <= arg->arg_len; i++) {
- switch (arg[i].arg_type) {
- case A_NULL:
- break;
- case A_LEXPR:
- case A_EXPR:
- saving |= arg_tosave(arg[i].arg_ptr.arg_arg);
- break;
- case A_CMD:
- cmd_tosave(arg[i].arg_ptr.arg_cmd);
- saving = TRUE; /* assume hanky panky */
- break;
- case A_WORD:
- case A_STAB:
- case A_LVAL:
- case A_READ:
- case A_GLOB:
- case A_ARYLEN:
- case A_SINGLE:
- case A_DOUBLE:
- case A_BACKTICK:
- break;
- case A_SPAT:
- saving |= spat_tosave(arg[i].arg_ptr.arg_spat);
- break;
- case A_NUMBER:
- break;
- }
- }
- switch (arg->arg_type) {
- case O_EVAL:
- case O_SUBR:
- saving = TRUE;
- }
- if (saving)
- apush(tosave,arg->arg_ptr.arg_str);
- return saving;
-}
-static int
-spat_tosave(spat)
-register SPAT *spat;
-{
- int saving = FALSE;
+ /*-------------------------------------.
+ | yyacceptlab -- YYACCEPT comes here. |
+ `-------------------------------------*/
+ yyacceptlab:
+ yyresult = 0;
+ parser->ps = parser->stack; /* disable cleanup */
+ goto yyreturn;
- if (spat->spat_runtime)
- saving |= arg_tosave(spat->spat_runtime);
- if (spat->spat_repl) {
- saving |= arg_tosave(spat->spat_repl);
- }
+ /*-----------------------------------.
+ | yyabortlab -- YYABORT comes here. |
+ `-----------------------------------*/
+ yyabortlab:
+ yyresult = 1;
+ goto yyreturn;
- return saving;
+ yyreturn:
+ LEAVE; /* force parser stack cleanup before we return */
+ return yyresult;
}
+
+/*
+ * Local variables:
+ * c-indentation-style: bsd
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ *
+ * ex: set ts=8 sts=4 sw=4 noet:
+ */