basic: fix: would crap out when 'REM' is not a first statement of a line

This commit is contained in:
minjaesong
2020-12-16 15:13:03 +09:00
parent e61fe9e0af
commit 9ca9990a19
6 changed files with 185 additions and 225 deletions

View File

@@ -0,0 +1 @@

View File

@@ -8,7 +8,8 @@ line =
linenumber = digits ;
stmt =
"IF" , expr_sans_asgn , "THEN" , stmt , ["ELSE" , stmt]
"REM" , ? anything ?
| "IF" , expr_sans_asgn , "THEN" , stmt , ["ELSE" , stmt]
| "DEFUN" , [ident] , "(" , [ident , {" , " , ident}] , ")" , "=" , expr
| "ON" , expr_sans_asgn , ("GOTO" | "GOSUB") , expr_sans_asgn , {"," , expr_sans_asgn}
| "(" , stmt , ")"

View File

@@ -37,7 +37,6 @@ digraph g {
LITERAL -> PAREN [label="()[]"]
LITERAL -> limbo [label=_]
LITERAL -> SEP [label=","]
LITERAL -> NUMBER [label="0..9"]
LITERAL -> OPERATOR [label="^*/+->=<"]
LITERAL -> LITERAL [label=otherwise]

View File

@@ -78,7 +78,8 @@ bF._parseTokens = function(lnum, tokens, states) {
/** Parses following EBNF rule:
stmt =
"IF" , expr_sans_asgn , "THEN" , stmt , ["ELSE" , stmt]
"REM" , ? anything ?
| "IF" , expr_sans_asgn , "THEN" , stmt , ["ELSE" , stmt]
| "DEFUN" , [ident] , "(" , [ident , {" , " , ident}] , ")" , "=" , expr
| "ON" , expr_sans_asgn , ident , expr_sans_asgn , {"," , expr_sans_asgn}
| "(" , stmt , ")"
@@ -90,14 +91,6 @@ bF._parseStmt = function(lnum, tokens, states, recDepth) {
/*************************************************************************/
let headTkn = tokens[0].toUpperCase();
let headSta = states[0];
let treeHead = new BasicAST();
treeHead.astLnum = lnum;
/*************************************************************************/
// case for: single word (e.g. NEXT for FOR loop)
if (tokens.length == 1 && states.length == 1) {
bF.parserPrintdbgline('$', "Single Word Function Call", lnum, recDepth);
@@ -106,6 +99,19 @@ bF._parseStmt = function(lnum, tokens, states, recDepth) {
/*************************************************************************/
let headTkn = tokens[0].toUpperCase();
let headSta = states[0];
let treeHead = new BasicAST();
treeHead.astLnum = lnum;
/*************************************************************************/
// case for: "REM" , ? anything ?
if (headTkn == "REM" && headSta != "qot") return;
/*************************************************************************/
let parenDepth = 0;
let parenStart = -1;
let parenEnd = -1;