3 ms·
I have been weigh which is the easier language to write lexical, parser and code generation for a new programming language. Is C or C++ the idea to start? To c
by nideguy 7y ago
I have been weigh which is the easier language to write lexical, parser and code generation for a new programming language. Is C or C++ the idea to start?
To compile to machine code, not bytecode.
- davismwfl 7y agoYou'll find many compilers and parsers are written in C, it gives great portability across platforms and gives the best performance. Whether you write in C or C++ I'd think is more a matter of design choices for a parser and code gen tool. I'd probably go with C++ myself, but either is completely reasonable. You'll also be able to find lots of examples online in C/C++. Also in this case while there are some compiler differences between platforms for C/C++ they are well documented and known. If you stay in the middle of the language and don't try to use fringe features of the language or a specific compiler then you won't have any issues. People that complain about portability or GCC etc are generally using language extensions of a specific platform compiler which can make portability a pain.
- nideguy 7y agoThanks, I have seen Lex, Yacc, Bison, do they still used in the industry? Some used LLVM and some used GCC/Clang, I'm splitting over which is a better choice to build "statically typed" programming language.
- davismwfl 7y agoI'd argue it is mainly personal preference. But it goes to my point that if you stay in the middle of language features and don't use compiler language extensions it won't matter. When I set my projects up I generally use gcc/g++, but that in no means is the only correct way. Just a personal preference given the number of platforms that gcc supports, including embedded.