- Parrot 教程
- Parrot - 主页
- Parrot - 概述
- Parrot - 安装
- Parrot - 说明
- Parrot - 垃圾回收
- Parrot - 数据类型
- Parrot - 寄存器
- Parrot - 操作
- Parrot - 分支
- Parrot 示例
- Parrot - 示例
- Parrot 资源
- Parrot - 快速指南
- Parrot - 有用资源
Parrot - 分支
在没有流控制的情况下,代码会有些枯燥;对于初学者,Parrot 了解分支和标签。分支操作相当于 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,以告诉它你使用的是哪种类型参数,尽管在此时此刻,汇编器可以通过阅读来推断这一点。
广告