Backus Naur form is what the compiler requires in order to be able to do syntax analysis however it is not very human readable. When the added complexity of recursion is added we tend to have a very difficult to read rule. In order to help we can define our rules in a diagram form to help a human reader to understand. It is important to remember however that a computer will not be able to use the diagram directly to do syntax analysis and as such it must be converted to BNF in order for the compiler to do its work.

 

Below are the symbols used.

We also need to look at how composition and alternation work. First of all lets look at how we can write the rule.

<sign> ::- + | -

 

The + and – are terminal symbols and as such we use the circle symbol. The two circle symbols are drawn on top of each other in order to show alternation. We read the diagram from left to right in the same direction as the arrows. Where the flow branches we have alternation. Conjunction is just as easy. Consider the following rule.

 

<Two_Digit_Number> ::= <Digit> <Digit>

The rectangular symbol shows a non-terminal symbols. As we know a digit is itself a rule. As such can be broken down into 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 . To show two digits one after the other all we need to do is put them next to each other on the diagram.

 

The last thing to look at is repetition. There is no special symbol for this. All he have to do is show a arrow looping back to itself. This means that the rule for a number becomes much simpler.

 

<Number> ::= <Digit> | <Digit> <Number>

As you can see there is no alternation in the diagram. This is because in the BNF we have to have what is known as a termination clause. In the diagram this is unnecessary. As such recursion is simply shown as a loop.