/    /  Compiler Design-Capabilities of Context-Free Grammar

Capabilities of Context-Free Grammar

 

The capabilities of Context free Grammars are:

  • Most of the programming languages are designed using context-free grammars.
  • An efficient parser can be easily constructed automatically if the grammar is properly written. 
  • Balanced parentheses, matching begin-end, corresponding if-then-else’s, etc. A context-free grammar is capable of describing nested structures.
  • Suitable grammars for expressions can be constructed, Using the features of associatively & precedence information.

 

Difference between Context Free Grammer and Regular Expressions

Regular Expressions:

  1. In the case of Regular expressions, Lexical Rules are very simple.
  2. It is not easy to understand the notations in Regular Expressions.
  3. Regular expressions are defined using a set of Strings.
  4. Efficient Recognizers are easy to construct from Regular Expressions.
  5. There are guidelines to be followed for Lexical analysis and Syntactical analysis in Regular Expressions.

 

Context-Free Grammar:

  1. In the case of Context-Free Grammar, Lexical Rules are difficult.
  2. It is quite simple and easy to understand the notations in Context-Free Grammer.
  3. Regular expressions are defined using a collection of productions.
  4. Efficient Recognizers are tough to construct from Context free grammars.
  5. There are no guidelines to be followed for Lexical analysis and Syntactical analysis in Context-Free Grammar.

 

Reference Link

Capabilities of Context-Free Grammar