Execute Brain****/Lua: Difference between revisions

no edit summary
No edit summary
Line 1:
{{implementation|Brainf***}}{{collection|RCBF}}
{{incorrect|Lua|Instead of jumping to the *next* close bracket when reaching a [ and memory[pointer] == 0, it should jump to the next *matching* close bracket such that embedded loops work}}
An implementation of a Brainf*** interpreter in [[Lua]].
<lang lua>memory = {0} --memory is bounded on one side, at 1
Line 29 ⟶ 30:
if memory[pointer] ~= 0 then
table.insert(retpoints, instruction)
else --if the pointer is zero, jump to the next close bracket
else
while program:sub(instruction, instruction) ~= "]" do
instruction = instruction + 1 --if the pointer is not zero, jump to the next close bracket
end
end
Anonymous user