Computing Students - Computer Science Degree Notes
Home Contact Shop Notes Questions Programming Links Dictionary Coursework FORUM Tutors
  Recommended Kelkoo Searches: Computer Science | Computing | Computer Systems | Database | Computing Revision  

Notes > Models of Computation > BNF (Backus-Naur Form)

BNF stands for "Backus-Naur Form" or "Backus Normal Form". It is a form of notation used for specifying the syntax of programming languages and command sets for example. The "syntax" means the structure of strings in a certain language. This is different from the language "semantics" which refers to the actual meaning of the strings in the language. BNF provides the ability to create notation which acts as a template for writing correct programs based around a certain syntax.

For programming languages that require a compiler to compile the code in order for it to then execute, the compiler will recognise and report any errors in the syntax of the code (e.g. missing parenthesis).

The symantics or logic of the code may have errors in it but this will become apparent as the compiler checks through the code. When the compiler checks through the code, it checks that integers contained within the code are valid.

A valid integer would be any series of digits that may or may not be signed (+/-). A series of digits may be too long to store an integer and different compilers will react differently to this. Some may report an error and some may simply truncate the number in order for it to be manageable.

Values with decimal points can be allowed by the compiler if a valid decimal number is defined in BNF as being a series of digits followed by a decimal point followed by another series of digits. The BNF specification below shows a basic example of how a set of valid numbers within a language can be defined using BNF.

    <digit> ---> 0|1|2|3|4|5|6|7|8|9
    <number> ---> <digit> | <digit> <number>
    <integer> ---> <number> | - <number> | + <number>
Operations such as "greater than" or "less than" can also be defined as valid so that the compiler allows them. This also applies to if statements or conditional statements. In this case, an expression must follow the "if" and a sequence (which may be a combination of statements) must follow the "then" in the code. If the code follows this syntax that has been defined using BNF, the compiler will recognize it as valid and allow it to be compiled.

The following BNF specification shows an example of how the syntax of a language can be defined using BNF. and will of course be defined in other BNF constructs.

    <condition> ---> if <expression> then <sequence>

Search for "BNF" on: Google | Kelkoo | Amazon | eBay (UK) | eBay (US)

Search for "BNF" on the rest of Computing Students: BNF






Home | Contact | Shop | Notes | Questions | Programming | Links | Dictionary | Coursework | Tutors Sponsored Links: Affiliate Program Articles | Computer Science Definitions | CS Degree Notes
Copyright © 2005-2006 ComputingStudents.com
This site is to be used in accordance with the ComputingStudents.com User Agreement
Acuras Website and Online Database Development and Management