Skip to content

Commit

Permalink
Simplify parse-instruction
Browse files Browse the repository at this point in the history
Avoid repetition of line and column parameters
  • Loading branch information
fraya committed May 8, 2024
1 parent 799a8b7 commit dbe4e02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
5 changes: 4 additions & 1 deletion dylan-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"category": "interpreters",
"description": "Brainfuck interpreter",
"dependencies": [ ],
"dev-dependencies": [ "[email protected]" ],
"dev-dependencies": [
"[email protected]",
"[email protected]"
],
"version": "0.1.0",
"url": "https://github.com/fraya/dylan-brainfuck"
}
25 changes: 13 additions & 12 deletions sources/brainfuck.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,19 @@ end;
define method parse-instruction
(char :: <character>)
=> (instruction :: false-or(<instruction>))
select (char)
'>' => make(<memory-pointer-increment>);
'<' => make(<memory-pointer-decrement>);
'+' => make(<memory-data-increment>);
'-' => make(<memory-data-decrement>);
'.' => make(<output>);
',' => make(<input>);
'[' => make(<jump-forward>);
']' => make(<jump-backward>);
otherwise
#f;
end select;
let type :: false-or(<class>) = select (char)
'>' => <memory-pointer-increment>;
'<' => <memory-pointer-decrement>;
'+' => <memory-data-increment>;
'-' => <memory-data-decrement>;
'.' => <output>;
',' => <input>;
'[' => <jump-forward>;
']' => <jump-backward>;
otherwise
=> #f;
end select;
if (type) make(type) else #f end
end;


Expand Down

0 comments on commit dbe4e02

Please sign in to comment.