brainfuck: Require loops to be non-empty, add test case.
parent
4b21217956
commit
88e5397b51
|
@ -1,7 +1,8 @@
|
|||
! Copyright (C) 2009 John Benediktsson
|
||||
! 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
|
||||
|
@ -48,4 +49,14 @@ USING: brainfuck io.streams.string multiline tools.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 ]]
|
||||
|
||||
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 ]]
|
||||
|
||||
|
|
Loading…
Reference in New Issue