Re:SmallerC – Small, Simple, Self-Compiling, Single Pass C C...
by qznc on Saturday October 14, 2017 @03:03AM
(#15471114)
I think C is fine for a simple compiler. Why are algebraic data types so relevant? Pattern matching is nice, because switch statements plus unpacking is more verbose.
For big optimizing compilers you appreciate abstractions like C++ enables. for example, a data flow Analysis framework.
Re:SmallerC – Small, Simple, Self-Compiling, Single Pass C C...
by jmite on Saturday October 14, 2017 @12:15PM
(#15472797)
Algebraic data is just so perfectly suited to abstract syntax. It's clearly possible to model an AST in C, but not to do it in an ergonomic z typesafe way.
Even (cough) C++ is better than C for this use case, e.g. comparing LLVM vs. GCC. But C++ has problems too though -- the TableGen language in LLVM is an interesting example of why a big C++ project like LLVM/Clang doesn't want all its logic/specification in C++. They really use C++ to the hilt and they still want/need a DSL.
Other interesting options would be Swift, Rust, OCaml, or Go. Swift, Rust, and OCaml all have algebraic data types.
I guess choosing something other than C or C++ is a little unusual because there is the tendency to self-host. The Rust, OCaml, and Go compilers are written in Rust, OCaml, and Go, respectively. I'm pretty sure Swift is a lot of C++, but that will probably change as times goes on.