brainfuck: some cleanup and make the ebnf simpler.
parent
dd280eae9a
commit
02181a5d50
|
@ -1,8 +1,8 @@
|
||||||
! Copyright (C) 2009 John Benediktsson
|
! Copyright (C) 2009 John Benediktsson
|
||||||
! See http://factorcode.org/license.txt for BSD license
|
! See http://factorcode.org/license.txt for BSD license
|
||||||
|
|
||||||
USING: accessors assocs fry io io.streams.string kernel macros math
|
USING: accessors assocs fry io io.streams.string kernel macros
|
||||||
peg.ebnf prettyprint quotations sequences strings ;
|
math peg.ebnf prettyprint sequences strings ;
|
||||||
|
|
||||||
IN: brainfuck
|
IN: brainfuck
|
||||||
|
|
||||||
|
@ -50,10 +50,10 @@ TUPLE: brainfuck pointer memory ;
|
||||||
|
|
||||||
EBNF: parse-brainfuck
|
EBNF: parse-brainfuck
|
||||||
|
|
||||||
inc-ptr = (">")+ => [[ length 1quotation [ (>) ] append ]]
|
inc-ptr = (">")+ => [[ length [ (>) ] curry ]]
|
||||||
dec-ptr = ("<")+ => [[ length 1quotation [ (<) ] append ]]
|
dec-ptr = ("<")+ => [[ length [ (<) ] curry ]]
|
||||||
inc-mem = ("+")+ => [[ length 1quotation [ (+) ] append ]]
|
inc-mem = ("+")+ => [[ length [ (+) ] curry ]]
|
||||||
dec-mem = ("-")+ => [[ length 1quotation [ (-) ] append ]]
|
dec-mem = ("-")+ => [[ length [ (-) ] curry ]]
|
||||||
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 1quotation [ [ (?) ] ] prepend [ while ] append ]]
|
loop = "[" {loop|ops}+ "]" => [[ second compose-all [ while ] curry [ (?) ] prefix ]]
|
||||||
|
|
||||||
code = (loop|ops|unknown)* => [[ compose-all ]]
|
code = (loop|ops|unknown)* => [[ compose-all ]]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue