Commits

gabriele renzi  committed f15e9cb

stack work

  • Participants
  • Parent commits cc22e47

Comments (0)

Files changed (4)

File src/builtins/say.pir

     .return ($P0)
 .end
     
+.sub 'push'
+    .param int a
+    $P0 = 'find_other'()
+    $P1 = $P0['value']
+    push $P1, a
+.end
 
+.sub 'pop'
+    $P0 = 'find_other'()
+    $P1 = $P0['value']
+    $I1 = pop $P1
+.end
 
 .sub 'open_heart'
     $P0 = 'find_other'()

File src/parser/actions.pm

   make mkcall( $($<value>), 'tap' );
 }
 
+method memorize($/) {
+  make mkcall( $($<value>), 'push' );
+}
+
+method recall($/) {
+  make mkcall0( 'pop' );
+}
+
 method plan($/) {
   make mkcall( $($<value>), 'plan' );
 }

File src/parser/grammar.pg

 rule sentence {
   | <tap> {*}  #= tap
   | <plan> {*} #= plan
+  | <memorize> {*} #= memorize
   | <branch>        {*} #= branch
   | <question> {*} #= question
   | <test>     {*} #= test
   | <io>          {*} #= io
   | <assignment>  {*} #= assignment
   | <value>       {*} #= value
+  | <recall> {*} #= recall
 }
 token end { <[.!?]> }
 
   'proove' <value> {*}
 }
 
+rule memorize {
+  'remember' <value> {*}
+}
+
+rule recall {
+  'recall' <-end>* {*}
+}
+
 rule plan {
   'plan' <value> {*}
 }
 }
 
 rule unary {
-  |'the' 'factorial' 'of' <value> {*} #= fact
-  |'the' 'square' 'of' <value> {*} #= square
-  |'the' 'square root' 'of' <value> {*} #= sqrt
-  |'the' 'cube' 'of' <value> {*} #= cube
+<article>?
+[
+  |'factorial' 'of' <value> {*} #= fact
+  |'square' 'of' <value> {*} #= square
+  |'square root' 'of' <value> {*} #= sqrt
+  |'cube' 'of' <value> {*} #= cube
   |'twice' <value> {*} #= dup
+]
 }
 
 rule value {

File t/13-stack.t

+Testing stack ops.
+
+romeo, a cool guy.
+juliet, a pretty girl.
+
+act I: dummy.
+
+scene i: foo.
+
+[enter romeo and juliet]
+romeo: You are a pretty rose. plan twice a pretty king! 
+juliet:  Remember me! proove a king!
+
+romeo: proove myself. 
+
+Scene II: four and three.
+romeo:you are the sum of myself and a rose.
+juliet:  Remember me!
+
+romeo: proove myself. 
+juliet: Recall your imminent death!
+
+romeo: proove twice myself. 
+