![]() |
Faculty of Engineering and Information Technology (FEIT)
Department of Computer Science
|
Introduction to Ada: Online Tutorial for Week 1 (and 2)The first part of COMP2310 and the first assignment will make use Ada. We use Ada as it provides good support for concurrent programming through the availability of a number of constructs, such as protected objects and rendezous, in a form that is relatively easy to use. Before using the concurrent aspects of Ada, however, you need to become familiar with some basic Ada! The aim of this web page is to point you in the direction of an online tutorial that will help you to achieve that knowledge. There is a variety of Ada material available online. I think the Lovelace site prepared by David Wheeler is particularly useful, but if you find other useful resources I encourage you to post them on the COMP2310 Discussion board.
Using Ada on the student systemAlthough the Lovelace tutorial provides snippets of code and indicates that these can be compiled using "WebAda", this does not appear to work. So you will need to compile and run the code snippets on the student system, or elswhere. In the labs and for the assignment we will be using the GNU Ada Compiler, known as GNAT. You can run this on the student system (any of the machines in the student lab or from outside the ANU by ssh to partch.anu.edu.au) or download a copy and install it on your own machine. (Note, if you install your own version you must do final testing of your assignment using the version of gnat on the student system).The gnat compiler expects to find Ada programs in files that have either a suffix of .ads (denoting Ada specifications) or of .adb (denoting Ada body). These files bear a similar relationship to the .h and .c files in a C program. The first example from the Loverlace tutorial is
-- Print a simple message to demonstrate a trivial Ada program.
with Ada.Text_IO;
procedure Hello is
begin
Ada.Text_IO.Put_Line("Hello, world!");
end Hello;
copy this program into a file called "hello.adb" on the
student system and then compile it by typing "gnatmake hello"
in the same directory. Then run the code by typing "./hello".
Here are the details of what I did on partch:
partch:~/comp2310/2007> pwd
/students/u9507815/comp2310/2007
partch:~/comp2310/2007> cat hello.adb
-- Print a simple message to demonstrate a trivial Ada program.
with Ada.Text_IO;
procedure Hello is
begin
Ada.Text_IO.Put_Line("Hello, world!");
end Hello;
partch:~/comp2310/2007> gnatmake hello
gcc-4.1 -c hello.adb
gnatbind -x hello.ali
gnatlink hello.ali
partch:~/comp2310/2007> ./hello
Hello, world!
Note that to compile the code we type gnatmake, dependencies usually
associated with a makefile are automatically handled via
gnatmake. (You should not attempt to compile and link without using
gnatmake!)I think all the other examples can be built in a similar fashion using only one file named something.adb. If you come across any problems, let me (Alistair) know. The Lovelace TutorialsThe master outline of the lovelace tutorials is given here. Before the first lab in week 3 you should aim to complete lessons 1-10. I would suggest the following.
|
|
Please direct all enquiries to: Alistair.Rendell@anu.edu.au Page authorised by: Head of Department, DCS |
| The Australian National University — CRICOS Provider Number 00120C |