diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2022-09-02 21:03:42 +1200 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2022-09-02 21:03:42 +1200 |
| commit | 4dd4e596ae6e5da84f2ce4296cbf9c030efe69bb (patch) | |
| tree | 401bf737a26c3cac4a32cf4862180d6288f9c010 /src/brainfuck/brainfuck.cr | |
| parent | dd2bcbdadf2068723bdd88729d295171b0291cd2 (diff) | |
Can read code from STDIN, can parse brainfuck
Diffstat (limited to 'src/brainfuck/brainfuck.cr')
| -rw-r--r-- | src/brainfuck/brainfuck.cr | 14 |
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 |
