brainfuck: more fries with that.
parent
96f2561b42
commit
bfd615b1e8
|
@ -35,10 +35,10 @@ TUPLE: brainfuck pointer memory ;
|
||||||
read1 set-memory ;
|
read1 set-memory ;
|
||||||
|
|
||||||
: (>) ( brainfuck n -- brainfuck )
|
: (>) ( brainfuck n -- brainfuck )
|
||||||
[ + ] curry change-pointer ;
|
'[ _ + ] change-pointer ;
|
||||||
|
|
||||||
: (<) ( brainfuck n -- brainfuck )
|
: (<) ( brainfuck n -- brainfuck )
|
||||||
[ - ] curry change-pointer ;
|
'[ _ - ] change-pointer ;
|
||||||
|
|
||||||
: (#) ( brainfuck -- brainfuck )
|
: (#) ( brainfuck -- brainfuck )
|
||||||
dup
|
dup
|
||||||
|
@ -50,10 +50,10 @@ TUPLE: brainfuck pointer memory ;
|
||||||
|
|
||||||
EBNF: parse-brainfuck
|
EBNF: parse-brainfuck
|
||||||
|
|
||||||
inc-ptr = (">")+ => [[ length [ (>) ] curry ]]
|
inc-ptr = (">")+ => [[ length '[ _ (>) ] ]]
|
||||||
dec-ptr = ("<")+ => [[ length [ (<) ] curry ]]
|
dec-ptr = ("<")+ => [[ length '[ _ (<) ] ]]
|
||||||
inc-mem = ("+")+ => [[ length [ (+) ] curry ]]
|
inc-mem = ("+")+ => [[ length '[ _ (+) ] ]]
|
||||||
dec-mem = ("-")+ => [[ length [ (-) ] curry ]]
|
dec-mem = ("-")+ => [[ length '[ _ (-) ] ]]
|
||||||
output = "." => [[ [ (.) ] ]]
|
output = "." => [[ [ (.) ] ]]
|
||||||
input = "," => [[ [ (,) ] ]]
|
input = "," => [[ [ (,) ] ]]
|
||||||
debug = "#" => [[ [ (#) ] ]]
|
debug = "#" => [[ [ (#) ] ]]
|
||||||
|
@ -61,7 +61,7 @@ space = (" "|"\t"|"\r\n"|"\n")+ => [[ [ ] ]]
|
||||||
unknown = (.) => [[ "Invalid input" throw ]]
|
unknown = (.) => [[ "Invalid input" throw ]]
|
||||||
|
|
||||||
ops = inc-ptr|dec-ptr|inc-mem|dec-mem|output|input|debug|space
|
ops = inc-ptr|dec-ptr|inc-mem|dec-mem|output|input|debug|space
|
||||||
loop = "[" {loop|ops}+ "]" => [[ second compose-all [ while ] curry [ (?) ] prefix ]]
|
loop = "[" {loop|ops}+ "]" => [[ second compose-all '[ [ (?) ] _ while ] ]]
|
||||||
|
|
||||||
code = (loop|ops|unknown)* => [[ compose-all ]]
|
code = (loop|ops|unknown)* => [[ compose-all ]]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue