Parsing (What Is It Good For?)
Resources:
- Crafting Interpreters (didn't like the first time, but may try again)
- Everything here
- For a high-level overview, "Parsing: A practical approach" is pretty decent, but if you're as dumb as I am you might struggle to apply some of the knowledge to computer science
- This and the subsequent video in the same chapter related themselves much more immediately and directly to computer science (for obvious reasons), and whether it was simply being re-exposed to the material or something about the way it was taught, it stuck a little better.
Don't read this to try and actually understand parsing, but:
- A "grammar" is the set of all possible "sentences" in your language.
- Dragon book 4.3: "Grammars are capable of describing most, but not all, of the syntax of programming languages." (I think they mean context-free grammars specifically? They introduce context-free grammars in chapter 2, but say they'll call them "grammars" for short)
- Read more of ch. 8
- You're trying to reconstruct a production tree (the production rules that created the "sentence" you are given)
- If your parser is written correctly, successfully reconstructing a production tree means that the sentence is valid (and, conversely, failing to reconstruct the tree means the sentence is grammatically invalid)
- What does the production tree actually get you
- I guess you're sort of translating between two languages, and can just map terminals and non-terminals to the respective representations in each?
- I have no idea if that makes any sense