Execute Brain****/Raku: Difference between revisions
m
Fixed syntax highlighting and added line numbers.
(added perl6) |
m (Fixed syntax highlighting and added line numbers.) |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 1:
{{works with|Rakudo|2018.03}}
<syntaxhighlight lang="raku"
has @
has @!mem;
has @!loop_stack;
Line 8 ⟶ 9:
method new (Str $code) {
BFInterpreter.bless(
}
Line 14 ⟶ 15:
$!c = 0;
$!m = 0;
while $!c < @
given @.code[$!c] {
when '>' { $!m++ }
when '<' { $!m-- }
Line 23:
when '.' { @!mem[$!m].chr.print }
when ',' {
@!input_buffer = $*IN.get.
@!mem[$!m] = @!input_buffer.shift;
}
when '[' {
@!mem[$!m] == 0 ?? self!jump
}
when ']' {
Line 42:
while $depth {
$!c++;
die "unbalanced code" if $!c >= @
$
$
}
}
}
# Test: "Hello World" program:▼
▲Test: "Hello World" program:
my $code = "++++++++++
[>+++++++>++++++++++>+++>+<<<<-]
Line 57:
my $bfi = BFInterpreter.new($code);
$bfi.run;</syntaxhighlight>
|