Regular Expressions are capable of describing the syntax of Tokens. Any syntactic construct that can be described by Regular Expression can also be described by the Context free grammar.

**Regular Expression:**

(a|b)(a|b|01)

**Context-free grammar:**

S --> aA|bA A --> aA|bA|0A|1A|e

*e denotes epsilon.

The Context-free grammar form NFA for the Regular Expression using the following construction rules:

- For each state there is a Non-Terminal symbol.
- If state A has a transition to state B on a symbol a

- IF state A goes to state B, input symbol is e

- If A is accepting state.

- Make the start symbol of the NFA with the start symbol of the grammar.

Every Regular set can be described the Context-free grammar that’s why we are using Regular Expression. There are several reasons and they are:

Regular Expressions | Context-free grammar |
---|---|

Lexical rules are quite simple in case of Regular Expressions. | Lexical rules are difficult in case of Context free grammar. |

Notations in regular expressions are easy to understand. | Notations in Context free grammar are quite complex. |

A set of string is defined in case of Regular Expressions. | In Context free grammar the language is defined by the collection of productions. |

It is easy to construct efficient recognizer from Regular Expressions. | By using the context free grammar, it is very difficult to construct the recognizer. |

There is proper procedure for lexical and syntactical analysis in case of Regular Expressions. | There is no specific guideline for lexical and syntactic analysis in case of Context free grammar. |

Regular Expressions are most useful for describing the structure of lexical construct such as identifiers, constant etc. | Context free grammars are most useful in describing the nested chain structure or syntactic structure such as balanced parenthesis, if else etc. and these can’t be define by Regular Expression. |

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

## Recommended Posts:

- Ambiguity in Context free Grammar and Context free Languages
- Ambiguity in Context free Grammar and Context free Languages
- Regular Expressions, Regular Grammar and Regular Languages
- Converting Context Free Grammar to Chomsky Normal Form
- Converting Context Free Grammar to Greibach Normal Form
- CYK Algorithm for Context Free Grammar
- Context-sensitive Grammar (CSG) and Language (CSL)
- Difference between Thread Context Switch and Process Context Switch
- Star Height of Regular Expression and Regular Language
- Classification of Context Free Grammars
- Closure Properties of Context Free Languages
- Check if the language is Context Free or Not
- Various Properties of context free languages (CFL)
- Simplifying Context Free Grammars
- Designing Finite Automata from Regular Expression (Set 1)
- Generating regular expression from Finite Automata
- Designing Finite Automata from Regular Expression (Set 6)
- Designing Finite Automata from Regular Expression (Set 2)
- Designing Finite Automata from Regular Expression (Set 3)
- Designing Finite Automata from Regular Expression (Set 4)

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.