-
I'm interested in making a really simple compiled scripting language. I don't understand why most scripting languages compile to bytecode and then interpret that. This requires the following steps:
1: Design a bytecode. 2: Write a compiler. 3: Write an interpreter.
It seems like it would be simpler to not bother with 1 and 3 and instead use machine code as the bytecode. A side benefit is that programs will run faster.
I think it is easy to generate machine code for x86_64, ARM64 and risvc64, as long as you don't mind it being 3x larger and slower than an optimizing compiler would generate. It ought to be easy because it is possible to only target the common subset of features these architectures support.
I made a start, https://github.com/abainbridge/mortar, but haven't got much past being able to compile and run a Fibonacci sequence generator. I have no experience with language design or compiler implementation.
Any comments or suggestions, including, "Don't bother, here's one I wrote earlier..."?
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
-
You may find the following useful for some necessary background;
Implementing Programming Languages: An Introduction to Compilers and Interpreters by Aarne Ranta (<150 pages!) - https://www.grammaticalframework.org/ipl-book/
The above book uses the BNF Converter Tool - https://bnfc.digitalgrammars.com/
BNF Converter Tutorial - https://bnfc.digitalgrammars.com/tutorial/bnfc-tutorial.html
For code generation, you can just walk the AST and emit the text of the assembly code for x86_64/ARM64/RISC-V and then leave the rest to the system assembler.
From your github i see you mention the "MicroC" subset of C language. Maybe follow the above book but with the syntax/grammar of MicroC for your implementation.
Related posts
-
The BNF Converter
-
How I Choose Which Open Source Issue to Work On (After Picking Wrong Ones)
-
How I Extended a Refaster Rule in Picnic's error-prone-support (and Recovered a PR GitHub Broke)
-
Modernizando Java legado com IA - o que funciona e o que dá errado
-
Show HN: ISPA – Parser generator with grammar-level debugger and error recovery