Explain the purpose of BNF Is EBNF usefullSolutionBNFit is k

Explain the purpose of BNF? Is EBNF usefull?

Solution

BNF-it is known as Backus Naur Form ,it is a systematic mathematical style to describe a language or you can say is a syntax for describing syntax,it was developed by John Backus to describe the syntax of the Algol 60 programming language.

its purpose is to formally define the grammer of a language,so that there is no disagreement or ambiguity as to what is allowed or what is not.it is so unambiguous that there is a lot of theory around these kinds of grammers,and one can actually mechanically build a parser for a language given a bnf grammer for it,programs which are able to perform this is known as \"compiler compilers\".YACC(Yet Another Compiler Compiler) is the most famous example for this.

BNF uses a declarative syntax that allows you to define terms via \"production rules.\" Each rule contains terms that each have more concrete rules until you get down to \"terminals,\" which are terms that we can only describe as specific characters (literal values).

this BNF is sort of like a mathematical game: you start with a symbol (called the start symbol and by convention usually named S in examples) and are then given rules for what you can replace this symbol with. The language defined by the BNF grammar is just the set of all strings you can produce by following these rules.

The rules are called production rules, and look like this:

symbol := alternative1 | alternative2

A production rule simply states that the symbol on the left-hand side of the := must be replaced by one of the alternatives on the right hand side. The alternatives are separated by |s. (One variation on this is to use ::= instead of :=, but the meaning is the same.) Alternatives usually consist of both symbols and something called terminals. Terminals are simply pieces of the final string that are not symbols. They are called terminals because there are no production rules for them: they terminate the production process. (Symbols are often called non-terminals.)

BNF\'s syntax itself may be represented with a BNF like the following:

<syntax>         ::= <rule> | <rule> <syntax>

<rule>           ::= <opt-whitespace> \"<\" <rule-name> \">\" <opt-whitespace> \"::=\" <opt-whitespace><expression> <line-end>

<opt-whitespace> ::= \" \" <opt-whitespace> | \" \"

<expression> ::= <list> | <list> <opt-whitespace> \"|\" <opt-whitespace> <expression>

<line-end>  ::= <opt-whitespace> <EOL> | <line-end> <line-end>

<list>     ::= <term> | <term> <opt-whitespace> <list>

<term>   ::= <literal> | \"<\" <rule-name> \">\"

<literal> ::= \'\"\' <text1> \'\"\' | \"\'\" <text2> \"\'\"

<text1>          ::= \"\" | <character1> <text1>

<text2>          ::= \"\" | <character2> <text2>

<character>      ::= <letter> | <digit> | <symbol>

<letter>         ::= \"A\" | \"B\" | \"C\" | \"D\" | \"E\" | \"F\" | \"G\" | \"H\" | \"I\" | \"J\" | \"K\" | \"L\" | \"M\" | \"N\" | \"O\" | \"P\" | \"Q\" | \"R\" | \"S\" | \"T\" | \"U\" | \"V\" | \"W\" | \"X\" | \"Y\" | \"Z\" | \"a\" | \"b\" | \"c\" | \"d\" | \"e\" | \"f\" | \"g\" | \"h\" | \"i\" | \"j\" | \"k\" | \"l\" | \"m\" | \"n\" | \"o\" | \"p\" | \"q\" | \"r\" | \"s\" | \"t\" | \"u\" | \"v\" | \"w\" | \"x\" | \"y\" | \"z\"

<digit>          ::= \"0\" | \"1\" | \"2\" | \"3\" | \"4\" | \"5\" | \"6\" | \"7\" | \"8\" | \"9\"

<symbol>         ::= \"|\" | \" \" | \"-\" | \"!\" | \"#\" | \"$\" | \"%\" | \"&\" | \"(\" | \")\" | \"*\" | \"+\" | \",\" | \"-\" | \".\" | \"/\" | \":\" | \";\" | \"<\" | \"=\" | \">\" | \"?\" | \"@\" | \"[\" | \"\\\" | \"]\" | \"^\" | \"_\" | \"`\" | \"{\" | \"|\" | \"}\" | \"~\"

<character1>     ::= <character> | \"\'\"

<character2>     ::= <character> | \'\"\'

<rule-name>      ::= <letter> | <rule-name>

<rule-char> <rule-char>      ::= <letter> | <digit> | \"-\"

BNF working examples are as follows:-

1.BNF grammar for the language of university of oklahoma course codes.

Example sentences:

CSI3125

MAT2743

PHY1200

EPI6581

CSI9999

Solution:

<coursecode>   ::= <acadunit> <coursenumber>

<acadunit>     ::= <letter> <letter> <letter>

<coursenumber> ::= <year> <semesters> <digit> <digit>

<year>         ::= <ugrad> | <grad>

<ugrad>        ::= 0 | 1 | 2 | 3 | 4

<grad>         ::= 5 | 6 | 7 | 9

<semesters>    ::= <onesemester> | <twosemesters>

<onesemester> ::= <frenchone> | <englishone> | <bilingual>

<frenchone>    ::= 5 | 7

<englishone>   ::= 1 | 3

<bilingual>    ::= 9

<twosemesters> ::= <frenchtwo> | <englishtwo>

<frenchtwo>    ::= 6 | 8

<englishtwo>   ::= 2 | 4

<digit>        ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

2.another example with explaination as follows:-

S := \'-\' FN |

The different symbols here are all abbreviations: S is the start symbol, FN produces a fractional number, DL is a digit list, while D is a digit.

Valid sentences in the language described by this grammar are all numbers, possibly fractional, and possibly negative. To produce a number, start with the start symbol S:

Then replace the S symbol with one of its productions. In this case we choose not to put a \'-\' in front of the number, so we use the plain FN production and replace S by FN:

The next step is then to replace the FN symbol with one of its productions. We want a fractional number, so we choose the production that creates two decimal lists with a \'.\' between them, and after that we keep choosing replacing a symbol with one of its productions once per line in the example below:

DL . DL

D . DL

Here we\'ve produced the fractional number 3.14

EBNF(extended Backus–Naur form):-

In DL I had to use recursion (ie: DL can produce new DLs) to express the fact that there can be any number of Ds. This is a bit awkward and makes the BNF harder to read. Extended BNF (EBNF, of course) solves this problem by adding three operators:

EBNF is not more powerful than BNF in terms of what languages it can define, just more convenient. Any EBNF production can be translated into an equivalent set of BNF productions.

uses of bnf and ebnf

Explain the purpose of BNF? Is EBNF usefull?SolutionBNF-it is known as Backus Naur Form ,it is a systematic mathematical style to describe a language or you can
Explain the purpose of BNF? Is EBNF usefull?SolutionBNF-it is known as Backus Naur Form ,it is a systematic mathematical style to describe a language or you can
Explain the purpose of BNF? Is EBNF usefull?SolutionBNF-it is known as Backus Naur Form ,it is a systematic mathematical style to describe a language or you can

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site