Section 3.2 - Identifiers

Ada requires names for procedures, packages, and many other constructs. These names are called identifiers. Sample identifiers include ``Hello'', ``Launch_Torpedo'', and ``X12''. Identifiers must begin with a letter, though after that initial letter they may also contain digits and underscores. As noted in the last section, upper and lower case are considered equivalent.

Here is the required syntax for an identifier in BNF format:

identifier ::= letter { [ "_" ] letter_or_digit }
letter_or_digit ::= letter | digit

All characters of an identifier are significant, and Ada compilers must support lines and identifier lengths of at least 200 (!) characters. Hopefully you won't use that many, of course, but the idea is to be very flexible.

One implication of this syntax is that underscores must not be adjacent to each other. This was intentional, because on some printers two adjacent underscores look the same as one underscore. Underscores also can't begin or end an identifier.

The Ada language permits the single letters "L" and "O" to be identifiers, but I recommend against it - a lower case "L" is nearly indistinguishable from a one, and an upper case "O" is nearly indistinguishable from a zero on some systems.


Quiz:


Here are some lists of identifiers:
  1. Hello, 2Run, Really_Quit
  2. Refresh_Screen, X22
Which of the preceding lists have only legal identifiers (ignoring the commas, which are there to separate the identifiers)?
  1. List 1
  2. List 2

You may also:

PREVIOUS Go back to the previous section

NEXT     Skip to the next section

OUTLINE  Go up to the outline of lesson 3

David A. Wheeler (wheeler@ida.org)