Javascript 将语言添加到脚本标记

Javascript 将语言添加到脚本标记,javascript,html,Javascript,Html,我正在尝试创建自己的编程语言。创建语言的代码如下所示: var printword=false; var waitforkey=false; function Process(text) { var words = text.split(/\s+/); var next = 0; this.nextWord = function () { if (next >= words.length) return null; return wo

我正在尝试创建自己的编程语言。创建语言的代码如下所示:

var printword=false;
var waitforkey=false;
function Process(text) {
    var words = text.split(/\s+/);
    var next = 0;
    this.nextWord = function () {
        if (next >= words.length) return null;
        return words[next++];
    };
}

function HackerScript() {
    var dictionary = {};

    this.stack = [];

    this.addWords = function (new_dict) {
        for (var word in new_dict)
        dictionary[word.toUpperCase()] = new_dict[word];
    };

    this.run = function (text) {
        var lexer = new Process(text);
        var word;
        var num_val;

        while (word = lexer.nextWord()) {
            while(waitforkey){
            waitforkey=false;
            }
            if(!printword){
            word = word.toUpperCase();
            }
            num_val = parseFloat(word);
            if (dictionary[word]) {
                dictionary[word](this);
            } 
            else {
                if(!printword){
                var createerror = document.createElement("p");
                createerror.appendChild(document.createTextNode("Could not process"));
                document.body.appendChild(createerror);
                }
                else{
                var print=document.createElement("p");
                print.appendChild(document.createTextNode(word));
                document.body.appendChild(print);
                printword=false;
                }
            }
        }
    };
}
var print = {
    "clearstack": function (terp) {
     var ensureclear=confirm("Are you sure you want to clear?");
        if(ensureclear){
     document.body.innerHTML="";
        }
    },
    "print":function(){
    printword=true;
    }
}
var wait={
    "waitkey":function(terp){
     waitforkey=true;
    }
}
var HackerScript = new HackerScript();
HackerScript.addWords(print);
HackerScript.addWords(wait);
然后可以通过键入来运行编程语言

HackerScript.run("code words here");
然而,我想让程序员更容易地执行编程语言。该语言的代码将通过创建一个带有src的script元素来执行,src指向包含该代码的文件。但是在那之后,用户仍然需要创建一个Javascript脚本标记并使用HackerScript变量的run函数。相反,我想将编程语言添加到HTML脚本标记中。例如:

<script type="text/Hackerscript">
key words here with no quotes
</script>

这里的关键词没有引号
探索window对象帮助我确定需要将此代码添加到window.HTMLScriptElement中,但我该如何做呢

以下是编程语言代码的链接:
您不能直接添加支持


但是,您可以编写手动查找所有
元素的代码(使用
document.querySelectorAll('script[type=“text/Hackerscript”]')
)并运行他们的
.textContent

我运行了您给我的代码,它给了我错误Uncaught TypeError:无法读取的属性“split”undefined@Mikey:使用调试器找出错误。错误指向定义代码的第4行,我在其中键入var words=text.split(/\s+/);由于某些原因,未正确处理运行document.querySelectorAll的文本内容。听起来您需要在数组中循环。它返回一个数组。这就是它不起作用的原因。我相信它返回了一个字符串,并试图传递它。让我看看它是否与循环一起工作。你不觉得这有点过分了吗?你自己的编程语言?