/* perly.y
*
- * Copyright (c) 1991-2003, Larry Wall
+ * Copyright (c) 1991-2002, 2003, 2004 Larry Wall
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
* All that is gold does not glitter, not all those who wander are lost.'
*/
-%{
-#include "EXTERN.h"
-#define PERL_IN_PERLY_C
-#include "perl.h"
-#ifdef EBCDIC
-#undef YYDEBUG
-#endif
-#define dep() deprecate("\"do\" to call subroutines")
-
-/* stuff included here to make perly_c.diff apply better */
-
-#define yydebug PL_yydebug
-#define yynerrs PL_yynerrs
-#define yyerrflag PL_yyerrflag
-#define yychar PL_yychar
-#define yyval PL_yyval
-#define yylval PL_yylval
-
-struct ysv {
- short* yyss;
- YYSTYPE* yyvs;
- int oldyydebug;
- int oldyynerrs;
- int oldyyerrflag;
- int oldyychar;
- YYSTYPE oldyyval;
- YYSTYPE oldyylval;
-};
-
-static void yydestruct(pTHX_ void *ptr);
-
-%}
+/* Make the parser re-entrant. */
-%start prog
+%pure_parser
-%{
-#if 0 /* get this from perly.h instead */
-%}
+%start prog
%union {
I32 ival;
GV *gvval;
}
-%{
-#endif /* 0 */
-
-#ifdef USE_PURE_BISON
-#define YYLEX_PARAM (&yychar)
-#define yylex yylex_r
-#endif
-
-%}
-
%token <ival> '{'
%token <opval> WORD METHOD FUNCMETH THING PMFUNC PRIVATEREF
%token COLONATTR
%type <ival> prog decl format startsub startanonsub startformsub
-%type <ival> progstart remember mremember '&'
+%type <ival> progstart remember mremember '&' savescope
%type <opval> block mblock lineseq line loop cond else
%type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
%type <opval> argexpr nexpr texpr iexpr mexpr mnexpr mtexpr miexpr
progstart:
{
-#if defined(YYDEBUG) && defined(DEBUGGING)
- yydebug = (DEBUG_p_TEST);
-#endif
PL_expect = XSTATE; $$ = block_start(TRUE);
}
;
{ $$ = block_start(FALSE); }
;
+savescope: /* NULL */ /* remember stack pos in case of error */
+ { $$ = PL_savestack_ix; }
+
/* A collection of "lines" in the program */
lineseq : /* NULL */
{ $$ = Nullop; }
| lineseq decl
{ $$ = $1; }
- | lineseq line
- { $$ = append_list(OP_LINESEQ,
- (LISTOP*)$1, (LISTOP*)$2);
+ | lineseq savescope line
+ { LEAVE_SCOPE($2);
+ $$ = append_list(OP_LINESEQ,
+ (LISTOP*)$1, (LISTOP*)$3);
PL_pad_reset_pending = TRUE;
- if ($1 && $2) PL_hints |= HINT_BLOCK_SCOPE; }
+ if ($1 && $3) PL_hints |= HINT_BLOCK_SCOPE; }
;
/* A "line" in the program */
subscripted: star '{' expr ';' '}' /* *main::{something} */
/* In this and all the hash accessors, ';' is
* provided by the tokeniser */
- { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
+ { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3));
+ PL_expect = XOPERATOR; }
| scalar '[' expr ']' /* $array[$element] */
{ $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3)); }
| term ARROW '[' expr ']' /* somearef->[$element] */
{ $$ = newUNOP(OP_NOT, 0, scalar($2)); }
| UNIOP /* Unary op, $_ implied */
{ $$ = newOP($1, 0); }
- | UNIOP block /* eval { foo }, I *think* */
+ | UNIOP block /* eval { foo } */
{ $$ = newUNOP($1, 0, $2); }
| UNIOP term /* Unary op */
{ $$ = newUNOP($1, 0, $2); }
{ $$ = newOP($1, OPf_SPECIAL); }
| FUNC1 '(' expr ')' /* not($foo) */
{ $$ = newUNOP($1, 0, $3); }
- | PMFUNC '(' term ')' /* split (/foo/) */
+ | PMFUNC '(' term ')' /* /foo/ */
{ $$ = pmruntime($1, $3, Nullop); }
- | PMFUNC '(' term ',' term ')' /* split (/foo/,$bar) */
+ | PMFUNC '(' term ',' term ')' /* s/foo/bar/ (or tr) */
{ $$ = pmruntime($1, $3, $5); }
| WORD
| listop
| PRIVATEREF
{ $$ = $1; }
;
-
-%% /* PROGRAM */
-
-/* more stuff added to make perly_c.diff easier to apply */
-
-#ifdef yyparse
-#undef yyparse
-#endif
-#define yyparse() Perl_yyparse(pTHX)
-