logoalt Hacker News

thaumasiotes • today at 6:29 AM • 0 replies • view on HN

> [I was] pointing out that even the Dragon Book talks about associating actions with parsing by attaching them to production rules for the parser.

But that's just a false claim. The book does no such thing. The book, in the quote you pulled, talks about attaching semantic actions to finished parser output. At that point, the parser has already completed its work. It will never do anything again. The actions will neither affect it nor be seen by it. It's kind of like saying that illustration is part of writing a novel because an artist inserts their work into the finished manuscript.

Did you not notice that your quote doesn't contain any form of the word "parse"?

In the diagram displayed in section 1.2 ("The Structure of a Compiler"; the diagram is Figure 1.6 and also Figure 1.7), we see a statement processed in turn by a lexical analyzer, a syntax analyzer, a semantic analyzer, an intermediate code generator, a code optimizer, and finally a code generator.

The book informs us explicitly that a "syntax analyzer" and a "parser" are the same thing.

But those semantic actions are associated with the intermediate code generator two steps down the pipeline. They've got nothing to do with the parser.