summaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2023-05-22 14:58:52 -0500
committersanine-a <sanine.not@pm.me>2023-05-22 14:58:52 -0500
commit9e8703d07e2e49d14e3d2092d77f8f7e75ee7e04 (patch)
tree548572958e4f368d7d1dbe0144c9e27a160c2ec3 /src/parser
parentf2a515a940ea5e66c9fbc9669e6293ae32b7041a (diff)
fix line labels ordering
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/grammar.jison4
-rw-r--r--src/parser/grammar.js4
-rw-r--r--src/parser/parser.js20
-rw-r--r--src/parser/stone.js6
4 files changed, 27 insertions, 7 deletions
diff --git a/src/parser/grammar.jison b/src/parser/grammar.jison
index 2f5b30a..83255e0 100644
--- a/src/parser/grammar.jison
+++ b/src/parser/grammar.jison
@@ -51,8 +51,8 @@
%%
program
- : lines END coda { yy.start = 0; return $lines; }
- | lines END label coda { yy.start = yy.getLabel($label); return $lines; }
+ : lines END coda { return { start: 0, program: $lines }; }
+ | lines END label coda { return { start: yy.getLabel($label), program: $lines }; }
;
coda
diff --git a/src/parser/grammar.js b/src/parser/grammar.js
index 21f6b89..f51d7f6 100644
--- a/src/parser/grammar.js
+++ b/src/parser/grammar.js
@@ -84,10 +84,10 @@ performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* actio
var $0 = $$.length - 1;
switch (yystate) {
case 1:
- yy.start = 0; return $$[$0-2];
+ return { start: 0, program: $$[$0-2] };
break;
case 2:
- yy.start = yy.getLabel($$[$0-1]); return $$[$0-3];
+ return { start: yy.getLabel($$[$0-1]), program: $$[$0-3] };
break;
case 7:
diff --git a/src/parser/parser.js b/src/parser/parser.js
index ef84be3..7d3dd95 100644
--- a/src/parser/parser.js
+++ b/src/parser/parser.js
@@ -22,15 +22,29 @@ parser.yy = {
return this.equ[l];
}
- return this.line[l] - this.pc;
+ return l;
+ },
+
+ tidyAddress: function(pc, addr) {
+ if (typeof(addr.value) === "string") {
+ addr.value = this.line[addr.value] - 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);
+ let program = parser.parse(data.toUpperCase());
+ if (typeof(program.start) === "string") {
+ program.start = parser.yy.line[program.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);
+ }
+ console.log(program);
console.log(parser.yy);
});
//}
diff --git a/src/parser/stone.js b/src/parser/stone.js
new file mode 100644
index 0000000..fe2a864
--- /dev/null
+++ b/src/parser/stone.js
@@ -0,0 +1,6 @@
+start mov <2, 3
+ add d1, start
+ jmp start
+ dat #0
+d1 dat #-5084, #5084
+end start