Search code examples
compiler-constructioncompiler-optimization

Which has a better application for compiler design?


It's always a daunting task to create a compiler, as most of us know. I do wonder which library has a better application for doing such, Java or C. The problem I see here is Java is substantially longer in comparison to C but has more freedom for control. C is shorter and possibly faster in compilation, but it doesn't allow for AS much control. In opinion, which one would have a better application for it?


Solution

  • Building a compiler mostly requires algorithms and data structures that are not native to the standard libraries provided by either language:

    • lexemes
    • lexical extraction by composing many regular expressions into a multi-exit state machine
    • streams of lexemes
    • Abstract Syntax Trees
    • Parsers for checking syntax and building ASTs
    • Control flow graphs
    • Control flow construction
    • ... many more...

    Pretty much to build a compiler you end up defining all of these datatypes as structs or objects, and hand-writing code to implement the ideas.

    So, neither C or Java is "easier" to use for this task.

    With some care, the C version may be faster than the equivalent Java version.

    If you really want to write a compiler quickly, you need to find a tool or framework that provides you with these structures and algorithms such as our DMS Software Reengineering Toolkit, so that you don't have to invent them all.