有谁知道将解释BASIC代码的PHP程序?我看到LOLCODE implementation似乎是一个很好的起点,但是如果有人已经开发出类似的东西,我会很感激。
答案 0 :(得分:2)
在PHP中找不到一个,但Javascript中有一个:http://stevehanov.ca/blog/index.php?id=92。如果你向下滚动那个页面,作者会花很多精力来解释这个东西是如何运作的,哪个IMO是一个好的起点。
答案 1 :(得分:2)
这实际上就是几个月前我写的:
http://pub.32kb.org/files/entry/pBasic/pBasic.zip
这是JAVA中一个文件BASIC实现的端口,名为jASIC,可在此处找到:
http://journal.stuffwithstuff.com/2010/07/18/jasic-a-complete-interpreter-in-one-java-file
用法是这样的:
$pbas = new pBasic();
$basicScript = file_get_contents('test.bas');
// execute
$pbas->interpret($basicScript);
这是我用于游戏概念的BASIC脚本示例:
' list all the files on the current server, by memmaker
println "" ' used to produce a blank line in the output, the "" is needed for the parser
if "bin" = arg1 then getbinaries ' determine which directory to show
print "Listing of / on " + _ENV_CONNECTED_SERVER
allfiles = list_files() ' get list of files from the system
goto init
getbinaries:
print "Listing of /bin on " + _ENV_CONNECTED_SERVER
allfiles = list_files(1) ' get list of bin files from the system
init:
filecount = count(allfiles) ' get the length of the array
counter = 0 ' init the counter for the loop
println " - " + filecount + " files found" ' print the file count, note the "" prefix is needed because pBasic infers the type from the left argument of a binary operator
println ""
beginloop:
println get_element(allfiles, counter) ' output the current filename
counter = counter + 1 ' increment the loop counter
if counter < filecount then beginloop ' break the loop when all files are output
正如您所看到的,我扩展了原始的jASIC解释器并添加了函数调用和其他一些小的更改。