views:

1487

answers:

13

Possible Duplicates:
References Needed for Implementing an Interpreter in C/C++
Books On Creating Interpreted Languages
How to create a language these days?
Learning to write a compiler

Possible Duplicate:
Learning to write a compiler

Ok so I'm only 13 years old. I know some c++, VERY good at php, pro at css html, okay at javascript. So I was thinking of how was c++ created I mean how can computer understand what codes mean? How can it read...... so is it possible I can create my own language and how?

+32  A: 

If you're interested in compiler design ("how can computer understand what codes mean"), I highly recommend Dragon Book. I used it while in college and went as far as to create programming language myself.

Nikita Rybak
+1: That's what I read too and created [Hindi Programming Language](http://www.sktnetwork.com/portfolio/hindi-programming-language)
shamittomar
I don't think I would recommend the dragon book to a 13-year-old.
Michael Myers
@mmyers, if he already knows some C++ and *very* good at php...he may have the skills and knowledge necessary to understand Dragon book. If nothing else it'll help to teach him what else he needs to know/learn *first*.
David Thomas
@mmyers Just because he's 13 doesn't make it easier to write a compiler.
Tyler Smith
@Tyler: he doesn't need to write a compiler, merely a front-end for an existing framework (gcc, llvm, etc...) Though that's still a daunting task :)
Matthieu M.
+3  A: 

It is possible. You should learn about compilers and/or interpreters: what they are for and how they are made.

Bernard
+2  A: 

Start learning ASM and reading up on how byte code works and you might have a chance :)

Marc Towler
Most compilers are written in their own languages [ http://en.wikipedia.org/wiki/Bootstrapping_(compilers) ]. Similarly, the PHP interpreter is primarly written in C -- there's little, if any assembly involved.
Frank Farmer
Err, you can write compilers for any language in any other language. I mean for practice in college we created lisp using java, then java using lips. Of course it was very exact syntax and not extremely smart.
Parris
@Frank: @Parris: I don't think Marc's point was that the compiler should be written in assembly, but that it should compile to assembly. Or maybe he was just answering the part of the question that said "how can computer understand what codes mean?".
sepp2k
@sepp2k There are many compilers that don't "compile to assembly". javac, any interpreted language...
Frank Farmer
+15  A: 

If you want to understand how the computer understands the code, you might want to learn some assembly language. It's a much lower-level language and will give you a better feel for the kinds of simple instructions that really get executed. You should also be able to get a feel for how one implements higher level constructs like loops with only conditional jumps.

For an even lower-level understanding, you'll need to study up on electronics. Digital logic shows you how you can take electronic "gates" and implement a generic CPU that can understand the machine code generated from the assembly language code.

For really-low level stuff, you can study material science which can teach you how to actually make the gates work at an atomic level.

You sound like a resourceful person. You'll want to hunt down books and/or websites on these topics tailored to your level of understanding and that focus on what you're interested in the most. A fairly complete understanding of all of this comes with a BS degree in computer science or computer engineering, but many things are quite understandable to a motivated person in your position.

Mr Fooz
Neither an understanding of assembly nor electronics is necessary for writing a high-level language (although they can certainly help). For example, a lot of recently-created languages run in the JVM: http://en.wikipedia.org/wiki/List_of_JVM_languages
Frank Farmer
Although these are fine things to learn, except for the first none of these things seem necessary for writing a compiler. Even the first isn't needed if one uses LLVM or similar technology.
ergosys
'high-level' wasn't specified in the question
Greg Domjan
Plus he also said “ you might want to “. It’s not that he has.
Martín Marconcini
"Compiler" wasn't specified in the question. He said he wants to create a new language. When designing a new language, typically a machine-code compiler is not the first implementation.
Potatoswatter
+6  A: 

Yup! It's definitely possible. Others have mentioned the Dragon Book, but there is also plenty of information online. llvm, for example, has a tutorial on implementing a programming language: http://llvm.org/docs/tutorial/

Niki Yoshiuchi
Ugh, I have professionally written several compilers for small domain-specific languages, and I recently did my first LLVM project and found the learning curve very very steep. Surely for a student it would be better to make a very tiny toy language and write their own simple recursive descent compiler and bytecode interpreter, rather than try to understand all the industrial-strength compiler concepts you need to make use of LLVM.
Larry Gritz
@Larry Gritz: depend if you are interested in writing the compiler or designing the language. If you contend yourself with generating llvm assembly I think it could be quite simple (once you have generated your AST), it doesn't mean you shouldn't read a good book though.
Matthieu M.
+3  A: 

If you know C -- it sounds like you do -- grab a used copy of this ancient book: http://www.amazon.com/Craft-Take-Charge-Programming-Book-Disk/dp/0078818826

In it there's a chapter where the author creates a "C" interpreter, in C. It's not academically serious like the Dragon book would be, but I remember it being pretty simple, very practical and easy to follow, and since you're just getting started, it would be an awesome introduction to the ideas of a "grammar" for languages, and "tokenizing" a program.

It would be a perfect place for you to start. Also, at $0.01 for a used copy, cheaper than the Dragon Book. ;)

