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