DIZNR INTERNATIONAL

Short trick method to find First of any grammar- Compiler Design

Short trick method to find First of any grammar- Compiler Design

https://www.gyanodhan.com/video/7B2.%20GATE%20CSEIT/Compiler%20Design/274.%20Short%20trick%20method%20to%20find%20First%20of%20any%20grammar-%20Compiler%20Design.mp4

✅ Short Trick to Find FIRST of Any Grammar (Compiler Design)

In Compiler Design, computing the FIRST set is essential for parsing table construction in LL(1) parsers. Here’s a short trick method with rules to find the FIRST set quickly and accurately.


🧠 What is FIRST?

The FIRST(X) set is the set of terminals that begin the strings derivable from symbol X (where X can be a terminal, non-terminal, or ε).


Short Trick Rules to Find FIRST

Rule 1: For terminals

If X is a terminal, then:

bash
FIRST(X) = { X }

Rule 2: For ε (epsilon)

bash
FIRST(ε) = { ε }

Rule 3: For non-terminals (A → α1 α2 α3…)

To find FIRST(A):


Shortcut Flow (for A → α):

α is… FIRST(A) contains…
Terminal a a
ε ε
Non-terminal B FIRST(B), and if ε ∈ FIRST(B), check next symbol
Sequence B C D... FIRST(B), and if ε ∈ FIRST(B), add FIRST(C), and so on

Example 1:

less
SA B
Aa | ε
Bb

Step-by-step:


Example 2:

css
S → A B
A → ε
B → ε

Then:


Example 3:

less
SA b
Ac | ε

Tips & Tricks Recap:

Go left to right in RHS
If you see a terminal, add it and stop
If you see ε, skip and check next
If all symbols can derive ε, then add ε to FIRST
Don’t forget to union all FIRSTs if multiple rules exist


Want a short PDF chart, video link, or practice problems with solutions? Let me know!

Short trick method to find First of any grammar- Compiler Design

LECTURE NOTES ON COMPILER DESIGN

compiler design lecture notes