- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to generate the language for context free grammar?
Problem
Generate the language for the given context free grammar.
S->0S, S-> λ
S-> A0, A->1A, A-> λ
S->000S, S-> λ
Solution
Context free grammar (CFG) is a formal grammar that is used to generate all the possible patterns of strings in a given formal language.
CFG is defined by four tuples
G=(V,T,P,S)
Where,
- T: Set of terminals (lowercase letters) symbols.
- V: Vertices or non-terminal symbols (Capital letters).
- P: Production rules.
- S: Start symbol.
Example 1
The grammar is −
S->0S, S->λ
Case 1 − S->0S
->0
Case 2 − S->0S
->00S
->00
Case 3 − S->0S
->00S
->000S
->000
Therefore, the language generated for the given grammar is −
L={e,0,00,000……..}
Example 2
The grammar is
S-> A0, A->1A, A-> λ
Case 1 − S->A0
->0
Case 2 − S->A0
->1A0 {A->1A}
->10
Case 3 − S->A0
->1A0
-> 11A0
->110
Therefore, the language generated based on given grammar is −
L={0,10,110,…………….}
Example 3
The grammar is
S->000S, S-> λ
Case 1 − S->000S
->000
Case 2 − S->000S
->000000S
->000000
Therefore, the language generated based on the given grammar is −
L={ ε,000,000000,……….}
- Related Articles
- Generate a Context-free grammar for the language L = {anbm| m≠n}?
- Generate a CNF for a given context free grammar
- Explain about CYK Algorithm for Context Free Grammar
- What is Context-Free Grammar?
- Convert the given Context free grammar to CNF
- Explain Pumping lemma for context free language
- How to convert context free grammar to push down automata?
- What are the closure properties for context free language?
- Explain about pumping lemma for context free language?
- Explain the simplification of context free grammar in TOC
- What is context free grammar? Explain with examples
- Explain removing unit productions in context free grammar
- Explain the context free language closure under concatenation?
- Explain the context free language closure under union operation?
- Give the examples of a context free language that are not regular?
