basic:array concat operator

This commit is contained in:
minjaesong
2020-11-24 14:25:51 +09:00
parent 003c8b9279
commit c98016875a

View File

@@ -306,7 +306,9 @@ let threeArgNum = function(lnum, args, action) {
let initBvars = function() { let initBvars = function() {
return { return {
"NIL": new BasicVar([], "array"), "NIL": new BasicVar([], "array"),
"PI": new BasicVar(Math.PI, "number") "PI": new BasicVar(Math.PI, "number"),
"TAU": new BasicVar(Math.PI * 2.0, "number"),
"EULER": new BasicVar(Math.E, "number")
}; };
} }
let bStatus = {}; let bStatus = {};
@@ -413,6 +415,15 @@ if no arg text were given (e.g. "10 NEXT"), args will have zero length
return lh.concat([rh]); return lh.concat([rh]);
}); });
}, },
"#" : function(lnum, args) { // array CONCAT
return twoArg(lnum, args, function(lh, rh) {
if (!Array.isArray(rh))
throw lang.illegalType(lnum, rh);
if (!Array.isArray(lh))
throw lang.illegalType(lnum, lh);
return lh.concat(rh);
});
},
"+" : function(lnum, args) { // addition, string concat "+" : function(lnum, args) { // addition, string concat
return twoArg(lnum, args, function(lh, rh) { return lh + rh; }); return twoArg(lnum, args, function(lh, rh) { return lh + rh; });
}, },
@@ -684,6 +695,9 @@ if no arg text were given (e.g. "10 NEXT"), args will have zero length
}; };
Object.freeze(bStatus.builtin); Object.freeze(bStatus.builtin);
let bF = {}; let bF = {};
bF._1os = {":":1,"~":1,"#":1,"<":1,"=":1,">":1,"*":1,"+":1,"-":1,"/":1,"^":1};
bF._2os = {"<":1,"=":1,">":1};
bF._uos = {"+":1,"-":1,"!":1};
bF._isNum = function(code) { bF._isNum = function(code) {
return (code >= 0x30 && code <= 0x39) || code == 0x5F; return (code >= 0x30 && code <= 0x39) || code == 0x5F;
}; };
@@ -694,13 +708,13 @@ bF._isNumSep = function(code) {
return code == 0x2E || code == 0x42 || code == 0x58 || code == 0x62 || code == 0x78; return code == 0x2E || code == 0x42 || code == 0x58 || code == 0x62 || code == 0x78;
}; };
bF._is1o = function(code) { bF._is1o = function(code) {
return code == 0x3A || code == 0x7E || (code >= 0x3C && code <= 0x3E) || code == 0x2A || code == 0x2B || code == 0x2D || code == 0x2F || code == 0x5E; return bF._1os[String.fromCharCode(code)]
}; };
bF._is2o = function(code) { bF._is2o = function(code) {
return (code >= 0x3C && code <= 0x3E); return bF._2os[String.fromCharCode(code)]
}; };
bF._isUnary = function(code) { bF._isUnary = function(code) {
return (code == 0x2B) || (code == 0x2D) || (code == 0x21); return bF._uos[String.fromCharCode(code)]
} }
bF._isParenOpen = function(code) { bF._isParenOpen = function(code) {
return (code == 0x28 || code == 0x5B); return (code == 0x28 || code == 0x5B);
@@ -732,6 +746,7 @@ bF._opPrc = {
"TO":13, "TO":13,
"STEP":14, "STEP":14,
":":15,"~":15, // array CONS and PUSH ":":15,"~":15, // array CONS and PUSH
"#": 16, // array concat
"=":999 "=":999
}; };
bF._opRh = {"^":1,"=":1,":":1}; bF._opRh = {"^":1,"=":1,":":1};