summaryrefslogtreecommitdiff
path: root/src/parser/parser.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-05-22 23:43:39 -0500
committersanine <sanine.not@pm.me>2023-05-22 23:43:39 -0500
commitc1709249728cb9ad7011b0d39d18ad87d4636f4b (patch)
treed4fae900af8cc4ee2956bbbe3c5c70c1664b193f /src/parser/parser.js
parentd6e89d16d332954dde3fc4c5ee7549af7c8bb556 (diff)
begin testing and make grammar more spec-compliant
Diffstat (limited to 'src/parser/parser.js')
-rw-r--r--src/parser/parser.js32
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;
+}