World's most popular travel blog for travel bloggers.

Why does the following Backus-Naur form reflect the following syntax diagram?

, , No Comments
Problem Detail: 

The definition of the variable

< number>::=< digit > | < digit >< number >

where < digit > is defined as

< digit > ::= 1|2|3|4|5

Apparently reflects the following syntax diagram

enter image description here

Please explain why this is the case. I am particularly confused with the clause after the vertical OR line (i.e. < digit >< number >) and whether it has something to do with the fact that number can consist of many digits.

Asked By : user98937
Answered By : adrianN

< number>::=< digit > | < digit >< number > means that a number is either just a digit, or a digit followed by a number. So 1 is a number (just a single digit), and 12 is also a number (a single digit, followed by a number that consists of just the single digit '2'). Similarly 123 is a number that consists of a single digit '1' and a number (that itself consists of a single digit '2' followed by a number (that consists of the single digit '3')).

Best Answer from StackOverflow

Question Source :

3200 people like this

 Download Related Notes/Documents


Post a Comment

Let us know your responses and feedback