TSToolSphere

LL(1) Parser

engineering100% Client-Side

Compute FIRST and FOLLOW sets, remove left recursion, build the LL(1) parsing table, detect conflicts and trace a parse step by step.

LL(1) Parser: FIRST & FOLLOW Calculator

Paste a grammar to get FIRST and FOLLOW sets, the LL(1) parsing table and a step-by-step parse.

Grammar (one rule per line)

Write rules as A -> α | β with spaces between symbols; use ε (or eps) for the empty string. Symbols that appear on a left-hand side are non-terminals, everything else is a terminal, and the first rule's left-hand side is the start symbol.

FIRST & FOLLOW sets

Non-terminalFIRSTFOLLOW
E{ (, id }{ $, ) }
E'{ +, ε }{ $, ) }
T{ (, id }{ +, $, ) }
T'{ *, ε }{ +, $, ) }
F{ (, id }{ *, +, $, ) }

LL(1) check

No conflicts: this grammar is LL(1).

LL(1) parsing table

Non-terminal+*()id$
EE → T E'E → T E'
E'E' → + T E'E' → εE' → ε
TT → F T'T → F T'
T'T' → εT' → * F T'T' → εT' → ε
FF → ( E )F → id

Parse an input string

Accepted in 17 steps

StepStackInputAction
1$ Eid + id * id $Output E → T E'
2$ E' Tid + id * id $Output T → F T'
3$ E' T' Fid + id * id $Output F → id
4$ E' T' idid + id * id $Match id
5$ E' T'+ id * id $Output T' → ε
6$ E'+ id * id $Output E' → + T E'
7$ E' T ++ id * id $Match +
8$ E' Tid * id $Output T → F T'
9$ E' T' Fid * id $Output F → id
10$ E' T' idid * id $Match id
11$ E' T'* id $Output T' → * F T'
12$ E' T' F ** id $Match *
13$ E' T' Fid $Output F → id
14$ E' T' idid $Match id
15$ E' T'$Output T' → ε
16$ E'$Output E' → ε
17$$Accept

About LL(1) Parser

FIRST, FOLLOW, and Why LL(1) Parsing Needs Both

An LL(1) parser decides which grammar production to apply by looking at just one token of lookahead — which only works if that single token unambiguously identifies the correct production. FIRST sets (which terminal symbols can begin a string derived from a given non-terminal) and FOLLOW sets (which terminals can immediately follow a non-terminal in some derivation) are the machinery that makes this one-token decision possible, by predicting exactly what token to expect next at each point in a derivation.

A grammar is genuinely LL(1)-parseable only if, for every non-terminal with multiple productions, their FIRST sets don't overlap (with FOLLOW sets brought in for productions that can derive the empty string) — if they do overlap, one token of lookahead isn't enough to decide which production applies, and the grammar needs restructuring (or a more powerful parsing strategy) before an LL(1) parser can handle it.

Building the parsing table from FIRST/FOLLOW sets, then tracing a token string through the parser's stack step by step, is exactly how compiler courses demonstrate whether a given grammar is well-behaved for simple top-down parsing — a check that's tedious but mechanical by hand, and easy to get wrong on a non-trivial grammar.

Worked example

For the classic expression grammar E → T E', E' → + T E' | ε, T → F T', T' → * F T' | ε, F → ( E ) | id:

  • FIRST(E) = FIRST(T) = FIRST(F) = { (, id }, FIRST(E') = { +, ε } and FIRST(T') = { *, ε }
  • FOLLOW(E) = FOLLOW(E') = { ), $ }, FOLLOW(T) = FOLLOW(T') = { +, ), $ } and FOLLOW(F) = { *, +, ), $ }

The parsing table has no conflicts, so the grammar is LL(1), and id + id * id is accepted. This grammar is the left-recursion-free form of E → E + T | T, T → T * F | F, F → ( E ) | id, which is exactly what the Remove left recursion button produces from it.

Frequently Asked Questions

Help Us Improve LL(1) Parser

Did you find this tool helpful? Tell us how we can make it even better, or report a bug or request a new feature in under 1 minute.

Submit Feedback