Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Antlr with compiler for CIL code

I'm doing a compiler for study purpose.

It uses Antlr tool targeted for c# code generation.

So far, i can handle the gramar. Lexical, Sintatic, my tests are ok.

My aim is to generate CIL bytecode, i'm kinda familiar with it.

The problem is... I don't know a good way to "output" the code. I'd like some advice, example to generate it.

One thought i have, is to create a Class "compiler" with tons of method related to the node and call the method as the tree is iterated.

Ideia:

Class Compiler
{
   private AppededStrings = "";

   void CreateClass();
   void EndClass();
   void AddParam();
   void setAtributeToTheClass("public");
   ... and so on ...
}

Is this a good approach? I could not find a topic talking specific about this.

like image 934
Ismael Avatar asked Mar 24 '26 04:03

Ismael


1 Answers

Some parts of the page http://msdn.microsoft.com/en-us/magazine/cc136756.aspx will work for you :)

like image 71
Caner Korkmaz Avatar answered Mar 25 '26 16:03

Caner Korkmaz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!