Hello students,
In previous video we studied about context free grammar and in this video we will study notations of context free grammar (CFG).
Question is, what is it? Grammar uses a way to write symbol, that is named as notation.
Context free grammar used basically two notations, Backus normal form (BNF), Extended Backus-Naur form (EBNF)
So, first one is BNF. BNF is a notation for context-free grammars, often used to describe the syntax of languages used in computing.
Many extensions and variants of the original backus–naur notation are used including extended backus–naur form (EBNF).
Many programming languages have a BNF description in their specification. BNF is meta-language (a language describing other languages) for programming languages.
It is simply a collection of rules. We can describe CFG using BNF.
In a BNF, the set of production rules are used in which a terminal symbol on LHS is substituted recursively with a terminal or non-terminal on its RHS till the desired string is obtained.
A sting is syntactically correct if it is derived using the production rules.
Every production rule in backus-naur form has the following structure. Name may expand into expansion , the symbol means may expand in to.
In this text, name is a non-terminal symbol and expansion can be set of terminal or non-terminal symbols.
In BNF, name is surrounded by angle brackets<> whether it appears on the left- or right-hand side of the rule.
A terminal symbol is a literal surrounded by " ". A vertical bar | indicates choice.
In BNF, the expression is of the form, := "+" |
For Example, integer number : ::= |
Further digit are may expend in operator, 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7| 8 | 9
Next is EBNF, It is the extended form of BNF which make grammars more convenient and expressive.
EBNF is more concise than BNF. Anything which can be expressed in BNF is also applicable in EBNF in a more precise form. EBNF is widely used.
Some of the extended notation in EBNF, • *(The Kleene Star), means 0 or more occurrences
• + (The Kleene Cross), means 1 or more occurrences
• ?: means 0 or 1 occurrences (sometimes [ ... ] used instead)
• (): Use of parentheses for grouping
Same grammar in EBNF, := '-'? + ('.' +)?
Further := '0' | '1' | '2' | '3' | '4' | 5' | '6' | '7' | '8' | '9'
Thank you