compiler

Thread Starter

vead

Joined Nov 24, 2011
629
hello,
I need some information If I want to create my own c compiler (like keil), Then what I need to learn
I am interested developing compiler. I know I need to learn one programming language. there are different type of language. which language should I learn

welcome for any Information
 

Papabravo

Joined Feb 24, 2006
21,226
No matter what language you learn, you're a long way from being able to write a C compiler in any language. One person, by themselves, might be able to do it in two to three years. Why bother? Certainly there are more creative things you can do. If you're bound and determined to do it anyway, start with something less ambitious, like PL0 from the book by Niklaus Wirth, "Algorithms + Data Structures = Programs". It is a simple recursive descent, one pass compiler, for a Pascal like language. This project can be done in a couple of weeks and will give you a taste of what you're in for. I seriously doubt that a one pass, recursive descent, C compiler could be constructed, but this stuff is a solid foundation for what you need to learn.

In any case, good luck

http://www.amazon.com/Algorithms-Structures-Prentice-Hall-Automatic-Computation/dp/0130224189/ref=sr_1_1?ie=UTF8&qid=1411992064&sr=8-1&keywords=Algorithms + Data Structures = Programs

A bargain at $9.97 plus shipping
 
Last edited:

sirch2

Joined Jan 21, 2013
1,037
One person, by themselves, might be able to do it in two to three years.
Whilst I agree about the "why bother" and there being better things to do, a number of so called "little languages" started out as student projects and were probably done in under a year alongside full time study. C only has around 22 statements and a handful of operators, IIRC and using something like YACC (but that could well be cheating since there is a C grammar available for YACC) to simplify the parsing, I'm guessing it could be done in a reasonable time. Linking may be another issue, I just realized that I've never really looked into how easy/hard it is to develop a linker...
 

Papabravo

Joined Feb 24, 2006
21,226
Developing a compiler is still not an undertaking for the faint hearted. I do agree with you about using "little languages" to create building blocks that can be used. C may only have 22 statements, but there is incredible variation and complexity in those statements. The challenge is to compile CORRECT code the first time and every time regardless of how complicated the construction. I estimate design at 30%, coding at 10% , and debug at 60% of the effort. A linker is not necessary, if the compiler output is assembly language and there is an available assembler and linker. The complexity of doing a linker depends a great deal on the target architecture.
 

sirch2

Joined Jan 21, 2013
1,037
Papabravo - is the design not already done in the C language specification? Anyway I don't want to get into a big debate over it and I agree that it may well take the OP a long time...

To the OP, a couple of ideas, there are a number of open source C compilers out there (Google it) it may be worth reviewing the code for those.

Another easier way to get into compiler design may be to write something like a Forth interpreter, that would get you going quicker and again there are open source examples out there. How about re-targetting a Forth compiler/interpreter to PIC or ATMega?
 

Thread Starter

vead

Joined Nov 24, 2011
629
I have little bit knowledge about c language , and data structure , algorithm
c compiler component
*file management
*text editor
*debugger
*linker
can I start with small part like text editor , debugger ?
what do you think If i write code for small part and then I will use whole component in compiler ?
example - text editor does following things
write text
edit text
text may be one or multiple passes
text should be line,keywords

*debugger
read the code
do syntax analyses
check the instruction ,comment error

I know that's not enough but I think I have to start with small part.
 

sirch2

Joined Jan 21, 2013
1,037
A compiler is an executable that takes files (usually in ASCII format) containing a program in human readable format and converts them to binary "machine code" instructions that the Processor can execute. That is all it does.

An IDE is a wrapper around a compiler/linker/debugger that aims to make using these tools easier and usually includes a text editor and other tools.
 

MrChips

Joined Oct 2, 2009
30,821
Keil, IAR EW, Attolic, Metrowerks, AVR Studio, Visual BASIC, Visual C, Visual Studio, Code Composer Studio etc. etc are all IDE.

They are not simply compilers.

What is an IDE?

An IDE is a text editor + compiler + assembler + linker + loader + debugger + project manager + file manager + library manager + revision control system, etc. etc.
 

vpoko

Joined Jan 5, 2012
267
Also, many IDE's (like Eclipse, NetBeans, etc) can work with any language, including ones that didn't exist when the IDE was created. If your goal is creating your own language, you don't need to create your own IDE. In fact, I don't think it's possible for one person to create an IDE as fully-featured as ones already out there. If you're interested in seeing what it takes, download the source code for Eclipse. Likewise, take a look at the source code for the GCC compiler to see what that involves. Neither of these are beginner (or even intermediate) projects.
 

Papabravo

Joined Feb 24, 2006
21,226
Papabravo - is the design not already done in the C language specification? ...
Not in my opinion. The language specification defines "sentences" in the language that are syntactically correct, and it associates semantics or meaning to those constructs. There are two general ways to design a parser called "top down" and "bottom up". Within those two categories are a number of sub-choices including how many symbols you want to look at at one time and how much context you need to to decide what is going on. Error recovery and restarting the process when there is an error is another huge issue.

I agree with you on writing interpreters as another possible stepping stone. It is hard to beat:
"Threaded Interpretive Languages" by Loeliger

http://www.amazon.com/Threaded-Inte...=UTF8&qid=1412029833&sr=8-1&keywords=Loeliger

A bargain for $16.38
 

takao21203

Joined Apr 28, 2012
3,702
I guess you'd have great difficulty even to make or even to compile a simple BASIC Interpreter.

BASIC Interpreter:

-Text editor
-File management
-Tokenizer
-Runtime engine (i.E. the interpreter)
-Single step mode (a primitive debugger)

You need perfect grasp of english language and grammar before you try to make a BASIC Interpreter or even a compiler not to speak of an IDE.

How about to make a BASIC program first by yourself?

Draw a circle by pixels, and rotate it, and color it differently, and rotate the colors too on a ring.

Took me an evening in QBASIC.

When you can do a program like that in one evening, you have maybe 1/2 what it takes to make a simple BASIC interpreter. Then you have maybe 1/3 what it takes to make a very simple C- like compiler.

With consideration of all the threads you make, I'd recommend a study of BCPL, and dont become confused by it- admittedly, it is kindof confusing how a BCPL Interpreter actually works.

That was the guy! He'd know how to make a compiler.
 

ActivePower

Joined Mar 15, 2012
155
Jack Crenshaw's 'Let's Build a Compiler' is an good reference too. It is short and gets into the fun stuff fairly quickly. It is written in Pascal IIRC but it should probably be fairly easy to parse (pun not intended) and recreate in a modern language like Python. Other recommendation is Niklaus Wirth's compiler construction book (as mentioned elsewhere in this thread) besides the Dragon Book for a more technical description.
 
Top