7. Syntax Diagram example 2

Defining a stock code

In this example, you are involved with writing a database to handle stock. The primary key for each stock item will be a stock code. Your task is to define the structure of this stock code and inform other programmers of its syntax.

A vaid stock code should look similar to this


Use syntax diagrams.

One answer.

syntax diagrams


The upper diagram shows that the first character has to be an 'alpha' this is always followed by a colon, the next character can be either a digit or another alpha. This can repeat as much as required.

The lower diagrams show the syntax for a digit and the item called alpha. In this case alpha is allowed to be one of four characters A, B, J or Z

Examples of invalid stock codes

  • 1:1ABJZ this has a leading digit which is an invalid syntax
  • AB199 the colon is missing and so is an invalid syntax
  • A:333R the R character is not allowed and so it an invalid syntax



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 diagrams



Copyright © www.teach-ict.com