From 4dd4e596ae6e5da84f2ce4296cbf9c030efe69bb Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Fri, 2 Sep 2022 21:03:42 +1200 Subject: Can read code from STDIN, can parse brainfuck --- src/brainfuck/brainfuck.cr | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/brainfuck/brainfuck.cr') diff --git a/src/brainfuck/brainfuck.cr b/src/brainfuck/brainfuck.cr index 78c504c..b75ad1c 100644 --- a/src/brainfuck/brainfuck.cr +++ b/src/brainfuck/brainfuck.cr @@ -13,5 +13,19 @@ module Brainfuck LoopStart LoopEnd end + + def self.opcode_from_char(c : Char) : Opcode? + case c + when '>' then Opcode::PtrRight + when '<' then Opcode::PtrLeft + when '+' then Opcode::Inc + when '-' then Opcode::Dec + when '.' then Opcode::Out + when ',' then Opcode::In + when '[' then Opcode::LoopStart + when ']' then Opcode::LoopEnd + else nil + end + end end -- cgit v1.2.1