From 26602c78ef04b8c4ec8d9b7237e7f623d7005dcb Mon Sep 17 00:00:00 2001 From: Malcolm Tyrrell Date: Thu, 17 Dec 2020 11:08:15 +0000 Subject: [PATCH 1/2] Lines beginning with E are allowed --- basicode.js | 10 +++++++++- test.html | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/basicode.js b/basicode.js index 4b2a226..a492c28 100644 --- a/basicode.js +++ b/basicode.js @@ -1376,6 +1376,7 @@ function Lexer(expr_string) { // start with a line break to get the parser to expect a line number var expr_list = [new SeparatorToken("\n")]; + var isAtLineStart = true for (pos=0; pos < expr_string.length; ++pos) { var char = expr_string[pos]; // deal with line breaks, CR, LF and CR LF all work @@ -1385,7 +1386,12 @@ function Lexer(expr_string) } char = "\n"; } - if (char in SYMBOLS) { + if (isAtLineStart && isNumberChar(char)) + { + var lineNumber = readInteger(); + expr_list.push(new LiteralToken(parseFloat(lineNumber + ".0"))); + } + else if (char in SYMBOLS) { var operator = char; // two-symbol operators all start with lt or gt if (char == "<" || char == ">") { @@ -1430,6 +1436,7 @@ function Lexer(expr_string) expr_list.push(new SeparatorToken(char)); console.log("Unexpected symbol `"+ char + "` during lexing"); } + isAtLineStart = (char === "\n") || (isAtLineStart && (char === " ")); } expr_list.push(new SeparatorToken("\n")); return expr_list; @@ -1818,6 +1825,7 @@ function Parser(expr_list, program) if (token.token_type != "literal") { throw new BasicError("Syntax error", "expected line number, got `"+token.payload+"`", current_line); } + //#### line_number = token.payload; // ignore lines < 1000 if (line_number >= 1000) break; diff --git a/test.html b/test.html index 2b204d2..869fff2 100644 --- a/test.html +++ b/test.html @@ -321,5 +321,14 @@ 1030 PRINT Z(9) + + From d39548149a355c632bd348baffc19b418920b219 Mon Sep 17 00:00:00 2001 From: Malcolm Tyrrell Date: Mon, 28 Dec 2020 15:40:41 +0000 Subject: [PATCH 2/2] Use parseInt instead of silly hack. --- basicode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basicode.js b/basicode.js index a492c28..a4766e2 100644 --- a/basicode.js +++ b/basicode.js @@ -1389,7 +1389,7 @@ function Lexer(expr_string) if (isAtLineStart && isNumberChar(char)) { var lineNumber = readInteger(); - expr_list.push(new LiteralToken(parseFloat(lineNumber + ".0"))); + expr_list.push(new LiteralToken(parseInt(lineNumber))); } else if (char in SYMBOLS) { var operator = char;