mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-11 15:24:05 +09:00
basic: 'dotest' now works
This commit is contained in:
@@ -1882,12 +1882,16 @@ bF._parseStmt = function(lnum, tokens, states, recDepth) {
|
|||||||
treeHead.astLeaves[0].astType = "lit";
|
treeHead.astLeaves[0].astType = "lit";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
bF.parserPrintdbgline('$', 'DEFUN Stmt Function Name:', lnum, recDepth);
|
||||||
treeHead.astLeaves[0] = bF._parseIdent(lnum, [tokens[1]], [states[1]], recDepth + 1);
|
treeHead.astLeaves[0] = bF._parseIdent(lnum, [tokens[1]], [states[1]], recDepth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse function arguments
|
// parse function arguments
|
||||||
treeHead.astLeaves[0].astLeaves = sepsOne.map(i=>i-1).concat([parenEnd - 1])
|
bF.parserPrintdbgline('$', 'DEFUN Stmt Function Arguments -- ', lnum, recDepth);
|
||||||
.map(i=>bF._parseIdent(lnum, [tokens[i]], [states[i]], recDepth + 2));
|
let defunArgDeclSeps = sepsOne.filter((i) => i < parenEnd + 1).map(i => i-1).concat([parenEnd - 1]);
|
||||||
|
bF.parserPrintdbgline('$', 'DEFUN Stmt Function Arguments comma position: '+defunArgDeclSeps, lnum, recDepth);
|
||||||
|
|
||||||
|
treeHead.astLeaves[0].astLeaves = defunArgDeclSeps.map(i=>bF._parseIdent(lnum, [tokens[i]], [states[i]], recDepth + 1));
|
||||||
|
|
||||||
// parse function body
|
// parse function body
|
||||||
treeHead.astLeaves[1] = bF._parseExpr(lnum,
|
treeHead.astLeaves[1] = bF._parseExpr(lnum,
|
||||||
|
|||||||
@@ -176,12 +176,16 @@ bF._parseStmt = function(lnum, tokens, states, recDepth) {
|
|||||||
treeHead.astLeaves[0].astType = "lit";
|
treeHead.astLeaves[0].astType = "lit";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
bF.parserPrintdbgline('$', 'DEFUN Stmt Function Name:', lnum, recDepth);
|
||||||
treeHead.astLeaves[0] = bF._parseIdent(lnum, [tokens[1]], [states[1]], recDepth + 1);
|
treeHead.astLeaves[0] = bF._parseIdent(lnum, [tokens[1]], [states[1]], recDepth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse function arguments
|
// parse function arguments
|
||||||
treeHead.astLeaves[0].astLeaves = sepsOne.map(i=>i-1).concat([parenEnd - 1])
|
bF.parserPrintdbgline('$', 'DEFUN Stmt Function Arguments -- ', lnum, recDepth);
|
||||||
.map(i=>bF._parseIdent(lnum, [tokens[i]], [states[i]], recDepth + 2));
|
let defunArgDeclSeps = sepsOne.filter((i) => i < parenEnd + 1).map(i => i-1).concat([parenEnd - 1]);
|
||||||
|
bF.parserPrintdbgline('$', 'DEFUN Stmt Function Arguments comma position: '+defunArgDeclSeps, lnum, recDepth);
|
||||||
|
|
||||||
|
treeHead.astLeaves[0].astLeaves = defunArgDeclSeps.map(i=>bF._parseIdent(lnum, [tokens[i]], [states[i]], recDepth + 1));
|
||||||
|
|
||||||
// parse function body
|
// parse function body
|
||||||
treeHead.astLeaves[1] = bF._parseExpr(lnum,
|
treeHead.astLeaves[1] = bF._parseExpr(lnum,
|
||||||
@@ -808,10 +812,14 @@ let states14 = ["lit","lit","paren","lit","paren","op","lit","lit","op","num","l
|
|||||||
let tokens15 = ["PRINT","MAP","(","FIB",",","1","TO","10",")"];
|
let tokens15 = ["PRINT","MAP","(","FIB",",","1","TO","10",")"];
|
||||||
let states15 = ["lit","lit","paren","lit","sep","num","op","num","paren"];
|
let states15 = ["lit","lit","paren","lit","sep","num","op","num","paren"];
|
||||||
|
|
||||||
|
// DEFUN KA(X)=IF X>2 THEN DO(PRINT(HAI);PRINT(X)) ELSE DO(PRINT(BYE);PRINT(X))
|
||||||
|
let tokens16 = ["DEFUN","KA","(","X",")","=","IF","X",">","2","THEN","DO","(","PRINT","(","HAI",")",";","PRINT","(","X",")",")","ELSE","DO","(","PRINT","(","BYE",")",";","PRINT","(","X",")",")"];
|
||||||
|
let states16 = ["lit","lit","paren","lit","paren","op","lit","lit","op","num","lit","lit","paren","lit","paren","qot","paren","sep","lit","paren","lit","paren","paren","lit","lit","paren","lit","paren","qot","paren","sep","lit","paren","lit","paren","paren"];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let trees = bF._parseTokens(lnum,
|
let trees = bF._parseTokens(lnum,
|
||||||
tokens15,
|
tokens16,
|
||||||
states15
|
states16
|
||||||
);
|
);
|
||||||
trees.forEach((t,i) => {
|
trees.forEach((t,i) => {
|
||||||
serial.println("\nParsed Statement #"+(i+1));
|
serial.println("\nParsed Statement #"+(i+1));
|
||||||
|
|||||||
Reference in New Issue
Block a user