目录

parrot - 分支机构( Branches)

代码在没有流量控制的情况下变得有点无聊; 对于初学者来说,Parrot知道分支和标签。 分支op等同于Perl的goto:

         branch TERRY
JOHN:    print "fjords\n"
         branch END
MICHAEL: print " pining"
         branch GRAHAM
TERRY:   print "It's"
         branch MICHAEL
GRAHAM:  print " for the "
         branch JOHN
END:     end

它还可以执行简单的测试以查看寄存器是否包含真值:

         set I1, 12
         set I2, 5
         mod I3, I2, I2
         if I3, REMAIND, DIVISOR
REMAIND: print "5 divides 12 with remainder "
         print I3
         branch DONE
DIVISOR: print "5 is an integer divisor of 12"
DONE:    print "\n"
         end

这是Perl中的样子,用于比较:

$i1 = 12;
$i2 = 5;
$i3 = $i1 % $i2;
if ($i3) {
   print "5 divides 12 with remainder ";
   print $i3;
} else {
   print "5 is an integer divisor of 12";
}
print "\n";
exit;

Parrot运算符

我们有全系列的数字比较器:eq,ne,lt,gt,le和ge。 请注意,您不能在不同类型的参数上使用这些运算符; 你可能甚至需要将后缀_i或_n添加到op中,告诉它你正在使用什么类型的参数,虽然汇编程序应该为你理解这一点,当你读到它时。

↑回到顶部↑
WIKI教程 @2018