diff options
author | sanine-a <sanine.not@pm.me> | 2023-05-22 15:09:10 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2023-05-22 15:09:10 -0500 |
commit | 9fa301a7cf8e8b5883521d1a966ee7b65ecf925e (patch) | |
tree | 38a87e7bc3b17dabd149c64f5d266f0589b717c5 | |
parent | 9e8703d07e2e49d14e3d2092d77f8f7e75ee7e04 (diff) |
fix comment parsing
-rw-r--r-- | src/parser/armadillo.red | 9 | ||||
-rw-r--r-- | src/parser/grammar.jison | 2 | ||||
-rw-r--r-- | src/parser/grammar.js | 2 | ||||
-rw-r--r-- | src/parser/parser.js | 15 |
4 files changed, 19 insertions, 9 deletions
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 @@ %% <<EOF>> { return "EOF"; } -<comment>"\n" { this.popState(); return "NEWLINE"; } +<comment>[\n] { this.popState(); return "NEWLINE"; } <comment>. { /* 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<program.program.length; pc += 1) { - parser.yy.tidyAddress(pc, program.program[pc].a); - parser.yy.tidyAddress(pc, program.program[pc].b); + for (let pc=0; pc<result.program.length; pc += 1) { + parser.yy.tidyAddress(pc, result.program[pc].a); + parser.yy.tidyAddress(pc, result.program[pc].b); } - console.log(program); + console.log(result.start); + console.log(result.program); console.log(parser.yy); }); //} |