Implement the preprocessor

Assigned to
3 years ago
1 year, 5 months ago
No labels applied.

~mcf 3 years ago

Made some progress on this. I pushed a branch preprocessor that is able to bootstrap without cpp. However, I'm not yet happy with the code, so I'll keep working on it in that branch. But it's at least good to have a baseline that works.

Still TODO:

  • String operator #
  • Paste operator ##
  • Variadic macros (so de85378a20 and d2b8ee0f91 are temporarily reverted)

Things to decide:

  • Should we remove the newline token, and instead keep track per-token whether it starts a line?
  • Should the tok global just be a pointer? This might make a few things easier.

~bugcrazy 1 year, 5 months ago

There is the pp preprocessor, which uses the same ISC license!


~mcf 1 year, 5 months ago

Seems like an interesting project, but pp-1 is not a C preprocessor. Rather, it looks to be some sort of document templating program.

~bugcrazy 1 year, 5 months ago

I should have explained better, that pp-1 is more for seeing code and inspiring ideas, sorry.

These are links from C preprocessor, which have permissive licenses, I hope it's useful!




~ach 1 year, 5 months ago

I think the chibicc preprocessor is another good one: https://github.com/rui314/chibicc/blob/main/preprocess.c

It is very small and handles a lot of real programs.

Register here or Log in to comment, or comment via email.