Post by scalion on Oct 15, 2018 13:36:19 GMT 1
You don't know ? Take a look in Wiki what this Brainf**k langage.
I'ts a 8 statements langage where each is a single caracter in ><+-.,[]
<> to increase or decrease data pointer
+- to increase or decrease value of pointed data
., write on screen or get from user a data byte
., write on screen or get from user a data byte
[ If pointes data = zero go after corresponding ]
] If pointed data > zero go after corresponding [
] If pointed data > zero go after corresponding [
For exemple a simple 'hello word!' programme :
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Now try your programs !
Source of Brainf.... interpretor :
' Interplanetary BrainFucker statements :
' > Inc data pointer
' < Dec data pointer
' + Inc pointed data
' - Dec pointed data
' . Write ascii of pointed data on screen
' , Store byte data key from user in pointed data
' [ If pointes data = zero go after corresponding ]
' ] If pointed data > zero go after corresponding [
BrainFuckInterpretor "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."
Proc BrainFuckInterpretor(P As String)
Local Long Adr, DSize, DAdr, DP = 0, BP = 0, i, StartAdr, AdrEnd
Adr = mAlloc(Len(P))
For i = 0 To Len(P) - 1
Poke Adr + i, Peek(V:P + i)
Next i
AdrEnd = Adr + Len(P) - 1
OpenW 1
FontName = "Lucida Console" : FontSize = 12
Me.Caption = "BrainFuck Interpretor"
Void SetForegroundWindow(Me.hWnd)
Me.AutoRedraw = 1 : Me.PrintScroll = 1 : Me.BackColor = 0 : Me.ForeColor = RGB(0, 255, 0)
DSize = 32000
DAdr = mAlloc(DSize)
MemBFill DAdr, DSize, 0
StartAdr = Adr
Do
PeekEvent : Exit If Me Is Nothing
TitleW 1, "Brain Fuck [" & Time$ & "] : " & Trim(Adr - StartAdr) & "->" & Chr$(Peek(Adr))
Select Peek(Adr)
Case 62 // >
Inc DP
If DP >= DSize
DSize = DSize + 30000
DAdr = mReAlloc(DAdr, DSize)
MemBFill DAdr + DSize - 30001, 30000, 0
EndIf
Inc Adr
Case 60 // <
Dec DP
If DP < 0
DSize = DSize + 30000
DAdr = mReAlloc(DAdr, DSize)
MemBFill DAdr + DSize - 30001, 30000, 0
For i = DAdr + DSize - 1 DownTo DAdr + 30000
Poke i, Peek(i - 30000)
Next i
DP = 29999
EndIf
Inc Adr
Case 43 // +
Poke DAdr + DP, Succ(Peek(DAdr + DP))
Inc Adr
Case 45 // -
Poke DAdr + DP, Pred(Peek(DAdr + DP))
Inc Adr
Case 46 // .
Print Chr(Peek(DAdr + DP));
Inc Adr
Case 44 // ,
Print "Press any key"
KeyGet i
Poke DAdr + DP, And(i, 255)
Inc Adr
Case 91 // [
If Peek(DAdr + DP) = 0
i = 1
Do
Inc Adr
If Peek(Adr) = 91
Inc i
Else If Peek(Adr) = 93
Dec i
EndIf
PeekEvent
Loop Until i = 0
EndIf
Inc Adr
Case 93 // ]
If Peek(DAdr + DP) > 0
i = 1
Do
Dec Adr
If Peek(Adr) = 93
Inc i
Else If Peek(Adr) = 91
Dec i
EndIf
PeekEvent
Loop Until i = 0
EndIf
Inc Adr
Case Else
Inc Adr
EndSelect
Loop Until Adr > AdrEnd
Void mFree(DAdr)
Void mFree(Adr)
Message "THE END"
CloseW 1
EndProc