develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r34259 - in trunk: . docs/pdds languages/pipp languages/pipp/src/pct languages/pipp/t/php

From:
bernhard
Date:
December 22, 2008 14:06
Subject:
[svn:parrot] r34259 - in trunk: . docs/pdds languages/pipp languages/pipp/src/pct languages/pipp/t/php
Message ID:
20081222220602.E3BB3CBA20@x12.develooper.com
Author: bernhard
Date: Mon Dec 22 14:06:01 2008
New Revision: 34259

Modified:
   trunk/NEWS
   trunk/languages/pipp/CREDITS
   trunk/languages/pipp/src/pct/actions.pm
   trunk/languages/pipp/src/pct/grammar.pg
   trunk/languages/pipp/t/php/control_flow.t

Changes in other areas also in this revision:
Modified:
   trunk/docs/pdds/pdd21_namespaces.pod

Log:
[Pipp] Support for do-while
Courtesy of Daniel Keane.


Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Mon Dec 22 14:06:01 2008
@@ -12,6 +12,8 @@
 - Languages
   + Pipp
     - added support for 'elsif'
+    - added support for 'do-while'
+
 
 New in 0.8.2
 - Implementation

Modified: trunk/languages/pipp/CREDITS
==============================================================================
--- trunk/languages/pipp/CREDITS	(original)
+++ trunk/languages/pipp/CREDITS	Mon Dec 22 14:06:01 2008
@@ -26,4 +26,6 @@
 D: Code beautification
 
 N: Daniel Keane
+E: keane.dp@gmail.com
 D: Implementation of 'elsif'
+D: Implementation of 'do-while'

Modified: trunk/languages/pipp/src/pct/actions.pm
==============================================================================
--- trunk/languages/pipp/src/pct/actions.pm	(original)
+++ trunk/languages/pipp/src/pct/actions.pm	Mon Dec 22 14:06:01 2008
@@ -225,7 +225,7 @@
                     :node($/)
                 );
     for $<expression> {
-        $past.push($($_));
+        $past.push( $($_) );
     }
 
     make $past;
@@ -240,8 +240,18 @@
     make $past;
 }
 
+method do_while_statement($/) {
+    my $past := PAST::Op.new(
+                    $( $<expression> ),
+                    $( $<block> ),
+                    :pasttype('repeat_while'),
+                    :node($/)
+                );
+    make $past;
+}
+
 method if_statement($/) {
-    my $past := $($<conditional_expression>);
+    my $past := $( $<conditional_expression> );
     $past.pasttype('if');
         
     my $else := undef;
@@ -253,7 +263,7 @@
         my $count := +$<elseif_clause> - 1;
         $first_eif := $( $<elseif_clause>[$count] );
         while $count != 0 {
-            my $eif := $($<elseif_clause>[$count]);
+            my $eif := $( $<elseif_clause>[$count] );
             $count--;
             my $eifchild := $( $<elseif_clause>[$count] );
             if ($else) {
@@ -277,11 +287,11 @@
 }
 
 method else_clause($/) {
-    make $($<block>);
+    make $( $<block> );
 }
 
 method elseif_clause($/) {
-    my $past := $($<conditional_expression>);
+    my $past := $( $<conditional_expression> );
     $past.pasttype('if');
 
     make $past;
@@ -338,7 +348,7 @@
 
 
 method while_statement($/) {
-    my $past := $($<conditional_expression>);
+    my $past := $( $<conditional_expression> );
     $past.pasttype('while');
     make $past;
 }
@@ -361,7 +371,7 @@
 # Handle the operator precedence table.
 method expression($/, $key) {
     if ($key eq 'end') {
-        make $($<expr>);
+        make $( $<expr> );
     }
     else {
         my $past := PAST::Op.new( :name($<type>),
@@ -508,7 +518,7 @@
     # nothing to do for $<const_definition,
     # setup of class constants is done in the 'loadinit' node
     for $<class_constant_definition> {
-       $past.push($($_));
+       $past.push( $($_) );
     }
 
     my $methods_block

Modified: trunk/languages/pipp/src/pct/grammar.pg
==============================================================================
--- trunk/languages/pipp/src/pct/grammar.pg	(original)
+++ trunk/languages/pipp/src/pct/grammar.pg	Mon Dec 22 14:06:01 2008
@@ -126,6 +126,7 @@
     | <expression_statement>    {*}  #= expression_statement
     | <if_statement>            {*}  #= if_statement
     | <while_statement>         {*}  #= while_statement
+    | <do_while_statement>      {*}  #= do_while_statement
     | <for_statement>           {*}  #= for_statement
     | <inline_sea_short_tag>    {*}  #= inline_sea_short_tag
     | <inline_sea_script_tag>   {*}  #= inline_sea_script_tag
@@ -198,6 +199,11 @@
     {*}
 }
 
+rule do_while_statement {
+    'do' <block> 'while' '(' <expression> ')' <.statement_delimiter>
+    {*}
+}
+
 rule for_statement {
     'for' '(' <var_assign> <expression> ';' <expression> ')' <block>
     {*}

Modified: trunk/languages/pipp/t/php/control_flow.t
==============================================================================
--- trunk/languages/pipp/t/php/control_flow.t	(original)
+++ trunk/languages/pipp/t/php/control_flow.t	Mon Dec 22 14:06:01 2008
@@ -24,7 +24,7 @@
 
 use Parrot::Config ();
 use Parrot::Test;
-use Test::More     tests => 16;
+use Test::More     tests => 18;
 
 language_output_is( 'Pipp', <<'CODE', <<'OUT', 'if, one statement in block' );
 <?php
@@ -219,6 +219,43 @@
 round 10
 OUT
 
+language_output_is('Pipp', <<'CODE', <<'OUT', 'do-while loop');
+<?php
+
+$count = 0;
+do { echo "round $count\n"; $count++; } while ($count <= 10);
+CODE
+round 0
+round 1
+round 2
+round 3
+round 4
+round 5
+round 6
+round 7
+round 8
+round 9
+round 10
+OUT
+
+language_output_is( 'Pipp', <<'CODE', <<'OUT', 'do-while with negated expression');
+<?php
+
+$count = 0;
+do { $count++; echo "round $count\n"; } while (!($count >= 10));
+CODE
+round 1
+round 2
+round 3
+round 4
+round 5
+round 6
+round 7
+round 8
+round 9
+round 10
+OUT
+
 language_output_is( 'Pipp', <<'CODE', <<'OUT', 'classic for-loop' );
 <?php
 



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About