; brainfuck based interpreter ; This lang is brilliant since its so simple ; though I've taken it upon myself to do it more efficently NewList stack.l();we store by ascii ; pointers? we have no pointers only a linked list ; This way hopefully we can prevent such large memory usage Global program$ program$ = "+>:+..]>:++++++]<<." ; fun or try ,.[,.] program$ = program$ + "E" ; E is just added char for making sure it executes count.l = 1 OpenConsole() Procedure tloop(count) Debug("start thread") search = count track = stack() Repeat loops: scc$ = Mid(program$, search, 1) scc$ = Trim(scc$) Debug "scc = " + scc$ Select scc$ Case "<" : Debug("Decrease Pointer"):PreviousElement(stack()) Case ">" : Debug("Increse Pointer"):AddElement(stack());NextElement(stack()) Case "+" : Debug("Add one"):stack() = stack() + 1 Case "-" : Debug("Subtract one"):stack() = stack() - 1 Case "." : Debug("Print thread "):PrintN(Chr(stack())) Case "," : stack() = Asc(Input()) Case "]" : Debug("Thread LOOP END") : If stack <> track And stack() < 256 And stack() > 0 search = count Goto loops Else Break EndIf Default : Debug("Default Threaded Loop");Debug stack(); do jack shit other than count EndSelect search = search + 1 Until stack() = 0 Debug("end thread") EndProcedure PrintN("Pure BrainFreeze v0.1") ; main loop AddElement(stack()) Repeat cc$ = Mid(program$, count, 1) cc$ = Trim(cc$) Debug cc$ Select cc$ Case "<" : Debug("Decrease Pointer"):PreviousElement(stack()) Case ">" : Debug("Increse Pointer"):AddElement(stack());NextElement(stack()) Case "+" : Debug("Add one"):stack() = stack() + 1 Case "-" : Debug("Subtract one"):stack() = stack() - 1 Case "." : Debug("Print "):PrintN(Chr(stack())) Case "," : stack() = Asc(Input()) Case ":" : Debug("Threaded Loop Start") : CreateThread(@tloop,count) : Debug(FindString(program$,"]",count)) ; threaded loop Case "[" : Debug("Start Loop"): ; start normal loop search = count track = stack() Repeat tloops: scc$ = Mid(program$, search, 1) scc$ = Trim(scc$) Debug "scc = " + scc$ Select scc$ Case "<" : Debug("Decrease Pointer"):PreviousElement(stack()) Case ">" : Debug("Increse Pointer"):AddElement(stack());NextElement(stack()) Case "+" : Debug("Add one"):stack() = stack() + 1 Case "-" : Debug("Subtract one"):stack() = stack() - 1 Case "." : Debug("Print "):PrintN(Chr(stack())) Case "," : stack() = Asc(Input()) Case "]" : Debug("LOOP END") : If stack <> track And stack() < 256 And stack() > 0 search = count Goto tloops Else Break EndIf Default : Debug("Default Loop");Debug stack(); do jack shit other than count EndSelect search = search + 1 Until stack() = 0 ; end normal loop If search+1 < Len(program$) Debug(Len(program$)) Debug(count) Debug(search) count = search Else Debug(Len(program$)) Debug(count) Debug(search) Break EndIf Default :Debug("Default main"): Debug(count);Debug stack(); do jack shit other than count EndSelect ;If count = Len(program$) ;count = count - 1 ;Else count = count + 1 ;EndIf Until count = Len(program$) And count < 256 ;MessageRequester("Information",a$,#PB_MessageRequester_Ok) ; IDE Options = PureBasic v3.94 (Windows - x86) ; CursorPosition = 109 ; FirstLine = 75 ; Folding = - ; Executable = bf.exe