Author: bernhard
Date: Tue Feb  6 13:20:41 2007
New Revision: 16913

Modified:
   trunk/languages/plumhead/src/partridge/Plumhead.pg
   trunk/languages/plumhead/src/partridge/PlumheadPAST.tg
   trunk/languages/plumhead/t/arithmetics.t

Log:
[Plumhead partridge]
Add support for 'echo 1 - 2;' but not 'echo 1 - 2 - 3'


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  6 13:20:41 2007
@@ -16,8 +16,9 @@
 
 token NUMBER                  { \d+ }
 
-token MINUS                   { \- }
-token PLUS                    { \+ }
+token UNARY_MINUS             { \- }
+token UNARY_PLUS              { \+ }
+token ADD_OP                  { \+ | \- }
 token MUL_OP                  { \* | / | % }
 
 token program     { ^ <SEA> <code> }
@@ -30,11 +31,11 @@
 
 rule adding_expression { <multiplying_expression> <summand>? }
 
-rule summand           { <?PLUS> <adding_expression> }
+rule summand           { <ADD_OP> <adding_expression> }
 
 rule multiplying_expression  { <unary_expression> ( <MUL_OP> 
<unary_expression> )* }
 
-rule unary_expression { <MINUS>? <postfix_expression> }
+rule unary_expression { <UNARY_MINUS>? <postfix_expression> }
 
 rule postfix_expression { <NUMBER> }
 

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  6 
13:20:41 2007
@@ -122,9 +122,16 @@
             mult = $P0['multiplying_expression']
            past_mult = tree.'get'('past', mult, 
'Plumhead::Grammar::expression')
            summand_0 = summand[0]
+            .local string add_op, pirop
+            pirop = 'n_add'
+            add_op = summand_0['ADD_OP']
+            if add_op != '-' goto not_minus
+                pirop = 'n_sub'
+            not_minus:
+            add_op = 'infix:' . add_op 
            past_summand_0 = tree.'get'('past', summand_0, 
'Plumhead::Grammar::expression')
             past = new 'PAST::Op'
-           past.init( past_mult, past_summand_0, 'name' => 'infix:+',  'pirop' 
=> 'n_add' )
+           past.init( past_mult, past_summand_0, 'name' => add_op, 'pirop' => 
pirop )
             goto handled_expression
        no_summand:
         past = tree.'get'('past', $P0, 'Plumhead::Grammar::expression')
@@ -141,7 +148,7 @@
     if null $P0 goto no_unary_expression
         $P1 = $P0['postfix_expression']
         if null $P1 goto handled_expression
-            $P2 = $P0['MINUS']
+            $P2 = $P0['UNARY_MINUS']
             if null $P2 goto no_minus
                 past = new 'PAST::Op'
                 past.init( 'node' => $P1, 'name' => 'prefix:-' )

Modified: trunk/languages/plumhead/t/arithmetics.t
==============================================================================
--- trunk/languages/plumhead/t/arithmetics.t    (original)
+++ trunk/languages/plumhead/t/arithmetics.t    Tue Feb  6 13:20:41 2007
@@ -72,6 +72,7 @@
     [ '1 - 1', '0', ],
     [ '1 - 2', '-1', ],
     [ '-1 - -2', '1', ],
+    [ '1 - 2 - 10', '-11', ],
     [ '-1 + -2 - -4 + 10', '11', ],
     [ '- 1 - - 6 + 3 - 2', '6', ],
     [ '2 * 2', '4', ],

Reply via email to