r/AskProgramming • u/notyetfallenicarus • Apr 19 '26
Career/Edu Which host language for creating my own programming language?
so i am going to build my own self hosted programming language and before that i want advice on which host programming language should i use. for context, i will enter 5th semester (ty) of btech. so gaining experience in which language will give me highest benifits in my career.
i heard that rust will be easier that cpp because of the built in memory safety but i want an honest opinion on which language does the industry seek proficiency in.
0
Upvotes
4
u/Interesting_Buy_3969 Apr 19 '26
Imho you should make use of the LLVM compiler infrastructure, and valid host languages list includes C++ and Rust. Explore what is LLVM and its IR - but basically it's a layer of "middle-level code" that is generated by your parser and then translated to machine code. LLVM gives you a lot of advantages, like: compile-time and link-time optimisations, compatibility between plenty platforms by default, etc.
So generally speaking, your task is to create a program that reads input file with source code written in your programming language -> parses it -> generates LLVM code -> invokes LLVM to generate platform-dependent machine code, and that's it. Note that LLVM provides an API that makes generating LLVM IR (the intermediate representation of the source code) much much simpler. Imo this is the most proper and simplest way to craft your own language.
A couple of links if you want to delve into LLVM:
https://llvm.org/docs/LangRef.html
http://llvm.org/docs/
6
u/ChanceCalligrapher21 Apr 19 '26
Rust is nice for writing compilers because of the memory safety sure, but honestly the first class pattern matching is particularly useful in that context as well.
In general I think functional languages really shine as languages for writing compilers (OCaml, Haskell, etc), but if your primary criteria is “what language is used the most in industry” (really this will depend on what specifically you want to do within the industry, and also a lot of skills are general over programming language), there are a million indexes online which rank programming languages by usage.
3
u/Slight_Manufacturer6 Apr 19 '26
Assembly
2
u/czlowiek4888 Apr 19 '26
So basically you want to write a compiler.
The question is do you want to write your language from the ground by yourself?
Or maybe you want to use standardized framework for writing compilers backends LLVM?
Or maybe you would prefer something more realistic to finish in single year and you would like to create a language that compiles to already existing language?
What is your end goal? What do you want to learn or get familiar with?
3
u/kissajr Apr 19 '26
If you want a fun and educational experience try haskell
1
u/zarlo5899 Apr 19 '26
i would go with C# or Go
1
u/high_throughput Apr 19 '26
Obviously the host would be your language. Do you mean bootstrapping language?
1
u/SwedishFindecanor Apr 19 '26
Recent related topic: What hobbyist compiler writers are actually using: https://www.reddit.com/r/Compilers/comments/1smumcd/whats_your_goto_language_for_building_compilers/
1
u/AustinVelonaut Apr 19 '26 edited Apr 19 '26
If your final goal is self-hosting a new language, then there are two main paths for choosing a bootstrap language:
I chose option 2) for Admiran, writing the initial bootstrap compiler in Miranda, then self-hosting it. Using a functional language like Miranda that has Algebraic Data Types, pattern-matching, and automatic memory management (garbage collection) helps a lot when writing compilers.
1
u/SmashStrider Apr 19 '26
I think what you mean more so is what language you would like to write the compiler in.
You don't really write a programming language in another programming language, in the sense that you don't necessarily have to make it so that your language will convert to C or C++ code in the background (a process known as transpilation), what you probably wanna do is build a program that takes your input file stream, breaks it down lexicographically and structurally, performs checks to validate the code, and then converts it into ASM or machine code. This is generally the compilation pipeline, that follows the stages Lexing -> Parsing (into an AST) -> Semantic Analysis -> IR Flattening -> Codegen (into assembly/bytecode). So you aren't actually using a host language for the code to be converted to, rather you are using a different language to build this 'compiler' that shall translate your user-readable code into a machine readable version.
As for your choice of language, Rust is a very nice option to make a compiler, although C++ is pretty standard too. Rust does have the memory safety benefit + wrapped enums (tagged unions) in Rust would make your life a LOT easier due to your compiler being a state machine, something I can vouch for personally as I'm working on a project to make my own high level programming language compiler in Rust. In addition, Rust also has a very actively growing community and the job postings in Rust are increasing dramatically, as companies switch to Rust over time. C++ is more of a standard, and it's more manual with memory control (although compilers, at least basic student ones, are not as performance critical as something like a VM might be, not to mention Rust can be just as fast as see), but C++ has a very mature job market, so if you wanna be on the safe side, you can opt to make your compiler in C++ instead.
Personally, I chose Rust, but it's really upto you and your goals.
1
u/Global-Time1746 Apr 20 '26
Glad to see that you are interested in Language Design, it's a pretty interesting subfield in computer science and can have lots of "close to the metal" aspects to it.
To your first question: Cpp still has broader industry presence, but Rust is growing in systems programming roles. Tbh, Cpp is still probably a better long-term investment. That said, I'd actually recommend ignoring both for this project. Writing your first PL in a compiled language adds a lot of incidental complexity (memory management, object code, linking, ect.) that are pretty advanced and distract from getting a good start with language design. A good project teaches you ONE thing at a time.
Instead, I'd probs pick up a functional language like OCaml or Scheme and build a simple recursive interpreter. Functional languages map very cleanly to the kinda "AST + evaluation" model that good starter language implementations rely on, and it'll be easier to wrap your head around the more core concepts like context-free grammars, Backus-Naur Form, recursive descent parsing, abstract syntax trees, environments, and closures this way.
By the way, building a language will genuinely make you a better computer scientist, but it's a long project, and I'm not sure folks in the industry will be that impressed with it. Make sure you actually find it interesting and this isn't just a resume padder.
If you want a guided starting point, I'd recommend "Essentials of Programming Languages" by Friedman and Wand. I used it in my Master's program, and I thought it was an AMAZING introduction to the topic. People also seem to like "Crafting Interpreters" by Nystrom (but I think that's in C/Java or something, which might be a less elegant first time experience).
1
u/balefrost Apr 21 '26
If your goal is to get to self-hosting, then you probably want to bootstrap with a language that gets you to self-hosting the fastest. To that end, I'd say you should use "whatever language you are most comfortable with". All the code you write to bootstrap yourself is essentially throw-away code. It's probably not worth learning a new language just for that.
Another reasonable answer would be "a language with semantics that are similar to your language". That could make it easier to port your bootstrap code to your target language.
Personally, I'd probably pick a garbage-collected language with support for sum types.
2
u/just_here_for_place Apr 19 '26
"The industry" is pretty big. Every popular language is used in some parts of it.
1
u/Useful_Calendar_6274 Apr 19 '26
I've pondered this at some length and you may laugh and all but after chatting a lot on various alternatives with chatgpt I landed on clojure
2
u/[deleted] Apr 19 '26
[removed] — view removed comment
1
u/[deleted] Apr 20 '26
[removed] — view removed comment
0
u/[deleted] Apr 19 '26 edited Apr 19 '26
[removed] — view removed comment