Task: Execute Brain____








VB: 



Function BFInpt(s, sp, d, dp, i, ip, o)
    While sp < Len(s)
        Select Case Mid(s, sp + 1, 1)
            Case "+"
                newd = Asc(d(dp)) + 1
                If newd > 255 Then newd = newd Mod 256    
                d(dp) = Chr(newd)
            Case "-"
                newd = Asc(d(dp)) - 1
                If newd < 0 Then newd = (newd Mod 256) + 256    
                d(dp) = Chr(newd)
            Case ">"
                dp = dp + 1
                If dp > UBound(d) Then
                    ReDim Preserve d(UBound(d) + 1)
                    d(dp) = Chr(0)
                End If
            Case "<"
                dp = dp - 1
            Case "."
                o = o & d(dp)
            Case ","
                If ip = Len(i) Then d(dp) = Chr(0) Else ip = ip + 1 : d(dp) = Mid(i, ip, 1)
            Case "["
                If Asc(d(dp)) = 0 Then
                    bracket = 1
                    While bracket And sp < Len(s)
                        sp = sp + 1
                        If Mid(s, sp + 1, 1) = "[" Then
                            bracket = bracket + 1
                        ElseIf Mid(s, sp + 1, 1) = "]" Then
                            bracket = bracket - 1
                        End If
                    WEnd
                Else
                    pos = sp - 1
                    sp = sp + 1
                    If BFInpt(s, sp, d, dp, i, ip, o) Then sp = pos
                End If
            Case "]"
                BFInpt = Asc(d(dp)) <> 0
                Exit Function
        End Select
        sp = sp + 1
    WEnd
End Function


Function BFuck(source, input)
    Dim data() : ReDim data(0)
    data(0)  = Chr(0)
    DataPtr  = 0
    SrcPtr   = 0
    InputPtr = 0
    output   = ""

    BFInpt source , SrcPtr   , _
           data   , DataPtr  , _
           input  , InputPtr , _
           output
    BFuck = output
End Function






code   = ">++++++++[<+++++++++>-]<.>>+>+>++>[-]+<[>[->+<<++++>]<<]>.+++++++..+++.>" & _
         ">+++++++.<<<[[-]<[-]>]<+++++++++++++++.>>.+++.------.--------.>>+.>++++."
inpstr = ""
WScript.StdOut.Write BFuck(code, inpstr)



Fortran:       MODULE BRAIN	
       INTEGER MSG,KBD
       CONTAINS		
        SUBROUTINE RUN(PROG,STORE)	
         CHARACTER*(*) PROG	
         CHARACTER*(1) STORE(:)	
         CHARACTER*1 C		
         INTEGER I,D		
          D = 1		
          I = 1		

          DO WHILE(I.LE.LEN(PROG))	
            C = PROG(I:I)			
            I = I + 1				
            SELECT CASE(C)			
             CASE(">"); D = D + 1				
             CASE("<"); D = D - 1				
             CASE("+"); STORE(D) = CHAR(ICHAR(STORE(D)) + 1)	
             CASE("-"); STORE(D) = CHAR(ICHAR(STORE(D)) - 1)	
             CASE("."); WRITE (MSG,1) STORE(D)			
             CASE(","); READ (KBD,1) STORE(D)			
             CASE("["); IF (ICHAR(STORE(D)).EQ.0) CALL SEEK(+1)	
             CASE("]"); IF (ICHAR(STORE(D)).NE.0) CALL SEEK(-1)	
             CASE DEFAULT				
		  						
            END SELECT				
          END DO			

    1     FORMAT (A1,$)	
         CONTAINS	
          SUBROUTINE SEEK(WAY)	
           INTEGER WAY		
           CHARACTER*1 AB,BA	
           INTEGER INDEEP	
            INDEEP = 0		
            I = I - 1		
            AB = PROG(I:I)	
            BA = "[ ]"(WAY + 2:WAY + 2)	
    1       IF (I.GT.LEN(PROG)) STOP "Out of code
            IF (PROG(I:I).EQ.AB) THEN		
              INDEEP = INDEEP + 1			
            ELSE IF (PROG(I:I).EQ.BA) THEN	
              INDEEP = INDEEP - 1			
            END IF				
            IF (INDEEP.GT.0) THEN	
              I = I + WAY			
              IF (I.GT.0) GO TO 1		
              STOP "Back to 0
            END IF			
            I = I + 1			
          END SUBROUTINE SEEK	
        END SUBROUTINE RUN	
      END MODULE BRAIN	

      PROGRAM POKE	
      USE BRAIN		
      CHARACTER*1 STORE(30000)	
      CHARACTER*(*) HELLOWORLD	
      PARAMETER (HELLOWORLD = "++++++++[>++++[>++>+++>+++>+<<<<-]"
     1 //" >+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------"
     2 //".--------.>>+.>++.")
      KBD = 5		
      MSG = 6		
      STORE = CHAR(0)	

      CALL RUN(HELLOWORLD,STORE)	

      END