Short trick to find the given grammar is (LL1) or not in Compiler Design In Hindi.

Short trick to find the given grammar is (LL1) or not in Compiler Design In Hindi.

play-rounded-fill play-rounded-outline play-sharp-fill play-sharp-outline
pause-sharp-outline pause-sharp-fill pause-rounded-outline pause-rounded-fill
00:00

LL(1) Grammar पहचानने की Short Trick | Compiler Design (in Hindi)

LL(1) Grammar एक Top-Down Parsing तकनीक है, जिसमें Left-to-Right scanning और Leftmost derivation का उपयोग किया जाता है, और इसमें 1 Lookahead symbol होता है।



 Short Trick to Check LL(1) Grammar

किसी भी दिए गए Grammar को LL(1) Grammar है या नहीं, यह चेक करने के लिए दो मुख्य Conditions होती हैं:

Step 1: First & First Condition (No Common Terminals in First Sets)

हर Non-Terminal के लिए FIRST सेट आपस में Disjoint (अलग-अलग) होने चाहिए।
 अगर किसी एक ही Non-Terminal की दो Productions में Common Terminal आता है, तो Grammar LL(1) नहीं होगी

Example (NOT LL(1)):

SaA | aB
Ax
By

FIRST(S) = {a, a}  (Common Terminal ‘a’ है) → Not LL(1)

Step 2: First & Follow Condition (No Conflict in Parsing Table)

 अगर A → α | β और FIRST(α) ∩ FIRST(β) ≠ ∅ (Common Elements) हैं, तो Grammar LL(1) नहीं होगी
अगर ε (epsilon) FIRST में है, तो FIRST(α) ∩ FOLLOW(A) = ∅ होना चाहिए।

Example (LL(1)):

SaA | b
Ac | ε

FIRST(A) = {c, ε} और FOLLOW(A) = {b}
FIRST(A) और FOLLOW(A) में कोई Common Element नहीं हैLL(1) Grammar है।

 Quick LL(1) Checking Shortcut

Step 1: FIRST सेट में Common Terminals नहीं होने चाहिए।
Step 2: अगर ε (epsilon) है, तो FIRST और FOLLOW का Intersection Empty होना चाहिए।
Step 3: अगर कोई भी Rule इन Conditions को तोड़ता है → Grammar LL(1) नहीं है।

 Final Summary (One-Liner Trick)

अगर किसी भी Non-Terminal की FIRST Sets Overlap नहीं करती और ε होने पर FOLLOW से Confusion नहीं होता, तो Grammar LL(1) होगी!

अगर आपको कोई और Example चाहिए तो पूछ सकते हैं!

Short trick to find the given grammar is (LL1) or not in Compiler Design In Hindi.

ACADEMIC REGULATIONS COURSE STRUCTURE AND …

An Autonomous Institution

Here is a short trick to determine whether a given grammar is LL(1) or not, explained in Hindi for easy understanding. This will help especially in Compiler Design problems.


📘 LL(1) Grammar कैसे चेक करें – Short Trick (In Hindi)

✅ LL(1) Grammar का मतलब:

LL(1) grammar वो grammar होता है जिसे Left to right पढ़कर और Leftmost derivation करते हुए सिर्फ 1 lookahead symbol से parse किया जा सकता है।


🧠 Short Trick: LL(1) Grammar चेक करने की Steps

🔹 Step 1: Left Recursion न हो

अगर grammar left recursive है (जैसे A → Aα | β), तो वो LL(1) नहीं हो सकती।

Trick:
अगर किसी production की right side उसी non-terminal से शुरू होती है – तो वो left recursive है।

Example:

less
AAα | β ❌ Not LL(1)

🔹 Step 2: Common Prefix न हो (Left Factoring)

अगर किसी non-terminal के दो productions की शुरुआत एक जैसे symbols से होती है, तो उसे left factor करना पड़ेगा। जब तक common prefix है, grammar LL(1) नहीं है।

Example:

java
A → ab | ac ❌ Not LL(1)

➡ इसे बनाएं:

less
AaB
Bb | c
✅ Now LL(1) candidate

🔹 Step 3: FIRST & FOLLOW Rule चेक करें

हर non-terminal के लिए:

  • अगर A → α | β, तो
    FIRST(α) ∩ FIRST(β) = ∅ (Empty Set होना चाहिए)
    और अगर ε ∈ FIRST(α),
    तो FIRST(α) ∩ FOLLOW(A) = ∅ होना चाहिए।

👉 अगर ये दोनों conditions satisfied हैं, तो grammar LL(1) है।


🧪 Example से समझें:

Grammar:

less
SiEtS | a
Eb

Step 1: Left Recursion नहीं है → ✅

Step 2: Left Factoring required?

less
SiEtS | a → कोई common prefix नहीं → ✅

Step 3: FIRST & FOLLOW:

  • FIRST(iEtS) = {i}

  • FIRST(a) = {a}

  • No common → ✅

  • No ε involved → FOLLOW check unnecessary.

✅ Conclusion: Grammar is LL(1)


📌 Final Note:

Step क्या चेक करें? Trick
1 Left Recursion Same non-terminal से शुरू हो रहा है? ❌
2 Left Factoring दो rules की शुरुआत एक जैसी है? ❌
3 FIRST/FOLLOW Rule FIRST sets में overlap है? ❌

अगर तीनों में ✅ मिल जाए – तो Grammar LL(1) है.


अगर आप चाहें तो मैं इस trick पर एक छोटा सा visual chart या Hindi explanation video recommend कर सकता हूँ।

क्या आप चाहेंगे कि मैं कुछ और examples या practice problems भी दूँ?



Leave a Reply

Your email address will not be published. Required fields are marked *

error: