0
$\begingroup$

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.

$\endgroup$
1
  • 1
    $\begingroup$ It seems to me that this question would be answered by simply reading the definition of BNF grammars... $\endgroup$ Commented Oct 4, 2016 at 13:50

1 Answer 1

2
$\begingroup$

< 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')).

$\endgroup$
1
  • $\begingroup$ Oh alright, got it now $\endgroup$
    – tsp216
    Commented Oct 4, 2016 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.