UBFIM interpreter

From Esolang
Jump to: navigation, search

This is an interpreter for Ultimate BF instruction minimalization!, written in Basic by User:Wh1teWolf:

UBFIM.BAS =

     DIM tape(1200)
     ptr=0
     b=0
     f=0
     lol=0
     REPEAT
       INPUT "" a$
       b=0
       ptr=3
       REPEAT
         b=b+1
         
         
         
         IF b>=999 THEN
           IF tape(ptr)=1 then b=0
         ENDIF
         
         
         
         
         IF MID$(a$,b,1)="<" THEN
           IF ptr>0 THEN ptr=ptr-1
         ENDIF
         
         
         
         
         
         IF MID$(a$,b,1)="(" THEN
           ptr=ptr+1
           IF tape(ptr)=1 THEN tape(ptr)=0 ELSE tape(ptr)=1
           
           IF tape(ptr)=0 THEN
             b=b+1
           ENDIF
         ENDIF
         
         
         
         
         
         
         IF tape(2)=1 THEN
           tape(2)=0
           lol=0
           IF tape(4)=1 THEN
             lol=1
           ENDIF
           IF tape(5)=1 THEN
             lol=lol+2
           ENDIF
           IF tape(6)=1 THEN
             lol=lol+4
           ENDIF
           IF tape(7)=1 THEN
             lol=lol+8
           ENDIF
           IF tape(8)=1 THEN
             lol=lol+16
           ENDIF
           IF tape(9)=1 THEN
             lol=lol+32
           ENDIF
           IF tape(10)=1 THEN
             lol=lol+64
           ENDIF
           IF tape(11)=1 THEN
             lol=lol+128
           ENDIF
           IF lol>0 THEN
             PRINT CHR$(lol)
           ELSE
             
             
             FOR f=4 TO 11
               tape(f)=0
             NEXT
             
             
             f=0
             
             
             REPEAT
               f=INKEY(1)
             UNTIL f<>-1
             
             
             PRINT CHR$(f)
             
             IF f>=128 THEN
               tape(11)=1
               f=f-128
             ENDIF
             IF f>=64   THEN
               tape(10)=1
               f=f-64
             ENDIF
             IF f>=32 THEN
               tape(9)=1
               f=f-32
             ENDIF
             IF f>=16 THEN
               tape(8)=1
               f=f-16
             ENDIF
             IF f>=8 THEN
               tape(7)=1
               f=f-8
             ENDIF
             IF f>=4 THEN
               tape(6)=1
               f=f-4
             ENDIF
             IF f>=2 THEN
               tape(5)=1
               f=f-2
             ENDIF
             IF f>=1 THEN
               tape(4)=1
               f=f-1
             ENDIF
           ENDIF
           
         ENDIF
         
         
         
         IF MID$(a$,b,1)="!" THEN
           IF tape(ptr)=1 THEN b=0 ELSE b=1000
         ENDIF
         
         
       UNTIL b>=1000
       a$=""
       b=0
     UNTIL FALSE


See Also