JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://javascript.crockford.com/tdop/tokens.js"></script>
<script>
// parse.js
// Parser for Simplified JavaScript written in Simplified JavaScript
// From Top Down Operator Precedence
// http://javascript.crockford.com/tdop/index.html
// Douglas Crockford
// 2010-06-26
var make_parse = function () {
var scope;
var symbol_table = {};
var token;
var tokens;
var token_nr;
var itself = function () {
return this;
};
var original_scope = {
define: function (n) {
var t = this.def[n.value];
if (typeof t === "object") {
n.error(t.reserved ? "Already reserved." : "Already defined.");
}
this.def[n.value] = n;
n.reserved = false;
n.nud = itself;
n.led = null;
n.std = null;
n.lbp = 0;
n.scope = scope;
return n;
},
find: function (n) {
var e = this, o;
while (true) {
o = e.def[n];
if (o && typeof o !== 'function') {
return e.def[n];
}
e = e.parent;
if (!e) {
o = symbol_table[n];
return o && typeof o !== 'function' ? o : symbol_table["(name)"];
}
}
},
pop: function () {
scope = this.parent;
},
reserve: function (n) {
if (n.arity !== "name" || n.reserved) {
return;
}
var t = this.def[n.value];
if (t) {
if (t.reserved) {
return;
}
if (t.arity === "name") {
n.error("Already defined.");
}
}
this.def[n.value] = n;
n.reserved = true;
}
};
var new_scope = function () {
var s =...
JavaScript
var parser = make_parse();
console.dir (
parser ("var t=1;t=2;")
);