Comment detail

BFコンパイラー (Nested Flatten)
Squeak Smalltalk で。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
| bf st op in |
bf := FileStream fileNamed: 'hello.bf'.
in := FileStream fileNamed: 'in.txt'.
in binary.
st := WriteStream with: '| ss | ss := ReadWriteStream with: #(0). ss reset'.
[(op := bf next) notNil] whileTrue: [
    st nextPutAll: (op caseOf: {
        [$>] -> ['. ss next. ss atEnd ifTrue: [ss nextPut: 0; back]'].
        [$<] -> ['. ss back'].
        [$+] -> ['. ss nextPut: ss peek + 1; back'].
        [$-] -> ['. ss nextPut: ss peek - 1; back'].
        [$.] -> ['. Transcript show: (ss peek asCharacter)'].
        [$,] -> ['. ss nextPut: ', in next printString,' value; back'].
        [$[] -> ['. [ss peek isZero] whileFalse: ['].
        [$]] -> [']']} otherwise: [''])].
bf close.  in close.
World findATranscript: nil.
Compiler evaluate: st contents

Index

Feed

Other

Link

Pathtraq

loading...