Results 1 to 2 of 2

Thread: This block of code doesnt make sense!!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    Indiana
    Posts
    73

    Question This block of code doesnt make sense!!

    Code:
    for( i=1,d=c; i && *c; c++ )
       i+=*c=='[', i-=*c==']';
    if(!i) {
       c[-1]=0;
       while(a[p])
       {
          interpret(d);
       }
       c[-1]=']';
       break;
    }
    This is C code for an interpreter for the Brainf*** language, and [ is the beginning of the looping structure. I am making a superset to the language, called TripleHack, but I NEED to understand this looping structure. I can't figure out what this does! The code is in the middle of the interpret function. I took out all the unnecessary stuff.

    Thank you


    It is said that the only language all programmers understand is profanity.
    Last edited by TadaTensai; Jun 3rd, 2001 at 03:08 PM.

  2. #2
    Zaei
    Guest
    In psudo code:
    Code:
    i = 1 at start of loop
    d = address of c
    while i <> 0 and data at address of c <> 0
      if data at address of c == '[' then add 1 to i, and subtract 1 from i if the data is ']'
    end while
    if i = 0 then
      the byte before the address of c = 0
      blah blah blah
      the byte before the address of c = ']'
      break
    end if
    Ill assume that c is a char*, with a line of code. What this code does is evaluate the code that is inside a series of brackets. It uses some pretty freaky stuff (ie, direct memory modification).

    Z.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width