diff options
author | sanine-a <sanine.not@pm.me> | 2023-05-22 14:26:10 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2023-05-22 14:26:10 -0500 |
commit | f2a515a940ea5e66c9fbc9669e6293ae32b7041a (patch) | |
tree | 478d369195e90380027fef4137b9caac833bb219 /src/parser/parser.js | |
parent | ff3fdee3841743e7fe101c3fc7020a4b043bc91b (diff) |
update label style and add implicit second operand
Diffstat (limited to 'src/parser/parser.js')
-rw-r--r-- | src/parser/parser.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/parser/parser.js b/src/parser/parser.js new file mode 100644 index 0000000..ef84be3 --- /dev/null +++ b/src/parser/parser.js @@ -0,0 +1,36 @@ +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 this.line[l] - this.pc; + }, +}; + +//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()); + console.log(result); + console.log(parser.yy); + }); +//} |