diff options
Diffstat (limited to 'src/parser/parser.js')
-rw-r--r-- | src/parser/parser.js | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/parser/parser.js b/src/parser/parser.js index 8672832..3434fee 100644 --- a/src/parser/parser.js +++ b/src/parser/parser.js @@ -33,19 +33,19 @@ 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 result = parser.parse(data.toUpperCase()); - if (typeof(result.start) === "string") { - result.start = parser.yy.line[result.start]; - } - 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(result.start); - console.log(result.program); - console.log(parser.yy); - }); -//} +exports.assemble = function(sourceCode) { + let result = parser.parse(sourceCode.toUpperCase()); + + // set start point + if (typeof(result.start) === "string") { + result.start = parser.yy.line[result.start]; + } + + // convert line labels to actual numbers + 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); + } + + return result; +} |