summaryrefslogtreecommitdiff
path: root/src/brainfuck/brainfuck.cr
diff options
context:
space:
mode:
Diffstat (limited to 'src/brainfuck/brainfuck.cr')
-rw-r--r--src/brainfuck/brainfuck.cr14
1 files changed, 14 insertions, 0 deletions
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