Not "Turing machine" in FB

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
Hezad
Posts: 469
Joined: Dec 17, 2006 23:37
Contact:

Not "Turing machine" in FB

Post by Hezad »

Hi ! it's me again..

This time, I played with turing machine :) I'm NOT saying I coded a real tuning machine ! This one is really, rea-ea-ly basic (for now, it accepts only integers instead of tables of characters and only a few of caracteristics are included but it's a start)

(If you don't know what is a turing machine --> http://en.wikipedia.org/wiki/Turing_machine )


The language for now :

"+" add 1 to the pointed cell
"-" substract 1 to the pointed cell
">" Point next cell
"<" Point previous cell
"a" cell pointed value = previous (-1) cell value + previous (-2) cell value


"?" print value of the pointed cell


How to use (in FB) :

Tur "your_code_in_turing_machine_language"

( watch 'main part to see an example : It is not a header file cause I'm waiting to have a fully working turing machine equivalent )

Code: Select all

'' turing machine
''
'' Programmed by Hezad (2007)
''
''
''
'' --->      (watch MAIN part to see how it works)
''
'
''  /!\       Language :
''
'' "+"   add 1 to the pointed cell
'' "-"   substract 1 to the pointed cell
'' ">"   Point next cell
'' "<"   Point previous cell
'' "a"   cell pointed value = previous (-1) cell value + previous (-2) cell value
'' "?"   print value of the pointed cell
'
'
'
' How to use it :
'
' code :
'
' Tur  "your_code_in_turing_machine_langage"
' 
'
'


Const MAX_MEM=1024

Dim shared as integer State(MAX_MEM) => {0}
Dim shared as integer pointeur=0,i

'' Declare subs
Declare Sub TUR(Comma as string)





'' MAIN


tur "++++++?"

print "+"

tur ">++++?"

print "="

tur ">a?"
    
sleep
    







'' SUB

Sub tur(Comma as string)
    Dim as integer i
    
    For i=0 to len(comma)
        select case mid(comma,i,1)
        case "+"
            State(pointeur)+=1
        case "-"
            State(pointeur)-=1
        case ">"
            pointeur+=1
        case "<"
            pointeur-=1
        case "?"
            print State(pointeur)
        case "a"
            state(pointeur)=state(pointeur-1)+state(pointeur-2)
        end select
    next
end sub

Hezad
Last edited by Hezad on Jun 23, 2007 10:42, edited 1 time in total.
ikkejw
Posts: 258
Joined: Jan 15, 2006 15:51
Location: Fryslân, the Netherlands
Contact:

Post by ikkejw »

err, this is Brainfvck, right?
Hezad
Posts: 469
Joined: Dec 17, 2006 23:37
Contact:

Post by Hezad »

Yep it's inspired by #%$@ but this is not exactly the same (even if it look like a lot for now)

The Typo will be the same or really near but the functioning won't be the same. Maybe i'll add functions (like "a" in my code)
Zamaster
Posts: 1025
Joined: Jun 20, 2005 21:40
Contact:

Post by Zamaster »

Wait a minute! Turing machines operate on a group of instructions, like I think they move once every instruction and switch states. I dont remember the details on them but I dont think this counts as one of them.
Hezad
Posts: 469
Joined: Dec 17, 2006 23:37
Contact:

Post by Hezad »

Well if it can't count as a turing machine, it will count NOT as a turing machine :p
HD_
Posts: 215
Joined: Jun 10, 2006 12:15
Contact:

Post by HD_ »

I'm going to go work on my NOT Halo 3 clone :D :P

Cool project idea ;)
Post Reply