Anonymous avatar Anonymous committed f15e9cb

stack work

Comments (0)

Files changed (4)

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'()

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' );
 }

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 {
+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. 
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.