Getting Started
Some Simple Programs!
do_nothing.adb
- The shortest Java program:
DoNothing.java
public class DoNothing{
public static void main(String[] args){;}
}
The shortest Ada program: do_nothing.adb
-- The shortest Ada program
procedure do_nothing is
begin
null; -- Does nothing
end do_nothing;
-- Well, is there a shorter Ada program?
Comments: -- to end of line, no multiline comments
a procedure is similar to a method
filename (do_nothing.adb) matches procedure name (do_nothing)
adb means ADa Body
Case: Ada is not case sensitive, but OS is (use lower case file name)
procedure do_nothing
is like public static void main
Execution begins at ... begin
No class needed - do_nothing is a top-level procedure, it's not contained in anything
do_nothing - you choose identifier for procedure name
identifier: Letter followed by 0 or more letters, digits, underscores. Underscore followed by letter or digit
No braces: begin/end instead
end do_nothing
- procedure name repeated (optional, but a good idea)
Statements followed by semicolons: where are the statements?
Command line compile and run:
gnatmake do_nothing
./do_nothing [or just do_nothing]
hello.adb
-- This program actually does something
with Ada.Text_IO; use Ada.Text_IO;
procedure hello is
begin
new_line;
put_line("Hi!");
new_line(2);
put("Welcome to");
put_line(" ITEC 320!");
end hello;
With and Use - similar to import (later we will see some differences!)
Ada.Text_IO - library for I/O of text - similar to System.out
Statements followed by semicolons: where are statements?
filename (hello.adb) matches procedure name (hello)
new_line and new_line(2)
put and put_line - similar to print and println
Strings in quotes
Command line compile and run:
gnatmake hello
./hello [or just hello]
Development Environments
Command Line
- Command line: Editor, gnatmake, run
- Command line environments: Windows cmd window, Mac and Linux terminal, putty connection to rucs
- Editor: vim or pico or ...
- gnatmake foo.adb # gnatmake must be on path
- ./foo [ run executable foo or foo.exe] [may not need ./]
AdaGIDE
GPS
- Full-featured IDE
- Requires a project file
- Either create a project file with wizard
- Or write your own (using editor such as vi or pico or notepad++) :
-- File foo.gpr
project foo is
for main use ("foo.adb");
end foo;
A better project file - include a directory for object files that you
don't want to see:
- Either Add the object directory using project/properties
- Or, edit the project file yourself:
-- File foo.gpr
project foo is
for main use ("foo.adb");
for object_dir use "obj";
end foo;
You must create directory obj
as a child of the directory that
contains the .adb
and .gpr
files
Click on project file to start GPS
- Project/Properties/main must specify a main program
- Can change main with Project options
- Or simply edit project file with an editor
Other Options
- Other options:
- TextMate
- jGrasp
- Eclipse: plugin available from libre.adacore.com (status is unclear)
- IntelliJ: plugin also available (untested and minimal, but intellij is a nice system)
- Visual Studio Code - Ada plugin not available as far as I know
- Some people combine options (ie edit with IDE and compile and/or run with
command line)
More Detail
- More detailed instructions compilation and running are on this page
Installation on Personal Machines
Personal Machine Installation
- Required: gnat. Easiest from: www.adacore.com/community
- A Windows installer is available on the Download page
- If given the opportunity, select the option to add to path
- For other platforms, click the link for "More packages ..."
- Instructions for Mac and Linux:
- Follow instructions here (2017
version not tested)
- GPS: Installing gnat also installs GPS
- AdaGIDE - For those who want it:
More Detail
- More detailed instructions on installing compilers and IDEs are on this page