blob: ef84be3a0c5286465dd9bbe37533bc095480abb1 (
plain)
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
32
33
34
35
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);
});
//}
|