#modcfunc local one_get
if o_length>o_index{
n=peek(o_string,o_index)
if ((n>=129)&(n<=159) )|( (n>=224)&(n<=252)){
o_index++
n2=peek(o_string,o_index)
o_index++
num=n*256+n2
return num
}else{
o_index++
return n
}
}
return -1
#modcfunc each_with_index var p_c,var p_i,local loc_len
loc_len=get_length@step_2byte_num(thismod)
p_i=o_index
p_c=indexed_get@step_2byte_num(thismod)
if get_index@step_2byte_num(thismod) >= loc_len:return -1
return 1
#global
sc= "++++++ [>++++++++++<-]>+++++."
/*
sc ="++++++++++"
sc+="++++++++++"
sc+="++++++++++"
sc+="++++++++++"
sc+="++++++++++"
sc+="++++++++++"
sc+="++++++++++"
sc+="++ ."
sc+=">++++++++++"
sc+="++++++++++"
sc+="++++++++++"
sc+="++++++++++"
sc+="++++++++++"
sc+="++++++++++"
sc+="++++++++++"
sc+="++++++++++"
sc+="++++++++++"
sc+="++++++++++"
sc+="+++++ .,"
//*/
;mes cur
;mB_init sc
mB_init_num sc
mB_run
repeat 200
logmes ""+(cnt)+":"+jumps@m_Brainf_ck.cnt
loop
#module m_stack o_array,o_index
#modinit int p
Empty=1
NotEmpty=-1
dim o_array, p
o_index = 0
return
#modfunc local push int p
o_array(o_index) = p
o_index++
return
#modcfunc local pop
o_index--
if o_index < 0 {
dialog "popしすぎです",1
return 0
}
return o_array(o_index)
#modcfunc local is_Empty
if o_index==0:return 1
return -1
#global
#module m_Brainf_ck; source,source_l
#define button_block(%1="") %tbtn1 %i0 button %1,*%p:%tbtn2 goto *%i %i0:%tbtn1 *%o
#define b_break %tbtn2 goto *%p
#define b_end %tbtn2 *%o:stop:*%o
;#deffunc mB_init str p
; sdim source,4000
; source=p
; source_l=strlen(source)
; return
#deffunc mB_init_num str p
newmod o_Bf,step_2byte_num,$400
set@step_2byte_num o_Bf,sc@
multi_set@step_2byte_num o_Bf
source_l=get_length@step_2byte_num(o_Bf)
;#deffunc analyze_jumps array jumps
newmod o_stack,m_stack,256
; meminit 256
dim jumps,$400
set_index@step_2byte_num o_Bf, 0
len=get_length@step_2byte_num(o_Bf)
repeat len
c=0:i=0
if each_with_index(o_Bf,c,i)==-1:break
if c==-1:break
if c=='['{
push@m_stack o_stack,i
}else{
if c==']'{
if is_Empty@m_stack(o_stack)==Empty@m_stack{
dialog "stack error ] が多すぎます",1
stop
}
from=pop@m_stack(o_stack)
to=i
jumps.from=to
jumps.to=from
}
}
loop
if is_Empty@m_stack(o_stack)==NotEmpty@m_stack{
dialog "stack error [ が多すぎます",1
stop
}
return
#deffunc mB_run
//mes "calc"
pos 0,0
pos_x=0
pos_y=0
dim tape,$400
pc=0
cur=0
while pc < source_l
cur_token=get@step_2byte_num(o_Bf,pc); peek(source,pc)
switch cur_token
case '+'
tape.cur += 1
swbreak
case '-'
tape.cur -= 1
swbreak
case '>'
cur += 1
swbreak
case '<'
cur -= 1
if cur<0{
dialog "開始地点より左には移動テできません",1
cur=0
}
swbreak
case '.'
n = peek(tape,cur*4)
sdim s,16
poke s,0,n
pos pos_x,0
mes s
; mes n
pos_x+=10
swbreak
case ','
pos 0,20
_4input=""
input _4input,150,20,1
while 1
if _4input!="":_break
wait 1
wend
; button_block "input"
n=peek(_4input,0)
tape.cur = n
clrobj
; stop
; goto *restart
; b_end
; stop
swbreak
case '['
if tape.cur==0: pc=jumps.pc
swbreak
case ']'
if tape.cur!=0: pc=jumps.pc
swbreak
swend
*restart
pc++
await 1
wend
return
#global
/*
i=0
while i<3
mes i
i++
wend
wend
Ruby本に載ってる簡単言語をHSPに翻訳しましたw
次はコレをCに翻訳したいですね
・+:カウンタを1増やす
・-:カウンタを1減らす
・>:カウンタを右に移動する
・<:カウンタを左に移動する
・.:カウンタの数値の文字を出力
・,:カウンタに文字入力
・[:ループ開始
・]:ループ終了
最終更新:2014年02月20日 21:41