Hacker News new | ask | show | jobs
by jpolitz 3471 days ago
> how it can turn recursive structures like expressions and statement blocks into linear sequences of instructions

I think this is one of the key concepts in a compiler, yet I don't think it has much to do with parsing.

Parsing (in a compiler) is the act of taking a linear sequence of characters or tokens, and turning them into a rich AST structure.

The back end of the compiler is what takes this recursive structure and flattens it out into a linear sequence of instructions that "mean" the same thing as the tree.

Parsing is critical, of course, for building a working compiler. But I think not focusing on surface syntax gets to the key recursive-to-linear insight you mention more directly!

1 comments

> and turning them into a rich AST structure.

This is not a necessary step, and is specifically not done in a lot of simpler compilers. E.g. most "Wirth-type" compilers never build an AST.

There are lots of good reasons to build ASTs if you want to do complex analysis and optimisation, and it simplifies the presentation of some things, but calling the code generator module straight from the parser in many ways makes the direction connection clearer.