Author Topic: BrainF*ck Complier Loops????  (Read 4199 times)

0 Members and 1 Guest are viewing this topic.

Offline Zeppelin

  • Newbie
  • Posts: 43
    • View Profile
    • Zeppelin Games ItchIo
BrainF*ck Complier Loops????
« on: September 15, 2018, 09:23:36 pm »
Hey,
I decided to type a mock up simple Brainf*ck compiler in QB and cant figure out a way to implement loops.
Any ideas or help is appreciated

Code: QB64: [Select]
  1. DIM dat(1000)
  2. INPUT "", bfin$
  3.  
  4. FOR n = 1 TO LEN(bfin$)
  5.     find$ = MID$(bfin$, n, 1)
  6.     IF find$ = "+" THEN
  7.         dat(index) = dat(index) + 1
  8.     ELSEIF find$ = "-" THEN
  9.         dat(index) = dat(index) - 1
  10.     ELSEIF find$ = ">" THEN
  11.         index = index + 1
  12.     ELSEIF find$ = "<" THEN
  13.         index = index - 1
  14.     ELSEIF find$ = "[" THEN
  15.  
  16.     ELSEIF find$ = "]" THEN
  17.  
  18.     ELSEIF find$ = "." THEN
  19.         IF dat(index) > 0 THEN
  20.             PRINT CHR$(dat(index));
  21.         ELSE
  22.             PRINT "Error 001: ASCII Index out of range"
  23.         END IF
  24.     ELSE
  25.         PRINT "Error 002: Unidentified command at "; n
  26.     END IF
  27.  
  28. PRINT "END"


Thanks
Zeppelin
+[--->++<]>+.+++[->++++<]>.[--->+<]>+.-[---->+<]>++.+[->+++<]>+.+++++++++++.----------.[--->+<]>----.+[---->+<]>+++.---[->++++<]>.------------.+.++++++++++.+[---->+<]>+++.+[->+++<]>++.[--->+<]>+.[->+++<]>+.++++++++++.+.>++++++++++.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: BrainF*ck Complier Loops????
« Reply #1 on: September 16, 2018, 08:21:03 am »
Hi Zeppelin

Recently discussed here: https://www.qb64.org/forum/index.php?topic=566.0
(A working translator can be found there. Your dat array will likely need to be _UNSIGNED _BYTE to read your signature at least)

I had had problem with reading your signature with my translator of QB45 code from Rosetta Code but Fellippe located the problem.

How did you code your signature message?

My real name is Mark also. :)
« Last Edit: September 16, 2018, 08:31:47 am by bplus »