Sign in to follow this  

Code generation and entropy coder

This topic is 834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone!

 

I've written a few blog posts that I thought might interest people around here, one is about a code generator and the other is about entropy coding/compression.

 

https://worldoffries.wordpress.com/2015/09/01/code-generator-and-other-fun-stuff/

https://worldoffries.wordpress.com/2015/08/25/simple-entropy-coder/

 

Enjoy!

Share this post


Link to post
Share on other sites

Your code generation article is really interesting, although got me wondering. 

The last time I did code generation, I used PHP. The syntax is generally really easy, it is a general-purpose language, so you can do mostly whatever you want, and it is high-level and productive. Also, it is really easy to use it for generating text because you can freely mix raw text and code ( instead of long print("..."); lines ). 

The example you show ( index the template xml itself ) could also be done, although would need some preprocessing. 

So, I'm curious as to why implement template-specific languages, instead of get download a php and type away. What are the pros and cons? 

Share this post


Link to post
Share on other sites

Well that’s a good point, or another idea could be to just use python and jinja2 itself, but I can give you 4 reasons why I did this.

 

Firstly the last time I checked, this was all only about 1000 lines of code and this will probably shrink once i write a decent parser and evaluator for the entire syntax that I’m using. At the moment there is a mix between two different parsers in there, one for control statements and one for math expression and function calls.

 

Secondly I’m not very familiar with python or php, and didn’t really want to add a whole package to my build pipeline as it would make interactions between the different parts of the pipeline more tedious to implement, so I stuck with C++. In hindsight i would have preferred C#.

 

Third reason is that I've never implemented a tokenizer/parser/evaluator for a script like language and I thought it would be a fun learning exercise.

 

And the forth is that now that it's working, someone else with the same requirements as I might not have to re-invent the wheel like I have.

 

The pros would that you could completely customize it to your needs since the entire source is there. The cons I guess are that I have to implement it, which is probably more work than doing it in php/python, but still only about 1000 lines of code :)

 

I hope this answers your question :)

Share this post


Link to post
Share on other sites

This topic is 834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this