
All commands you must enter are given in this typeface. The computer's responses are shown in normal this typeface. You should go to a terminal, log in to felix, and follow this handout, step-by-step.
When you run the class setup, you gain access to a set of easy-to-use command scripts for working with GNAT. Once you really become familiar with the compiler, you can start using GNAT's real commands, which are more flexible but require more detailed knowledge. This handout describes only the simplified scripts.
All programs from the Feldman/Koffman book used in CSci 51, and some others, are located in the programs51 directory, to which you gain access when you run the class setup. These programs are filed according to the GNAT file-naming rule, which prefers a program unit MyProg to be stored in a file myprog.adb. You can copy programs from this subdirectory, but can't store anything into it; it belongs to the instructor. We'll see how to copy a program into your current directory, which Unix calls .(yes, it's just a dot). First log in to felix. The CSci 51 setup has created a directory called csci51. Try changing to that directory,
csstud@felix:11: cd csci51
then trying:
csstud@felix:12: cp programs51/hello.adb .
csstud@felix:13: cat hello.adb
WITH Ada.Text_IO; PROCEDURE Hello IS BEGIN -- Hello Ada.Text_IO.Put (Item => "Hello there. "); Ada.Text_IO.Put (Item => "We hope you enjoy studying Ada!"); Ada.Text_IO.New_Line; END Hello; csstud@felix:14:
Your next step is to try a compilation.
csstud@felix:14: gcompile hello.adb Compilation of hello.adb started on Tue Jan 14 15:22:46 EST 1997 Compilation ended on Tue Jan 14 15:22:53 EST 1997
If there were compilation errors, a message to that effect appears as well. The compiler produces a "listing file" which gives an "official" record of the compilation. If there were compilation errors, the messages occur interspersed with the lines of Ada.
You can see this file using cat or more; you can also print a hard (paper) copy of it in the usual way. Let's look at the listing file from our compilation:
csstud@felix:15: cat hello.lsb
GNAT 3.07 (961007) Copyright 1991-1996 Free Software Foundation, Inc.
Compiling: hello.adb (source file time stamp: 1996-01-23 03:03:19)
1. WITH Ada.Text_IO;
2. PROCEDURE Hello IS
3.
4. BEGIN -- Hello
5.
6. Ada.Text_IO.Put (Item => "Hello there. ");
7. Ada.Text_IO.Put (Item => "We hope you enjoy studying Ada!");
8. Ada.Text_IO.New_Line;
9.
10. END Hello;
The next step is to link the program. The linker requires a file with an .ali file type.
csstud@felix:16: glink hello.ali Linking of hello.ali started on Tue Jan 14 15:23:11 EST 1997 Linking ended on Tue Jan 14 15:23:15 EST 1997
Finally, we execute the program. While neither GNAT nor Unix requires a particular file type for executables, our scripts give them an .exe file type, and so should you.
csstud@felix:17: gexecute hello.exe Hello there. We hope you enjoy studying Ada!
You can execute a program any number of times without re-compiling.
csstud@felix:18: gexecute hello.exe Hello there. We hope you enjoy studying Ada!
You can use Unix commands to see which program units you've compiled and linked.
csstud@felix:19: ls -l *.ali -rw-r--r-- 1 csstud user 727 Jan 14 15:22 hello.ali csstud@felix:20: ls -l hello.exe -rwxr-xr-x 1 csstud user 119556 Jan 14 15:23 hello.exe
Let's try another program. We'll compile, link, and execute it, and then enter some "bad" data (alphabetic instead of integer). Note the exception "traceback" telling you in which line of your program the exception was raised.
csstud@felix:21: gcompile distance.adb Compilation of distance.adb started on Tue Jan 14 15:29:10 EST 1997 gcc: distance.adb: No such file or directory gcc: No input files Compilation ended on Tue Jan 14 15:29:10 EST 1997
Oops! We forgot to copy the program!
csstud@felix:22: cp programs51/distance.adb .
csstud@felix:23: gcompile distance.adb
Compilation of distance.adb started on Tue Jan 14 15:29:29 EST 1997
Compilation ended on Tue Jan 14 15:29:36 EST 1997
csstud@felix:24: glink distance.ali
Linking of distance.ali started on Tue Jan 14 15:29:47 EST 1997
Linking ended on Tue Jan 14 15:29:53 EST 1997
csstud@felix:25: gexecute distance.exe
How many hours will you be driving (integer) ? XYZ
raised ADA.IO_EXCEPTIONS.DATA_ERROR
Trace Back Information
Program Name File Name Line
------------ --------- ----
distance distance.adb 22
Oops! We entered XYZ instead of a numerical value! Running the program again with correct data input will give a reasonable answer.
csstud@felix:26: gexecute distance.exe How many hours will you be driving (integer) ? 5 At what average speed (miles per hour, integer) ? 55 You will travel about 275 miles
We require that you submit a "script" of your compilation, link, and test execution(s). The turnin command will allow you to create a transcript of everything you do on the terminal. One you have started turnin, everything that you type or the computer displays, until you type exit, will be copied into your script file. You can then print the file to submit as part of your project. As an example, let's try copying a program hello_name.adb, then compiling, linking, and executing it with the script running.
csstud@felix:27: cp programs51/hello_name.adb . csstud@felix:28: turnin Project name ? just-a-test Turnin started; type exit to leave turnin. Script started, file is just-a-test.turnin script> csstud@felix:29: gcompile hello_name.adb Compilation of hello_name.adb started on Tue Jan 14 15:33:26 EST 1997 Compilation ended on Tue Jan 14 15:33:29 EST 1997 script> csstud@felix:30: glink hello_name.ali Linking of hello_name.ali started on Tue Jan 14 15:33:37 EST 1997 Linking ended on Tue Jan 14 15:33:40 EST 1997 script> csstud@felix:31: gexecute hello_name.exe Enter your first name, exactly 10 letters. Add spaces at the end if it's shorter.> Jennifer Hello Jennifer . We hope you enjoy studying Ada! script> csstud@felix:32: exit Script done, file is just-a-test.turnin csstud@felix:33
The file just-a-test.turnin can be printed out to turn it in, and will remain in your file system until you remove it.
Enjoy CSci 51 and Ada 95 and GNAT!