What is Context Free Grammar ?
What is Context Free Grammar ?
In general, a context-free grammar G is a quadruple(4-tuple) (V,
Σ(T), R(P), S) where,
V
is a set of variables,
Σ set of terminal symbols and subset of V,
R is a set of rules called as production rules (V − Σ) × V*,
S is a start symbol V − Σ.
(Nonterminals are usually represented by capital letters and terminals by lower case letters.)
Every CFG production rule can be written as S→a, where
S is a unique nonterminal symbol and a is some combination of non-terminals or
production rules.
For example, the following is context-free grammar, as is any combination
of the rules in isolation.
Rule 1: S→aSa
Rule 2: S→bSb
Rule 3: S→ϵ
(Epsilon is the empty string.)
The following are examples of strings that may be constructed by this
grammar: that is, members of the CFL, L, described by this CFG, and the
corresponding derivations.
aa: Rule 1, followed by Rule 3
aabb: Rule 1, followed by Rule 2, followed by Rule
3.
The empty string (Rule 3)
The grammar G, with productions
S → abB,
A → aaBb,
B → bbAa,
A → λ,
is context-free. We leave it to the reader to show
that
L (G) = {ab (b b a a) n b
b a (b a) n : n ≥ 0}
Context-free grammars are used in compilers and in particular for parsing,
taking a string-based program, and figuring out what it means. Typically, CFGs
are used to define the high-level structure of a programming language.
Click here to have Examples based on Context-Free Grammar
What are the applications of context-free grammar?
- A context-free grammar is used as the basis for compiler design and implementation.
- Context-free grammars are used as specification mechanisms for programming languages
- Designers of compilers use such grammars to implement compiler’s components, such as scanners, parsers, code generators, code synthesizers.
- The implementation of almost any programming language is preceded by a context-free grammar that specifies it.
Also, Study about:
- Mealy Machine
- Moore Machine
- Rice Theorem
- Brief about Turing Machine
- Multi Dimension Turing Machine
- Multiple Turing Machine
- Parikh Theorem in TOC
- Parse Tree or Derivation Tree
- What do you Understand by Derivation
- MyHill Nerode Theorem
- Minimize Myhill Nerode Theorem
- Push Down Automata
- Know Where we use Automata
- What do you understand by Derivation of Grammar
- What is Context-free Grammar
- Example based on CFG
- Regular Expression in TOC
- What is Two-way infinite Turing machine?
- Example to generate Parse tree from the given grammar
Also Read, some interview tips
- Why Should I Hire You?
- What are your weaknesses?
- What are your greatest strengths?
- Tell me about yourself.
- What's the reason behind leaving your current position at your company?
- Do You Know how the power of Keywords impacts on Resume?
- Top 8 Proofreading Tips and Techniques in 2022.
- Top Ten Technical Resume Writing Tips in 2022.
- Tips for your resume before you get entry to Job Market
- What Questions you can ask HR during the Interview.
- How to make an impressive resume?
- Best Resume writing Technique.
- What Questions you can ask HR during the Interview.
No comments