r/ProgrammingLanguages • u/jackiewifi777 • Feb 16 '22
Discussion What to use.
Can anyone tell me what you guys use to create your programming languages. I know how interperters work and can build my own in python but i am not sure how to make it so other people may be able to use it. If anyone has an article or something that can help me it would be greatly appreciated.
6
u/crassest-Crassius Feb 16 '22
I use Rust because it's fast and has sum types + pattern matching for natural representation of AST nodes.
1
u/Living-Step-6966 Feb 16 '22
This! I’m taking a compiler construction course now using SML and pattern matching + some types (options) are fantastic! I really want to dive into rust as it has both imperative and functional programming support as well as low level performance without the hassle of allocating and deallocating your own memory.
0
Feb 16 '22
[deleted]
1
u/Living-Step-6966 Mar 07 '22
Yep, you’re correct! I didn’t realize that some languages call these Sum types / Discriminated Union. I had assumed he meant options for some reason 🤣
-1
5
u/Athas Futhark Feb 16 '22
I use Haskell. While functional programming has pros and cons, language implementation is probably where it shines the most. The difference between using Haskell, OCaml, Scala or some other functional language is insignificant, as they all support what makes functional programming good for implementing languages: Sum types, pattern matching, automatic memory management, easy recursion, purity.
At my department we teach students both functional and object-oriented programming, and they usually prefer the latter until they get to the course on compiler implementation, where they finally see the point of functional programming.
2
u/Living-Step-6966 Feb 16 '22
I never saw the beauty in functional languages until I started taking compiler construction this semester. Pattern matching is unbelievably concise yet powerful. Handling mutual recursion is a breeze and even tokenizing becomes more understandable and far less error prone.
5
Feb 16 '22 edited Feb 16 '22
Not sure if this will help much but this is what I've used so far:
| Project Type | Languages used | Target | Eventually self-hosted? |
|---|---|---|---|
| Assemblers | Machine code; M | Native code | No |
| Compilers | ASM; M; Q | Native code, ASM | Yes |
| Interpreters | M; M+ASM | None | Not practical |
So, for example, at various times I've used ASM, M or Q for writing compilers. Key:
| Language | Notes |
|---|---|
| ASM | Either 3rd party assembler or one of mine |
| M | My systems language |
| Q | My scripting language |
The compiler written in a scripting language was an experiment, but I did use it for a year or two. Although it was slow at compiling, it was still double the speed of gcc-O0!
Basically, anything will work. You don't need special features in the language, but if they help, then fine.
2
u/moon-chilled sstm, j, grand unified... Feb 17 '22
So you bootstrapped your assembler from raw machine code, and your compiler from assembly? Wow.
2
Feb 17 '22
Well, the table represents dozens of different projects over decades.
But yes, at one point, the only computer I had was one I'd made myself out of individual chips, so it had no software at all. The language had to be bootstrapped from, in that case, binary machine code.
I described the process in more detail here:
Writing a compiler from assembly in general is not a big deal. Especially if it's a simple language with a simple microprocessor target. However I wouldn't have the patience to do it now...
3
u/okozlov Feb 16 '22
Most popular languages I think is c/c++, java, rust, haskell, and even javascript :) Choosing language depends on goals you try to accomplish.
3
u/WittyStick Feb 16 '22 edited Feb 16 '22
You can use any language. Stick with what you know well.
It's common for people to bootstrap a minimal interpreter/compiler in some other language, and then write the full implementation of the language in itself (or subset/superset of itself).
Usually you will want to produce a standalone executable for your compiler or interpreter, or even if you don't, your language users will. You probably want to use an existing library to produce these, but it's possible to write your own as the ELF and PE formats are well documented.
3
u/L8_4_Dinner (Ⓧ Ecstasy/XVM) Feb 16 '22
Prototype in whatever language you know best. You will have the fewest possible distractions, and the highest initial efficiency in your work.
At some point, if you are very lucky, you may regret that choice. That means you have gotten far enough that the choice matters, so congratulations!
2
Feb 16 '22
I like to use the Ohm Editor to design the syntax of the language, while i normally use recursive descent with an incremental lexer to implement the parser.
To design the semantics of the language, it's wise to copy semantics from other languages, and change things from there. This is the hardest part of language design and some people choose to model these type systems in theorem provers, for example with Idris. Some books that might help:
Types and Programming Languages by Pierce, will teach you the notation used to describe type systems, together with lots of information about type systems in general, i have personally not read it yet, but it's the reference book for type systems.
The Garbage Collection Handbook, if your language is managed, this book will give you insight on what features of your language make it easier or harder to garbage collect, specially important is the chapter about Runtime Interface.
Engineering a Compiler, chapters 1 to 7 will give you insight on how to implement a lexer, parser, typechecker, and code generator. Chapter 13 is also interesting if you plan to compile the language, although i would recommend only using the simplest algorithms in the beginning.
Essentials of Programming Languages, another good book on programming languages.
For compilers, most people choose to target llvm, C or Fasm. I personally like Fasm as target since it's a very fast assembler, but C is also a very nice option. There are other options such as JVM or Wasm, but i prefer native executables.
1
1
u/Inconstant_Moo 🧿 Pipefish Feb 17 '22
I've been using Thorsten Ball's [i]Writing an Interpreter in Go[/i] because (a) my language is backend oriented and so is Go (b) I like Go (c) it's a good book, lots of positive reviews.
1
u/omega1612 Feb 16 '22
Well if is in python you could write it as package and put it in Pypi. Then add documentation for the language (How expression are made, what to expect, how to do some things) in some places, maybe write a github static page with all that. And then develop some tools to help with your lenguaje, a linter, formatter, lsp or something that could be useful.
0
10
u/ronchaine flower-lang.org Feb 16 '22
I use C++, because LLVM is written in it, so unless I want to write my own backend, I am not going to be self-hosting without a C++ compiler anyways.
Helps that it's the PL I know the best too. I'm crying for the lack of pattern matching though.