Part 2 of the Compiler Design & Implementation series. Parsing is where the compiler determines the validity of an input program’s syntax. Conceptually, the parser takes the flat stream of tokens produced by the scanner and gives it structure — a tree that captures the grammatical relationships between language constructs.

What This Post Covers

The Parser’s Job

The scanner doesn’t understand structure. It sees if, (, x, >, 0, ), { as a flat sequence of tokens. The parser’s job is to recognize that this sequence forms an if-statement, with a condition and a body — and to reject sequences that don’t form valid programs.

In progress — full implementation coming soon.