View Full Version : [Qustion] how to make compiler with c/c++
No2002
09-08-2004, 03:19 PM
Hello ,
i want ask if any person had lesson talk about this subject .
and how i can bulid programming language with c/c++ ?
thanks .. 8)
stuka
09-08-2004, 08:44 PM
Compiled language:
1) Define a syntax for your language.
2) Write a C/C++ program (the compiler) that takes the syntax you define and turns it into object code for the appropriate platform.
3) Write a second program (the linker) that takes the output from step 2, and links it together with any required system libraries, and puts them into an appropriate executable format for the OS.
Interpreted language:
1) Define a language syntax.
2) Write an interpreter that converts statements from the syntax into appropriate system calls for the underlying OS.
Whiteknight
09-09-2004, 10:47 AM
I think that I want to get into compiler design next. I sort of want to write my own OS, but without a compiler for that OS, and a set of libraries for it, it would be useless to start writing it. I wanted to buy a book on the subject, but i cant find anything that looks any good.
sicarius
09-09-2004, 05:46 PM
Well, there is a book called "Compilers" by Alfred Aho and others. It is commonly refered to as "The Dragon Book". That a look at it and you should understand why.
The book I used in college was "Modern Compiler Design" by Someguy Idontrecall. They are both pretty good, although the Moder Compiler Design book has a little bit more detailed content.
If you are unfamiliar with the theory of computation you should also pick up a good book on it. Michael Sipser's book is a good start, although expensive. If you find Theory of Comp a tough subject, back up a little and grab a book on basic set and or graph theory, anything claiming to be a book on discrete math should suffice.
sicarius
09-09-2004, 05:47 PM
Also, without doing all the research you should be able to kludge together a simple C compiler. C was designed to be really simple, and you can parse the C grammar in a pretty brute force way.
kryptech.net
09-09-2004, 09:11 PM
yes, I could write a C compiler if I had been programming for 12 more years... :)
sans-hubris
09-09-2004, 10:50 PM
Originally posted by kryptech.net
yes, I could write a C compiler if I had been programming for 12 more years... :) If you take out all of the syntactic sugar (http://catb.org/~esr/jargon/html/S/syntactic-sugar.html) out of C, then one should have little trouble writing a compiler for C. My professor for Compilers had us do that. It wasn't that difficult. I actually wanted to add syntactic sugar simply because it was so easy.
I would say that someone starting out should avoid trying to write a linker. Those are complex beasts.
Whiteknight
09-10-2004, 09:11 AM
I've heard of this "dragon book" and even have looked it up on amazon (it got like 4 or 5 stars). I'm no slouch in computational theory, or graphs, algebra, discreet math or logic (math is my forte) so that wont be a problem at all. I was thinking of trying to start writing my own language (which would of course require either an compiler or interpreter) or i just just do something stupid and whimsical like write a C interpreter.
whichever, since school has just started, i dont have the time or the money now to do any of those things.
sicarius
09-10-2004, 11:55 AM
Even if you are thinking of designing your own language it wouldn't be a bad idea to write a compiler for a simple language first.
C was designed in part to be easy to parse.
vBulletin® v3.7.0, Copyright ©2000-2010, Jelsoft Enterprises Ltd.