16.2 LL(1) PARSE TABLE

To simplify the parsing process, information from the npda combined with lookaheads can be stored in a table called the LL(k) Parse Table. For now we focus on k = 1, and show how to build an LL(1) Parse Table.

LL(1) Parse Table

For a context-free grammar G = (V, T, S, P), the rows of the table are labeled with AV and the columns of the table are labeled with aT∪{$}, the symbols that could be a lookahead.

To construct the LL(1) Parse Table. Let AV, and w ∈ (VT)*.

  1. For each production Aw.
    1. For each a in FIRST(w), add w to LL[A, a].
    2. If λ ∈ FIRST(w), add w to LL[A, b] for each b in FOLLOW(A).
  2. Each undefined entry is error.

Get An Introduction to Formal Languages and Automata, 7th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.