10 CLEAR 500
20 DIM X(255),XX(256),JP(255)
30 READ A$
40 DATA "+,-.<>[]"
50 FOR I=1 TO 8
60 JP(ASC(MID$(A$,I,1)))=I
70 NEXT
80 READ A$
90 IF A$<>"END" THEN PG$=PG$+A$:GOTO 80
100 FOR PC=1 TO LEN(PG$)
110 IF XC<0 THEN VL=XX(-XC):GOTO 160
120 IF XX(1)=0 THEN VL=X(XC):GOTO 160
130 AD=XX(2)+XX(3)*256+XC
140 IF AD>65535 THEN AD=AD-65536
150 VL=PEEK(AD)
160 ON JP(ASC(MID$(PG$,PC,1))) GOSUB 200,300,400,500,600,700,800,900
170 NEXT
180 END
200 VL=VL+1
210 IF VL>255 THEN VL=0
220 IF XX(1) AND XC=-5 THEN XX(4)=PEEK(xx(2)+xx(3)*256)
230 GOSUB 1000
240 RETURN
300 IN$=INKEY$
310 IF IN$="" THEN 300
320 VL=ASC(IN$)
330 GOSUB 1000
340 RETURN
400 VL=VL-1
410 IF VL<0 THEN VL=255
420 GOSUB 1000
430 RETURN
500 PRINT CHR$(VL);
510 RETURN
600 XC=XC-1
610 RETURN
700 XC=XC+1
710 RETURN
800 IF VL>0 THEN RETURN
810 IF MID$(PG$,PC,1)="[" THEN BR=BR+1
820 IF MID$(PG$,PC,1)="]" THEN BR=BR-1
830 IF BR=0 THEN RETURN
840 PC=PC+1
850 GOTO 800
900 IF MID$(PG$,PC,1)="]" THEN BR=BR+1
910 IF MID$(PG$,PC,1)="[" THEN BR=BR-1
920 PC=PC-1
930 IF BR=0 THEN RETURN
940 GOTO 900
1000 IF XC<0 THEN XX(-XC)=VL:RETURN
1010 IF XX(1)=0 THEN X(XC)=VL
1020 IF XX(1) THEN POKE AD,VL
1030 RETURN
10000 DATA ++++++++++[>+++++++>++++++++++>+++>+<<<<-]
10010 DATA >++.>+.+++++++..+++.>++.<<+++++++++++++++.>.
10020 DATA +++.------.--------.>+.>.+++.
10030 DATA END
トップ > 雑多なもの > Tiny Brainfuck for PC-6001 > ソースコード