Search code examples
language-agnosticcompiler-constructionprogramming-languages

How does one write a language?


How does one write a language? I really can't imagine how this would be done. Do you have to write some binary code? I think I'm far from capable of writing a real programming language -- I'm a hobby programmer -- but I just want to understand how it works.
I don't ask for 'a working demo' (because I presume that'd be a demo like ten pages long) but the general steps one has to take, what you have to write and what that what you have to write has to do, what language do you recommend (that I think I'm not capable of it doesn't mean I don't want to try).

EDIT:
So is my assumption that one would write some code in an arbitrary language that translates it into an already existent language and compile that to machine code?

PS I accidentally voted to reopen my own question, but I think it's reasonable it's closed, so how can I undo that?


Solution

  • Start by writing a specification and grammar that describe what your language does.

    Then, write a parser and compiler that turns your language into a simpler language, such as C or MSIL or Javascript.

    Finally, run an existing compiler for that language.

    You may want to look into LLVM.