Total Pageviews

Thursday, September 10, 2026

FIRST AND FOLLOW LL(1) STEP BY STEP

🔤 FIRST & FOLLOW Calculator

15 Grammar Examples • Step-by-Step • Animated Learning

📖 FIRST and FOLLOW — First Understand

🔵 FIRST

FIRST(X) is the set of terminals that can appear at the beginning of strings derived from X.

FIRST(X) = Possible starting terminals

🟣 FOLLOW

FOLLOW(A) is the set of terminals that can appear immediately after the non-terminal A.

FOLLOW(A) = Symbols occurring after A

⚪ Epsilon

The symbol ε means the empty string. If a symbol can generate ε, we may need to examine the next symbol.

💲 End Marker

The symbol $ represents the end of the input. For the start symbol:

$ ∈ FOLLOW(Start Symbol)

📚 Important Rules

FIRST Rule 1

If X is a terminal:

FIRST(X) = {X}
FIRST Rule 2

For A → aα:

a ∈ FIRST(A)
FOLLOW Rule 1

For the start symbol:

$ ∈ FOLLOW(S)
FOLLOW Rule 2

For A → αBβ:

FIRST(β) − {ε} ⊆ FOLLOW(B)

🎓 15 Practice Examples

Example 1 of 15
Example 1

Grammar

S → aA | bB A → c B → d

🔎 Step-by-Step Calculation

✅ Final FIRST & FOLLOW

🎬 Animated FIRST → FOLLOW Visualization

📜
Grammar
🔵
FIRST

Check ε
Press "Animate" to start
FIRST / FOLLOW

📋 15 Examples — Quick Reference

No. Grammar Type Main Concept
1 Simple Grammar Basic FIRST
2 A → a | ε Epsilon
3 S → ABC Multiple Symbols
4 S → aS | b Recursion
5 S → (S)S | ε Balanced Structure
6 Expression Grammar FIRST/FOLLOW
7 Epsilon Grammar Propagation
8 Arithmetic Grammar LL(1)
9 Assignment Terminal After NT
10 Nested Expression Nested FOLLOW
11 Multiple Epsilon Epsilon Propagation
12 Boolean Grammar Logical Operators
13 List Grammar Repeated Elements
14 Statement Grammar Parser Design
15 Complex LL(1) Complete Revision

⭐ Why FIRST and FOLLOW Are Important?

1️⃣ LL(1) Parser

FIRST and FOLLOW are fundamental for constructing LL(1) predictive parsing tables.

2️⃣ Production Selection

They help the parser select the correct production for a given input symbol.

3️⃣ ε Productions

FOLLOW helps determine when an ε-production should be selected.

4️⃣ Syntax Analysis

They are important concepts in the syntax-analysis phase of compiler design.

No comments:

Post a Comment