Definition

First parsers for high-level programming languages. Had to work for the first recursive language, ALGOL.

Two Views

String View

Determine a leftmost derivation of the input while reading the input from left to right while looking ahead at most 1 input token. We can very easily create sets for the Inference Rules with these types of compilers.

Tree View

Beginning with the start symbol, grow a parse tree top-down in left-to-right preorder while looking ahead at most 1 token beyond the input prefix matched by the parse tree derived so far.

Expression Grammar

Constructing Parsing Tables

Easy Case

The grammar:

  • has no productions
  • every production begins with a terminal symbol

Easy to fill in the parsing table. If there are two or more productions in a given spot on the table, it is not SLL(1).

Generalizing Construction (Medium Case)

What if some production s start with non-terminal symbols? Still no productions.

For each production

  • Enter production into Table for each terminal in FIRST()

Generalizing Construction (Hard Case)

Now we need to handle productions, but this leads to two problems:

  • Where should the production go in the parsing table?
    • Insert into Table if in FOLLOW()
  • Where should go in the parsing table?

We then enter production into Table for all such that

  • and