summary refs log tree commit diff
path: root/pc-thing/the_e_programming_language/lang.ts
diff options
context:
space:
mode:
authorWlodekM <[email protected]>2025-03-31 19:47:54 +0300
committerWlodekM <[email protected]>2025-03-31 19:47:54 +0300
commitcccb99226d3951fd9dfe1c4cf1c43126a1309d51 (patch)
tree518d3e965558ba313f103cee6161cd2b6aedb3b9 /pc-thing/the_e_programming_language/lang.ts
parentef4e8c20719822eebd6318a878cc37902c2b85a5 (diff)
move to pc-thing/
Diffstat (limited to 'pc-thing/the_e_programming_language/lang.ts')
-rwxr-xr-xpc-thing/the_e_programming_language/lang.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/pc-thing/the_e_programming_language/lang.ts b/pc-thing/the_e_programming_language/lang.ts
new file mode 100755
index 0000000..5c00b98
--- /dev/null
+++ b/pc-thing/the_e_programming_language/lang.ts
@@ -0,0 +1,31 @@
+import Tokenizer from "./tokenizer.ts";
+import ASTGen from "./ast.ts";
+import Compiler from "./compiler.ts";
+const input = Deno.readTextFileSync('test.e')
+
+const tokenizer = new Tokenizer(input);
+const tokens = tokenizer.tokenize();
+
+console.log(tokens)
+
+const astGenerator = new ASTGen(tokens);
+
+let ast;
+try {
+    ast = astGenerator.parse()
+} catch (error) {
+    console.error(error);
+    console.log('at', astGenerator.position, tokens.map((a, i) => i == astGenerator.position ? `${a.type}(${a.value}) <--` : `${a.type}(${a.value})`).join('\n'))
+    Deno.exit(1)
+}
+
+console.log(ast)
+
+const compiler = new Compiler(ast);
+
+for (const node of compiler.AST) {
+    compiler.compile(node)
+}
+
+Deno.writeTextFileSync('ast.json', JSON.stringify(ast, null, 4))
+Deno.writeTextFileSync('code.txt', compiler.instructions.map(i => `${i.opcode}${i.args.length > 0 ? ' ' : ''}${i.args.join(',')}`).join('\n'))
\ No newline at end of file