This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
numeric.c: White-space only
[perl5.git] / perly.y
diff --git a/perly.y b/perly.y
index 0997e3e..184fb0c 100644 (file)
--- a/perly.y
+++ b/perly.y
 %token <ival> PERLY_BRACKET_OPEN
 %token <ival> PERLY_BRACKET_CLOSE
 %token <ival> PERLY_COMMA
+%token <ival> PERLY_DOLLAR
 %token <ival> PERLY_DOT
 %token <ival> PERLY_EQUAL_SIGN
 %token <ival> PERLY_MINUS
 %token <ival> PERLY_PERCENT_SIGN
 %token <ival> PERLY_PLUS
 %token <ival> PERLY_SEMICOLON
+%token <ival> PERLY_SLASH
 %token <ival> PERLY_SNAIL
 %token <ival> PERLY_STAR
 
@@ -67,6 +69,7 @@
 %token <ival> FORMAT SUB SIGSUB ANONSUB ANON_SIGSUB PACKAGE USE
 %token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR
 %token <ival> GIVEN WHEN DEFAULT
+%token <ival> TRY CATCH
 %token <ival> LOOPEX DOTDOT YADAYADA
 %token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP
 %token <ival> MULOP ADDOP
 %nonassoc <ival> PREC_LOW
 %nonassoc LOOPEX
 
-%left <ival> OROP DOROP
+%left <ival> OROP
 %left <ival> ANDOP
 %right <ival> NOTOP
 %nonassoc LSTOP LSTOPSUB
@@ -229,7 +232,7 @@ formblock:  PERLY_EQUAL_SIGN remember PERLY_SEMICOLON FORMRBRACK formstmtseq PERL
                        }
        ;
 
-remember:      /* NULL */      /* start a full lexical scope */
+remember:      %empty  /* start a full lexical scope */
                        { $$ = block_start(TRUE);
                          parser->parsed_sub = 0; }
        ;
@@ -241,13 +244,13 @@ mblock    :       PERLY_BRACE_OPEN mremember stmtseq PERLY_BRACE_CLOSE
                        }
        ;
 
-mremember:     /* NULL */      /* start a partial lexical scope */
+mremember:     %empty  /* start a partial lexical scope */
                        { $$ = block_start(FALSE);
                          parser->parsed_sub = 0; }
        ;
 
 /* A sequence of statements in the program */
-stmtseq        :       /* NULL */
+stmtseq        :       %empty
                        { $$ = NULL; }
        |       stmtseq[list] fullstmt
                        {   $$ = op_append_list(OP_LINESEQ, $list, $fullstmt);
@@ -258,7 +261,7 @@ stmtseq     :       /* NULL */
        ;
 
 /* A sequence of format lines */
-formstmtseq:   /* NULL */
+formstmtseq:   %empty
                        { $$ = NULL; }
        |       formstmtseq[list] formline
                        {   $$ = op_append_list(OP_LINESEQ, $list, $formline);
@@ -457,6 +460,15 @@ barestmt:  PLUGSTMT
                                  newFOROP(0, NULL, $mexpr, $mblock, $cont));
                          parser->copline = (line_t)$FOR;
                        }
+       |       TRY mblock[try] CATCH PERLY_PAREN_OPEN 
+                       { parser->in_my = 1; }
+               remember scalar 
+                       { parser->in_my = 0; intro_my(); }
+               PERLY_PAREN_CLOSE mblock[catch]
+                       {
+                         $$ = newTRYCATCHOP(0,
+                                 $try, $scalar, block_end($remember, op_scope($catch)));
+                       }
        |       block cont
                        {
                          /* a block is a loop that happens once */
@@ -512,7 +524,7 @@ formline:   THING formarg
                        }
        ;
 
-formarg        :       /* NULL */
+formarg        :       %empty
                        { $$ = NULL; }
        |       FORMLBRACK stmtseq FORMRBRACK
                        { $$ = op_unscope($stmtseq); }
@@ -542,7 +554,7 @@ sideff      :       error
        ;
 
 /* else and elsif blocks */
