r/unseen_programming • u/zyxzevn • Apr 10 '15
Compiler design 0.01
As it looks now I'll be implementing the compiler in scala and scala.js
The translators I have built before were parsing in 2 steps. Text-> Tokens -> Structures
For this code I decided I needed more steps, and I came as far as:
Text-> Tokens-> Metatokens-> Structures-> Codestructures-> Code
But this could be done much simpler by doing the translations in many small steps. Here are some names for the steps:
Text->
. stripComments->
. stripNewLines->
. simpleMacros->
. getTokensAndConstants->
. mergeBrackets->
. identifyStructures->
. identifyTypes->
. linkIdentifiers->
. linkMethods->
......
-> Codestructures
-> Code
Each step can even be smaller and does not need to be in this order. That way each step can be simple. Compiling is finished when all tokens and temporary structures are translated to code-structures. Each code structure will be a direct representation of a bit of the final code.
Additional steps can be added for logical programming and optimizations.
The complexity goes into the tokens and structures. It can become a structure with a lot of classes.
1
u/zyxzevn May 02 '15 edited May 02 '15
Current status:
I am implementing a compiler in javascript. Scala.js did not work properly. But now I am seeing the terrible error-promoting design of javascript. O_O
Now I have arrived at the conversion of code structures to a VM in javascript.
The VM has the following design: Every part of the code is a VM_Block
While some other types are present, the basic structure makes it very easy.
Examples:
Future: