Like Tree1Likes
  • 1 Post By MK27

Compiler design

This is a discussion on Compiler design within the General Discussions forums, part of the Community Boards category; So i'm taking a course on functional programming where we learn the ins and outs of Standard ML, today my ...

  1. #1
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964

    Compiler design

    So i'm taking a course on functional programming where we learn the ins and outs of Standard ML, today my instructor told me that one of the areas where such languages really shine is in compilers. A program that takes some very well defined input (C++ code for example), does optimizations on said input, and then translates it to assembly or bytecode or whatever. Apparently the mechanisms (pattern matching in particular) of functional programming languages such as ML and Haskell are very well suited for those tasks.

    Yet he couldn't answer me why a compiler as big and advanced as GCC was implemented in C, and not in a functional language.

    There must be a reason, enlighten me gurus.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Neo1 View Post
    Yet he couldn't answer me why a compiler as big and advanced as GCC was implemented in C, and not in a functional language.
    Here's a guess:

    - what does "well suited" mean? If it means, well suited from a programming point of view, big deal. By that standard, whatever language you are best at will be the language best suited to you writing a compiler.

    - that Haskell etc. are "well suited to the task" does not mean that C is not. Generally, when I see a newer language lauded for "what it shines at", I take that to mean: these are the things where an implementation of this language rivals the performance of some widely used implementation of C (such as GCC). Not that it is better, but that it can compete with "the best" performance wise (C itself). Performance is a very objective measure. "Well suited for programming" is much more subjective.

    - that the aspects of a compiler to which functional languages are well suited, are not the only aspects of a compiler.

    - a Haskell compiler for a language other than Haskell is going to be hamstrung by it's dependency on whatever libraries Haskell uses, which would otherwise be totally unnecessary. GCC was/is first and foremost a C compiler.

    Richard Stallman, the original author of GCC, is also a long term lisp fanatic. I've worked with RMS and he's very clear about that: he programs in either lisp or C, that's all, and really likes lisp. Yet while lisp is a functional language, GCC is in C. You could always inquire to him:

    Richard Stallman's Personal Page

    His email address is at the very bottom of the page. Be specific and succinct, he is very cantankerous but may answer your question anyway: "Why did you not use lisp for GCC? Do you consider C to be better suited to the task?"
    Last edited by MK27; 10-11-2011 at 01:37 PM.
    Yarin likes this.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    GCC was designed to be bootstrapped on systems that offer very little in the way of existing tools. On most such systems, you would expect some really bad C compiler to be around. The GCC C compiler core can be compiled by such a compiler; the rest of GCC is then compiled using this newly compiled mini-GCC.
    Requiring a decent Lisp implementation to be around is much more demanding than requiring some kind of C compiler (especially as GCC comes from a time where there wasn't really such a thing as a decent Lisp implementation on general purpose hardware), and this low barrier to entry was undoubtedly one of the reasons for GCC's success.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help in Compiler Design ?
    By Gaurav Singh in forum C Programming
    Replies: 1
    Last Post: 01-26-2011, 01:41 AM
  2. Help with yacc/compiler design/seg fault
    By trippeer in forum C Programming
    Replies: 1
    Last Post: 04-08-2005, 04:43 AM
  3. compiler design
    By c_cool in forum Tech Board
    Replies: 3
    Last Post: 11-26-2004, 01:36 AM
  4. Compiler Design... Anyone That Can Help!
    By ComputerNerd888 in forum C++ Programming
    Replies: 3
    Last Post: 09-27-2003, 10:48 AM
  5. Compiler design and implementation: token parsing
    By Unregistered in forum C Programming
    Replies: 15
    Last Post: 04-30-2002, 02:12 PM

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