From 9fa301a7cf8e8b5883521d1a966ee7b65ecf925e Mon Sep 17 00:00:00 2001 From: sanine-a Date: Mon, 22 May 2023 15:09:10 -0500 Subject: fix comment parsing --- src/parser/armadillo.red | 9 +++++++++ src/parser/grammar.jison | 2 +- src/parser/grammar.js | 2 +- src/parser/parser.js | 15 ++++++++------- 4 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 src/parser/armadillo.red diff --git a/src/parser/armadillo.red b/src/parser/armadillo.red new file mode 100644 index 0000000..f8f1d5b --- /dev/null +++ b/src/parser/armadillo.red @@ -0,0 +1,9 @@ +; armadillo +; author: stefan strack + +bomb spl 0 +loop add #3039, ptr +ptr mov bomb, 81 + jmp loop + mov 1, <-1 +end bomb diff --git a/src/parser/grammar.jison b/src/parser/grammar.jison index 83255e0..edcca5c 100644 --- a/src/parser/grammar.jison +++ b/src/parser/grammar.jison @@ -5,7 +5,7 @@ %% <> { return "EOF"; } -"\n" { this.popState(); return "NEWLINE"; } +[\n] { this.popState(); return "NEWLINE"; } . { /* ignore anything else inside a comment */ } ";" { this.pushState('comment'); } diff --git a/src/parser/grammar.js b/src/parser/grammar.js index f51d7f6..6d055c7 100644 --- a/src/parser/grammar.js +++ b/src/parser/grammar.js @@ -737,7 +737,7 @@ case 31: return "LABEL"; break; } }, -rules: [/^(?:$)/,/^(?:\\n)/,/^(?:.)/,/^(?:;)/,/^(?:[\n])/,/^(?:\s)/,/^(?:MOV\b)/,/^(?:ADD\b)/,/^(?:SUB\b)/,/^(?:CMP\b)/,/^(?:SLT\b)/,/^(?:JMP\b)/,/^(?:JMZ\b)/,/^(?:JMN\b)/,/^(?:DJN\b)/,/^(?:SPL\b)/,/^(?:DAT\b)/,/^(?:EQU\b)/,/^(?:END\b)/,/^(?:,)/,/^(?:#)/,/^(?:@)/,/^(?:<)/,/^(?:\$)/,/^(?:\()/,/^(?:\))/,/^(?:\+)/,/^(?:-)/,/^(?:\*)/,/^(?:\/)/,/^(?:[0-9]+)/,/^(?:[A-Z][A-Z0-9_]+)/], +rules: [/^(?:$)/,/^(?:[\n])/,/^(?:.)/,/^(?:;)/,/^(?:[\n])/,/^(?:\s)/,/^(?:MOV\b)/,/^(?:ADD\b)/,/^(?:SUB\b)/,/^(?:CMP\b)/,/^(?:SLT\b)/,/^(?:JMP\b)/,/^(?:JMZ\b)/,/^(?:JMN\b)/,/^(?:DJN\b)/,/^(?:SPL\b)/,/^(?:DAT\b)/,/^(?:EQU\b)/,/^(?:END\b)/,/^(?:,)/,/^(?:#)/,/^(?:@)/,/^(?:<)/,/^(?:\$)/,/^(?:\()/,/^(?:\))/,/^(?:\+)/,/^(?:-)/,/^(?:\*)/,/^(?:\/)/,/^(?:[0-9]+)/,/^(?:[A-Z][A-Z0-9_]+)/], conditions: {"comment":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31],"inclusive":true},"INITIAL":{"rules":[0,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31],"inclusive":true}} }); return lexer; diff --git a/src/parser/parser.js b/src/parser/parser.js index 7d3dd95..8672832 100644 --- a/src/parser/parser.js +++ b/src/parser/parser.js @@ -36,15 +36,16 @@ parser.yy = { //if (process.argv[1] === 'parser.js' && process.argv.length >= 3) { fs.readFile(process.argv[2], 'utf8', (err, data) => { if (err) throw err; - let program = parser.parse(data.toUpperCase()); - if (typeof(program.start) === "string") { - program.start = parser.yy.line[program.start]; + let result = parser.parse(data.toUpperCase()); + if (typeof(result.start) === "string") { + result.start = parser.yy.line[result.start]; } - for (let pc=0; pc