Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
53
Task/Execute-Brain-/Seed7/execute-brain-.seed7
Normal file
53
Task/Execute-Brain-/Seed7/execute-brain-.seed7
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
$ include "seed7_05.s7i";
|
||||
|
||||
const proc: brainF (in string: source, inout file: input, inout file: output) is func
|
||||
local
|
||||
var array char: memory is 100000 times '\0;';
|
||||
var integer: dataPointer is 50000;
|
||||
var integer: instructionPointer is 1;
|
||||
var integer: nestingLevel is 0;
|
||||
begin
|
||||
while instructionPointer <= length(source) do
|
||||
case source[instructionPointer] of
|
||||
when {'>'}: incr(dataPointer);
|
||||
when {'<'}: decr(dataPointer);
|
||||
when {'+'}: incr(memory[dataPointer]);
|
||||
when {'-'}: decr(memory[dataPointer]);
|
||||
when {'.'}: write(output, memory[dataPointer]);
|
||||
when {','}: memory[dataPointer] := getc(input);
|
||||
when {'['}: # Forward if zero at dataPointer
|
||||
if memory[dataPointer] = '\0;' then
|
||||
nestingLevel := 1;
|
||||
repeat
|
||||
incr(instructionPointer);
|
||||
case source[instructionPointer] of
|
||||
when {'['}: incr(nestingLevel);
|
||||
when {']'}: decr(nestingLevel);
|
||||
end case;
|
||||
until nestingLevel = 0;
|
||||
end if;
|
||||
when {']'}: # Backward if non-zero at dataPointer
|
||||
if memory[dataPointer] <> '\0;' then
|
||||
nestingLevel := 1;
|
||||
repeat
|
||||
decr(instructionPointer);
|
||||
case source[instructionPointer] of
|
||||
when {'['}: decr(nestingLevel);
|
||||
when {']'}: incr(nestingLevel);
|
||||
end case;
|
||||
until nestingLevel = 0;
|
||||
end if;
|
||||
end case;
|
||||
incr(instructionPointer);
|
||||
end while;
|
||||
end func;
|
||||
|
||||
const proc: brainF (in string: source) is func
|
||||
begin
|
||||
brainF(source, IN, OUT);
|
||||
end func;
|
||||
|
||||
const proc: main is func
|
||||
begin
|
||||
brainF("++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.");
|
||||
end func;
|
||||
Loading…
Add table
Add a link
Reference in a new issue