Wednesday, February 3, 2016

First Ada Program - Hello, World! With How-to and Feedback on Compiler

Hello, World!

I will quickly state here the source code and output for "Hello, World!" in Ada along with an explanation of some of the lines. The next section will explain how one obtains this compiler and how to create and run programs on it.

Source code:


This code prints "Hello, World!" to the output.

The way Ada works is we must specify that we are going to use the text input output before writing the procedure.

This is done using the first line of the code given:

                  with Ada.Text_IO; use Ada.Text_IO;

Next, Put_Line is used to specify what to output.

                  Syntax: Put_Line("[insert text]");
The output can be seen in the "Run" Section at the bottom of the compiler interface. I highlighted it to make it more obvious.




How to Acquire the Compiler GNAT - GPS (Gnat Programming Studio) for Ada

One obtains this compiler by going to http://libre.adacore.com/

Follow the pictures to install for windows. I have not been successful installing it on my Mac.

1. Go to Site and click Download.


2. Choose usage and hit build package.


3. Select x86 Windows (32 bits) and click the first .exe file under GNAT Ada GPL 2015



4.  After completing install, to run search gps.exe and run that. That will open GPS!

How To Create a Project and Run Programs

VERY IMPORTANT SECTION.

1. ALWAYS create new project with the Wizard. Otherwise the project will not function correctly nor run. This also gives you the option to Open and Existing Project. Select OK.



2. Choose Single Project. It is the most simple for our purposes for the time being. Then, hit Forward.



3. Now, type the name of the project you would like to create and choose a directory to store the project file in. This will be where your Program Files will be stored as well, such as the source code for Hello, World!

Click Forward.

4. The next screen you will see is a Languages screen. Select Ada and then choose Apply. We do not have to change anything else right now.



5. You have now created a Project! This is the main screen. The files under the blue file-bin-icon thing will probably be names "0" and "1" for you. Those are just the directory file names hidden by those numbers. There is a setting that allows you to disclose the file directory names, which I selected. It is not needed to run a program, just preference.


6. Now we must create a New file. This will be your program file where you type source code. Click the page icon with a plus at the top of the interface near File and Edit.


Doing so will bring up a blank, editable page named "Untitled". Below is the edited version of it with source code for Hello. World! After or before editing, save the file as the default name it gives you. In this case, it is "hello.adb" because the procedure name will be the name of your file.

Example: procedure HiBye is --> name of file = "hibye.adb"

The extension for your program file MUST be .adb --- NOT .ada as it would make sense to be.








7. Now, for the weird part. Go to the top of the interface and select Project, then Properties. A window will appear. Select Main files. Click the +Add button and select the program file you just created. Doing so will result in a screen like this:



























Select OK.

8. Now, we must Build the program. Select this icon at the top of the interface: 



Doing so will result in these messages.


If it results with "process terminated successfully," you're good to go!

9. Lastly, we have to Run the program. Select this icon at the top of the interface:



This will execute your program and show your output in the Run: section at the bottom of the interface. The highlighted portion is your output!




Feedback on Ada - Reactions so far

As of right now, I think Ada is pretty simple and actually very easy to learn.

However, although Ada is simple, getting the program to run for the first time was such a hassle. It was absurd how many steps it took to just get it to run. The compiler interface's warnings about what is wrong did not inform me enough about what to do to fix the problem. I had to resort to a couple hours of google searching and whatnot to compose a formula as to how to get it to successfully build and run the program.

Now that the compiler issue is out of the way, I think this language will be a lot more fun to learn!












































No comments:

Post a Comment