0

What are the various tools that are required to build a compiler for a particular programming language, say C?

I want to know how each part of the compiler works. So, I am trying to use all the existing tools like loader, linker, etc, and combine them together to build one compiler (or can just say "compiling a compiler"). Can any one list out all such tools that are required to build a fully functional one?

kevin
  • 119
  • 5
  • compiling C++ is a pain of the highest level, start something simpler like C or a home made simpler language – ratchet freak Oct 24 '13 at 15:42
  • 2
    One typically starts with reading [Lets build a compiler](http://compilers.iecc.com/crenshaw/), the [dragon book](http://www.amazon.com/Compilers-Principles-Techniques-Alfred-Aho/dp/0201100886) and then becoming familiar with [flex and bison](http://gnuu.org/2009/09/18/writing-your-own-toy-compiler/) or [antlr](http://www.antlr.org). Then go on to more things... –  Oct 24 '13 at 15:45
  • @MichaelT I looked at that question and it is about writing a compiler, in general. But, my question is about using the various existing components to build one functional compiler. So, I guess this question is not a duplicate of that. – kevin Oct 24 '13 at 15:50
  • @kevin, meet LLVM, your new best friend. – dan_waterworth Oct 24 '13 at 15:54
  • 2
    You likely need to think more deeply about the structure of a compiler. One doesn't just take off the shelf tools and make a compiler. You design a language, write a lexer, write a parser. Thinking about linking (if at all) is very late in the process. The tools to build a compiler are the ones to make building a lexer and parser easier (rather than doing it by hand). Yacc (the predecessor of bison) stands for "Yet Another Compiler Compiler" and antlr is "ANother Tool for Language Recognition". These are the tools you use to build the tools that you will use. –  Oct 24 '13 at 15:56
  • @MichaelT I thought, it would be motivating to first build a compiler from the available tools for an existing programming language and then start writing my own code for another language. So, now it looks like there are only general purpose tools to help enhance the already written code, and not the components of a compiler itself, if im not wrong. – kevin Oct 24 '13 at 16:14
  • @kevin existing programing languages are often complex. C++ is among the most complex of the complex ones (seriously, look at the size and source of gcc to get an idea). The [clang](http://en.wikipedia.org/wiki/Clang) toolchain is more modular and might be kind of what you're thinking - but again, its very complex. One doesn't modify gcc or clang for a new language easily at all. You are much better off learning the fundamentals of language design and writing the compiler from scratch (with appropriate code generating tools). –  Oct 24 '13 at 16:19
  • The only tool that's *required* for building a compiler is ... another compiler. Tools that make writing a compiler *easier* are lexer/parser generators (lex/yacc, flex/bison, antlr). – John Bode Oct 24 '13 at 19:27

0 Answers0