28. Syntax Diagram

Another popular method way of defining grammatical rules of a language or data type is to use a graphical method called 'Syntax Diagrams'.

Syntax diagrams are made up of a few specific symbols that together define any grammatical rule.

Symbol: A circle with some text inside

Syntax Diagram Item

This is an item that is not defined in any more detail. There are no lower level syntax diagrams defining this any further. This is called a 'terminal symbol'

This is because the item described is self-evident. For example if the number '1' was inside the circle, then there is no need to define what '1' means (unless you are a mathematician).

Symbol: A rectangle with some text inside

Syntax Rectangle

This is an item that is defined in some more greater detail in another syntax diagram. For example the text might be 'postal address' and because it is a rectangle rather than a circle, you should expect to see a syntax diagram describing the internal structure of 'postal-address'.

Symbol: Arrow

syntax diagram arrow

An arrow in a syntax diagram indicates the direction in which you are allowed to read the overall diagram. For example

syntax arrow path

This shows you should read it from left to right.

An arrow that loops back to an earlier point indicates a repetition of the items in-between. For example

syntax looping

This indicates that there is at least one address, but there may be any number of additional addresses as well because the arrow is allowing you to read the item again and again.

Example : Defining an integer using a syntax diagram

syntax diagram integer

This indicates that an integer is made up of one or more digits. But note that digit itself needs further definition.

Defining a digit.

syntax diagram digit

Following the rules discussed earlier, you begin to read this diagram from the left. The arrow points to a number of parallel terminator symbols, but you can only follow a single path through them. Parallel symbols are effectively an 'OR' choice. In this case a digit is defined to consist of a single number ranging from zero to nine.

As a comparison, the BNF notation describes a digit as

digit :== 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0

Therefore an integer can be defined using two syntax diagrams, one for the integer itself and another that describes a digit.

 

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

Click on this link: Syntax Diagram

 

Copyright © www.teach-ict.com