Author: bernhard
Date: Tue Feb 13 12:59:49 2007
New Revision: 16972

Modified:
   trunk/languages/plumhead/src/antlr3/Plumhead.g
   trunk/languages/plumhead/src/partridge/Plumhead.pg
   trunk/languages/plumhead/src/partridge/PlumheadPAST.tg

Log:
[Plumhead partridge]
Slightly nicer register names.
Support for 'else' block.


Modified: trunk/languages/plumhead/src/antlr3/Plumhead.g
==============================================================================
--- trunk/languages/plumhead/src/antlr3/Plumhead.g      (original)
+++ trunk/languages/plumhead/src/antlr3/Plumhead.g      Tue Feb 13 12:59:49 2007
@@ -95,7 +95,7 @@
   : ECHO^ expression ';'! 
   | IF '(' relational_expression ')' '{' s1=statements '}'
     ( ELSE '{' s2=statements '}' -> ^( IF relational_expression ^( STMTS $s1 ) 
^( STMTS $s2 ) )
-    |                           -> ^( IF relational_expression ^( STMTS $s1 ) )
+    |                            -> ^( IF relational_expression ^( STMTS $s1 ) 
)
     ) 
   | CODE_END SEA CODE_START -> ^( ECHO NOQUOTE_STRING[$SEA] )
   | SCALAR ASSIGN_OP^ expression ';'!

Modified: trunk/languages/plumhead/src/partridge/Plumhead.pg
==============================================================================
--- trunk/languages/plumhead/src/partridge/Plumhead.pg  (original)
+++ trunk/languages/plumhead/src/partridge/Plumhead.pg  Tue Feb 13 12:59:49 2007
@@ -30,8 +30,9 @@
 rule  code                    { <?CODE_START> <statement>* <?CODE_END> }
 
 rule statement                { <ECHO> <expression> ;
-                              | <IF> <?PAREN_OPEN> <expression> <?PAREN_CLOSE> 
\{ <statement>* \}
+                              | <IF> <?PAREN_OPEN> <expression> <?PAREN_CLOSE> 
\{ <statement>* \} <else_clause>? 
                               }
+rule else_clause              { <?ELSE> \{ <statement>* \} }
 
 token expression              { <DOUBLEQUOTE_STRING> | <SINGLEQUOTE_STRING> | 
<adding_expression> }
 

Modified: trunk/languages/plumhead/src/partridge/PlumheadPAST.tg
==============================================================================
--- trunk/languages/plumhead/src/partridge/PlumheadPAST.tg      (original)
+++ trunk/languages/plumhead/src/partridge/PlumheadPAST.tg      Tue Feb 13 
12:59:49 2007
@@ -11,9 +11,9 @@
     past = new 'PAST::Block'
     past.'init'( 'node' => node, 'name'=>'plumhead' )
     
-    .local pmc cpast
-    cpast = tree.'get'('past', node, 'Plumhead::Grammar::program')
-    past.'push'(cpast)
+    .local pmc past_program
+    past_program = tree.'get'('past', node, 'Plumhead::Grammar::program')
+    past.'push'(past_program)
 
     .return (past)
 }
@@ -73,31 +73,37 @@
         iter = new .Iterator, $P0
         iter_loop:
             unless iter goto iter_end
-            .local pmc cnode, cpast, cpast2, cpast3
+            .local pmc cnode, past_expression, past_echo, past_if, 
past_if_block, past_else_block
             cnode = shift iter
             if null cnode goto iter_loop
                  $P1 = cnode['ECHO']
                  if null $P1 goto no_echo
                      $P2 = cnode['expression']
                      if null $P2 goto iter_loop
-                         cpast = tree.'get'('past', $P2, 
'Plumhead::Grammar::expression')
-                         if null cpast goto iter_loop
-                         cpast2 = new 'PAST::Op'
-                         cpast2.'init'( cpast, 'node'=> node, 'name' => 
'print' )  
-                         past.'push'(cpast2)
+                         past_expression = tree.'get'('past', $P2, 
'Plumhead::Grammar::expression')
+                         if null past_expression goto iter_loop
+                         past_echo = new 'PAST::Op'
+                         past_echo.'init'( past_expression, 'node'=> node, 
'name' => 'print' )  
+                         past.'push'(past_echo)
                          goto iter_loop
                  no_echo:
                  $P1 = cnode['IF']
                  if null $P1 goto no_if
                      $P2 = cnode['expression']
-                     if null $P2 goto iter_loop
-                         cpast = tree.'get'('past', $P2, 
'Plumhead::Grammar::expression')
-                         if null cpast goto iter_loop
-                         cpast3 = tree.'get'('past', cnode, 
'Plumhead::Grammar::code')
-                         cpast2 = new 'PAST::Op'
-                         cpast2.'init'( cpast, cpast3, 'node'=> node, 
'pasttype' => 'if' )  
-                         past.'push'(cpast2)
-                         goto iter_loop
+                     past_expression = tree.'get'('past', $P2, 
'Plumhead::Grammar::expression')
+                     if null past_expression goto iter_loop
+                     # past_if_block takes care of the <statement>
+                     past_if_block = tree.'get'('past', cnode, 
'Plumhead::Grammar::code')
+                     past_if = new 'PAST::Op'
+                     past_if.'init'( past_expression, past_if_block, 'node'=> 
node, 'pasttype' => 'if' )  
+                     $P3 = cnode['else_clause']
+                     if null $P3 goto no_else_clause
+                         $P4 = $P3[0]
+                         past_else_block = tree.'get'('past', $P4, 
'Plumhead::Grammar::code')
+                         past_if.'push'(past_else_block)
+                     no_else_clause:
+                     past.'push'(past_if)
+                     goto iter_loop
                  no_if:
                  goto iter_loop
          iter_end:
@@ -188,9 +194,9 @@
             $P2 = $P0['UNARY_MINUS']
             if null $P2 goto no_minus
                 past = new 'PAST::Op'
-                .local pmc cpast
-                cpast = tree.'get'('past', $P1, 
'Plumhead::Grammar::expression')
-                past.init( cpast, 'node' => $P0, 'name' => 'prefix:-' )
+                .local pmc past_expression
+                past_expression = tree.'get'('past', $P1, 
'Plumhead::Grammar::expression')
+                past.init( past_expression, 'node' => $P0, 'name' => 
'prefix:-' )
                 goto handled_expression
             no_minus:
             $P2 = $P1['expression']

Reply via email to