Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C23 to C11, C99 transpiler

51 views
Skip to first unread message

Thiago Adams

unread,
Jun 28, 2022, 1:19:08 PM6/28/22
to
As some of you may remember I have a c front end where
I experiment features in C and then I translate the experimental
features to standard C.

With the approach of the new Standard C23 and a
new draft
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2912.pdf

I decided to incorporate the C23 changes in my front end converting
from C23 to C11 or C99. I still have some experimental features.

There is an online version compiled with emcripten here
http://thradams.com/web3/index.html


It is interesting that there is a lot of changes that can be make
at tokenizer level.

For instance:
- binary literals
- digit separators
- #elifdef #elifndef *(some parsing is necessary but not full)
- static assert, bool ,true , false are a keywords..
Other transformation like typeof , _Generic requires compiler inference..

One feature that may be transformed on tokenizer level is attributes.
But attributes don't have a especial token. The [[ is not a single token.
I am removing this at parser visit level.. but the "visit" code is not 100% complete so the attributes are not there yet. But I am considering in doing
this at "token" level then the AST visit is not necessary.

I also added the conversion from u8 literals to C99.
(The input of the compiler is utf8 only so the job is just print the bytes. No need for locales)

The features that are showed are just experimental (this is a hobby project)
and there is bugs..but I am trying to get the front end right and I
need to spend more time in erros and unit tests.
This king of project may be useful or not..I am not sure.

_Generic is missing. I have seen some interest in atomic conversion.

I am also considering to check attributes. Then the front end can be
used as a lint and convert to C99 if necessary.

The transformation tries to preserve the original code comments macros..
this is not always possible. So I have a pragma to expand some macros.
and a mode to compile as the parser phase sees the code.(no preprocessor anymore)


In my previous version I had more experimental features like defer.
http://thradams.com/web2/cprime.html
the new version v3 is a new code more prepared to full semantic
analysis but the code in incomplete yet.




0 new messages