Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > ddfdf0b0f2e10c06cbb5bbb1f4ee8dd8 > files > 86

perl-Parse-Eyapp-1.182.0-3.mga4.x86_64.rpm

# File: Shift.trg
{
=head1 SYNOPSIS

Compile the grammar and tree transformations first:

     $ eyapp Rule5
     $ treereg Shift

Then execute it with:

     $ ./useruleandshift.pl

Try input: 

     a = b * 8

=cut
}

{
  sub log2 { 
    my $n = shift; 
    return log($n)/log(2); 
  }

  my $power;
}
mult2shift: TIMES($e, NUM($m)) 
  and { $power = log2($m->{attr}); (1 << $power) == $m->{attr} } => { 
    $_[0]->delete(1);
    $_[0]->{shift} = $power;
    $_[0]->type('SHIFTLEFT');
  }