To program in Ada, you need an Ada compiler. If you are involved in academics (student, teacher, etc), you can download it free from the GNAT programming studio that will provide you with an Ada compiler (you may have to create an account on the web site to be registered and activate the software). After downloading GNAT, you can install it. The default installation would be C:\GNAT\2009. The installation would create an icon for the GNAT programming studio. The icon is named GPS:
After installing GNAT, you can start creating applications (you should first use a file utility, such as Windows Explorer, to create a folder that will contain the project; otherwise, the GPS can create the folder for you. For this project, we will use a folder named Exercise1 created in the C:\ drive).
To launch the GNAT programming studio, you can double-click the gps.exe icon. This would start with a splash screen:
After the GPS splash screen, the Welcome to GPS dialog box would display. To start a project, click the Create A New Project With Wizard radio button:
Click OK. This would display the first page of the Create New Project wizard.
Create the Single Project radio button:
In the second page of the Create New Project wizard, you must enter a name for the project. After entering the name of the project, you must specify the folder where the project will be stored:
When you are ready, click Forward.
In the third page of the wizard, make sure (only) the Ada check box is checked:
In the fourth page of the wizard, click Forward.
In the fifth page of the wizard, click Forward.
In the sixth page of the wizard, you must specify a folder for the build. You can use the same path you specified in the second page of the wizard. Otherwise, you can enter another. the scenario would the the same we reviewed in the second page:
Once you are ready, click Forward.
In the seventh page of the wizard, if you had already created an Ada source file, you can click Add to locate, select, and add it. If not, you don't have to do anything: you will add the files later on:
Once you are ready, click Forward.
In the eighth page of the wizard, click Forward.
In the ninth page of the wizard, accept the defaults and click Apply. If the path you specified in the second (and the sixth) page of the wizard exists already, the wizard would end and the project would be created. If the path is wrong, the wizard would display a message and ask if you want it to create the directory:
In this case, you can click Yes. The wizard would complete the project creation. When the project has been created, the GPS - GNAT Programming Studio would come up, divided in various windows. The lower-right window would indicate that the project doesn't have a source file:
To make an Ada program useful, you must add a source file to it. To create a source file:
This would create an empty file. In it, type the following:
with Ada.Text_IO; use Ada.Text_IO; procedure Welcome is begin Put_Line("Welcome to Ada Programming"); end Welcome;
After typing the code, you must save the document. To do this:
If the file had not been saved before, this action would display the Save File As dialog box. Locate and select the folder that contains the project. Normally, a name will be suggested for the file and it should have the .adb extension (otherwise, make sure you provide this information):
Once you are ready, click Save.
After creating a source file, you must add it to the project. To do this, on the main menu, click Project -> Edit Project Properties:
On the left list of buttons, click Main Files.
In the Main Files section, click Add. In the Select Files dialog box, click the check box of the file you had saved:
To build the project, on the main menu, you can click Build, position the mouse on Project, and click either Build <current file> or the name of the file
This would display the Build Main dialog box:
Click Execute. The compiler would build the executable and display the result in the lower-right window:
Once a project has been built, to see its result, you must execute it. To execute the application, on the main menu, click Build, position the mouse on Run, and click the name of the file:
This would display the Arguments Selection dialog box:
Click OK. The result would appear in the lower-right window:
A comment is text that will not be considered when the project is built. Therefore, you can write anything you want as part of a comment.
A comment starts with --. Anything on the right side of that, up to the end of the line, is considered a comment.
A pragma is something that asks the compiler to take a certain action, such as to import something from an external file. This is referred to as a directive.
To create a pragma directive, start with the pragma keyword followed by the instruction.