DEV Community

Discussion on: How and why are new programming languages created?

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

There are several reasons for creating a new language:

  • You see deficiencies and what to create a language that is easier to use, or more robust
  • The domain you're working in could benefit from having it's own language (domain specific languages)
  • You want to challenge yourself or test a theory in language design
  • You want to extend/create vendor lock-in to a platform

To create a new language you need to produce a compiler -- or interpreter, but the differences at the high-level aren't important. These consist of a few general parts:

  • Parser: Processes text files and converts them to a language usable by the next step. This is the abstract syntax tree (AST).
  • Apply Semantics: Go through the AST and figure out the proper type, as well as change the structure for various language features. I called this the "Typing" stage in my compiler, though I guess some languages emphasis more the structure here.
  • Reduce: Convert the expanded AST into an intermediate langauge (IL). This may be done in one or two steps, depending on the language. I had two steps in my compiler, one for a custom IR, and then to LLVM-IR to make use of standard tools.
  • Emit: Convert the IR into a target specific machine code -- which may be an actual machine code, or the byte code of a VM.

Compilers are written in other languages. A few end up as self-hosting, which means the compiler is eventually rewritten in the language it compiles. Though the vast majority of compilers are not self-hosted, and there's rarely a good reason to do self-hosting.

Collapse
 
nanythery profile image
Nadine M. Thêry

Thank you very much for enlighting me and sharing this :)