 dec-mem  = ("-")+  => [[ length 1quotation [ (-) ] append ]]
 output   = "."  => [[ [ (.) ] ]]
 input    = ","  => [[ [ (,) ] ]]
+debug    = "#"  => [[ [ (#) ] ]]
 space    = (" "|"\t"|"\r\n"|"\n")+ => [[ [ ] ]] 
 unknown  = (.)  => [[ "Invalid input" throw ]]
 
-ops   = inc-ptr | dec-ptr | inc-mem | dec-mem | output | input | space
+ops   = inc-ptr|dec-ptr|inc-mem|dec-mem|output|input|debug|space
 loop  = "[" {loop|ops}* "]" => [[ second compose-all 1quotation [ [ (?) ] ] prepend [ while ] append ]]
 
 code  = (loop|ops|unknown)*  => [[ compose-all ]]

: (<) ( brainfuck n -- brainfuck ) 
    [ dup pointer>> ] dip - >>pointer ;

: compose-all ( seq -- quot ) 
    [ ] [ compose ] reduce ;


! See http://factorcode.org/license.txt for BSD license

USING: accessors assocs fry io io.streams.string kernel macros math 
peg.ebnf prettyprint quotations sequences strings ;

IN: brainfuck

