Ada Programming Language An Introduction-Modern Programing Language-Lecture Handout, Exercises of Programming Languages

Modern Programing Language is about different languages of today era. It explains pros and cons of some new languages and their differences with old ones. Languages like java, c sharp, c plus plus, c, fotran are included in this course. This lecture handout is about: Ada, Programming, Language, Design, Manipulation, Interface, Operator, Integer, Enumeration, Discrete, Boolean, Arrays

Typology: Exercises

2011/2012

Uploaded on 08/04/2012

dhanvin
dhanvin 🇮🇳

4.2

(14)

108 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Ada Programming Language: An Introduction (Lecture 13-17) VU
Ada Programming Language: An Introduction (Lecture 13-17)
Design Goals
Ada is a computer programming language originally designed to support the construction
of long-lived, highly reliable software systems. Its design emphasizes readability, avoids
error-prone notation, encourages reuse and team coordination, and it is designed to be
efficiently implementable.
A significant advantage of Ada is its reduction of debugging time. Ada tries to catch as
many errors as reasonably possible, as early as possible. Many errors are caught at
compile-time by Ada that aren't caught or are caught much later by other computer
languages.
Ada programs also catch many errors at run-time if they can't be caught at compile-time
(this checking can be turned off to improve performance if desired).
In addition, Ada includes a problem (exception) handling mechanism so that these
problems can be dealt with at run-time.
The main design goals of Ada were:
Program reliability and maintenance
Military software systems are expected to have a minimum lifetime of 30 years.
Programming as a human activity
Efficiency
Hence emphasis was placed on program readability over ease of writing.
Ada History
The need for a single standard language was felt in 1975 and the draft requirements
were given the code name strawman. Strawman was refined to Woodman and then
Tinman in 1976. It was further refined to ironman. At that time proposals were invited
for the design of a new language. Out of the 17 proposals received, four were selected
and given the code names of green, red, blue, and yellow. Initial designs were submitted
in 1978 and red and green short listed on the basis of these designs. Standard
requirements were then refined to steelman. The designs were refined further and
finally Green was selected in 1979. DoD announced that the language will be called
Ada. The 1995 revision of Ada (Ada 95) was developed by a small team led by Tucker
Taft. In both cases, the design underwent a public comment period where the designers
responded to public comments.
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Ada Programming Language An Introduction-Modern Programing Language-Lecture Handout and more Exercises Programming Languages in PDF only on Docsity!

Ada Programming Language: An Introduction (Lecture 13-17)

Design Goals

Ada is a computer programming language originally designed to support the construction of long-lived, highly reliable software systems. Its design emphasizes readability, avoids error-prone notation, encourages reuse and team coordination, and it is designed to be efficiently implementable. A significant advantage of Ada is its reduction of debugging time. Ada tries to catch as many errors as reasonably possible, as early as possible. Many errors are caught at compile-time by Ada that aren't caught or are caught much later by other computer languages.

Ada programs also catch many errors at run-time if they can't be caught at compile-time (this checking can be turned off to improve performance if desired).

In addition, Ada includes a problem (exception) handling mechanism so that these problems can be dealt with at run-time.

The main design goals of Ada were:  Program reliability and maintenance  Military software systems are expected to have a minimum lifetime of 30 years.  Programming as a human activity  Efficiency

Hence emphasis was placed on program readability over ease of writing.

Ada History

The need for a single standard language was felt in 1975 and the draft requirements were given the code name strawman. Strawman was refined to Woodman and then Tinman in 1976. It was further refined to ironman. At that time proposals were invited for the design of a new language. Out of the 17 proposals received, four were selected and given the code names of green, red, blue, and yellow. Initial designs were submitted in 1978 and red and green short listed on the basis of these designs. Standard requirements were then refined to steelman. The designs were refined further and finally Green was selected in 1979. DoD announced that the language will be called Ada. The 1995 revision of Ada (Ada 95) was developed by a small team led by Tucker Taft. In both cases, the design underwent a public comment period where the designers responded to public comments.

Ada Features The salient features of Ada language are as follows:  Packages (modules) of related types, objects, and operations can be defined.  Packages and types can be made generic (parameterized through a template) to help create reusable components.  It is strongly typed  Errors can be signaled as exceptions and handled explicitly. Many serious errors (such as computational overflow and invalid array indexes) are automatically caught and handled through this exception mechanism, improving program reliability.  Tasks (multiple parallel threads of control) can be created and communicate. This is a major capability not supported in a standard way by many other languages.  Data representation can be precisely controlled to support systems programming.  A predefined library is included; it provides input/output (I/O), string manipulation, numeric functions, a command line interface, and a random number generator (the last two were available in Ada 83, but are standardized in Ada 95).  Object-oriented programming is supported (this is a new feature of Ada 95). In fact, Ada 95 is the first internationally standardized object-oriented programming language.  Interfaces to other languages (such as C, Fortran, and COBOL) are included in the language.

The first Example – Ada “Hello World”

with Ada.Text_Io; -- intent to use use Ada.Text_Io; -- direct visibility

-- the first two statements are kind of include in C

procedure Hello is -- procedure without parameters is the -- starting point begin Put_Line("Hello World!"); -- this statement prints “Hello World” on the output end Hello;

It may be noted that Ada is not case sensitive.

Operator Overloading

Ada allows a limited overloading of operators. The exception in Ada is that the assignment operator ( := ) cannot be overridden. It can be overridden in case of inheritance from a special kind of “abstract class”. When you override the equality operator ( = ) you also implicitly override the inequality operator ( /= ).

Ada Types Ada provides a large number of kinds of data types. Ada does not have a predefined inheritance hierarchy like many object oriented programming languages. Ada allows you to define your own data types, including numeric data types. Defining your own type in Ada creates a new type.

Elementary Types

The elementary Ada type are:

 Scalar Types  Discrete Types  Real Types  Fixed Point Types  Access Types

Discrete Types

Discrete types include Integer types, Modular types, Character types, enumeration types, and Boolean type.

Integer Types

We first look at Signed Integer types. Ada, like other languages, supports signed integers. However, in this languages we can also define our own integer type with a limited set of values as shown in the following example:

type Marks is range 0..100;

This defines a type Marks with the property that a variable of this type can only have values between 0 and 100.

We can now create variable with this type as shown below:

finalScore : Marks;

You may also note that the syntax of Ada for variable declaration is different from C. In this case, the type comes after the variable name and is separated by a : from the variable names.

Unsigned (Modular) Types

Modular types support modular arithmetic and have wrap around property. This concept is elaborated with the help of the following example:

type M is mod 7; -- values are 0,1,2,3,4,5,

q : m := 6; -- initialization … q := q + 2; -- result is 1

It is most commonly used as conventional unsigned numbers where overflows and underflows are wrapped around.

type Uns_32 is mod 2 ** 32;

Remember that twos complement arithmetic is equivalent to mod 2**wordsize.

Character Types

There are two built in character types in Ada  Simple 8-bit ASCII Characters  Wide_Character that support 16-bit Unicode/ISO standard 10646.

These are good enough for most purposes, but you can define your own types just like the integer types:

type LetterGrades is („A‟, „B‟, „C‟, „D‟, „F‟, „I‟, „W‟);

This can now be used to declare variables of this type.

Enumeration Types

Just like C, an enumeration type in Ada is a sequence of ordered enumeration literals:

type Colors is (Red, Orange, Yellow, Green, Blue, Indigo, Violet); type State is (Off, Powering_Up, On);

It is however different from C in many respects:

  1. There is no arithmetic defined for these types. For example: S1, S2 : State; S1 := S1 + S2; -- Illegal
  2. One can however add/subtract one (sort of increment and decrement) using the Pred and Succ as shown below:

State‟Pred (S1) State‟Succ (S2)

In the case of decimal fixed point types, the distance between values is implemented as a power of 10.

type Balances is delta 0.01 digits 9 range 0.0 .. 9_999_999.99;

The important difference in the definition of a decimal fixed point type from an ordinary fixed point type is the specification of the number of digits of precision.

This example also shows how Ada allows you to specify numeric literals with underscores separating groups of digits. The underscore is used to improve readability.

Arrays

Like most other languages, Ada also supports arrays. One major difference between the arrays in Ada and C is that the indexes of arrays in Ada do not start from 0. In fact, the range of indexes to be used can be defined by the programmer as shown below:

type Int_Buffer is array (1..10) of Integer;

type Normalized_Distribution is array (-100..100) of Natural;

An array type can also be defined without a specific size. In this case the size is defined at the time of instantiation of a variable of that type. For example:

type String is array (Positive range <>) of Character;

Can now be used to create variable of specific size as shown below:

Last_Name : String(1..20);

Another very interesting feature of Ada is that the array indexes can be of any discrete type. For example if we define Days as below:

type Days is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);

then we can create an array which uses Days (or any sub-range of Days) as the array indexes as shown below.

type Daily_Sales is array (Days) of Float;

Now the type Daily_Sales is an array type of size 7 and indexes Monday through Sunday. Also note that these literals will be used as indexes in the statements that reference array elements.

Record Definitions

Record types are like structures in C. The following example shows a record type Address with three fields.

type Address is record Street : Unbounded_String;