brainfuck: Require loops to be non-empty, add test case.
parent
f01c66cf8b
commit
a72f5da857
|
@ -1,7 +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: brainfuck io.streams.string multiline tools.test ;
|
USING: brainfuck kernel io.streams.string math math.parser math.ranges
|
||||||
|
multiline quotations sequences tools.test ;
|
||||||
|
|
||||||
|
|
||||||
[ "+" run-brainfuck ] must-infer
|
[ "+" run-brainfuck ] must-infer
|
||||||
|
@ -48,4 +49,14 @@ USING: brainfuck io.streams.string multiline tools.test ;
|
||||||
|
|
||||||
[ "ABC" ] [ "ABC\0" [ ",[.,]" get-brainfuck ] with-string-reader ] unit-test
|
[ "ABC" ] [ "ABC\0" [ ",[.,]" get-brainfuck ] with-string-reader ] unit-test
|
||||||
|
|
||||||
|
! Squares of numbers from 0 to 100
|
||||||
|
|
||||||
|
100 [0,b] [ dup * number>string ] map "\n" join "\n" append 1quotation
|
||||||
|
[ <" ++++[>+++++<-]>[<+++++>-]+<+[
|
||||||
|
>[>+>+<<-]++>>[<<+>>-]>>>[-]++>[-]+
|
||||||
|
>>>+[[-]++++++>>>]<<<[[<++++++++<++>>-]+<.<[>----<-]<]
|
||||||
|
<<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++>
|
||||||
|
[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-] ">
|
||||||
|
get-brainfuck ] unit-test
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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 1quotation [ [ (?) ] ] prepend [ while ] append ]]
|
||||||
|
|
||||||
code = (loop|ops|unknown)* => [[ compose-all ]]
|
code = (loop|ops|unknown)* => [[ compose-all ]]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue