📄 v8-earley-boyer.js
字号:
result = tmp; } } return result; };}function sc_Values(values) { this.values = values;}/*** META ((export #t) (peephole (values)))*/function sc_values() { if (arguments.length === 1) return arguments[0]; else return new sc_Values(arguments);}/*** META ((export #t)) */function sc_callWithValues(producer, consumer) { var produced = producer(); if (produced instanceof sc_Values) return consumer.apply(null, produced.values); else return consumer(produced);}/*** META ((export #t)) */function sc_dynamicWind(before, thunk, after) { before(); try { var res = thunk(); return res; } finally { after(); }}// TODO: eval/scheme-report-environment/null-environment/interaction-environment// LIMITATION: 'load' doesn't exist without files.// LIMITATION: transcript-on/transcript-off doesn't exist without files.function sc_Struct(name) { this.name = name;}sc_Struct.prototype.sc_toDisplayString = function() { return "#<struct" + sc_hash(this) + ">";};sc_Struct.prototype.sc_toWriteString = sc_Struct.prototype.sc_toDisplayString;/*** META ((export #t) (peephole (hole 1 "new sc_Struct(" name ")")))*/function sc_makeStruct(name) { return new sc_Struct(name);}/*** META ((export #t) (type bool) (peephole (postfix " instanceof sc_Struct")))*/function sc_isStruct(o) { return (o instanceof sc_Struct);}/*** META ((export #t) (type bool) (peephole (hole 2 "(" 1 " instanceof sc_Struct) && ( " 1 ".name === " 0 ")")))*/function sc_isStructNamed(name, s) { return ((s instanceof sc_Struct) && (s.name === name));}/*** META ((export struct-field) (peephole (hole 3 0 "[" 2 "]")))*/function sc_getStructField(s, name, field) { return s[field];}/*** META ((export struct-field-set!) (peephole (hole 4 0 "[" 2 "] = " 3)))*/function sc_setStructFieldBang(s, name, field, val) { s[field] = val;}/*** META ((export #t) (peephole (prefix "~")))*/function sc_bitNot(x) { return ~x;}/*** META ((export #t) (peephole (infix 2 2 "&")))*/function sc_bitAnd(x, y) { return x & y;}/*** META ((export #t) (peephole (infix 2 2 "|")))*/function sc_bitOr(x, y) { return x | y;}/*** META ((export #t) (peephole (infix 2 2 "^")))*/function sc_bitXor(x, y) { return x ^ y;}/*** META ((export #t) (peephole (infix 2 2 "<<")))*/function sc_bitLsh(x, y) { return x << y;}/*** META ((export #t) (peephole (infix 2 2 ">>")))*/function sc_bitRsh(x, y) { return x >> y;}/*** META ((export #t) (peephole (infix 2 2 ">>>")))*/function sc_bitUrsh(x, y) { return x >>> y;}/*** META ((export js-field js-property) (peephole (hole 2 o "[" field "]")))*/function sc_jsField(o, field) { return o[field];}/*** META ((export js-field-set! js-property-set!) (peephole (hole 3 o "[" field "] = " val)))*/function sc_setJsFieldBang(o, field, val) { return o[field] = val;}/*** META ((export js-field-delete! js-property-delete!) (peephole (hole 2 "delete" o "[" field "]")))*/function sc_deleteJsFieldBang(o, field) { delete o[field];}/*** META ((export #t) (peephole (jsCall)))*/function sc_jsCall(o, fun) { var args = new Array(); for (var i = 2; i < arguments.length; i++) args[i-2] = arguments[i]; return fun.apply(o, args);}/*** META ((export #t) (peephole (jsMethodCall)))*/function sc_jsMethodCall(o, field) { var args = new Array(); for (var i = 2; i < arguments.length; i++) args[i-2] = arguments[i]; return o[field].apply(o, args);}/*** META ((export new js-new) (peephole (jsNew)))*/function sc_jsNew(c) { var evalStr = "new c("; evalStr +=arguments.length > 1? "arguments[1]": ""; for (var i = 2; i < arguments.length; i++) evalStr += ", arguments[" + i + "]"; evalStr +=")"; return eval(evalStr);} // ======================== RegExp ====================/*** META ((export #t)) */function sc_pregexp(re) { return new RegExp(sc_string2jsstring(re));}/*** META ((export #t)) */function sc_pregexpMatch(re, s) { var reg = (re instanceof RegExp) ? re : sc_pregexp(re); var tmp = reg.exec(sc_string2jsstring(s)); if (tmp == null) return false; var res = null; for (var i = tmp.length-1; i >= 0; i--) { if (tmp[i] !== null) { res = sc_cons(sc_jsstring2string(tmp[i]), res); } else { res = sc_cons(false, res); } } return res;} /*** META ((export #t)) */function sc_pregexpReplace(re, s1, s2) { var reg; var jss1 = sc_string2jsstring(s1); var jss2 = sc_string2jsstring(s2); if (re instanceof RegExp) { if (re.global) reg = re; else reg = new RegExp(re.source); } else { reg = new RegExp(sc_string2jsstring(re)); } return jss1.replace(reg, jss2);} /*** META ((export pregexp-replace*)) */function sc_pregexpReplaceAll(re, s1, s2) { var reg; var jss1 = sc_string2jsstring(s1); var jss2 = sc_string2jsstring(s2); if (re instanceof RegExp) { if (re.global) reg = re; else reg = new RegExp(re.source, "g"); } else { reg = new RegExp(sc_string2jsstring(re), "g"); } return jss1.replace(reg, jss2);}/*** META ((export #t)) */function sc_pregexpSplit(re, s) { var reg = ((re instanceof RegExp) ? re : new RegExp(sc_string2jsstring(re))); var jss = sc_string2jsstring(s); var tmp = jss.split(reg); if (tmp == null) return false; return sc_vector2list(tmp);} /* =========================================================================== *//* Other library stuff *//* =========================================================================== *//*** META ((export #t) (peephole (hole 1 "Math.floor(Math.random()*" 'n ")")))*/function sc_random(n) { return Math.floor(Math.random()*n);}/*** META ((export current-date) (peephole (hole 0 "new Date()")))*/function sc_currentDate() { return new Date();}function sc_Hashtable() {}sc_Hashtable.prototype.toString = function() { return "#{%hashtable}";};// sc_toWriteString == sc_toDisplayString == toStringfunction sc_HashtableElement(key, val) { this.key = key; this.val = val;}/*** META ((export #t) (peephole (hole 0 "new sc_Hashtable()")))*/function sc_makeHashtable() { return new sc_Hashtable();}/*** META ((export #t)) */function sc_hashtablePutBang(ht, key, val) { var hash = sc_hash(key); ht[hash] = new sc_HashtableElement(key, val);}/*** META ((export #t)) */function sc_hashtableGet(ht, key) { var hash = sc_hash(key); if (hash in ht) return ht[hash].val; else return false;}/*** META ((export #t)) */function sc_hashtableForEach(ht, f) { for (var v in ht) { if (ht[v] instanceof sc_HashtableElement) f(ht[v].key, ht[v].val); }}/*** META ((export hashtable-contains?) (peephole (hole 2 "sc_hash(" 1 ") in " 0)))*/function sc_hashtableContains(ht, key) { var hash = sc_hash(key); if (hash in ht) return true; else return false;}var SC_HASH_COUNTER = 0;function sc_hash(o) { if (o === null) return "null"; else if (o === undefined) return "undefined"; else if (o === true) return "true"; else if (o === false) return "false"; else if (typeof o === "number") return "num-" + o; else if (typeof o === "string") return "jsstr-" + o; else if (o.sc_getHash) return o.sc_getHash(); else return sc_counterHash.call(o);}function sc_counterHash() { if (!this.sc_hash) { this.sc_hash = "hash-" + SC_HASH_COUNTER; SC_HASH_COUNTER++; } return this.sc_hash;}function sc_Trampoline(args, maxTailCalls) { this['__trampoline return__'] = true; this.args = args; this.MAX_TAIL_CALLs = maxTailCalls;}// TODO: call/cc stuffsc_Trampoline.prototype.restart = function() { var o = this; while (true) { // set both globals. SC_TAIL_OBJECT.calls = o.MAX_TAIL_CALLs-1; var fun = o.args.callee; var res = fun.apply(SC_TAIL_OBJECT, o.args); if (res instanceof sc_Trampoline) o = res; else return res; }}/*** META ((export bind-exit-lambda)) */function sc_bindExitLambda(proc) { var escape_obj = new sc_BindExitException(); var escape = function(res) { escape_obj.res = res; throw escape_obj; }; try { return proc(escape); } catch(e) { if (e === escape_obj) { return e.res; } throw e; }}function sc_BindExitException() { this._internalException = true;}var SC_SCM2JS_GLOBALS = new Object();// default tail-call depth.// normally the program should set it again. but just in case...var SC_TAIL_OBJECT = new Object();SC_SCM2JS_GLOBALS.TAIL_OBJECT = SC_TAIL_OBJECT;// ======================== I/O =======================/*------------------------------------------------------------------*/function sc_EOF() {}var SC_EOF_OBJECT = new sc_EOF();function sc_Port() {}/* --------------- Input ports -------------------------------------*/function sc_InputPort() {}sc_InputPort.prototype = new sc_Port();sc_InputPort.prototype.peekChar = function() { if (!("peeked" in this)) this.peeked = this.getNextChar(); return this.peeked;}sc_InputPort.prototype.readChar = function() { var tmp = this.peekChar(); delete this.peeked; return tmp;}sc_InputPort.prototype.isCharReady = function() { return true;}sc_InputPort.prototype.close = function() { // do nothing}/* .............. String port ..........................*/function sc_ErrorInputPort() {};sc_ErrorInputPort.prototype = new sc_InputPort();sc_ErrorInputPort.prototype.getNextChar = function() { throw "can't read from error-port.";};sc_ErrorInputPort.prototype.isCharReady = function() { return false;}; /* .............. String port ..........................*/function sc_StringInputPort(jsStr) { // we are going to do some charAts on the str. // instead of recreating all the time a String-object, we // create one in the beginning. (not sure, if this is really an optim) this.str = new String(jsStr); this.pos = 0;}sc_StringInputPort.prototype = new sc_InputPort();sc_StringInputPort.prototype.getNextChar = function() { if (this.pos >= this.str.length) return SC_EOF_OBJECT; return this.str.charAt(this.pos++);};/* ------------- Read and other lib-funs -------------------------------*/function sc_Token(type, val, pos) { this.type = type; this.val = val; this.pos = pos;}sc_Token.EOF = 0/*EOF*/;sc_Token.OPEN_PAR = 1/*OPEN_PAR*/;sc_Token.CLOSE_PAR = 2/*CLOSE_PAR*/;sc_Token.OPEN_BRACE = 3/*OPEN_BRACE*/;sc_Token.CLOSE_BRACE = 4/*CLOSE_BRACE*/;sc_Token.OPEN_BRACKET = 5/*OPEN_BRACKET*/;sc_Token.CLOSE_BRACKET = 6/*CLOSE_BRACKET*/;sc_Token.WHITESPACE = 7/*WHITESPACE*/;sc_Token.QUOTE = 8/*QUOTE*/;sc_Token.ID = 9/*ID*/;sc_Token.DOT = 10/*DOT*/;sc_Token.STRING = 11/*STRING*/;sc_Token.NUMBER = 12/*NUMBER*/;sc_Token.ERROR = 13/*ERROR*/;sc_Token.VECTOR_BEGIN = 14/*VECTOR_BEGIN*/;sc_Token.TRUE = 15/*TRUE*/;sc_Token.FALSE = 16/*FALSE*/;sc_Token.UNSPECIFIED = 17/*UNSPECIFIED*/;sc_Token.REFERENCE = 18/*REFERENCE*/;sc_Token.STORE = 19/*STORE*/;sc_Token.CHAR = 20/*CHAR*/;var SC_ID_CLASS = SC_LOWER_CLASS + SC_UPPER_CLASS + "!$%*+-./:<=>?@^_~";function sc_Tokenizer(port) { this.port = port;}sc_Tokenizer.prototype.peekToken = function() { if (this.peeked) return this.peeked; var newToken = this.nextToken(); this.peeked = newToken; return newToken;};sc_Tokenizer.prototype.readToken = function() { var tmp = this.peekToken(); delete this.peeked; return tmp;};sc_Tokenizer.prototype.nextToken = function() { var port = this.port; function isNumberChar(c) { return (c >= "0" && c <= "9"); }; function isIdOrNumberChar(c) { return SC_ID_CLASS.indexOf(c) != -1 || // ID-char (c >= "0" && c <= "9"); } function isWhitespace(c) { return c === " " || c === "\r" || c === "\n" || c === "\t" || c === "\f"; }; function isWhitespaceOrEOF(c) { return isWhitespace(c) || c === SC_EOF_OBJECT; }; function readString() { res = ""; while (true) { var c = port.readChar(); switch (c) { case '"': return new sc_Token(11/*STRING*/, res); case "\\": var tmp = port.readChar(); switch (tmp) { case '0': res += "\0"; break; case 'a': res += "\a"; break; case 'b': res += "\b"; break; case 'f': res += "\f"; break; case 'n': res += "\n"; break; case 'r': res += "\r"; break; case 't': res += "\t"; break; case 'v': res += "\v"; break; case '"': res += '"'; break; case '\\': res += '\\'; break; case 'x':
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -