Andy Marks
Ben Pfistner
Chris Nisbet
Josh Justice
Owen Webb
In a cost study done in 1973-1974 it was determined that the US Department of Defense was spending $3 billion annually on software, over half of which was spent on embedded computer systems. It was decided that a new language needed to be developed for these needs. The Higher Order Language Working Group (HOLWG) was formed in January 1975 with Willia m Whitaker as chair. In April 1975 the initial language requirements were compiled in a document known as Strawman. Based on the response to this document, revised requirements created known as, Woodenman, August 1975, and Tinman, January 1976.
The HOLWG evaluated 23 existing languages against the Tinman requirements: FORTRAN, COBOL, PL/I, HAL/S, TACPOL, CMS-2, CS-4, SPL/I, JOVIAL J3, JOVIAL J73, ALGOL 60, ALGOL 68, CORAL 66, Pascal, SUMULA 67, LIS, LTR, TRL/2, EUCLID, PDL2, PEARL, M ORAL, EL/I concluding in January 1977 that none were suitable, though Pascal, ALGOL 68 or PL/I would be a good starting point.
The ideal language specification, Ironman, appeared in January 1977. Request for proposals were issued April 1977; 17 proposals received. Four contractors were picked to produce prototype languages:
The revised Ironman requirements were published in SIGPLAN, December 1977. The Red and Green languages were chosen finalists in April 1978 after an extensive, public review. The final language requirements, Steelman, appeared in June 1978. Cii Honeywell Bull (green) chosen the winner in May 1979.
The language, known only as DoD-1 (Department of Defense) up to that point, was given the name Ada in May 1979. HOLWG dissolved and was replaced by the Ada Joint Program Office (AJPO) charted 12 December 1980.
The Ada/Ed implementation of the language was validated in April 1983. AJPO established the Ada 9X Project in July 1988 to revise the Ada programming language. The revision requirements document produced by the "requirements team," December 1990 Intermetrics, Inc. was the prime contractor for the "mapping/revision team" for the new Ada 9X standard. S. Tucker Taft served as Technical Direc tor.
Ada95, a joint ISO and ANSI standard for the language, was accepted in February 1995.
Sources:
www.cs.fit.edu/~ryan/ada/ada-hist.html
www.adahome.com/History/
Ada comment lines begin with two hypens --
Every program has the following format:
Syntax |
---|
procedure Procedure_Name is -- variable declarations and subprogram definitions begin -- executable statements end Procedure_Name; |
Ada uses the entire ASCII character set.
(back to top)Identifiers must adhere to the following rules:
The following are the reserved words in Ada. Just like any other identifiers in the language, these are case insensitive.
abort else new return
abs elsif not reverse
abstract end
null
accept entry select
access exception separate
aliased exit of subtype
all or
and for others tagged
array function out task
at
terminate
generic package then
begin goto pragma type
body private
if procedure
case in protected until
constant is use
raise
declare range when
delay limited record while
delta loop rem with
digits
renames
do mod requeue xor
|
Ada comes with a number of built-in types, as well as advanced facilities for creating your own types out of them.
All variables must be declared between the "is" and "begin" statement of the subprogram they're to be used in. Declarations have the following form:
Name [ , ... ] : Type [ := Value ] ;
Type | Examples | Operations |
---|---|---|
Boolean | true false |
and or xor not < /td> |
Integer | 42 -27 |
+ - * / ** (exponentiate) > >= < <= = /= (not equal) |
Float | 42.0 (decimal point required) 3.14159 -27.18 |
(same as integers) |
Character | 'a' 'Z' '?' |
= /= (more in package Characters.Handling) |
S ome of Ada's most advanced features are in the area of creating user-defined types.
Syntax |
---|
type Type_Name is range Min .. Max ; |
Example |
type Month |
Unfortunately, this creates a type totally distinct from integers, which means, for example, that you can't set a variable of type Month to 7, because 7 is an integer. More useful is creating a subtype, which is still an integer but also adds range restrictions:
Syntax |
---|
subtype Type_Name is Parent_Type [ range Min .. Max ]; |
Example |
type Month is range 1 .. 12; type Spring_Month is Month range 3 .. 5; |
Enumerations are a way t o represent lists of elements as their own type.
Syntax |
---|
type Type_Name is ( Element_1 [, ...] ); |
Example |
type Mood is ( Excited, Content, Somber, Restless ) ;td> |
Variables of an enumerated type can be assigned values and compared to one another:
Example |
---|
My_Mood, Your_Mood : Mood; ... My_Mood := Content; Your_Mood := Somber; My_Mood = Your_Mood; -- returns false |
Ada supports one- or multi-dimensional arrays. The unique thing about Ada arrays is that they are n't necessarily indexed by integer -- t hey can be indexed by any range or range type! Arrays themselves are not types; to get an array with certain indices, declare an array type, and then create a variable of that type.
Syntax |
---|
type Type_Name is Array( Range [, ...] ) of Elemen t_Type ; |
Example |
type My_Int_Array_Type is Array( 1..10 ) of Integer; type My_Month_Array_Type is Array( Month ) of Integer; type My_2D_Array_Type is Array( 1..10, 1..10 ) of Float; ... My_Int_Array : My_Int_Array_Type; My_Month_Array : My_Month_Array_Type; My_2D_Array : My_2D_Array_Type; ... My_Int_Array( 3 ) := -42; My_Month_Array( July ) := 9; My_2D_Array( 5, 7 ) := 3.14159; |
Records gather together multiple variables in one place. Record types can be created as follows:
Syntax |
---|
type Type_Name is record Field_Name : Field_Type [ := Value ] ; [...] end record; |
Record fields are accessed by using the record variable name, a dot, and then the field name -- just like in Java or C++.
String constants are w ritten in quotes, i.e. "Hello, world!".
String variables are declared by specifying an index range to use to refer to the characters in the string.
Syntax |
---|
Variable [, ...] : String( Min..Max ) [ := Value ]; |
Individual charac ters in a string can be referenced like array elements, i.e. My_String( 5 ). Substrings within a string can also be used, i .e. My_String( 5 .. 10 ). Characters can be overwritten with other characters, and substrings with substrings of the same length.
(back to top)Assignment statements use the := operator, rather than the = operator as in many recent languages.
Syntax |
---|
Variable := Expression ; |
Operators are listed under their corresponding types.
(back to top)Controls statements in Ada work much the same as those in other programming languages. They inc lude the if statement, the case statement, the loop statement, and the exit statement.
The If Statement is the most common way to select a path or branch in the code.
Basic Syntax:
Syntax |
---|
if Boolean expression then -- sequence of statements end if ; |
Complete Form:
Syntax |
---|
if<
/span> Boolean expression then
-- sequence of statements
elsif Boolean expression then
-- sequence of statements
[...]
else
-- sequence of statements
end if;
|
In the if statement, the boolean expression is evaluated. If it is true, the following statements are executed , otherwise control drops to the next control of the if statement, whether that be an elseif, else, or end if. All if statements require ending with an end if statement. The end if statement is the only control line in the if that can have a semicolon after it.
If control drops t o and else if or else, that Boolean expression is evaluated and control proceeds downward.
Example |
---|
X := 3; if x < 0 then x := x + 1; elsif x > 0 then x := x - 1; | < /tr>
The case statement is useful to choose between several different paths. It is preferable to a long if statement because it makes for a clearer program.
Syntax |
---|
case selector is when value [| ...] => -- sequence of statemen ts [...] end case; |
Example |
x := 3; case x is when 1 => Put("One"); when< /span> 2 => Put("Two"); when 3 => Put("Three"); end case; |
Alternatives may be added to the when statements, and the key word 'oth ers' refers to any value not listed in the alternatives.
Example |
---|
x := 3; case x is when 1 | 2 | => Put("X < 3, X > 0"); when 4| 5 | 6 => Put("X > 3, x < 7"); when others => Put("X < 1, X = 3, X > 6"); end case; |
The loop statement does just that, loops lines of code.
Simple loop statement (infinite loop):
Syntax |
---|
loop -- sequence of statements end loop; |
The loop statement may be used with a for key word to loop a specifed number of times.
Syntax |
---|
for loop_parameters in start_value..end_value loop -- sequence of statements end loop; |
Example |
for x in 1..10 loop Put(x); end loop; |
Output: 12345678910
The loop statement can also be used with a while keyword that evaluates a Boolean expression. This will loop while th e Boolean expression evaulates to true, and break out when false.
Loop statement with while:
Syntax |
---|
while Boolean expression loop -- sequence of statements end loop; |
Example |
x := 3;
while x > 0 loop
x := x - 1;
Put(x);
end loop;
< /td> |
Output: 210
The exit statement is used to break out of other control structures.
(back to top)Input and output in ADA requires calling procedures from Ada.Text_IO, Ada.Ineger_Text_IO, and Ada.Float_Text_IO packages/librarie s.
To do this you must place a context clause at the beginning of the program. Using Integer_Text_IO the following is an example of the context clause, or with statement.
Example |
---|
with Ada.Integer_Text_IO;
|
To use this, tough, you would have to type "package.procedure" whenever you wanted to call a procedure in that package.
The re is a way to get around this, however. Along with the with statement at the beginning of the file you can add a use statement that will allow you to not type the 'package.". The statement at the beginning of the program would then look like:
Example |
---|
with Ada.Integer_Text_IO; use Ada.Integ er_Text_IO; |
And to ma ke a call on this you would type only the procedure call as seen in the I/O Precedure Calls section.
The 5 procedures used by I/O are the following:
New_Line ( Spacing
=> positive_integer );
Put_Line ( Item => expression );
Put ( Item
=> expression );
Get ( Item => variable_name );
Skip_Line;
New_Line can be used in the following two ways, where no number given will enter o ne line or positive_integer is t he number of new lines desired.
Syntax |
---|
New_Line;
New_Line(positive_integer);
|
Put_Line will place what is passed to it on a line and then place the cursor on the next line. It can be used in the following ways, where the object is a string, or variable that can be printed. Those variables include at least string, numb er. See documentaion for more on this.
Syntax |
---|
Put_Line(object);
Put_Line("I would appear on a line with the cursor placed on the next line");
|
Put is the same as Put_Line but for the exception that it will not return a new line.
Syntax |
---|
Put(object);
Put("I would appear on a line.");
|
Get requires a variable to be placed into it. The type of that variable determines what the Get procedurewill require. A variable declared as a string of length 10 will require that what is retrieved in a string of length ten. Placing a variable that is an Integer into the Get procedurewill require a Integer being given. The following is syntax for the Get pr ocedure. There are mor e types that the Get function can retrieve, for more on this see the documentation.
Syntax |
---|
Get(String_variable); Get(Integer_variable); |
Skip_Line is best described by the Ada documentation, which says the following:
Skip_Line is an input procedure and will caus e the input to skip to the next line. This is useful to remove the carriage return from the input buffer. Skip_Line should be performed after any call to a Get procedure. It can also be used to make a program pause and wait for a carriage return to be entered.
Syntax |
---|
Skip_Line; |
There are two ways to be m odular in Ada. You can create either functions or procedures. There are some key differences that we will look at.
Procedures
Procedures are useful to encapsulate often used tasks. They don't return anything to they can't be used for comparison or assignment. They are only useful when it is necessary to duplicate large chunks of code repeatedly.
User-defined
While there are many predefined procedures in Ada, you will probably end up needing to use one you define yourself.
Syntax |
---|
Procedure name [ parameter list ] is -- Declarations begin -- Executable code end name; |
Note: The parameter list is semicolon delimited and structured like this:
Syntax |
---|
( parameter1 [, ...] : [in] [out] type [; ...]) |
The "in out" defines whether or not you want to use that parameter as an "in" parameter or an "out" parameter or both. "Out" paramaters are those variables which the procedure can modify. "In" parameters are the ones you want to use. It is not required that you have either since "in" is the default. This is called the parameter mode.
Important Note:If you are not passing any parameters then you completely take the parentheses out so it looks like:
Syntax |
---|
Procedure name is... |
Example |
---|
procedure GetColumn( Column : in out Board_Dimension ) is Valid : Boolean; Column_Letter : Character; begin loop Valid := true; Ada.Text_IO.Get(Column_Letter); case Column_Letter is when 'A'|'a' => Column := 1; when 'B'|'b' => Column := 2; when 'C'|'c' => Column := 3; when 'D'|'d' => Column := 4; when 'E'|'e' => Column := 5; when 'F'|'f' => Column := 6; when 'G'|'g' => Column := 7; when 'H'|'h' => Column := 8; whe n 'I'|'i' => Column := 9; when 'J'|'j' => Column := 10; when others => Valid := false; end case; exit when Valid = true; end loop; end GetColumn; |
Functions
These are extremely similar to procedures, but can have a return parameter. Their limitation is that you cannot use output parameters in a function. Functions can only use input parameters to modify the return value (which is the way a function in math works).
User-defined
There are also many predefined functions in Ada, you again will probably end up needing to use one you define yourself so lets discover how to do that. The syntax we use is this:
Syntax |
---|
Important Note:If you are not passing any parameters then you completely take the parentheses out so it looks like:
Syntax |
---|
Function name return type is... |
Example |
---|
function Prompt_Orientation return Ship_Orientation is Letter : Character; begin Put( "Orientation (H)orizontal/(V)ertical: " ); Get( Letter ); case Letter is when 'H' | 'h' => return Horizontal; when others => return Vertical; end case; end Prompt_Orientation; |
General Rules
Any function or procedure that takes no parameters has no parentheses.
(back to top)