Like Tree3Likes
  • 1 Post By AndrewHunter
  • 1 Post By manasij7479
  • 1 Post By laserlight

Compiler

This is a discussion on Compiler within the C Programming forums, part of the General Programming Boards category; How to Start making a compiler based on c? This is our assignment make a compiler then make it using ...

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    13

    Unhappy Compiler

    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??

  2. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by niwradz View Post
    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).
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    Registered User
    Join Date
    Aug 2011
    Posts
    13
    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...

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,551
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    2,579
    Quote Originally Posted by Salem View Post
    Here's a tutorial on how to build a compiler.
    Let's Build a Compiler
    Warning from http://compilers.iecc.com/crenshaw/tutor1.txt
    I will be using Turbo Pascal
    4.0 on a PC clone.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,551
    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....
    Code:
    var
       i: Integer;
     
     begin
       for i := 1 to 10 do
          begin
             Writeln('Hello');
             Writeln('This is loop ',i);
          end;
    end.
    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.
    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 support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by Salem
    ...especially with a block of tutorial text describing what is going on....
    I just read through the first two chapters....(..Thanks for the link..)
    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 )
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  8. #8
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by manasij7479 View Post
    I just read through the first two chapters....(..Thanks for the link..)
    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.
    stahta01 likes this.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  9. #9
    Registered User
    Join Date
    Apr 2006
    Posts
    2,037
    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.

  10. #10
    Registered User
    Join Date
    Aug 2011
    Posts
    13
    Quote Originally Posted by AndrewHunter View Post
    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.

    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...

  11. #11
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by niwradz
    My teacher said make it using c language
    ..So make it...
    Nobody said otherwise..
    Salem likes this.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  12. #12
    Registered User
    Join Date
    Aug 2011
    Posts
    13
    Quote Originally Posted by manasij7479 View Post
    ..So make it...
    Nobody said otherwise..
    I said it already where do i start???

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,744
    Quote Originally Posted by niwradz
    where do i start?
    By defining the grammar.
    AndrewHunter likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #14
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,551
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  15. #15
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by niwradz View Post
    I said it already where do i start???
    Quote Originally Posted by laserlight View Post
    By defining the grammar.
    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.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 12-13-2010, 09:02 PM
  2. Replies: 4
    Last Post: 09-12-2009, 01:10 PM
  3. Replies: 2
    Last Post: 02-04-2008, 01:34 AM
  4. Compiler
    By Suudsu2200 in forum C++ Programming
    Replies: 2
    Last Post: 12-29-2007, 08:58 AM
  5. hp iPAQ 6300 && C compiler || C# compiler
    By xddxogm3 in forum Tech Board
    Replies: 2
    Last Post: 12-07-2004, 06:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21