One of its unique features is the transpiler that can generate readable code, preserving macros and formatting.
See it online: http://thradams.com/web3/playground.html
#include <stdio.h>
int main()
{
puts("hello world");
return 0;
}
Got: source:5:4: error: not found 'puts'
5 | puts("hello world");
|I will added it. Thanks.
Meanwhile you can add:
int puts( const char *str );
If I was interested in using the C23 features, wouldn't I use a C23-ready compiler?
That said... I do wonder how long it will be until ARM and GCC have a C23 toolchain - or did I just answer my own question?
The new C23 language has a lot of features that makes your code not compile in previous C versions like attributes digit separators etc.. Someone may wants to create a new project in C23 and soon regret because the users of the code may need C99. This would be one use case, you can create a C23 code and have C99 versions of the same base code.
Unfortunately my transpiler is not "production ready" yet and I don't have IDE plugins etc.. that is required to make the tool more productive.
The other advantage, if we had a production ready transpiler with a IDE support etc.. it that we could use C23 and compile to C99 without having to wait for compilers like msvc to implements the standards.
Also some experimental features (like defer) can be used and you can distribute your code in standard C99. We have more freedom to use wherever we want and distribute a "readable" C99 code.
By the way most of the C transpilers or compilers generates C code only for immediate compilation. CFront was like that.
My transpiler have two modes one is for direct compilation and other is to distribute generated code.
Each mode has advantages and disadvantages.
Ah. I was not aware of this.
Because you are required to use Visual Studio or some compiler that barely even does C99/C11.
> If I was interested in using the C23 features, wouldn't I use a C23-ready compiler?
Yes, but maybe you can't guarantee a C23-capable compiler on all the platforms you care about, or maybe you are required to support VS/VC.
> That said... I do wonder how long it will be until ARM and GCC have a C23 toolchain - or did I just answer my own question?
You did :)
Transpiling is just a very useful idea. Sure, why even bother, the world should be perfect already! But the world isn't. And anyways, transpiling is a very cool idea. If you have time and funding (e.g., maybe you're a graduate student), then you might build it. If you don't have the time and funding you might wonder why even bother, except maybe you have the need and then you get the funding? Even if you don't have the time or funding, you might make an idea you care about into a hobby. So there's many reasons why one might want to build a transpiler.
In another thread we were talking about transpilers for SQL. There the motivation is much stronger and clearer than here, but it's of the same sort: portability. In the case of SQL there's so much variation across RDBMSes that if you must support more than one, you'll quickly wish you had a transpiler for some dialect, or even for an alternative query language.
Another thing is that a transpiler won't need to do much analysis or optimization, so it can be fairly simple compared to a full compiler, but! a transpiler can be much less ambitious than -and a great starting point for- constructing a compiler.
Maybe you want to add some neat new features - like Circle C++ https://www.circle-lang.org/
A language without preprocessor and a simple grammar saves a lot time and you can go direct for the funny parts.
I live in Germany now and I often hear "funny" (lustig) used where "fun" (Spaß, used in English as an adjective too - something like spaßig but that's still considered "funny") should instead be used. Just a tip!
This project is awesome, by the way. Thanks for posting it.
I should spend some more time reading through what you have, but can you answer: what parts of this should I be looking at if I just want something to generate an AST for C99 (no transpiling needed)?
There’s some source analysis I’d like to do (on student C code) and right now I’m considering the (python-based) C parser in CFFI, but your’s might be more complete?
You can use it as reference to create different "visits". For instance, I am implementing a code format at "visitformat.c".
I have implemented a "naming convention checker" inside the parser, but it also can be a "visit".
Static analysis etc..can be a visit.
Inside the visit context you will find
struct ast ast;
That is the AST.
I would say the syntactic analysis parser is 100% complete C23.
Semantic analysis that is not 100%.
As long as we’re on this tangent, here’s the challenge I’m facing with automated analysis of student code: from foo.c make bar.c which is identical to foo.c except that comments have been turned into spaces. I think this is annoyingly non-trivial.
EDIT: I see it has an option to target C99, but I wonder if it's sufficiently constrained C99 to support VC's not-quite-C99-hah-hah dialect of C. I'll have to try it at some point.
[1] https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-...
https://github.com/mozilla/narcissus https://wiki.mozilla.org/Narcissus
So is it a compiler, a front-end (which emits IR for another compiler), or a transpiler?