7 ms·
As a learning experience I don't think it is a bad thing, though I would generally agree with what you're saying for any new compilers. Really though, writing a
by DSMan195276 9y ago
As a learning experience I don't think it is a bad thing, though I would generally agree with what you're saying for any new compilers. Really though, writing a new compiler doesn't really make much sense anyway. Adding a frontend to LLVM or GCC would likely give much better results (Though I can't really say which one is easier - writing a dumb compiler for a simple language isn't too hard).
It's also worth noting that his compiler creates an intermediate AST (As any sane compiler should), so it's really not that hard to write multiple backends if he wanted.
- pjmlp 9y agoNot really, for many optimization algorithms an IR like SSA is required, ASTs are not that good for that. AST are better suitable for the frontend, and even then, they only became a thing after we started having tons of RAM available.
- DSMan195276 9y agoI suppose I should clarify, I would consider a basic AST the sane choice when talking about creating toy compilers as a learning experience - as opposed to creating a compiler that just reads in text and spits out assembly without any real intermediate representation. Which, there are legitimate compilers that do that (And as you mentioned, older compilers tended to work this way as well), but for learning I don't really think you get nearly as much out of doing it that way. That said, if you want to do something more advanced or use or use something better then a basic AST, I agree go for it. But if you're actually writing the compiler for a project that isn't just a toy or as a learning experience, you're almost definitely better off just building a frontend on an existing platform like LLVM.
- pjmlp 9y agoAh, got it.