-else   :       /* NULL */
+else   :       %empty
                        { $$ = NULL; }
        |       ELSE mblock
                        {
@@ -559,26 +571,26 @@ else      :       /* NULL */
        ;
 
 /* Continue blocks */
-cont   :       /* NULL */
+cont   :       %empty
                        { $$ = NULL; }
        |       CONTINUE block
                        { $$ = op_scope($block); }
        ;
 
 /* determine whether there are any new my declarations */
-mintro :       /* NULL */
+mintro :       %empty
                        { $$ = (PL_min_intro_pending &&
                            PL_max_intro_pending >=  PL_min_intro_pending);
                          intro_my(); }
 
 /* Normal expression */
-nexpr  :       /* NULL */
+nexpr  :       %empty
                        { $$ = NULL; }
        |       sideff
        ;
 
 /* Boolean expression */
-texpr  :       /* NULL means true */
+texpr  :       %empty /* NULL means true */
                        { YYSTYPE tmplval;
                          (void)scan_num("1", &tmplval);
                          $$ = tmplval.opval; }
@@ -600,21 +612,21 @@ mnexpr    :       nexpr
        ;
 
 formname:      BAREWORD        { $$ = $BAREWORD; }
-       |       /* NULL */      { $$ = NULL; }
+       |       %empty  { $$ = NULL; }
        ;
 
-startsub:      /* NULL */      /* start a regular subroutine scope */
+startsub:      %empty  /* start a regular subroutine scope */
                        { $$ = start_subparse(FALSE, 0);
                            SAVEFREESV(PL_compcv); }
 
        ;
 
-startanonsub:  /* NULL */      /* start an anonymous subroutine scope */
+startanonsub:  %empty  /* start an anonymous subroutine scope */
                        { $$ = start_subparse(FALSE, CVf_ANON);
                            SAVEFREESV(PL_compcv); }
        ;
 
-startformsub:  /* NULL */      /* start a format subroutine scope */
+startformsub:  %empty  /* start a format subroutine scope */
                        { $$ = start_subparse(TRUE, 0);
                            SAVEFREESV(PL_compcv); }
        ;
@@ -625,13 +637,13 @@ subname   :       BAREWORD
        ;
 
 /* Subroutine prototype */
-proto  :       /* NULL */
+proto  :       %empty
                        { $$ = NULL; }
        |       THING
        ;
 
 /* Optional list of subroutine attributes */
-subattrlist:   /* NULL */
+subattrlist:   %empty
                        { $$ = NULL; }
        |       COLONATTR THING
                        { $$ = $THING; }
@@ -653,7 +665,7 @@ myattrlist: COLONATTR THING
  */
 
 /* the '' or 'foo' part of a '$' or '@foo' etc signature variable  */
-sigvarname:     /* NULL */
+sigvarname:     %empty
                        { parser->in_my = 0; $$ = NULL; }
         |       PRIVATEREF
                         { parser->in_my = 0; $$ = $PRIVATEREF; }
@@ -685,7 +697,7 @@ sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */
        ;
 
 /* default part of sub signature scalar element: i.e. '= default_expr' */
-sigdefault:    /* NULL */
+sigdefault:    %empty
                        { $$ = NULL; }
         |       ASSIGNOP
                         { $$ = newOP(OP_NULL, 0); }
@@ -695,7 +707,7 @@ sigdefault: /* NULL */
 
 /* subroutine signature scalar element: e.g. '$x', '$=', '$x = $default' */
 sigscalarelem:
-                '$' sigvarname sigdefault
+                PERLY_DOLLAR sigvarname sigdefault
                         {
                             OP *var     = $sigvarname;
                             OP *defexpr = $sigdefault;
@@ -779,13 +791,13 @@ siglist:
        ;
 
 /* () or (....) */
-siglistornull:         /* NULL */
+siglistornull:         %empty
                        { $$ = NULL; }
        |       siglist
                        { $$ = $siglist; }
 
 /* optional subroutine signature */
-optsubsignature:       /* NULL */
+optsubsignature:       %empty
                        { $$ = NULL; }
        |       subsignature
                        { $$ = $subsignature; }
@@ -899,8 +911,6 @@ expr        :       expr[lhs] ANDOP expr[rhs]
                        { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
        |       expr[lhs] OROP[operator] expr[rhs]
                        { $$ = newLOGOP($operator, 0, $lhs, $rhs); }
-       |       expr[lhs] DOROP expr[rhs]
-                       { $$ = newLOGOP(OP_DOR, 0, $lhs, $rhs); }
        |       listexpr %prec PREC_LOW
        ;
 
@@ -1246,7 +1256,7 @@ term[product]     :       termbinop
                        { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
                            op_append_elem(OP_LIST, $optlistexpr, scalar($subname)));
                        }
-       |       term[operand] ARROW '$' PERLY_STAR
+       |       term[operand] ARROW PERLY_DOLLAR PERLY_STAR
                        { $$ = newSVREF($operand); }
        |       term[operand] ARROW PERLY_SNAIL PERLY_STAR
                        { $$ = newAVREF($operand); }
@@ -1337,21 +1347,21 @@ myterm  :       PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
        ;
 
 /* Basic list expressions */
-optlistexpr:   /* NULL */ %prec PREC_LOW
+optlistexpr:   %empty %prec PREC_LOW
                        { $$ = NULL; }
        |       listexpr    %prec PREC_LOW
                        { $$ = $listexpr; }
        ;
 
-optexpr:       /* NULL */
+optexpr:       %empty
                        { $$ = NULL; }
        |       expr
                        { $$ = $expr; }
        ;
 
-optrepl:       /* NULL */
+optrepl:       %empty
                        { $$ = NULL; }
-       |       '/' expr
+       |       PERLY_SLASH expr
                        { $$ = $expr; }
        ;
 
@@ -1378,7 +1388,7 @@ amper     :       PERLY_AMPERSAND indirob
                        { $$ = newCVREF($PERLY_AMPERSAND,$indirob); }
        ;
 
-scalar :       '$' indirob
+scalar :       PERLY_DOLLAR indirob
                        { $$ = newSVREF($indirob); }
        ;