[inseparable changes from patch from perl5.003_12 to perl5.003_13]
[p5sagit/p5-mst-13.2.git] / toke.c
diff --git a/toke.c b/toke.c
index ae91a1a..4c79d7b 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -40,27 +40,39 @@ static void missingterm _((char *s));
 static void no_op _((char *what, char *s));
 static void set_csh _((void));
 static I32 sublex_done _((void));
+static I32 sublex_push _((void));
 static I32 sublex_start _((void));
 #ifdef CRIPPLED_CC
 static int uni _((I32 f, char *s));
 #endif
-static char * filter_gets _((SV *sv, PerlIO *fp));
+static char * filter_gets _((SV *sv, PerlIO *fp, STRLEN append));
 static void restore_rsfp _((void *f));
 
+static char *linestart;                /* beg. of most recently read line */
+
+static char pending_ident;     /* pending identifier lookup */
+
+static struct {
+    I32 super_state;   /* lexer state to save */
+    I32 sub_inwhat;    /* "lex_inwhat" to use */
+    OP *sub_op;                /* "lex_op" to use */
+} sublex_info;
+
 /* The following are arranged oddly so that the guard on the switch statement
  * can get by with a single comparison (if the compiler is smart enough).
  */
 
-#define LEX_NORMAL             9
-#define LEX_INTERPNORMAL       8
-#define LEX_INTERPCASEMOD      7
-#define LEX_INTERPSTART                6
-#define LEX_INTERPEND          5
-#define LEX_INTERPENDMAYBE     4
-#define LEX_INTERPCONCAT       3
-#define LEX_INTERPCONST                2
-#define LEX_FORMLINE           1
-#define LEX_KNOWNEXT           0
+#define LEX_NORMAL             10
+#define LEX_INTERPNORMAL        9
+#define LEX_INTERPCASEMOD       8
+#define LEX_INTERPPUSH          7
+#define LEX_INTERPSTART                 6
+#define LEX_INTERPEND           5
+#define LEX_INTERPENDMAYBE      4
+#define LEX_INTERPCONCAT        3
+#define LEX_INTERPCONST                 2
+#define LEX_FORMLINE            1
+#define LEX_KNOWNEXT            0
 
 #ifdef I_FCNTL
 #include <fcntl.h>
@@ -69,6 +81,12 @@ static void restore_rsfp _((void *f));
 #include <sys/file.h>
 #endif
 
+/* XXX If this causes problems, set i_unistd=undef in the hint file.  */
+#ifdef I_UNISTD
+#  include <unistd.h> /* Needed for execv() */
+#endif
+
+
 #ifdef ff_next
 #undef ff_next
 #endif
@@ -141,7 +159,7 @@ char *s;
 {
     char tmpbuf[128];
     char *oldbp = bufptr;
-    bool is_first = (oldbufptr == SvPVX(linestr));
+    bool is_first = (oldbufptr == linestart);
     bufptr = s;
     sprintf(tmpbuf, "%s found where operator expected", what);
     yywarn(tmpbuf);
@@ -173,7 +191,7 @@ char *s;
     }
     else if (multi_close < 32 || multi_close == 127) {
        *tmpbuf = '^';
-       tmpbuf[1] = multi_close ^ 64;
+       tmpbuf[1] = toCTRL(multi_close);
        s = "\\n";
        tmpbuf[2] = '\0';
        s = tmpbuf;
@@ -208,19 +226,20 @@ SV *line;
     char *s;
     STRLEN len;
 
-    SAVEINT(lex_dojoin);
-    SAVEINT(lex_brackets);
-    SAVEINT(lex_fakebrack);
-    SAVEINT(lex_casemods);
-    SAVEINT(lex_starts);
-    SAVEINT(lex_state);
+    SAVEI32(lex_dojoin);
+    SAVEI32(lex_brackets);
+    SAVEI32(lex_fakebrack);
+    SAVEI32(lex_casemods);
+    SAVEI32(lex_starts);
+    SAVEI32(lex_state);
     SAVESPTR(lex_inpat);
-    SAVEINT(lex_inwhat);
-    SAVEINT(curcop->cop_line);
+    SAVEI32(lex_inwhat);
+    SAVEI16(curcop->cop_line);
     SAVEPPTR(bufptr);
     SAVEPPTR(bufend);
     SAVEPPTR(oldbufptr);
     SAVEPPTR(oldoldbufptr);
+    SAVEPPTR(linestart);
     SAVESPTR(linestr);
     SAVEPPTR(lex_brackstack);
     SAVEPPTR(lex_casestack);
@@ -257,7 +276,7 @@ SV *line;
        sv_catpvn(linestr, "\n;", 2);
     }
     SvTEMP_off(linestr);
-    oldoldbufptr = oldbufptr = bufptr = SvPVX(linestr);
+    oldoldbufptr = oldbufptr = bufptr = linestart = SvPVX(linestr);
     bufend = bufptr + SvCUR(linestr);
     SvREFCNT_dec(rs);
     rs = newSVpv("\n", 1);
