使い初めたばっかりのHSP (Hot Soup Processor)でHQ9+のインタープリタを書いてみた、とりあえず。
;======================================== ;HQ9+ interpreter in HSP ;c4se project: http://c4se.sakura.ne.jp/ ;Nemu Inoue: utakata.c4se@gmail.com ;======================================== #pack "c4se.bmp" #module #defcfunc beer ;99 bottles of beer on the wall. beer_s = "" i = 0 for i,99,0,-1 /*beer_s += str(i) + " bottles of beer on the wall, " beer_s += str(i) + " bottles of beer, " beer_s += "You take on down, pass it around, " beer_s += str(i-1) + " bottles of beer on the wall. "*/ beer_s += str(i) next return beer_s #defcfunc interpret_hq str argument1 ;to interprit the code hq_code = argument1 hq_r = "" accumlator = 0 hq_length = strlen(hq_code) hq_s = "" repeat hq_length,0 hq_s = strmid(hq_code,cnt,1) if hq_s == "H" { hq_r += "Hello World!" }else :if hq_s == "Q" { hq_r += hq_code }else :if hq_s == "9" { hq_r += beer() }else :if hq_s == "+" { accumlator += 1 } loop return hq_r #global ;main() title "HQ9+ interpreter in HSP - c4se project" font "",,1 color 255,0,0 mes "HQ9+ interpreter in HSP - c4se project" pos 0,15 font "",,0 color 0,0,0 mes "HQ9+ Code" hq_code = "H" mesbox hq_code,300,200,1,0 pos 155,230 objsize 100 button gosub "evaluate HQ9+",*Interpret pos 315,15 mes "Result" hq_res = "Hello World!" mesbox hq_res,300,200,0,0 mesbox_id = stat pos 0,245 picload "c4se.bmp",1 stop *Interpret hq_res = interpret_hq(hq_code) objprm mesbox_id,hq_res return
改行の挙動がJavaScript版と異なるけどあしからず。
HQ9+ Interpliter on JavaScript
http://d.hatena.ne.jp/Kureduki_Maari/20081105/1225863749