2 ms·
I second the notion of a front-end like CFront. It's a fun exercise. It took me about a week to do a Pascal to C translator a couple of decades ago. One prob
by russell 17y ago
I second the notion of a front-end like CFront. It's a fun exercise. It took me about a week to do a Pascal to C translator a couple of decades ago. One problem is that the grammar for C is not context free. If you are using a top down parser, it's probably manageable, If you are using yacc, bison or the like, you will probably need some kind of parser or lexer hack. Unfortunately, I cant remember where the problem lies.
Ordinarily I would recommend getting a ready-made parser, but they usually generate an abstract syntax tree and often throw away things like formatting and comments that you want in your generated code. I also recommend using Python or your favorite scripting language. Doing it in C hurts the flexibility that you want in your experimentation.