mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-10 23:04:04 +09:00
basic:abandoning the idea of (:) -- executor cannot index things statement-wise, only line-wise; major re-write should be possible but NOT TODAY
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
1 FOR I = 99 TO 1
|
1 FOR I = 99 TO 1
|
||||||
2 (MODE = 1):(GOSUB 12)
|
2 MODE = 1
|
||||||
|
3 GOSUB 12
|
||||||
4 PRINT(I+" bottle"+BOTTLES$+" of beer on the wall, "+i+" bottle"+BOTTLES$+" of beer.")
|
4 PRINT(I+" bottle"+BOTTLES$+" of beer on the wall, "+i+" bottle"+BOTTLES$+" of beer.")
|
||||||
5 (MODE = 2):(GOSUB 12)
|
5 MODE = 2
|
||||||
|
6 GOSUB 12
|
||||||
7 PRINT("Take one down and pass it around, "+(i-1)+" bottle"+BOTTLES$+" of beer on the wall.")
|
7 PRINT("Take one down and pass it around, "+(i-1)+" bottle"+BOTTLES$+" of beer on the wall.")
|
||||||
8 NEXT
|
8 NEXT
|
||||||
9 PRINT "No more bottles of beer on the wall, no more bottles of beer."
|
9 PRINT "No more bottles of beer on the wall, no more bottles of beer."
|
||||||
|
|||||||
@@ -421,9 +421,6 @@ 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) { // functional sequence
|
|
||||||
// TODO alternative method of impl: make syntax tree to have two or more consequent command "roots" and execute from there
|
|
||||||
},
|
|
||||||
"+" : 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; });
|
||||||
},
|
},
|
||||||
@@ -532,14 +529,14 @@ if no arg text were given (e.g. "10 NEXT"), args will have zero length
|
|||||||
return oneArgNum(lnum, args, function(lh) {
|
return oneArgNum(lnum, args, function(lh) {
|
||||||
if (lh < 0) throw lang.syntaxfehler(lnum, lh);
|
if (lh < 0) throw lang.syntaxfehler(lnum, lh);
|
||||||
bStatus.gosubStack.push(lnum + 1);
|
bStatus.gosubStack.push(lnum + 1);
|
||||||
println(lnum+" GOSUB into "+lh);
|
//println(lnum+" GOSUB into "+lh);
|
||||||
return lh;
|
return lh;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
"RETURN" : function(lnum, args) {
|
"RETURN" : function(lnum, args) {
|
||||||
var r = bStatus.gosubStack.pop();
|
var r = bStatus.gosubStack.pop();
|
||||||
if (r === undefined) throw lang.nowhereToReturn(lnum);
|
if (r === undefined) throw lang.nowhereToReturn(lnum);
|
||||||
println(lnum+" RETURN to "+r);
|
//println(lnum+" RETURN to "+r);
|
||||||
return r;
|
return r;
|
||||||
},
|
},
|
||||||
"CLEAR" : function(lnum, args) {
|
"CLEAR" : function(lnum, args) {
|
||||||
@@ -710,7 +707,7 @@ 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,":":1};
|
bF._1os = {"!":1,"~":1,"#":1,"<":1,"=":1,">":1,"*":1,"+":1,"-":1,"/":1,"^":1};
|
||||||
bF._2os = {"<":1,"=":1,">":1};
|
bF._2os = {"<":1,"=":1,">":1};
|
||||||
bF._uos = {"+":1,"-":1};
|
bF._uos = {"+":1,"-":1};
|
||||||
bF._isNum = function(code) {
|
bF._isNum = function(code) {
|
||||||
@@ -764,7 +761,6 @@ bF._opPrc = {
|
|||||||
"!":15,"~":15, // array CONS and PUSH
|
"!":15,"~":15, // array CONS and PUSH
|
||||||
"#": 16, // array concat
|
"#": 16, // array concat
|
||||||
"=":999,
|
"=":999,
|
||||||
":":9999, // instructions separator
|
|
||||||
};
|
};
|
||||||
bF._opRh = {"^":1,"=":1,"!":1};
|
bF._opRh = {"^":1,"=":1,"!":1};
|
||||||
bF._keywords = {
|
bF._keywords = {
|
||||||
@@ -1156,10 +1152,6 @@ bF._parserElaboration = function(lnum, tokens, states) {
|
|||||||
k += 1;
|
k += 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
|
||||||
* @returns BasicAST
|
|
||||||
*/
|
|
||||||
bF._parseTokens = function(lnum, tokens, states, recDepth) {
|
|
||||||
// DO NOT PERFORM SEMANTIC ANALYSIS HERE
|
// DO NOT PERFORM SEMANTIC ANALYSIS HERE
|
||||||
// at this point you can't (and shouldn't) distinguish whether or not defuns/variables are previously declared
|
// at this point you can't (and shouldn't) distinguish whether or not defuns/variables are previously declared
|
||||||
|
|
||||||
@@ -1224,6 +1216,10 @@ f Line 10 (function)
|
|||||||
|
|
||||||
for input "DEFUN sinc(x) = sin(x) / x"
|
for input "DEFUN sinc(x) = sin(x) / x"
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* @returns BasicAST
|
||||||
|
*/
|
||||||
|
bF._parseTokens = function(lnum, tokens, states, recDepth) {
|
||||||
|
|
||||||
function isSemanticLiteral(token, state) {
|
function isSemanticLiteral(token, state) {
|
||||||
return "]" == token || ")" == token ||
|
return "]" == token || ")" == token ||
|
||||||
@@ -1255,10 +1251,6 @@ for input "DEFUN sinc(x) = sin(x) / x"
|
|||||||
treeHead.astDepth = recDepth;
|
treeHead.astDepth = recDepth;
|
||||||
treeHead.astLnum = lnum;
|
treeHead.astLnum = lnum;
|
||||||
|
|
||||||
// TODO ability to parse arbitrary parentheses
|
|
||||||
// test string: print((minus(plus(3,2),times(8,7))))
|
|
||||||
// ^ ^ these extra parens break your parser
|
|
||||||
|
|
||||||
// LITERAL
|
// LITERAL
|
||||||
if (tokens.length == 1 && (isSemanticLiteral(tokens[0], states[0]))) {
|
if (tokens.length == 1 && (isSemanticLiteral(tokens[0], states[0]))) {
|
||||||
// special case where there were only one word
|
// special case where there were only one word
|
||||||
@@ -1272,7 +1264,7 @@ for input "DEFUN sinc(x) = sin(x) / x"
|
|||||||
}
|
}
|
||||||
// else, screw it
|
// else, screw it
|
||||||
else {
|
else {
|
||||||
throw lang.syntaxfehler(lnum);
|
throw lang.syntaxfehler(lnum, "TRAP_LITERALLY_LITERAL");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1305,7 +1297,7 @@ for input "DEFUN sinc(x) = sin(x) / x"
|
|||||||
}
|
}
|
||||||
|
|
||||||
// generate tree
|
// generate tree
|
||||||
if (indexThen === undefined) throw lang.syntaxfehler(lnum);
|
if (indexThen === undefined) throw lang.syntaxfehler(lnum, "IF without THEN");
|
||||||
|
|
||||||
treeHead.astValue = "if";
|
treeHead.astValue = "if";
|
||||||
treeHead.astType = "function";
|
treeHead.astType = "function";
|
||||||
@@ -1374,6 +1366,8 @@ for input "DEFUN sinc(x) = sin(x) / x"
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// == AUTOPAREN ==
|
||||||
|
// TODO do it properly by counting number of arguments and whatnot
|
||||||
if (parenDepth != 0) throw lang.syntaxfehler(lnum, lang.unmatchedBrackets);
|
if (parenDepth != 0) throw lang.syntaxfehler(lnum, lang.unmatchedBrackets);
|
||||||
if (_debugSyntaxAnalysis) serial.println("Paren position: "+parenStart+", "+parenEnd);
|
if (_debugSyntaxAnalysis) serial.println("Paren position: "+parenStart+", "+parenEnd);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user