Question:
How to make a programming language?
Michael
2013-07-17 21:48:41 UTC
I am 13 years old and I have always been interested in many things in programming such as game making. My interest for game making has gone away though. One thing that always made me interested in programming is making a programming language. I have the dragon book but I don't know if I should actually read it or I could find better resources for free and not waste my time. I want to start making a programming language while I still can rather than programming as a job or anything else.

So, is there any books that are better then the dragon book?

I want to make a compiler so should I learn assembly or other things like llvm

Where can I learn about how parsers, tokenizer, ast, and codegen work

which language should I learn to do this.(I know Java, C#, C++, and I am willing to learn any other language to do this).

anything else?
Three answers:
Jonathan
2013-07-17 23:57:32 UTC
There are several dragon book editions. All are pretty good. I've read them. And I've written a C compiler. But for someone 13 I would NOT recommend the dragon book unless you are very, very skilled already. It's for those with some background to build on.



Probably the easiest way to write something useful and without too much complexity is to get Niklaus Wirth's "Algorithms + data structures = programs" book. See 1st link below. Near the end of the book you are taught from scratch how to write your own PL/0 compiler. It's a pretty good lesson for beginners and I think you will enjoy the process a lot.



Another excellent book to get is more recent (the above one is from 1976, I think.) It is Hanson and Fraser's "Retargetable C Compiler: Design and Implementation." See 2nd link below. It's VERY EXCELLENT and not difficult to read, either.



Neither book above is difficult or excessively long. Both are MUCH MUCH EASIER to read than any of the dragon books. (Though, once you get through the above two and get some experience behind you, you may then enjoy some of the sections in the dragon book -- particularly on optimizations.)



I really do think you should give both books a shot. And if you are really interested in another really good book recommendation, and if you want to try your hand at writing a simple operating system (you should buy a microcontroller board for that, though, as the IBM PC is crazy-complex and you need to start simple), then I'd recommend Douglas Comer's first (not the later editions) XINU book. See 3rd and 4th link below. That book is kind of hard to get (the red one), but it is fantastic for beginners. I think there are paperbacks available for less, though.



And just to offer another very fun book to read, I'd recommend the first half (at least) of Clive Maxfield's "Bebop Bytes Back: An Unconventional Guide to Computers." It teaches complete neophytes (beginners) how to design microprocessors and does a commendable job of explaining the details. Even if you never get a chance to code up a CPU on your own (programming it into an FPGA board using VHDL or Verilog, for example), it's still a huge education about how they work inside and you will learn a lot from it. See 5th link below. (I think I bought up all the cheap ($10) copies of it a couple of years ago -- got a nice stack here that I like to give away from time to time.)



EDIT: The very first thing you should do, though, is to learn how to write your own expression analyzer. This is step #1. If you can write an algebraic calculator program that can parse and accept parentheses and handle operator precedence properly, you are taking a good step towards your goals. I'd recommend starting there. Write me if you want some thoughts about how to go about it.



Any language will do, by the way. You can write a compiler without knowing a lot of assembly code -- in fact, C++ was originally compiled using CFRONT, which accepted C++ input and produced C output. Then that was fed into a C compiler to produce the final code. You can cause the compiler to generate machine code, if you want. Or you can make it generate something you make up, if you then write an interpreter for that code (which also doesn't have to use assembly code.) Or you can just write an interpreter. But some assembly code knowledge does allow you broader choices.
Cool Guy
2013-07-18 05:12:46 UTC
Keep at this. You're 13 and you know that llvm is a compiler. Just that right there blows my mind. Simple, but think about it.



Now, creating a language isn't easy. Like, at all. Pros do it. Same goes with a compiler/debugger/linker/whatever. But program, my friend. Find 1 language and stick to it no matter what. I've been programming for a couple years (I am 16, I can kind of relate.) and out of all the languages I've had a crash course on (HTML/CSS/JS, C++, Python, Ruby, Perl, Pascal, the list will go on...) I found C to stick with me. So, I would recommend C. If it's too much, go to Python. It really is an extensive language once you use it for a few months. Assembly is awesome too, it's what I am studying right now, actually (Got a pdf on Intel processor registers and writing compatible asm code on current gen intel 64-bit processors).



So, yeah. Don't get discourage like I did and waste a year and a half doing nothing. If you have a passion for this, don't quit. If you think you suck at it, keep going. Just don't give up.



I got carried away. To answer your question: Learn C for this low level stuff like compilers.
Tom
2013-07-18 07:10:05 UTC
I would not focus on making your own programming language but try to write a compiler or virtual machine. I would also see how much more you can learn about the languages you mentioned. No offence, but I find it hard to believe you "know" all these languages in depth.



If you are interesting in learning some cool things, I would start doing more advanced concepts.

With C++: see if you can write a compiler or see if you can write an STL library.

With Java try playing around with Reflection and JNI.

With Python write a cgi webservice from scratch.



Assembly language is chip specific, so learning it is pretty niche. If you learn a CISC based architecture like x86 you will not be able to apply these concept to RISC based architectures like ARM.



Goodluck


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...