Task: Execute Brain____

C: #include <stdio.h>
int main(){
     int ptr=0, i=0, cell[7];
     for( i=0; i<7; ++i) cell[i]=0;
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 8;
     while(cell[ptr])
     {
          ptr-= 1;
          if(ptr<0) perror("Program pointer underflow");
          cell[ptr]+= 9;
          ptr+= 1;
          if(ptr>=7) perror("Program pointer overflow");
          cell[ptr]-= 1;
     }
     ptr-= 1;
     if(ptr<0) perror("Program pointer underflow");
     putchar(cell[ptr]);
     ptr+= 2;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 1;
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 1;
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 2;
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     while(cell[ptr])
     {
          cell[ptr]-= 1;
     }
     cell[ptr]+= 1;
     ptr-= 1;
     if(ptr<0) perror("Program pointer underflow");
     while(cell[ptr])
     {
          ptr+= 1;
          if(ptr>=7) perror("Program pointer overflow");
          while(cell[ptr])
          {
               cell[ptr]-= 1;
               ptr+= 1;
               if(ptr>=7) perror("Program pointer overflow");
               cell[ptr]+= 1;
               ptr-= 2;
               if(ptr<0) perror("Program pointer underflow");
               cell[ptr]+= 4;
               ptr+= 1;
               if(ptr>=7) perror("Program pointer overflow");
          }
          ptr-= 2;
          if(ptr<0) perror("Program pointer underflow");
     }
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     putchar(cell[ptr]);
     cell[ptr]+= 7;
     putchar(cell[ptr]);
     putchar(cell[ptr]);
     cell[ptr]+= 3;
     putchar(cell[ptr]);
     ptr+= 2;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 7;
     putchar(cell[ptr]);
     ptr-= 3;
     if(ptr<0) perror("Program pointer underflow");
     while(cell[ptr])
     {
          while(cell[ptr])
          {
               cell[ptr]-= 1;
          }
          ptr-= 1;
          if(ptr<0) perror("Program pointer underflow");
          while(cell[ptr])
          {
               cell[ptr]-= 1;
          }
          ptr+= 1;
          if(ptr>=7) perror("Program pointer overflow");
     }
     ptr-= 1;
     if(ptr<0) perror("Program pointer underflow");
     cell[ptr]+= 15;
     putchar(cell[ptr]);
     ptr+= 2;
     if(ptr>=7) perror("Program pointer overflow");
     putchar(cell[ptr]);
     cell[ptr]+= 3;
     putchar(cell[ptr]);
     cell[ptr]-= 6;
     putchar(cell[ptr]);
     cell[ptr]-= 8;
     putchar(cell[ptr]);
     ptr+= 2;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 1;
     putchar(cell[ptr]);
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 4;
     putchar(cell[ptr]);
     return 0;
}










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