3 ms·
Quote from Niklaus Wirth: > ... I would feel utterly incapable of constructing a good compiler for Ada. Source: The School of Niklaus Wirth - "The Art of Simp
by hwj 8y ago
Quote from Niklaus Wirth:
> ... I would feel utterly incapable of constructing a good compiler for Ada.
Source: The School of Niklaus Wirth - "The Art of Simplicity"
- thesz 8y agoIn one of my job I took a part of creating a compiler for VHDL, which is superset of some old version of Ada (and diverging from it). Here's list of problems one would encounter in creating a compiler for VHDL: Floating keywords. The versions of VHDL introduce and then drop keywords from keyword list. A custom lexer would solve that and our solution was exactly a custom lexer. Overuse of single quote. The single quote starts character literal (as in '1'), the use of attribute (SOMETHING'ATTRIBUTE_OF(args)) and the use of value constructor (RECORD_TYPE'(arg1, arg2, arg3)). In the latter case it is possible to have something like REC'('1',2, true) which, as you can see, clashes with the character literal rule if lexer is not context-aware. We used separate lexer and parser with the fixed direction of data flow and we skipped that concrete pecularity. Context-aware lexers are not unheard of for, I would guess, 20 years now and actually quite easy to construct right now. You can use monadic parser combinators which are breeze to work with in right language. I specifically implemented VHDL-AMS parser in Haskell and from start to complete parse of full test suite I spent about a month, part time. BTW, it was faster than ANTLR version in Java. Other than these things outlined above, VHDL is more or less straightforward language, with complexity equal to Pascal. All these pesky attributes, interesting FOR loops, etc, can easily be translated into SSA and compiled and executed efficiently. And, to conclude, Wirth was right. It was not possible to built good compiler for Ada in 1980-s. You are, on contrary, not right in your quote - it is quite possible to build good compiler for Ada (and pretty much anything) now, with wide range of goodness, from good error messages to optimizing away constants that are created with functions on arrays.