How to Start making a compiler based on c? This is our assignment make a compiler then make it using the c programming language... can anybody help me??
How to Start making a compiler based on c? This is our assignment make a compiler then make it using the c programming language... can anybody help me??
The assignment makes it sound like "Making a compiler" is like a Hello World program.
It is one of the most complicated topics in programming.
Read some good books on it ..(there are plenty) , if you have a good grasp of C and Computer Science in general(If you don't, you're taking the wrong course).
I know better on c but can you tell me where do i start?? In fact it is just a simple compiler that only requires these data types: int, char, float, bool. A selection structure of "if" only and "< > ==" and the basic arithmetic operations...
Here's a tutorial on how to build a compiler.
Let's Build a Compiler
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Warning from http://compilers.iecc.com/crenshaw/tutor1.txt
I will be using Turbo Pascal
4.0 on a PC clone.
Good - it means they simply can't copy/paste an answer from a tutorial.
Sure they probably won't know Pascal well enough to be able to write it - but that isn't the point.
Anyone with any programming experience should be able to make a pretty reasonable stab at getting the general idea of what's going on, especially with a block of tutorial text describing what is going on.
Eg, guess what this does....
If they can't translate from a student friendly language like Pascal (it was originally invented as a teaching language after all), they should probably just give up.Code:var i: Integer; begin for i := 1 to 10 do begin Writeln('Hello'); Writeln('This is loop ',i); end; end.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I just read through the first two chapters....(..Thanks for the link..)Originally Posted by Salem
The author doesn't go into much description though, instead insisting on showing examples with code, the purpose of which wasn't obvious to me at all.(Though I looked up a simple Pascal tutorial just now, after which it is fairly simple )
Crenshaw actually has one of the best tutorials I have seen on the subject. He doesn't bother with the theory, just the code, as he points out in his introduction. His presentation of the subject matter, IMO, is done quite well and provides an actual "real world" example vice just talking about compiler theory for 500 pages with very little code produced.
@OP: This is a BS question for a thread. I think you need to explain better what it is your assigment is, perhaps you have misunderstood the requirements. If your teacher actually has told you that you have to make a compiler, and not an interpreter/some sort of shell, and this is your question; give up now and save yourself the hassle.
Writing a compiler is what I would expect to be the outcome of a whole semester class, and you would then learn where to start by paying attention in class.
Probably I would start with making sure I have good test cases and test harness, including both input code and the exact output code you expect your compiler to produce. This would mean manually compiling your test cases.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
Actually it is an interpreter using only these data types: int, char, float, bool...
a selection structure: if
relational operation: '>' '<' '=='
and arithmetic operation: +,-,*,/,%
My teacher said make it using c language... and then the output is like an editor in C and can compile simple porgrams...
..So make it...Originally Posted by niwradz
Nobody said otherwise..
By defining the grammar.Originally Posted by niwradz
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
> I said it already where do i start???
The same place you started for all the other assignments.
- read your course notes
- read the course book
- read some online tutorials (use google to find more)
You must be well past the "hello world" stage, otherwise you would not be being asked to do this particular assignment. You must at least be able to open a text file and read it.
That is unless you've just coasted through the course up until now, just submitting "found" code.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
If you do not know what Laser is saying then you have not been paying attention to your courses up to date. This is a semester level project but not year 1 for comp sci. If you have gotten this far and still don't understand where you are suppose to start then you deserve to fail this course. Go back through your course notes and book as Salem has suggested then come back here with specific questions. No one here is going to hand you the code to do this.