quixoto
+7  A: 

Yes it's possible to create your own language. Take a look at compiler compilers. Or the source code to some scripting languages if you dare. Some useful tools are yacc and bison and lexx.

Others have mentioned the dragon book. We used a book that I think was called "compiler theory and practice" back in my university days.

It's not necessary to learn assembler to write a language. For example, Javascript runs in something called an interpreter which is an application that executes javascript files. In thise case, the interpreter is usually built into the browser.

The easiest starting program language might be to write a simple text based calculator. i.e. taking a text file, run through it and perform the calculations. You could write that in C++ very easily.

My first language for a college project was a language defined in BNF given to us. We then had to write a parser which parsed it into a tree structure in memory and then into something called 3 address code (which is assembler like). You could quite easily turn 3 address code into either real assembler or write an interpreter for that.

Matt H
+1 for starting with writing a calculator. I would however try to read something like the Dragon Book and use a compiler compiler such as Bison or ANTLR.
Andre Holzner
+3  A: 

Start with creating a parser. Read up on EBNF grammars. This will answer your question about how the computer can read code. This is a very advanced topic, so don't expect too much of yourself, but have fun. Some resources I've used for this are bison, flex, and PLY.

Gary
+32  A: 

"Every now and then I feel a temptation to design a programming language but then I just lie down until it goes away." — L. Peter Deutsch

EDIT (for those who crave context):

"[L. Peter Deutsch] also wrote the PDP-1 Lisp 1.5 implementation, Basic PDP-1 LISP, 'while still in short pants' between the age of 12-15 years old."

anthony
David Thomas
thanks for the link. i wonder if my life would have been better or worse had i read "Coders at Work" when i was 13...
anthony
I could say the exact same thing. I also do this with "big space game" and "mmo".
Nick Bedford
Thomas Matthews
This advice would be right on if the question was asked by a professional language developer.
Larry Gritz
+1 for making me laugh... At 13, I was using my computer *just* to play games.. i think it was the good ol' NFS... :)
liaK
+1  A: 

If you want a really general (but very well written) introduction to this topic -- computing fundamentals -- I highly recommend a book titled Code by Charles Petzold. He explains a number of topics you are interest and from there you can decide what you want to create yourself.

Ulysses
+1  A: 

Check out this book, The Elements of Computing Systems: Building a Modern Computer from First Principles it takes you step by step through several aspects of designing a computer language, a compiler, a vm, the assembler, and the computer. I think this could help you answer some of your questions.

cirons42
+4  A: 

I really recommend Programming Language Pragmatics. It's a great book that takes you all the way from what a language is through how compilers work and creating your own. It's a bit more accessible than the Dragon Book and explains how things work before jumping in headfirst.

Rohan Singh
+2  A: 

Yes! Getting interested in compilers was my hook into professional CS (previously I'd been on a route to EE, and only formally switched sides in college), it's a great way to learn a TON about a wide range of computer science topics. You're a bit younger (I was in high school when I started fooling around with parsers and interpreters), but there's a whole lot more information at your fingertips these days.

Start small: Design the tiniest language you can possibly think of -- start with nothing more than a simple math calculator that allows variable assignment and substitution. When you get adventurous, try adding "if" or loops. Forget arcane tools like lex and yacc, try writing a simple recursive descent parser by hand, maybe convert to simple bytecodes and write an interpreter for it (avoid all the hard parts of understanding assembly for a particular machine, register allocation, etc.). You'll learn a tremendous amount just with this project.

Like others, I recommend the Dragon book (1986 edition, I don't like the new one, frankly).

I'll add that for your other projects, I recommending using C or C++, ditch PHP, not because I'm a language bigot, but just because I think that working through the difficulties in C/C++ will teach you a lot more about underlying machine architecture and compiler issues.

(Note: if you were a professional, the advice would be NOT to create a new language. That's almost never the right solution. But as a project for learning and exploration, it's fantastic.)

Larry Gritz