10 GO SUB 1000 20 LET e=LEN p$ 30 LET a$=p$(ip) 40 IF a$=">" THEN LET dp=dp+1 50 IF a$="<" THEN LET dp=dp-1 60 IF a$="+" THEN LET d(dp)=d(dp)+1 70 IF a$="-" THEN LET d(dp)=d(dp)-1 80 IF a$="." THEN PRINT CHR$ d(dp); 90 IF a$="," THEN INPUT d(dp) 100 IF a$="[" THEN GO SUB 500 110 IF a$="]" THEN LET bp=bp-1: IF d(dp)<>0 THEN LET ip=b(bp)-1 120 LET ip=ip+1 130 IF ip>e THEN PRINT "eof": STOP 140 GO TO 30 499 REM match close 500 LET bc=1: REM bracket counter 510 FOR x=ip+1 TO e 520 IF p$(x)="[" THEN LET bc=bc+1 530 IF p$(x)="]" THEN LET bc=bc-1 540 IF bc=0 THEN LET b(bp)=ip: LET be=x: LET x=e: REM bc will be 0 once all the subnests have been counted over 550 IF bc=0 AND d(dp)=0 THEN LET ip=be: LET bp=bp-1 560 NEXT x 570 LET bp=bp+1 580 RETURN 999 REM initialisation 1000 DIM d(100): REM data stack 1010 LET dp=1: REM data pointer 1020 LET ip=1: REM instruction pointer 1030 DIM b(30): REM bracket stack 1040 LET bp=1: REM bracket pointer 1050 LET p$="++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>+++++.": REM program, marginally modified from Wikipedia; outputs CHR$ 13 at the end instead of CHR$ 10 as ZX Spectrum Basic handles the carriage return better than the line feed 1060 RETURN