@@ -333,6 +352,7 @@ register char *s;
        return s;
     }
     for (;;) {
+       STRLEN prevlen;
        while (s < bufend && isSPACE(*s))
            s++;
        if (s < bufend && *s == '#') {
@@ -343,7 +363,7 @@ register char *s;
        }
        if (s < bufend || !rsfp || lex_state != LEX_NORMAL)
            return s;
-       if ((s = filter_gets(linestr, rsfp)) == Nullch) {
+       if ((s = filter_gets(linestr, rsfp, (prevlen = SvCUR(linestr)))) == Nullch) {
            if (minus_n || minus_p) {
                sv_setpv(linestr,minus_p ? ";}continue{print" : "");
                sv_catpv(linestr,";}");
@@ -351,7 +371,7 @@ register char *s;
            }
            else
                sv_setpv(linestr,";");
-           oldoldbufptr = oldbufptr = bufptr = s = SvPVX(linestr);
+           oldoldbufptr = oldbufptr = bufptr = s = linestart = SvPVX(linestr);
            bufend = SvPVX(linestr) + SvCUR(linestr);
            if (preprocess && !in_eval)
                (void)my_pclose(rsfp);
@@ -362,14 +382,15 @@ register char *s;
            rsfp = Nullfp;
            return s;
        }
-       oldoldbufptr = oldbufptr = bufptr = s;
-       bufend = bufptr + SvCUR(linestr);
+       linestart = bufptr = s + prevlen;
+       bufend = s + SvCUR(linestr);
+       s = bufptr;
        incline(s);
        if (perldb && curstash != debstash) {
            SV *sv = NEWSV(85,0);
 
            sv_upgrade(sv, SVt_PVMG);
-           sv_setsv(sv,linestr);
+           sv_setpvn(sv,bufptr,bufend-bufptr);
            av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
        }
     }
@@ -506,7 +527,10 @@ int kind;
        force_next(WORD);
        if (kind) {
            op->op_private = OPpCONST_ENTERED;
-           gv_fetchpv(s, TRUE,
+           /* XXX see note in pp_entereval() for why we forgo typo
+              warnings if the symbol must be introduced in an eval.
+              GSAR 96-10-12 */
+           gv_fetchpv(s, in_eval ? GV_ADDMULTI : TRUE,
                kind == '$' ? SVt_PV :
                kind == '@' ? SVt_PVAV :
                kind == '%' ? SVt_PVHV :
@@ -529,7 +553,7 @@ char *s;
     if(isDIGIT(*s)) {
         char *d;
         int c;
-        for( d=s, c = 1; isDIGIT(*d) || (*d == '.' && c--); d++);
+        for( d=s, c = 1; isDIGIT(*d) || *d == '_' || (*d == '.' && c--); d++);
         if((*d == ';' || isSPACE(*d)) && *(skipspace(d)) != ',') {
             s = scan_num(s);
             /* real VERSION number -- GBARR */
@@ -594,19 +618,40 @@ sublex_start()
        return THING;
     }
 
+    sublex_info.super_state = lex_state;
+    sublex_info.sub_inwhat = op_type;
+    sublex_info.sub_op = lex_op;
+    lex_state = LEX_INTERPPUSH;
+
+    expect = XTERM;
+    if (lex_op) {
+       yylval.opval = lex_op;
+       lex_op = Nullop;
+       return PMFUNC;
+    }
+    else
+       return FUNC;
+}
+
+static I32
+sublex_push()
+{
     push_scope();
-    SAVEINT(lex_dojoin);
-    SAVEINT(lex_brackets);
-    SAVEINT(lex_fakebrack);
-    SAVEINT(lex_casemods);
-    SAVEINT(lex_starts);
-    SAVEINT(lex_state);
+
+    lex_state = sublex_info.super_state;
+    SAVEI32(lex_dojoin);
+    SAVEI32(lex_brackets);
+    SAVEI32(lex_fakebrack);
+    SAVEI32(lex_casemods);
+    SAVEI32(lex_starts);
+    SAVEI32(lex_state);
     SAVESPTR(lex_inpat);
-    SAVEINT(lex_inwhat);
-    SAVEINT(curcop->cop_line);
+    SAVEI32(lex_inwhat);
+    SAVEI16(curcop->cop_line);
     SAVEPPTR(bufptr);
     SAVEPPTR(oldbufptr);
     SAVEPPTR(oldoldbufptr);
+    SAVEPPTR(linestart);
     SAVESPTR(linestr);
     SAVEPPTR(lex_brackstack);
     SAVEPPTR(lex_casestack);
@@ -614,7 +659,7 @@ sublex_start()
     linestr = lex_stuff;
     lex_stuff = Nullsv;
 
-    bufend = bufptr = oldbufptr = oldoldbufptr = SvPVX(linestr);
+    bufend = bufptr = oldbufptr = oldoldbufptr = linestart = SvPVX(linestr);
     bufend += SvCUR(linestr);
     SAVEFREESV(linestr);
 
@@ -631,21 +676,13 @@ sublex_start()
     lex_state = LEX_INTERPCONCAT;
     curcop->cop_line = multi_start;
 
-    lex_inwhat = op_type;
-    if (op_type == OP_MATCH || op_type == OP_SUBST)
-       lex_inpat = lex_op;
+    lex_inwhat = sublex_info.sub_inwhat;
+    if (lex_inwhat == OP_MATCH || lex_inwhat == OP_SUBST)
+       lex_inpat = sublex_info.sub_op;
     else
-       lex_inpat = 0;
+       lex_inpat = Nullop;
 
-    expect = XTERM;
-    force_next('(');
-    if (lex_op) {
-       yylval.opval = lex_op;
-       lex_op = Nullop;
-       return PMFUNC;
-    }
-    else
-       return FUNC;
+    return '(';
 }
 
 static I32
@@ -666,7 +703,7 @@ sublex_done()
     if (lex_repl && (lex_inwhat == OP_SUBST || lex_inwhat == OP_TRANS)) {
        linestr = lex_repl;
        lex_inpat = 0;
-       bufend = bufptr = oldbufptr = oldoldbufptr = SvPVX(linestr);
+       bufend = bufptr = oldbufptr = oldoldbufptr = linestart = SvPVX(linestr);
        bufend += SvCUR(linestr);
        SAVEFREESV(linestr);
        lex_dojoin = FALSE;
@@ -787,10 +824,8 @@ char *start;
                continue;
            case 'c':
                s++;
-               *d = *s++;
-               if (isLOWER(*d))
-                   *d = toUPPER(*d);
-               *d++ ^= 64;
+               len = *s++;
+               *d++ = toCTRL(len);
                continue;
            case 'b':
                *d++ = '\b';
@@ -996,6 +1031,8 @@ GV *gv;
        /* filehandle or package name makes it a method */
        if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
            s = skipspace(s);
+           if ((bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
+               return 0;       /* no assumptions -- "=>" quotes bearword */
            nextval[nexttoke].opval =
                (OP*)newSVOP(OP_CONST, 0,
                            newSVpv(tmpbuf,0));
@@ -1146,20 +1183,22 @@ filter_read(idx, buf_sv, maxlen)
 }
 
 static char *
-filter_gets(sv,fp)
+filter_gets(sv,fp, append)
 register SV *sv;
 register PerlIO *fp;
+STRLEN append;
 {
     if (rsfp_filters) {
 
-        SvCUR_set(sv, 0);      /* start with empty line        */
+       if (!append)
+            SvCUR_set(sv, 0);  /* start with empty line        */
         if (FILTER_READ(0, sv, 0) > 0)
             return ( SvPVX(sv) ) ;
         else
            return Nullch ;
     }
     else 
-        return (sv_gets(sv, fp, 0)) ;
+        return (sv_gets(sv, fp, append));
     
 }
 
@@ -1179,6 +1218,59 @@ yylex()
     register I32 tmp;
     STRLEN len;
 
+    if (pending_ident) {
+       char pit = pending_ident;
+       pending_ident = 0;
+
+       if (in_my) {
+           if (strchr(tokenbuf,':'))
+               croak(no_myglob,tokenbuf);
+           yylval.opval = newOP(OP_PADANY, 0);
+           yylval.opval->op_targ = pad_allocmy(tokenbuf);
+           return PRIVATEREF;
+       }
+
+       if (!strchr(tokenbuf,':') && (tmp = pad_findmy(tokenbuf))) {
+           if (last_lop_op == OP_SORT &&
+               tokenbuf[0] == '$' &&
+               (tokenbuf[1] == 'a' || tokenbuf[1] == 'b')
+               && !tokenbuf[2])
+           {
+               for (d = in_eval ? oldoldbufptr : linestart;
+                    d < bufend && *d != '\n';
+                    d++)
+               {
+                   if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
+                       croak("Can't use \"my %s\" in sort comparison",
+                             tokenbuf);
+                   }
+               }
+           }
+
+           yylval.opval = newOP(OP_PADANY, 0);
+           yylval.opval->op_targ = tmp;
+           return PRIVATEREF;
+       }
+
+       /* Force them to make up their mind on "@foo". */
+       if (pit == '@' && lex_state != LEX_NORMAL && !lex_brackets) {
+           GV *gv = gv_fetchpv(tokenbuf+1, FALSE, SVt_PVAV);
+           if (!gv || ((tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv))) {
+               char tmpbuf[1024];
+               sprintf(tmpbuf, "Literal %s now requires backslash", tokenbuf);
+               yyerror(tmpbuf);
+           }
+       }
+
+       yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf+1, 0));
+       yylval.opval->op_private = OPpCONST_ENTERED;
+       gv_fetchpv(tokenbuf+1, in_eval ? GV_ADDMULTI : TRUE,
+                  ((tokenbuf[0] == '$') ? SVt_PV
+                   : (tokenbuf[0] == '@') ? SVt_PVAV
+                   : SVt_PVHV));
+       return WORD;
+    }
+
     switch (lex_state) {
 #ifdef COMMENTARY
     case LEX_NORMAL:           /* Some compilers will produce faster */
@@ -1262,6 +1354,9 @@ yylex()
                return yylex();
        }
 
+    case LEX_INTERPPUSH:
+        return sublex_push();
+
     case LEX_INTERPSTART:
        if (bufptr == bufend)
            return sublex_done();
@@ -1362,6 +1457,8 @@ yylex()
        goto fake_eof;                  /* emulate EOF on ^D or ^Z */
     case 0:
        if (!rsfp) {
+           last_uni = 0;
+           last_lop = 0;
            if (lex_brackets)
                yyerror("Missing right bracket");
            TOKEN(0);
@@ -1405,7 +1502,7 @@ yylex()
                }
            }
            sv_catpv(linestr, "\n");
-           oldoldbufptr = oldbufptr = s = SvPVX(linestr);
+           oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
            bufend = SvPVX(linestr) + SvCUR(linestr);
            if (perldb && curstash != debstash) {
                SV *sv = NEWSV(85,0);
@@ -1417,7 +1514,7 @@ yylex()
            goto retry;
        }
        do {
-           if ((s = filter_gets(linestr, rsfp)) == Nullch) {
+           if ((s = filter_gets(linestr, rsfp, 0)) == Nullch) {
              fake_eof:
                if (rsfp) {
                    if (preprocess && !in_eval)
@@ -1431,12 +1528,12 @@ yylex()
                if (!in_eval && (minus_n || minus_p)) {
                    sv_setpv(linestr,minus_p ? ";}continue{print" : "");
                    sv_catpv(linestr,";}");
-                   oldoldbufptr = oldbufptr = s = SvPVX(linestr);
+                   oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
                    bufend = SvPVX(linestr) + SvCUR(linestr);
                    minus_n = minus_p = 0;
                    goto retry;
                }
-               oldoldbufptr = oldbufptr = s = SvPVX(linestr);
+               oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
                sv_setpv(linestr,"");
                TOKEN(';');     /* not infinite loop because rsfp is NULL now */
            }
@@ -1447,14 +1544,14 @@ yylex()
                /* Incest with pod. */
                if (*s == '=' && strnEQ(s, "=cut", 4)) {
                    sv_setpv(linestr, "");
-                   oldoldbufptr = oldbufptr = s = SvPVX(linestr);
+                   oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
                    bufend = SvPVX(linestr) + SvCUR(linestr);
                    doextract = FALSE;
                }
            }
            incline(s);
        } while (doextract);
-       oldoldbufptr = oldbufptr = bufptr = s;
+       oldoldbufptr = oldbufptr = bufptr = linestart = s;
        if (perldb && curstash != debstash) {
            SV *sv = NEWSV(85,0);
 
@@ -1519,7 +1616,7 @@ yylex()
                                 we must not do it again */
                        {
                            sv_setpv(linestr, "");
-                           oldoldbufptr = oldbufptr = s = SvPVX(linestr);
+                           oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
                            bufend = SvPVX(linestr) + SvCUR(linestr);
                            preambled = FALSE;
                            if (perldb)
@@ -1672,35 +1769,19 @@ yylex()
        Mop(OP_MULTIPLY);
 
     case '%':
-       if (expect != XOPERATOR) {
-           s = scan_ident(s, bufend, tokenbuf + 1, TRUE);
-           if (tokenbuf[1]) {
-               expect = XOPERATOR;
-               tokenbuf[0] = '%';
-               if (in_my) {
-                   if (strchr(tokenbuf,':'))
-                       croak(no_myglob,tokenbuf);
-                   nextval[nexttoke].opval = newOP(OP_PADANY, 0);
-                   nextval[nexttoke].opval->op_targ = pad_allocmy(tokenbuf);
-                   force_next(PRIVATEREF);
-                   TERM('%');
-               }
-               if (!strchr(tokenbuf,':')) {
-                   if (tmp = pad_findmy(tokenbuf)) {
-                       nextval[nexttoke].opval = newOP(OP_PADANY, 0);
-                       nextval[nexttoke].opval->op_targ = tmp;
-                       force_next(PRIVATEREF);
-                       TERM('%');
-                   }
-               }
-               force_ident(tokenbuf + 1, *tokenbuf);
-           }
-           else
-               PREREF('%');
-           TERM('%');
+       if (expect == XOPERATOR) {
+           ++s;
+           Mop(OP_MODULO);
+       }
+       tokenbuf[0] = '%';
+       s = scan_ident(s, bufend, tokenbuf+1, TRUE);
+       if (!tokenbuf[1]) {
+           if (s == bufend)
+               yyerror("Final % should be \\% or %name");
+           PREREF('%');
        }
-       ++s;
-       Mop(OP_MODULO);
+       pending_ident = '%';
+       TERM('%');
 
     case '^':
        s++;
@@ -1775,7 +1856,7 @@ yylex()
        case XOPERATOR:
            while (s < bufend && (*s == ' ' || *s == '\t'))
                s++;
-           if (s < bufend && (isALPHA(*s) || *s == '_')) {
+           if (s < bufend && isIDFIRST(*s)) {
                d = scan_word(s, tokenbuf, FALSE, &len);
                while (d < bufend && (*d == ' ' || *d == '\t'))
                    d++;
@@ -1867,7 +1948,7 @@ yylex()
            AOPERATOR(ANDAND);
        s--;
        if (expect == XOPERATOR) {
-           if (dowarn && isALPHA(*s) && bufptr == SvPVX(linestr)) {
+           if (dowarn && isALPHA(*s) && bufptr == linestart) {
                curcop->cop_line--;
                warn(warn_nosemi);
                curcop->cop_line++;
@@ -1905,7 +1986,7 @@ yylex()
            warn("Reversed %c= operator",tmp);
        s--;
        if (expect == XSTATE && isALPHA(tmp) &&
-               (s == SvPVX(linestr)+1 || s[-2] == '\n') )
+               (s == linestart+1 || s[-2] == '\n') )
        {
            if (in_eval && !rsfp) {
                d = bufend;
@@ -1983,67 +2064,72 @@ yylex()
        Rop(OP_GT);
 
     case '$':
-       if (s[1] == '#'  && (isALPHA(s[2]) || strchr("_{$:", s[2]))) {
-           s = scan_ident(s+1, bufend, tokenbuf+1, FALSE);
-           if (expect == XOPERATOR) {
-               if (lex_formbrack && lex_brackets == lex_formbrack) {
-                   expect = XTERM;
-                   depcom();
-                   return ','; /* grandfather non-comma-format format */
-               }
-               else
-                   no_op("Array length",s);
+       CLINE;
+
+       if (expect == XOPERATOR) {
+           if (lex_formbrack && lex_brackets == lex_formbrack) {
+               expect = XTERM;
+               depcom();
+               return ','; /* grandfather non-comma-format format */
            }
-           else if (!tokenbuf[1])
+       }
+
+       if (s[1] == '#' && (isALPHA(s[2]) || strchr("_{$:", s[2]))) {
+           if (expect == XOPERATOR)
+               no_op("Array length", bufptr);
+           tokenbuf[0] = '@';
+           s = scan_ident(s+1, bufend, tokenbuf+1, FALSE);
+           if (!tokenbuf[1])
                PREREF(DOLSHARP);
-           if (!strchr(tokenbuf+1,':')) {
-               tokenbuf[0] = '@';
-               if (tmp = pad_findmy(tokenbuf)) {
-                   nextval[nexttoke].opval = newOP(OP_PADANY, 0);
-                   nextval[nexttoke].opval->op_targ = tmp;
-                   expect = XOPERATOR;
-                   force_next(PRIVATEREF);
-                   TOKEN(DOLSHARP);
-               }
-           }
            expect = XOPERATOR;
-           force_ident(tokenbuf+1, *tokenbuf);
+           pending_ident = '#';
            TOKEN(DOLSHARP);
        }
+
+       if (expect == XOPERATOR)
+           no_op("Scalar", bufptr);
+       tokenbuf[0] = '$';
        s = scan_ident(s, bufend, tokenbuf+1, FALSE);
-       if (expect == XOPERATOR) {
-           if (lex_formbrack && lex_brackets == lex_formbrack) {
-               expect = XTERM;
-               depcom();
-               return ',';     /* grandfather non-comma-format format */
-           }
-           else
-               no_op("Scalar",s);
+       if (!tokenbuf[1]) {
+           if (s == bufend)
+               yyerror("Final $ should be \\$ or $name");
+           PREREF('$');
        }
-       if (tokenbuf[1]) {
-           expectation oldexpect = expect;
 
-           /* This kludge not intended to be bulletproof. */
-           if (tokenbuf[1] == '[' && !tokenbuf[2]) {
-               yylval.opval = newSVOP(OP_CONST, 0,
-                                       newSViv((IV)compiling.cop_arybase));
-               yylval.opval->op_private = OPpCONST_ARYBASE;
-               TERM(THING);
-           }
-           tokenbuf[0] = '$';
-           if (dowarn) {
-               char *t;
-               if (*s == '[' && oldexpect != XREF) {
-                   for (t = s+1; isSPACE(*t) || isALNUM(*t) || *t == '$'; t++) ;
+       /* This kludge not intended to be bulletproof. */
+       if (tokenbuf[1] == '[' && !tokenbuf[2]) {
+           yylval.opval = newSVOP(OP_CONST, 0,
+                                  newSViv((IV)compiling.cop_arybase));
+           yylval.opval->op_private = OPpCONST_ARYBASE;
+           TERM(THING);
+       }
+
+       d = s;
+       if (lex_state == LEX_NORMAL)
+           s = skipspace(s);
+
+       if ((expect != XREF || oldoldbufptr == last_lop) && intuit_more(s)) {
+           char *t;
+           if (*s == '[') {
+               tokenbuf[0] = '@';
+               if (dowarn) {
+                   for(t = s + 1;
+                       isSPACE(*t) || isALNUM(*t) || *t == '$';
+                       t++) ;
                    if (*t++ == ',') {
                        bufptr = skipspace(bufptr);
-                       while (t < bufend && *t != ']') t++;
+                       while (t < bufend && *t != ']')
+                           t++;
                        warn("Multidimensional syntax %.*s not supported",
-                           t-bufptr+1, bufptr);
+                            (t - bufptr) + 1, bufptr);
                    }
                }
-               if (*s == '{' && strEQ(tokenbuf, "$SIG") &&
-                 (t = strchr(s,'}')) && (t = strchr(t,'='))) {
+           }
+           else if (*s == '{') {
+               tokenbuf[0] = '%';
+               if (dowarn && strEQ(tokenbuf+1, "SIG") &&
+                   (t = strchr(s, '}')) && (t = strchr(t, '=')))
+               {
                    char tmpbuf[1024];
                    STRLEN len;
                    for (t++; isSPACE(*t); t++) ;
@@ -2054,113 +2140,44 @@ yylex()
                    }
                }
            }
-           expect = XOPERATOR;
-           if (lex_state == LEX_NORMAL && isSPACE(*s)) {
-               bool islop = (last_lop == oldoldbufptr);
-               s = skipspace(s);
-               if (!islop || last_lop_op == OP_GREPSTART)
-                   expect = XOPERATOR;
-               else if (strchr("$@\"'`q", *s))
-                   expect = XTERM;             /* e.g. print $fh "foo" */
-               else if (strchr("&*<%", *s) && isIDFIRST(s[1]))
-                   expect = XTERM;             /* e.g. print $fh &sub */
-               else if (isDIGIT(*s))
-                   expect = XTERM;             /* e.g. print $fh 3 */
-               else if (*s == '.' && isDIGIT(s[1]))
-                   expect = XTERM;             /* e.g. print $fh .3 */
-               else if (strchr("/?-+", *s) && !isSPACE(s[1]))
-                   expect = XTERM;             /* e.g. print $fh -1 */
-               else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]))
-                   expect = XTERM;             /* print $fh <<"EOF" */
-           }
-           if (in_my) {
-               if (strchr(tokenbuf,':'))
-                   croak(no_myglob,tokenbuf);
-               nextval[nexttoke].opval = newOP(OP_PADANY, 0);
-               nextval[nexttoke].opval->op_targ = pad_allocmy(tokenbuf);
-               force_next(PRIVATEREF);
-           }
-           else if (!strchr(tokenbuf,':')) {
-               if (oldexpect != XREF || oldoldbufptr == last_lop) {
-                   if (intuit_more(s)) {
-                       if (*s == '[')
-                           tokenbuf[0] = '@';
-                       else if (*s == '{')
-                           tokenbuf[0] = '%';
-                   }
-               }
-               if (tmp = pad_findmy(tokenbuf)) {
-                   if (!tokenbuf[2] && *tokenbuf =='$' &&
-                       tokenbuf[1] <= 'b' && tokenbuf[1] >= 'a')
-                   {
-                       for (d = in_eval ? oldoldbufptr : SvPVX(linestr);
-                           d < bufend && *d != '\n';
-                           d++)
-                       {
-                           if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
-                               croak("Can't use \"my %s\" in sort comparison",
-                                   tokenbuf);
-                           }
-                       }
-                   }
-                   nextval[nexttoke].opval = newOP(OP_PADANY, 0);
-                   nextval[nexttoke].opval->op_targ = tmp;
-                   force_next(PRIVATEREF);
-               }
-               else
-                   force_ident(tokenbuf+1, *tokenbuf);
-           }
-           else
-               force_ident(tokenbuf+1, *tokenbuf);
-       }
-       else {
-           if (s == bufend)
-               yyerror("Final $ should be \\$ or $name");
-           PREREF('$');
        }
+
+       expect = XOPERATOR;
+       if (lex_state == LEX_NORMAL && isSPACE(*d)) {
+           bool islop = (last_lop == oldoldbufptr);
+           if (!islop || last_lop_op == OP_GREPSTART)
+               expect = XOPERATOR;
+           else if (strchr("$@\"'`q", *s))
+               expect = XTERM;         /* e.g. print $fh "foo" */
+           else if (strchr("&*<%", *s) && isIDFIRST(s[1]))
+               expect = XTERM;         /* e.g. print $fh &sub */
+           else if (isDIGIT(*s))
+               expect = XTERM;         /* e.g. print $fh 3 */
+           else if (*s == '.' && isDIGIT(s[1]))
+               expect = XTERM;         /* e.g. print $fh .3 */
+           else if (strchr("/?-+", *s) && !isSPACE(s[1]))
+               expect = XTERM;         /* e.g. print $fh -1 */
+           else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]))
+               expect = XTERM;         /* print $fh <<"EOF" */
+       }
+       pending_ident = '$';
        TOKEN('$');
 
     case '@':
-       s = scan_ident(s, bufend, tokenbuf+1, FALSE);
        if (expect == XOPERATOR)
-           no_op("Array",s);
-       if (tokenbuf[1]) {
-           GV* gv;
-
-           tokenbuf[0] = '@';
-           expect = XOPERATOR;
-           if (in_my) {
-               if (strchr(tokenbuf,':'))
-                   croak(no_myglob,tokenbuf);
-               nextval[nexttoke].opval = newOP(OP_PADANY, 0);
-               nextval[nexttoke].opval->op_targ = pad_allocmy(tokenbuf);
-               force_next(PRIVATEREF);
-               TERM('@');
-           }
-           else if (!strchr(tokenbuf,':')) {
-               if (intuit_more(s)) {
-                   if (*s == '{')
-                       tokenbuf[0] = '%';
-               }
-               if (tmp = pad_findmy(tokenbuf)) {
-                   nextval[nexttoke].opval = newOP(OP_PADANY, 0);
-                   nextval[nexttoke].opval->op_targ = tmp;
-                   force_next(PRIVATEREF);
-                   TERM('@');
-               }
-           }
-
-           /* Force them to make up their mind on "@foo". */
-           if (lex_state != LEX_NORMAL && !lex_brackets &&
-                   ( !(gv = gv_fetchpv(tokenbuf+1, FALSE, SVt_PVAV)) ||
-                     (*tokenbuf == '@'
-                       ? !GvAV(gv)
-                       : !GvHV(gv) )))
-           {
-               char tmpbuf[1024];
-               sprintf(tmpbuf, "Literal @%s now requires backslash",tokenbuf+1);
-               yyerror(tmpbuf);
-           }
+           no_op("Array", s);
+       tokenbuf[0] = '@';
+       s = scan_ident(s, bufend, tokenbuf+1, FALSE);
+       if (!tokenbuf[1]) {
+           if (s == bufend)
+               yyerror("Final @ should be \\@ or @name");
+           PREREF('@');
+       }
+       if (lex_state == LEX_NORMAL)
+           s = skipspace(s);
+       if ((expect != XREF || oldoldbufptr == last_lop) && intuit_more(s)) {
+           if (*s == '{')
+               tokenbuf[0] = '%';
 
            /* Warn about @ where they meant $. */
            if (dowarn) {
@@ -2176,13 +2193,8 @@ yylex()
                    }
                }
            }
-           force_ident(tokenbuf+1, *tokenbuf);
-       }
-       else {
-           if (s == bufend)
-               yyerror("Final @ should be \\@ or @name");
-           PREREF('@');
        }
+       pending_ident = '@';
        TERM('@');
 
     case '/':                  /* may either be division or pattern */
@@ -2199,7 +2211,7 @@ yylex()
 
     case '.':
        if (lex_formbrack && lex_brackets == lex_formbrack && s[1] == '\n' &&
-               (s == SvPVX(linestr) || s[-1] == '\n') ) {
+               (s == linestart || s[-1] == '\n') ) {
            lex_formbrack = 0;
            expect = XSTATE;
            goto rightbracket;
@@ -2326,12 +2338,29 @@ yylex()
        if (*s == ':' && s[1] == ':' && strNE(tokenbuf, "CORE"))
            goto just_a_word;
 
+       d = s;
+       while (d < bufend && isSPACE(*d))
+               d++;    /* no comments skipped here, or s### is misparsed */
+
+       /* Is this a label? */
+       if (expect == XSTATE && d < bufend && *d == ':' && *(d + 1) != ':') {
+           if (len == 1 && strchr("syq", tokenbuf[0]) ||
+               len == 2 && ((tokenbuf[0] == 't' && tokenbuf[1] == 'r') ||
+                            (tokenbuf[0] == 'q' &&
+                             strchr("qwx", tokenbuf[1]))))
+               ; /* no */
+           else {
+               s = d + 1;
+               yylval.pval = savepv(tokenbuf);
+               CLINE;
+               TOKEN(LABEL);
+           }
+       }
+
+       /* Check for keywords */
        tmp = keyword(tokenbuf, len);
 
        /* Is this a word before a => operator? */
-       d = s;
-       while (d < bufend && (*d == ' ' || *d == '\t'))
-               d++;    /* no comments skipped here, or s### is misparsed */
        if (strnEQ(d,"=>",2)) {
            CLINE;
            if (dowarn && (tmp || perl_get_cv(tokenbuf, FALSE)))
@@ -2371,19 +2400,8 @@ yylex()
                        croak("Bad name after %s::", tokenbuf);
                }
 
-               /* Do special processing at start of statement. */
-
-               if (expect == XSTATE) {
-                   while (isSPACE(*s)) s++;
-                   if (*s == ':') {    /* It's a label. */
-                       yylval.pval = savepv(tokenbuf);
-                       s++;
-                       CLINE;
-                       TOKEN(LABEL);
-                   }
-               }
-               else if (expect == XOPERATOR) {
-                   if (bufptr == SvPVX(linestr)) {
+               if (expect == XOPERATOR) {
+                   if (bufptr == linestart) {
                        curcop->cop_line--;
                        warn(warn_nosemi);
                        curcop->cop_line++;
@@ -2510,6 +2528,7 @@ yylex()
                if (hints & HINT_STRICT_SUBS &&
                    lastchar != '-' &&
                    strnNE(s,"->",2) &&
+                   last_lop_op != OP_TRUNCATE &&  /* S/F prototype in opcode.pl */
                    last_lop_op != OP_ACCEPT &&
                    last_lop_op != OP_PIPE_OP &&
                    last_lop_op != OP_SOCKPAIR)
@@ -2571,6 +2590,8 @@ yylex()
                    fcntl(fd,F_SETFD,fd >= 3);
                }
 #endif
+               /* Mark this internal pseudo-handle as clean */
+               IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
                if (preprocess)
                    IoTYPE(GvIOp(gv)) = '|';
                else if ((PerlIO*)rsfp == PerlIO_stdin())
@@ -2764,10 +2785,16 @@ yylex()
        case KEY_for:
        case KEY_foreach:
            yylval.ival = curcop->cop_line;
-           while (s < bufend && isSPACE(*s))
-               s++;
-           if (isIDFIRST(*s))
-               croak("Missing $ on loop variable");
+           s = skipspace(s);
+           if (isIDFIRST(*s)) {
+               char *p = s;
+               if ((bufend - p) >= 3 &&
+                   strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
+                   p += 2;
+               p = skipspace(p);
+               if (isIDFIRST(*p))
+                   croak("Missing $ on loop variable");
+           }
            OPERATOR(FOR);
 
        case KEY_formline:
@@ -2826,10 +2853,10 @@ yylex()
            FUN0(OP_GPWENT);
 
        case KEY_getpwnam:
-           FUN1(OP_GPWNAM);
+           UNI(OP_GPWNAM);
 
        case KEY_getpwuid:
-           FUN1(OP_GPWUID);
+           UNI(OP_GPWUID);
 
        case KEY_getpeername:
            UNI(OP_GETPEERNAME);
@@ -2871,10 +2898,10 @@ yylex()
            FUN0(OP_GGRENT);
 
        case KEY_getgrnam:
-           FUN1(OP_GGRNAM);
+           UNI(OP_GGRNAM);
 
        case KEY_getgrgid:
-           FUN1(OP_GGRGID);
+           UNI(OP_GGRGID);
 
        case KEY_getlogin:
            FUN0(OP_GETLOGIN);
@@ -2888,7 +2915,7 @@ yylex()
 
        case KEY_if:
            yylval.ival = curcop->cop_line;
-           OPERATOR(IF);
+           PRETERMBLOCK(IF);
 
        case KEY_index:
            LOP(OP_INDEX,XTERM);
@@ -2919,7 +2946,6 @@ yylex()
            UNI(OP_LCFIRST);
 
        case KEY_local:
-           yylval.ival = 0;
            OPERATOR(LOCAL);
 
        case KEY_length:
@@ -2970,8 +2996,7 @@ yylex()
 
        case KEY_my:
            in_my = TRUE;
-           yylval.ival = 1;
-           OPERATOR(LOCAL);
+           OPERATOR(MY);
 
        case KEY_next:
            s = force_word(s,WORD,TRUE,FALSE,FALSE);
@@ -3060,6 +3085,19 @@ yylex()
            s = scan_str(s);
            if (!s)
                missingterm((char*)0);
+           if (dowarn && SvLEN(lex_stuff)) {
+               d = SvPV_force(lex_stuff, len);
+               for (; len; --len, ++d) {
+                   if (*d == ',') {
+                       warn("Possible attempt to separate words with commas");
+                       break;
+                   }
+                   if (*d == '#') {
+                       warn("Possible attempt to put comments in qw() list");
+                       break;
+                   }
+               }
+           }
            force_next(')');
            nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, q(lex_stuff));
            lex_stuff = Nullsv;
@@ -3191,16 +3229,16 @@ yylex()
            LOP(OP_SETPRIORITY,XTERM);
 
        case KEY_sethostent:
-           FUN1(OP_SHOSTENT);
+           UNI(OP_SHOSTENT);
 
        case KEY_setnetent:
-           FUN1(OP_SNETENT);
+           UNI(OP_SNETENT);
 
        case KEY_setservent:
-           FUN1(OP_SSERVENT);
+           UNI(OP_SSERVENT);
 
        case KEY_setprotoent:
-           FUN1(OP_SPROTOENT);
+           UNI(OP_SPROTOENT);
 
        case KEY_setpwent:
            FUN0(OP_SPWENT);
@@ -3392,11 +3430,11 @@ yylex()
 
        case KEY_until:
            yylval.ival = curcop->cop_line;
-           OPERATOR(UNTIL);
+           PRETERMBLOCK(UNTIL);
 
        case KEY_unless:
            yylval.ival = curcop->cop_line;
-           OPERATOR(UNLESS);
+           PRETERMBLOCK(UNLESS);
 
        case KEY_unlink:
            LOP(OP_UNLINK,XTERM);
@@ -3448,7 +3486,7 @@ yylex()
 
        case KEY_while:
            yylval.ival = curcop->cop_line;
-           OPERATOR(WHILE);
+           PRETERMBLOCK(WHILE);
 
        case KEY_warn:
            hints |= HINT_BLOCK_SCOPE;
@@ -4226,20 +4264,21 @@ I32 ck_uni;
        *d = *s++;
     d[1] = '\0';
     if (*d == '^' && *s && (isUPPER(*s) || strchr("[\\]^_?", *s))) {
-       *d = *s++ ^ 64;
+       *d = toCTRL(*s);
+       s++;
     }
     if (bracket) {
        if (isSPACE(s[-1])) {
            while (s < send && (*s == ' ' || *s == '\t')) s++;
            *d = *s;
        }
-       if (isALPHA(*d) || *d == '_') {
+       if (isIDFIRST(*d)) {
            d++;
            while (isALNUM(*s) || *s == ':')
                *d++ = *s++;
            *d = '\0';
            while (s < send && (*s == ' ' || *s == '\t')) s++;
-           if ((*s == '[' || *s == '{')) {
+           if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
                if (dowarn && keyword(dest, d - dest)) {
                    char *brack = *s == '[' ? "[...]" : "{...}";
                    warn("Ambiguous use of %c{%s%s} resolved to %c%s%s",
@@ -4276,10 +4315,8 @@ void pmflag(pmfl,ch)
 U16* pmfl;
 int ch;
 {
-    if (ch == 'i') {
-       sawi = TRUE;
+    if (ch == 'i')
        *pmfl |= PMf_FOLD;
-    }
     else if (ch == 'g')
        *pmfl |= PMf_GLOBAL;
     else if (ch == 'o')
@@ -4306,14 +4343,14 @@ char *start;
        lex_stuff = Nullsv;
        croak("Search pattern not terminated");
     }
+
     pm = (PMOP*)newPMOP(OP_MATCH, 0);
     if (multi_open == '?')
        pm->op_pmflags |= PMf_ONCE;
-
     while (*s && strchr("iogmsx", *s))
        pmflag(&pm->op_pmflags,*s++);
-
     pm->op_pmpermflags = pm->op_pmflags;
+
     lex_op = (OP*)pm;
     yylval.ival = OP_MATCH;
     return s;
@@ -4391,8 +4428,6 @@ register PMOP *pm;
        ) {
        if (!(pm->op_pmregexp->reganch & ROPT_ANCH))
            pm->op_pmflags |= PMf_SCANFIRST;
-       else if (pm->op_pmflags & PMf_FOLD)
-           return;
        pm->op_pmshort = SvREFCNT_inc(pm->op_pmregexp->regstart);
        pm->op_pmslen = SvCUR(pm->op_pmshort);
     }
@@ -4539,7 +4574,7 @@ register char *s;
     if (!rsfp) {
        d = s;
        while (s < bufend &&
-         (*s != term || bcmp(s,tokenbuf,len) != 0) ) {
+         (*s != term || memNE(s,tokenbuf,len)) ) {
            if (*s++ == '\n')
                curcop->cop_line++;
        }
@@ -4551,14 +4586,14 @@ register char *s;
        s += len - 1;
        sv_catpvn(herewas,s,bufend-s);
        sv_setsv(linestr,herewas);
-       oldoldbufptr = oldbufptr = bufptr = s = SvPVX(linestr);
+       oldoldbufptr = oldbufptr = bufptr = s = linestart = SvPVX(linestr);
        bufend = SvPVX(linestr) + SvCUR(linestr);
     }
     else
        sv_setpvn(tmpstr,"",0);   /* avoid "uninitialized" warning */
     while (s >= bufend) {      /* multiple line string? */
        if (!rsfp ||
-        !(oldoldbufptr = oldbufptr = s = filter_gets(linestr, rsfp))) {
+        !(oldoldbufptr = oldbufptr = s = linestart = filter_gets(linestr, rsfp, 0))) {
            curcop->cop_line = multi_start;
            missingterm(tokenbuf);
        }
@@ -4572,7 +4607,7 @@ register char *s;
              (I32)curcop->cop_line,sv);
        }
        bufend = SvPVX(linestr) + SvCUR(linestr);
-       if (*s == term && bcmp(s,tokenbuf,len) == 0) {
+       if (*s == term && memEQ(s,tokenbuf,len)) {
            s = bufend - 1;
            *s = ' ';
            sv_catsv(linestr,herewas);
@@ -4717,7 +4752,7 @@ char *start;
     if (s < bufend) break;     /* string ends on this line? */
 
        if (!rsfp ||
-        !(oldoldbufptr = oldbufptr = s = filter_gets(linestr, rsfp))) {
+        !(oldoldbufptr = oldbufptr = s = linestart = filter_gets(linestr, rsfp, 0))) {
            sv_free(sv);
            curcop->cop_line = multi_start;
            return Nullch;
@@ -4763,8 +4798,9 @@ char *start;
        croak("panic: scan_num");
     case '0':
        {
-           U32 i;
+           UV u;
            I32 shift;
+           bool overflowed = FALSE;
 
            if (s[1] == 'x') {
                shift = 4;
@@ -4774,8 +4810,10 @@ char *start;
                goto decimal;
            else
                shift = 3;
-           i = 0;
+           u = 0;
            for (;;) {
+               UV n, b;
+
                switch (*s) {
                default:
                    goto out;
@@ -4788,25 +4826,27 @@ char *start;
                    /* FALL THROUGH */
                case '0': case '1': case '2': case '3': case '4':
                case '5': case '6': case '7':
-                   i <<= shift;
-                   i += *s++ & 15;
-                   break;
+                   b = *s++ & 15;
+                   goto digit;
                case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
                case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
                    if (shift != 4)
                        goto out;
-                   i <<= 4;
-                   i += (*s++ & 7) + 9;
+                   b = (*s++ & 7) + 9;
+                 digit:
+                   n = u << shift;
+                   if (!overflowed && (n >> shift) != u) {
+                       warn("Integer overflow in %s number",
+                            (shift == 4) ? "hex" : "octal");
+                       overflowed = TRUE;
+                   }
+                   u = n | b;
                    break;
                }
            }
          out:
            sv = NEWSV(92,0);
-           tryi32 = i;
-           if (tryi32 == i && tryi32 >= 0)
-               sv_setiv(sv,tryi32);
-           else
-               sv_setnv(sv,(double)i);
+           sv_setuv(sv, u);
        }
        break;
     case '1': case '2': case '3': case '4': case '5':
@@ -4846,6 +4886,7 @@ char *start;
        }
        *d = '\0';
        sv = NEWSV(92,0);
+       SET_NUMERIC_STANDARD();
        value = atof(tokenbuf);
        tryi32 = I_32(value);
        if (!floatit && (double)tryi32 == value)
@@ -4896,8 +4937,8 @@ register char *s;
        }
        s = eol;
        if (rsfp) {
-           s = filter_gets(linestr, rsfp);
-           oldoldbufptr = oldbufptr = bufptr = SvPVX(linestr);
+           s = filter_gets(linestr, rsfp, 0);
+           oldoldbufptr = oldbufptr = bufptr = linestart = SvPVX(linestr);
            bufend = bufptr + SvCUR(linestr);
            if (!s) {
                s = bufptr;
@@ -4946,22 +4987,20 @@ start_subparse()
     CV* outsidecv = compcv;
     AV* comppadlist;
 
-#ifndef __QNX__
     if (compcv) {
        assert(SvTYPE(compcv) == SVt_PVCV);
     }
-#endif
     save_I32(&subline);
     save_item(subname);
-    SAVEINT(padix);
+    SAVEI32(padix);
     SAVESPTR(curpad);
     SAVESPTR(comppad);
     SAVESPTR(comppad_name);
     SAVESPTR(compcv);
-    SAVEINT(comppad_name_fill);
-    SAVEINT(min_intro_pending);
-    SAVEINT(max_intro_pending);
-    SAVEINT(pad_reset_pending);
+    SAVEI32(comppad_name_fill);
+    SAVEI32(min_intro_pending);
+    SAVEI32(max_intro_pending);
+    SAVEI32(pad_reset_pending);
 
     compcv = (CV*)NEWSV(1104,0);
     sv_upgrade((SV *)compcv, SVt_PVCV);
@@ -5030,7 +5069,7 @@ char *s;
            (void)strcpy(tname,"within string");
     }
     else if (yychar < 32)
-       (void)sprintf(tname,"next char ^%c",yychar+64);
+       (void)sprintf(tname,"next char ^%c",toCTRL(yychar));
     else
        (void)sprintf(tname,"next char %c",yychar);
     (void)sprintf(buf, "%s at %s line %d, %s\n",