How to create our own programming language and a compiler for it? | SoloLearn: Learn to code for FREE!


How to create our own programming language and a compiler for it?

I can't understand how people create programming languages and devise compilers for it. I also couldn't understand how people create OS like Windows, Mac, UNIX, DOS and so on. The other thing that is mysterious to me is how people create libraries like OpenGL, OpenCL, OpenCV and so on. The last thing I am unable to figure out is how scientists devise an assembly language and an assembler for a microprocessor. I would really like to learn all of these stuff😊.

2/18/2020 5:15:02 PM

Yaseen Akbari

8 Answers

New Answer


A programming language works just like a human language: it has grammar (syntactic rules how you formulate instructions) and vocabulary (keywords and symbols which make up the tools available to the programmer). A program has to strictly follow these rules at all times. A compiler turns these instructions into machine code. Normally this is done by syntactic and semantic analysis, by building up an Abstract Syntax Tree and converting it to machine language that computers understand. To write a good compiler you would need to have a good understanding of the hardware too.


That's a lot of questions for a single post! It isn't possible to answer all of your questions here as you are basically asking for computer science to be explained to you. If you really want to learn all of this stuff then take a computer science degree. Any answer that can be written in 2000 characters or less is going to give you more questions than answers.


Simple: how compilers work and how to create our own programming language?


I strongly suggest asking those as separate questions so you get more actual answers to your questions instead of responses like "get a CS degree." For the assembly language question, I recommend you get an old DOS emulator and create your own COM assembler. The com file format is as simple as executable files can be and the old instruction sets for 8086 are far simpler than what is supported now so the old technology would be easier to support. Use a hex editor and an x86 instruction set reference to get started. Even if you don't make a complete polished assembler, getting some simple features to work and some trivial little programs generated will teach you the fundamentals of assembly and machine languages. The assembler I wrote is at: which includes a screenshot of a running program made with it. Creating your own high level programming language seems more challenging in many ways. I took a university course on it and still found teaching myself to make an assembler easier. guides you a little on creating a parser from a context-free grammar. Those tools are enough to make a high level language to other high level language translator. This way you can design a new language and translating to a better supported language like Java or c++ gives your new language a path from your custom language's source code to compiled .class, .dll, .exe... executable files.


Complicated and hard question 🤔


These questions are very complex to answer. To better understand all this you really need a CS degree. Making a language requires you to make a compiler for it. To make an OS you need to make your own files for it or use the existing ones for it like in the case of linux. The scientist that make and study the microprocessor already know a lot of the old ones and will in most cases innovate on the existing systems than create an entire new system.


I always thinking about when I will develop my own programming language