Execute Brain****/Raku: Difference between revisions
m
Fixed syntax highlighting and added line numbers.
No edit summary |
m (Fixed syntax highlighting and added line numbers.) |
||
(3 intermediate revisions by 2 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 @
when '>' { $!m++ }
when '<' { $!m-- }
Line 41 ⟶ 42:
while $depth {
$!c++;
die "unbalanced code" if $!c >= @
$depth++ if @
$depth-- if @
}
}
}
# Test: "Hello World" program:
[>+++++++>++++++++++>+++>+<<<<-]
>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.
Line 55 ⟶ 57:
my $bfi = BFInterpreter.new($code);
$bfi.run;</syntaxhighlight>
|