basic: actually the parser was correct

This commit is contained in:
minjaesong
2020-12-12 23:48:31 +09:00
parent 2acdb4d0c1
commit 24cd1a030f

View File

@@ -2062,15 +2062,18 @@ bF._parseExpr = function(lnum, tokens, states, recDepth, ifMode) {
/*************************************************************************/
// ## case for:
// (* at this point, if OP is found in paren-level 0, skip function_call *)
// | function_call ;
try {
bF.parserPrintdbgline('E', "Trying Function Call...", lnum, recDepth);
return bF._parseFunctionCall(lnum, tokens, states, recDepth + 1);
}
// if ParserError is raised, continue to apply other rules
catch (e) {
bF.parserPrintdbgline('E', 'It was NOT!', lnum, recDepth);
if (!(e instanceof ParserError)) throw e;
if (topmostOp === undefined) {
try {
bF.parserPrintdbgline('E', "Trying Function Call...", lnum, recDepth);
return bF._parseFunctionCall(lnum, tokens, states, recDepth + 1);
}
// if ParserError is raised, continue to apply other rules
catch (e) {
bF.parserPrintdbgline('E', 'It was NOT!', lnum, recDepth);
if (!(e instanceof ParserError)) throw e;
}
}
/*************************************************************************/
@@ -2245,14 +2248,17 @@ bF._parseFunctionCall = function(lnum, tokens, states, recDepth) {
// unmatched brackets, duh!
if (parenDepth != 0) throw lang.syntaxfehler(lnum, lang.unmatchedBrackets);
let parenUsed = (parenStart == 1 && parenEnd == states.length - 1);
let parenUsed = (parenStart == 1);
// && parenEnd == tokens.length - 1);
// if starting paren is found, just use it
// this prevents "RND(~~)*K" to be parsed as [RND, (~~)*K]
/*************************************************************************/
// ## case for:
// ident , "(" , [expr , {argsep , expr} , [argsep]] , ")"
// | ident , expr , {argsep , expr} , [argsep] ;
bF.parserPrintdbgline(String.fromCharCode(0x192), 'Function Call', lnum, recDepth);
bF.parserPrintdbgline(String.fromCharCode(0x192), `Function Call (parenUsed: ${parenUsed})`, lnum, recDepth);
let treeHead = new BasicAST();
treeHead.astLnum = lnum;
@@ -2265,10 +2271,10 @@ bF._parseFunctionCall = function(lnum, tokens, states, recDepth) {
// 1 6 9 12
let argStartPos = [1 + (parenUsed)].concat(argSeps.map(k => k+1));
// [1,5) [6,8) [9,11) [12,end)
let argPos = argStartPos.map((s,i) => {return{start:s, end:(argSeps[i] || tokens.length - (parenUsed))}}); // use end of token position as separator position
let argPos = argStartPos.map((s,i) => {return{start:s, end:(argSeps[i] || (parenUsed) ? parenEnd : tokens.length )}}); // use end of token position as separator position
// check for trailing separator
let hasTrailingSep = (states[states.length - 1 - (parenUsed)] == "sep");
let hasTrailingSep = (states[((parenUsed) ? parenEnd : states.length) - 1] == "sep");
// exclude last separator from recursion if input tokens has trailing separator
if (hasTrailingSep) argPos.pop();
@@ -2322,6 +2328,7 @@ bF._parseLit = function(lnum, tokens, states, recDepth) {
return treeHead;
}
// @return is defined in BasicAST
let JStoBASICtype = function(object) {
if (typeof object === "boolean") return "bool";