Close

Results 1 to 10 of 10
  1. #1
    DF VIP Member Mario87's Avatar
    Join Date
    Jan 2002
    Location
    Sunny Aberdeen
    Posts
    7,228
    Thanks
    115
    Thanked:        92
    Karma Level
    691

    Default Programming a Compiler in C/C++...

    Does anyone know of any good books and/or e-books for programming a compiler in C/C++?

    Cheers!

  2. #2
    DF VIP Member /dev/null's Avatar
    Join Date
    Feb 2004
    Location
    Behind You
    Posts
    2,952
    Thanks
    0
    Thanked:        0
    Karma Level
    451

    Default Re: Programming a Compiler in C/C++...

    Hi,
    For what language are you trying to program a compiler for?
    Are you planning on writing your own lexial analyser etc, or are you planning on using third party tools such as lex/yacc?
    Are you looking for information on how to program a compiler in general (ie, the "workings" behind a compiler) or just how to implement an idea you already have but in c/c++?
    You may find this book useful for the former case... Right-Click-->Save as
    Last edited by /dev/null; 26th October 2006 at 01:24 PM.

  3. #3
    DF VIP Member nitelife's Avatar
    Join Date
    Nov 2002
    Location
    Reading, Berks
    Posts
    1,170
    Thanks
    115
    Thanked:        13
    Karma Level
    337

    Default Re: Programming a Compiler in C/C++...

    These all have high reviews on amazon:

    Compilers: Principles, Techniques and Tools (Paperback)
    by Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman has high reviews on amazon

    Modern Compiler Design (World Wide Series in Computer Science) (Paperback)
    by D. Grune, H. Bal, C. Jacobs, K. Langendoen

    Advanced Compiler Design and Implementation (Hardcover)
    by Steven S. Muchnick

    Modern Compiler Implementation in C (Paperback)
    by Andrew W. Appel, Maia Ginsburg

    This has no reviews but looks good:
    Build Your Own .Net Language and Compiler (Paperback)
    by Edward G. Nilges

    Search for "compiler"...

    Are you just taking an interest? or are you planning on taking over the world?

  4. #4
    DF VIP Member /dev/null's Avatar
    Join Date
    Feb 2004
    Location
    Behind You
    Posts
    2,952
    Thanks
    0
    Thanked:        0
    Karma Level
    451

    Default Re: Programming a Compiler in C/C++...

    In addition, my university lecturer who teaches the compilers course recommends the following:

    Aho, A. V. Sethi, R. and Ullman, J. D., compilers, Principles, techniques and Tools (ISBN 0-201-101-947), Addison Wesley 1985

    Keith Cooper, Linda Torczon, "Engineering a Compiler", Morgan Kaufmann, 2003.

    Further Reading

    Hunter, R., The Essence of Compilers, Prentice Hall, 1999

    Wilhelm, R. and Maurer, D., Compiler Design, Addison Wesley 1995

    Grune, Bal, Jacobs, Langendoen, Modern Compiler Design, Wiley, 2001

  5. #5
    DF VIP Member Mario87's Avatar
    Join Date
    Jan 2002
    Location
    Sunny Aberdeen
    Posts
    7,228
    Thanks
    115
    Thanked:        92
    Karma Level
    691

    Default Re: Programming a Compiler in C/C++...

    Hey guys! Cheers for all the replies! This is for my uni assignment! In the next seven weeks my lecturer wants me to program a compiler in C or C++!

    Basically I need a book that explains the ideas behind a compiler, and how to implement those ideas into an actual working compiler!

    My lecturer has been a bit vaugue as to what he actually wants, because his definition of a compiler is a "program that converts from one language to another" (like from C/C++ to machine code), he said that he would even class a web browser as a compiler, because it converts HTML into text and pictures!

    Any help much appreciated!

  6. #6
    DF VIP Member /dev/null's Avatar
    Join Date
    Feb 2004
    Location
    Behind You
    Posts
    2,952
    Thanks
    0
    Thanked:        0
    Karma Level
    451

    Default Re: Programming a Compiler in C/C++...

    hmmm... sounds a bit of a strange assignment to me...! He's not given you any language to "compile" (or interperet), not told you how he wants you to do it, what he is expecting, whether you are allowed to use code generation tools like lex/yacc....

    I'd personally ask him for some more details and a better spec if I were you!

  7. #7
    DF VIP Member Mario87's Avatar
    Join Date
    Jan 2002
    Location
    Sunny Aberdeen
    Posts
    7,228
    Thanks
    115
    Thanked:        92
    Karma Level
    691

    Default Re: Programming a Compiler in C/C++...

    Will do m8! Will get back to you as soon as I find out exactly what needs to be done!

  8. #8
    DF VIP Member Mario87's Avatar
    Join Date
    Jan 2002
    Location
    Sunny Aberdeen
    Posts
    7,228
    Thanks
    115
    Thanked:        92
    Karma Level
    691

    Default Re: Programming a Compiler in C/C++...

    Right, just had a look online, and these are the slides that tells us about the assignment!

    Assessment

    •Write a compiler in C or C++ that reads C source code and compiles main to Three Address Code (TAC) implemented in C.

    • Deadline - Monday of week 10. That is, 12 December, 2006.

    • Submit a hard copy of a word processed report to the Student Information Office by the deadline.

    • The report should explain the design of your compiler, give the input and output of example runs, and contain the full source code of the compiler.
    Note
    There are two different ways to write a compiler.

    • Specify the language in a right-recursive grammar and translate this by hand to recursive subroutines that implement the lexical analyser, parser, and code generator.

    • Specify the language in a left-recursive grammar and use a compiler generator to generate the lexical analyser and parser from the grammar. The grammar will be augmented with hand-written code that is used to generate a code generator.

    • There is an algorithm for converting left-recursive grammars to right-recursive ones and vice versa.
    Last edited by Mario87; 26th October 2006 at 05:27 PM.

  9. #9
    DF VIP Member /dev/null's Avatar
    Join Date
    Feb 2004
    Location
    Behind You
    Posts
    2,952
    Thanks
    0
    Thanked:        0
    Karma Level
    451

    Default Re: Programming a Compiler in C/C++...

    Hi,
    Have you drawn up your grammar yet? I'd personally go for the second option and use lex/yacc to implement it (design your grammar by hand first), however if you haven't used them before you may want to do an alternate option.
    It seems a bit "harsh" asking you to create a compiler for c though, lol! - Rather you than me!!!
    Perhaps they are not asking for you to create it that will parse the entire semantics of c, maybe just a smaller set?

    Either way, you will first need to design your grammar (you may be able to "borrow" it from the www or the www however I never said that! ). What approach you take to this will determine how you undertake the next part (according to the "notes" above).
    Last edited by /dev/null; 26th October 2006 at 06:12 PM.

  10. #10
    DF VIP Member OrangeJuicey's Avatar
    Join Date
    Aug 2006
    Location
    London
    Posts
    1,283
    Thanks
    1
    Thanked:        4
    Karma Level
    289

    Default Re: Programming a Compiler in C/C++...

    I don't think he wants you to implement a programming language compiler becuase thats what i'm doing for my uni project and there are 6 of us doing it together. The first thing is you'll need your base language which for you is C/C++ i'm using Haskell(50x more powerful than C hence so can my language be 50x more powerful than C). Then you'll need some assembler language. I'm using Pentium Assembler on my project.

    The basic layout is
    Text --> Read Source Prog --Parse--> Tree --Traversal--> Result

    The traversal is done in C/C++ and reads from the data tree

    Ok so i'm not got very far so far, i'm made a language Zero which can have ints Add and Multiply

    data Term = Con Int | Add Term Term | Mul Term Term

    This ^^ is then defined in the Traversal (e.g eval ::Term --> Int)

    this can then be made into a tree. e.g
    13+4*(2+3)
    2::Term
    2 is Con2
    2+3 Add(con2)(con3)

    Add(con3)(Mul (Con4)(Add(con2)(con3)) <-- this is the tree but its hard to represent.

    hope some of this helps you, its pretty hard to write down lol take ez.

Similar Threads

  1. Good Programming Magazine/E-zine/Community?
    By Cavefish in forum Programming
    Replies: 2
    Last Post: 20th December 2002, 01:42 PM
  2. psx programming unit
    By Portishead in forum Sony Consoles
    Replies: 0
    Last Post: 23rd October 2002, 03:24 AM
  3. Programming keyboard
    By trippie in forum The Dog and Duck
    Replies: 1
    Last Post: 24th September 2002, 03:28 AM
  4. programming help wanted
    By frankie413 in forum Digital Satellite TV
    Replies: 1
    Last Post: 9th September 2002, 11:31 AM

Social Networking Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •