# LL1 parser

## Basic idea

Top-down, predictive parser using a single token of lookahead. Either hand-coded as recursive-descent functions, or table-driven from a FIRST/FOLLOW analysis. Fast and gives great error messages — at the price of grammar restrictions (no left recursion, no common prefixes).

## Key formulas

* Parse time: $O(n)$, space $O(\text{depth})$ for recursive descent.
* Predict set: $\mathrm{PREDICT}(A \to \alpha) = \mathrm{FIRST}(\alpha) \cup (\mathrm{FOLLOW}(A)$ if $\varepsilon \in \mathrm{FIRST}(\alpha))$.
* LL(1) condition: predict sets of alternatives for the same nonterminal are pairwise disjoint.

Two types: hand coded recursive descent which is essentially LL(\*) or table driven.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://isubasinghe.gitbook.io/isithas-wiki/computer_science/programming_language_theory/parsers/ll1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
