# Earley parser

## Basic idea

Bottom-up chart parser that handles *any* context-free grammar — including ambiguous and left-recursive ones. Maintains a set of "items" (dotted productions with a start index) per input position.

## Key formulas

* General CFG: $O(n^3)$
* Unambiguous CFG: $O(n^2)$
* Deterministic / LR-style grammar: $O(n)$
* Memory: $O(n^2)$

Can parse all CFG's but are slow


---

# 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/earley.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.
