Commits

Anonymous committed 0fc9dc5

lookup works for names

  • Participants
  • Parent commits 8aa35a3

Comments (0)

Files changed (4)

src/builtins/say.pir

 
 .namespace []
 
+.sub 'onload' :anon :load :init
+  $P0 = new 'ResizablePMCArray' 
+  set_global 'the_cast', $P0
+  $P0 = 0
+  set_global 'the_condition', $P0
+.end
+
 .sub 'say'
     .param pmc args            :slurpy
     .local pmc iter
 .sub 'declare'
     .param string char
     $P0 = new 'Hash'
+    $P0['name']  = char
+    $P0['value'] = 0
+    $P0['onstage'] = 0
     set_global char, $P0
+
+    get_global $P1 , 'the_cast'
+    $P1.'push'($P0)
+.end
+
+.sub 'assign'
+    .param int val
+    .param string speaker
+    .local int i, size, status
+    .local pmc person
+    .local string name
+    get_global $P0, 'the_cast'
+    size = $P0
+    i = 0
+  loop:
+    if i == size goto end_loop
+    person = $P0[i]
+    i += 1
+
+    status = person['onstage']
+
+    unless status goto loop
+    name = person['name']
+    if name == speaker goto loop
+    person['value'] = val
+  end_loop:
+.end
+
+
+.sub 'valueof'
+    .param string char
+    get_global $P0, char
+    $P1 = $P0['value']
+    .return ($P1)
 .end
 
 .sub 'enter'
     .param string char
-    print "enter: "
-    print char
-    print "\n"
     get_global $P0, char
-    $P0['active'] = 1
-    .return ()
+    unless null $P0 goto fin
+    die "no such character in the cast!"
+  fin:
+    $P0['onstage'] = 1
 .end
 .sub 'exit'
     .param string char
-    print "exit: "
-    print char
-    print "\n"
     get_global $P0, char
-    $P0['active'] = 0
+    $P0['onstage'] = 0
     .return ()
 .end
 .sub 'say2'

src/parser/actions.pm

 
 method TOP($/) {
   my $past := PAST::Block.new( :node( $/ ) );
-  my $tc := PAST::Var.new( 
-    :name('the_condition'), 
-    :isdecl(1), 
-    :scope('package'),
-    :node( $/ ) );
-  $past.push($tc);
   for $<chardef> {
 =begin
     $past.push(PAST::Var.new(
   make $past;
 }
 
+method assignment($/) {
+  make PAST::Op.new(
+    $($<value>), 
+    :name('assign'),
+    :pasttype('call'),
+    :node($/));
+}
+
 method events($/, $k) {
   dbg("evs:"~$k);
   make $( $/{$k} );
     dbg("line:");
     my $past := PAST::Stmts.new( :node( $/ ) );
     for $<sentence> {
-      $past.push( $( $_ ) );
+      if $_<assignment> {
+        my $op := $( $_ );
+        $op.push(PAST::Val.new(
+            :value($<character>), 
+            :returns('String'),
+            :node($_)) );
+        $past.push($op);
+      }
+      else      {
+        $past.push( $( $_ ) );
+      }
     }
     make $past;
 }
   make $res;
 }
 
-method immediate($/) {
-  my $value := $($<noun>);
-  for $<adjective> {
-    unless $_<first_person_possessive> || $_<second_person_possessive> {
-      $value:= $value*2;
-    }
-  }
-  make PAST::Val.new( :value( $value ), :returns('Integer'), :node($/) );
+method reference($/) {
+  my $res := PAST::Op.new( 
+    :name('valueof'),
+    :pasttype('call'),
+    :node( $/ ) );
+  $res.push( PAST::Val.new(
+      :value($<character>), 
+      :returns('String'),
+      :node($<character>)) );
+  make $res;
 }
 
+
 method enters($/) {
   my $past := PAST::Stmts.new(:node($/));
 
   }
   make $past;
 }
+
 method exits($/) {
   my $past := PAST::Stmts.new(:node($/));
 
   make $past;
 }
 
-method noun($/,$k) {
-  if $k eq 'one'{
-   make 1;
+method immediate($/) {
+  my $value := 1;
+  if $<noun><negative_noun> {
+    $value := -1;
   }
-  elsif $k eq 'minus_one' {
-    make -1;
+  for $<adjective> {
+    unless $_<first_person_possessive> || $_<second_person_possessive> {
+      $value:= $value*2;
+    }
   }
-  elsif $k eq 'lookup' {
-    say("you");
-    panic();
-  }
+  make PAST::Val.new( :value( $value ), :returns('Integer'), :node($/) );
+}
 
-}
 
 method tap($/) {
   my $res := PAST::Op.new(:name('tap'),:pasttype('call'),:node($/));
   $res.push( $($<value>) );
   make $res;
 }
+
 method plan($/) {
   my $res := PAST::Op.new(:name('plan'),:pasttype('call'),:node($/));
   $res.push( $($<value>) );
     :pasttype($k), 
     :node($/) );
 }
+
 method computation($/, $key) {
   make $( $/{$key} );
 }
   $res.push( $( $<value> ) );
   make $res;
 }
+
 method binary($/, $key) {
   my $res := PAST::Op.new( :name( $key ), :pasttype('call'), :node( $/ ) );
   for $<value> {

src/parser/grammar.pg

 }
 
 rule assignment {
-  | 'you' 'are' 'as' <adjective> 'as' <value>
+  [
+  | 'you' 'are' 'as' <adjective> 'as' <value> 
   | 'you' 'are' <value>
   | 'you' <value>
+  ]
+  {*}
 }
 
 rule branch {
 }
 
 rule value {
-  |<immediate> {*} #= immediate
-  |<computation> {*}  #= computation
+  |<immediate> {*}   #= immediate
+  |<computation> {*} #= computation
+  |<reference> {*}   #= reference
 }
 
 rule immediate {
-  |<article>? [<adjective> ]* <noun> {*} 
+ <article>? [<adjective> ]* <noun> {*} 
 }
 
 token noun {
 |<positive_noun>{*} #= one
 |<negative_noun>{*} #= minus_one
 |<neutral_noun> {*} #= one
-|<second_person_reflexive> {*} #= lookup
 |<first_person> {*} #= one
-|<second_person> {*} #= lookup
 |<nothing> {*} #= one
 }
 
+token reference {
+[
+|<second_person_reflexive> 
+|<second_person>
+|<character>
+] {*}
+}
+
 token adjective {
 |<positive_adjective>
 |<neutral_adjective>

t/08-assignment.t

+juliet, smo.
+hamlet, smo.
+othello, smo.
+romeo, smo.
+                    Scene I: The insulting of Romeo.
+[enter othello]
+othello: plan a pretty pretty king.
+[Enter Hamlet]
+
+Hamlet: you are as sweet as a flower.
+
+othello: proove othello.
+Hamlet: you are twice othello.
+othello: proove othello.
+[exeunt othello]
+
+[enter juliet]
+juliet: you are as pretty as the sum of a pretty king and a rose.
+
+[exeunt hamlet]
+[enter othello]
+juliet: you are as pretty as 
+  the difference between 
+    the sum of  hamlet and othello
+  and a rose.
+[exeunt juliet]
+
+othello: proove hamlet.
+othello: proove othello.