Javatpoint Logo
Javatpoint Logo

Formal grammar

  • Formal grammar is a set of rules. It is used to identify correct or incorrect strings of tokens in a language. The formal grammar is represented as G.
  • Formal grammar is used to generate all possible strings over the alphabet that is syntactically correct in the language.
  • Formal grammar is used mostly in the syntactic analysis phase (parsing) particularly during the compilation.

Formal grammar G is written as follows:


N describes a finite set of non-terminal symbols.
V describes a finite set of terminal symbols.
P describes a set of production rules
S is the start symbol.


Production rules:

Through this production we can produce some strings like: bab, baab, baaab etc.

This production describes the string of shape banab.

Formal grammar

      Fig: Formal grammar

Next TopicBNF Notation

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA