Code Generation sample (courtesy of Javier JBM)
MIT License
Code Generation sample (courtesy of Javier JBM)
This is a simple code generation example using C#. It has been created originally by Javier (JBM) in Java and ported to C# by me (@SuperJMN). So, all credits go to him :)
The application translates high level expressions to Intermediate Code.
Code generation is the process of converting a language into another, usually simpler and closer to the machine that will execute it.
This high level expression:
a = b + c * d
is turned into:
T1 = c * d
T2 = b + T1
a = T2
PLEASE NOTICE that the code is generated from an AST, not from the actual source code (a string). The generation of an AST from source code belongs to another (previous) stage of the compiling process.
Feel free to copy or investigate / ask!