const process = require('node:process'); const fs = require('node:fs'); const parser = require('./grammar.js').parser; parser.yy = { pc: 0, step: function() { this.pc += 1; }, equ: {}, line: {}, setEqu: function(l, v) { this.equ[l] = v; }, setLine: function(l) { this.line[l] = this.pc; }, getLabel: function(l) { if (this.equ[l] !== undefined) { return this.equ[l]; } return l; }, tidyAddress: function(pc, addr) { if (typeof(addr.value) === "string") { addr.value = this.line[addr.value] - pc; } }, }; 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