4. BNF example 3


Some of the BNF notation include:

 < > used to enclose a syntactic item 
 ::= means "is defined by" or "consists of"
 | when placed between two items means an OR choice between them
 { } curly brackets means zero or more repetitions of the content. 

Example 3 Defining an integer

Backus-Naur Form BNF example 3

Note that <integer> appears twice in the rule

This is called a 'recursive' statement. A recursive statement makes use of itself as part of its definition.

In this case the rule, stated in English becomes "An integer consists of a single digit or a single digit followed by another integer."

So you can see that this allows an integer to be any length and yet it is a very concise statement in BNF.



Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: Using subroutines



Copyright © www.teach-ict.com