Source

shakespeare-parrot / src / parser / actions.pm

gabriele renzi dac4469 
gabriele renzi 04e8bf0 

gabriele renzi 8ad37b3 
gabriele renzi 8aa35a3 
fperrad_ 0f816d6 
gabriele renzi 8aa35a3 
gabriele renzi 3ab8807 
fperrad_ 0f816d6 
gabriele renzi 27d223c 

gabriele renzi 04e8bf0 
gabriele renzi 1d88f29 
gabriele renzi 0f80dcc 
fperrad_ 0f816d6 
gabriele renzi 0f80dcc 
gabriele renzi 9461739 

gabriele renzi c5d1644 

gabriele renzi 9461739 
gabriele renzi e0ab232 

gabriele renzi 0fc9dc5 
fperrad_ 0f816d6 
gabriele renzi 0fc9dc5 

gabriele renzi 34b23a8 
fperrad_ 0f816d6 
gabriele renzi 34b23a8 

gabriele renzi 3ab8807 



fperrad_ 0f816d6 

gabriele renzi 3ab8807 


fperrad_ 0f816d6 
gabriele renzi 3ab8807 



gabriele renzi 1d88f29 
gabriele renzi 3ab8807 
gabriele renzi 248149c 
fperrad_ 0f816d6 
gabriele renzi 34b23a8 
fperrad_ 0f816d6 
gabriele renzi 1d88f29 


gabriele renzi b859cee 

gabriele renzi 3ab8807 
fperrad_ 0f816d6 
gabriele renzi b859cee 

gabriele renzi e0ab232 
gabriele renzi 6b6c822 
gabriele renzi b859cee 


gabriele renzi 1d88f29 
gabriele renzi 248149c 
gabriele renzi c5d1644 

fperrad_ 0f816d6 
gabriele renzi 0f80dcc 

gabriele renzi c5d1644 

gabriele renzi 1d88f29 
fperrad_ 0f816d6 
gabriele renzi 1d88f29 


gabriele renzi 9461739 
gabriele renzi 1d88f29 
fperrad_ 0f816d6 
gabriele renzi 1d88f29 


gabriele renzi 04e8bf0 
fperrad_ 0f816d6 
gabriele renzi 04e8bf0 

gabriele renzi 027d2fa 
fperrad_ 0f816d6 
gabriele renzi 28cde2a 
fperrad_ 0f816d6 
gabriele renzi 28cde2a 



gabriele renzi a5b154f 
fperrad_ 0f816d6 
gabriele renzi a5b154f 

gabriele renzi abb0969 
gabriele renzi 9f7f734 
fperrad_ 0f816d6 
gabriele renzi 9f7f734 
gabriele renzi 1fafd96 
gabriele renzi 9461739 
gabriele renzi 1fafd96 
gabriele renzi 9f7f734 
gabriele renzi 9461739 
gabriele renzi 9f7f734 
gabriele renzi 0947675 

gabriele renzi 7888b67 
gabriele renzi 248149c 
gabriele renzi 7888b67 

fperrad_ 0f816d6 
gabriele renzi 7888b67 
gabriele renzi 75018de 

gabriele renzi 7888b67 
fperrad_ 0f816d6 
gabriele renzi e05c49b 
gabriele renzi 31eb43f 
gabriele renzi 04a667a 
gabriele renzi 0fc9dc5 



gabriele renzi 0947675 
gabriele renzi 128c853 


gabriele renzi 0fc9dc5 
gabriele renzi 9c0478b 
fperrad_ 0f816d6 
gabriele renzi 0fc9dc5 
gabriele renzi 0947675 
fperrad_ 0f816d6 
gabriele renzi 0fc9dc5 
gabriele renzi 0947675 
gabriele renzi 04e8bf0 
gabriele renzi fbd009a 
fperrad_ 0f816d6 
gabriele renzi fbd009a 
gabriele renzi 0fc9dc5 
gabriele renzi f15e9cb 
fperrad_ 0f816d6 
gabriele renzi f15e9cb 


fperrad_ 0f816d6 
gabriele renzi f15e9cb 

gabriele renzi fbd009a 
fperrad_ 0f816d6 
gabriele renzi fbd009a 
gabriele renzi 04e8bf0 
gabriele renzi 28cde2a 
fperrad_ 0f816d6 

gabriele renzi 28cde2a 
gabriele renzi 0fc9dc5 
gabriele renzi 04e8bf0 
fperrad_ 0f816d6 
gabriele renzi 04e8bf0 

gabriele renzi 9461739 
fperrad_ 0f816d6 
gabriele renzi 04e8bf0 
gabriele renzi 0fc9dc5 
gabriele renzi 04e8bf0 
fperrad_ 0f816d6 



gabriele renzi 04e8bf0 
class shakespeare::Grammar::Actions;

method TOP($/) {
  my $past := PAST::Block.new();
  for $<chardef> {
    $past.push(mkcall('declare', mkstr($_<character>)));
  }
  for $<act> {
    $past.push($_.ast);
  }
  make $past;
}

sub mkstr($arg) {
  return PAST::Val.new(:value('' ~ $arg));
}
sub mkcall($name, $arg) {
  return PAST::Op.new($arg, :name($name), :pasttype('call'));
}
sub mkcall0($name) {
  return PAST::Op.new(:name($name), :pasttype('call'));
}

method assignment($/) {
  make mkcall('assign', $<value>.ast);
}

method events($/, $k) {
  make $/{$k}.ast;
}

method act($/, $k) {
    my $past := PAST::Stmts.new();
    if $k eq 'open' {
      #fugly
      our $?ACT := '' ~ $<roman>;
      $past.push(PAST::Op.new(:inline('act_' ~ $?ACT ~ ':')));
    }
    else {
      for $<scene> {
        $past.push($_.ast);
      }
    }
    make $past;
}
method scene($/) {
    our $?ACT;
    my $past := PAST::Stmts.new(:name($<roman>));
    $past.push(PAST::Op.new(:inline('scene_' ~ $?ACT ~ '_' ~ $<roman> ~ ':')));
    for $<events> {
      $past.push($_.ast);
    }
    make $past;
}

method branch($/) {
  our $?ACT;
  make PAST::Op.new(:inline('goto ' ~ 'scene_' ~ $?ACT ~ '_' ~ $<roman>));
}

method io($/,$k) {
  make mkcall0($k);
}


method line($/) {
    my $past := PAST::Stmts.new();
    $past.push(
      PAST::Op.new(
        PAST::Var.new(:name('the_speaker'), :scope('package')),
        mkstr($<character>),
        :pasttype('bind')
      )
    );
    for $<sentence> {
      $past.push($_.ast);
    }
    make $past;
}

method sentence($/, $key) {
  make $/{$key}.ast;
}


method value($/, $key) {
  make $/{$key}.ast;
}

method question($/) {
  my  $res := $<comparison>.ast;
  for $<value> {
    $res.push($_.ast);
  }
  make $res;
}

method comparison($/,$k) {
    make mkcall0($k);
}

method reference($/, $k) {
  if $k eq 'named_ref' {
    make mkcall('valueof', mkstr($<character>));
  }
  elsif $k eq 'you_ref' {
    make mkcall('valueof', mkcall0('find_other_name'));
  }
  else {
    make mkcall('valueof', mkcall0('get_speaker_name'));
  }
}

method move($/, $k) {
  my $past := PAST::Stmts.new();
  if $<character> {
    for $<character> {
      $past.push(mkcall($k, mkstr($_)));
    }
  }
  else {
    $past.push(mkcall0('exeunt_omnes'));
  }
  make $past;
}

method immediate($/) {
  my $value := 1;
  if $<noun><negative_noun> {
    $value := -1;
  }
  elsif $<noun><nothing> {
    $value := 0;
  }
  for $<adjective> {
    unless $_<first_person_possessive> || $_<second_person_possessive> || $_<third_person_possessive> {
      $value := $value * 2;
    }
  }
  make PAST::Val.new(:value($value));
}


method tap($/) {
  make mkcall('tap', $<value>.ast);
}

method memorize($/) {
  make mkcall('push', $<value>.ast);
}

method recall($/) {
  make mkcall0('pop');
}

method plan($/) {
  make mkcall('plan', $<value>.ast);
}

method test($/, $k) {
  my $test := PAST::Var.new(:name('the_condition'), :scope('package'));
  make PAST::Op.new( $test, $<sentence>.ast, :pasttype($k));
}

method computation($/, $key) {
  make $/{$key}.ast;
}

method unary($/, $k) {
  make mkcall($k, $<value>.ast);
}

method binary($/, $key) {
  my $res := PAST::Op.new(:pirop($key));
  for $<value> {
    $res.push($_.ast)
  }
  make $res;
}