Hub Nexus
Updated

AuthorNo author yetClaim it

See something to improve? Propose a change.

Support

Computing » Computer Science » Computer Programming » Ada Programming

Character set

The character set used in Ada programs is composed of:

  • Upper-case letters: A, ..., Z and lower-case letters: a, ..., z.
  • Digits: 0, ..., 9.
  • Special characters.

Take into account that in Ada 95 the letter range includes accented characters and other letters used in Western Europe languages, those belonging to the ISO Latin-1 character set, as ç, ñ, ð, etc.

In Ada 2005 the character set has been extended to the full Unicode set, so the identifiers and comments can be written in almost any language in the world.

Ada is a case-insensitive language, i. e. the upper-case set is equivalent to the lower-case set except in character string literals and character literals.

Lexical elements

In Ada we can find the following lexical elements:

Example:

Temperature_In_Room := 25; -- Temperature to be preserved in the room.

This line contains 5 lexical elements:

  • The identifier Temperature_In_Room.
  • The compound delimiter :=.
  • The number 25.
  • The single delimiter ;.
  • The comment -- Temperature to be preserved in the room..

Identifiers

Definition in BNF:

identifier ::= letter { [ underscore ] letter | digit }
letter ::= A | ... | Z | a | ... | z
digit ::= 0 | ... | 9
underscore ::= _

From this definition we must exclude the keywords that are reserved words in the language and cannot be used as identifiers.

Examples:

The following words are legal Ada identifiers:

Time_Of_Day TimeOfDay El_Niño_Forecast Façade counter ALARM

The following ones are NOT legal Ada identifiers:

Time_Of_Day 2nd_turn Start Access Price_In_$ General__Alarm

Exercise: could you give the reason for not being legal for each one of them?

Numbers

The numeric literals are composed of the following characters:

  • digits 0 .. 9
  • the decimal separator .,
  • the exponentiation sign e or E,
  • the negative sign - (in exponents only) and
  • the underscore _.

The underscore is used as separator for improving legibility for humans, but it is ignored by the compiler. You can separate numbers following any rationale, e.g. decimal integers in groups of three digits, or binary integers in groups of eight digits.

For example, the real number such as 98.4 can be represented as: 9.84E1,
98.4e0, 984.0e-1 or 0.984E+2, but not as 984e-1.

For integer numbers, for example 1900, it could be written as 1900, 19E2, 190e+1 or 1_900E+0.

A numeric literal could also be expressed in a base different to 10, by enclosing the number between # characters, and preceding it by the base, which can be a number between 2 and 16. For example, 2#101#
is 1012, that is 510; a hexadecimal number with exponent is 16#B#E2, that is 11 × 16² = 2,816.

Note that there are no negative literals; e.g. -1 is not a literal, rather it is the literal 1 preceded by the unary minus operator.

Character literals

Their type is Standard.Character, Wide_Character or Wide_Wide_Character. They are delimited by an apostrophe (').

Examples:

'A' 'n' '%'

String literals

String literals are of type Standard.String, Wide_String or Wide_Wide_String. They are delimited by the
quotation mark (").

Example:

"This is a string literal"

Delimiters

Single delimiters are one of the following special characters:

& ' ( ) * + , - . /  :  ; < = >

Compound delimiters are composed of two special characters, and they are the following ones:

=> .. **  := /= >= <= << >> <>

You can see a full reference of the delimiters in Ada Programming/Delimiters.

Comments

Comments in Ada start with two consecutive hyphens (--) and end in the end of line.

-- This is a comment in a full line
My_Savings := My_Savings * 10.0; -- This is a comment in a line after a sentence
My_Savings := My_Savings * -- This is a comment inserted inside a sentence
1_000_000.0;

A comment can appear where an end of line can be inserted.

Reserved words

Reserved words are equivalent in upper-case and lower-case letters, although the typical style is the one from the Reference Manual, that is to write them in all lower-case letters.

In Ada some keywords have a different meaning depending on context. You can refer to Ada Programming/Keywords and the following pages for each keyword.

Ada Keywords
abortelsenewreturn
abselsifnotreverse
abstract (Ada 95)endnull
acceptentryselect
accessexceptionofseparate
aliased (Ada 95)exitorsome (Ada 2012)
allotherssubtype
andforoutsynchronized (Ada 2005)
arrayfunctionoverriding (Ada 2005)
attagged (Ada 95)
genericpackagetask
begingotoparallel (Ada 2022)terminate
bodypragmathen
ifprivatetype
caseinprocedure
constantinterface (Ada 2005)protected (Ada 95)until (Ada 95)
isuse
declareraise
delaylimitedrangewhen
deltalooprecordwhile
digitsremwith
domodrenames
requeue (Ada 95)xor

See also

Wikibook

Ada Reference Manual

Where this page came from

This page was imported from Wikibooks. From “Ada Programming” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

In these publicationsAda Programming

LanguagesEnglish

Licence: CC BY-SA 4.0 · Adapted from en.wikibooks.org

1

0

0

0

Spinner Logo

Comments

Spinner Logo
Version: 2CC0 1.0 — public domain
The runaway star that left the Tarantula Nebula
Version: 2CC0 1.0 — public domain
The Blackwell School, where segregation had no law behind it
Version: 2CC0 1.0 — public domain
The Eagle Nebula, seen in the infrared
Version: 2CC0 1.0 — public domain
The house where the Equal Rights Amendment was written
Version: 2CC0 1.0 — public domain
The Aleutians, the forgotten front of the Second World War
Version: 2CC0 1.0 — public domain
The Cosmic Cliffs are not cliffs