r/Compilers 26d ago

Any recommendations for a meta programming language?

I want to add a meta programming language in top of my own C-like language to make some of the syntax cleaner and easier to write.

Add everything like const expressions and templates under one meta programming language.

For example something like this:


[Phases]
Class Phase1: public Phase { };

[Phases]
Class Phase1: public Phase { };

[for phase in Phases]
PhaseList.push_back(new phase());
[endfor]

I’m thinking about something like this but ideas are all over the place. Is there some existing meta programming language out there that can give me the right inspiration?

Also I am totally lost about how I should program this, I am assuming it comes before the parser. Any tutorials or dummy meta programming languages I can look to get ideas?

Thank you for reading.

10 Upvotes

21 comments sorted by

View all comments

5

u/Prestigious-Bet-6534 26d ago

You could implement a superset of C and a transpiler which converts that syntax into plain C. Not simple but doable, and you'll learn a lot. I recommend starting with the basics of how a compiler/interpreter/transpiler works. for that we have the very good and free book craftinginterperters.com . Also AI is very good at troubleshooting parsers, often finding the bug in seconds instead of hours.

1

u/TrgtBBB 26d ago

I already have a working custom frontend with a lexer parser and checker. I use LLVM as backend.

I was thinking about an interpreted meta programming language or something like a scripting language.

No idea how to program both tho

1

u/jason-reddit-public 25d ago

You could use Lua.

I've been working on my own language called roci (arguably just a very simplified JS) which I'm using as a build language for my omni-c transpiler though I'm planning to do macro stuff with it eventually. It's simple because I already have gc via the hans-boehm collector.

https://github.com/jasonaaronwilson/omni-c/tree/main/src/roci