首页 > 学院 > 开发设计 > 正文

从零开始学习Ada(入门)

2019-11-08 19:44:33
字体:
来源:转载
供稿:网友

What is Ada?

Ada 语言最初设计是为了构建长周期的、高度可靠的软件系统。它提供了一系列功能来定义相关的数 据类型(type)、对象(object)和操作(Operation)的程序包(package)。程序包可以被参数化,数据类型可以被扩 展以支持可重用库的构建。操作既可以使用方便的顺序控制结构,通过子程序(subPRogram)来实现,也可以 通过包含并发线程同步控制的入口(entry)来实现。Ada 也支持单独编译(separate compilation),在物理层上 支持模块性。

Ada 包含了很复杂的功能以支持实时(real-time),并发程序设计(concurrentprogramming)。错误可以作为 异常(exception)来标示,并可以被明确地处理。Ada 也覆盖了系统编程(system programming);这需要对数 据表示和系统特性访问的精确控制。最后,提供了预定义的标准程序包,包括输入输出、字符串处理、数值计算的基本函数和随机数生成。

What is available for Ada?

There are many Ada compilers, including a free Ada 95 compiler called GNAT based on the Free Software Foundation’s gcc. There are also many Ada-related tools and on-line reference documents. A later section of this tutorial provides more information about on-line Ada information sources.

如何安装GNAT在下面的帖子里有详细说明。不得不说,上述这篇写的非常详细,对小弟非常有帮助。 在WINDOWS系统上安装GNAT GPL 2015 ADA开发环境

当然GPS作为集成开发环境,也支持很多语言,按需要选择目标语言。

但是我个人在运行Helloworld.exe的时候,cmd显示了:

C:/>Gnatwork/helloworld>helloworld.exeaccess is denied.

也是颇感郁闷。

Ada HelloWold

-- Ada 2017 Hello, world.with Ada.Text_Io;use Ada.Text_Io;procedure Helloworld isbegin Put_Line("Hello, World!");end Helloworld;Ada的标注是 “–”,和C++ 的// 一样with clause, which specifies the library units (other items) that we need. This particular with clause specifies that we need Ada.Text_IO. The library unit Ada.Text_IO is a predefined library unit that provides operations to perform basic text input and output.Defining a new procedure named Hello. 相比起(in C and C++, it must be called main, and in Pascal, it must be specially identified as the program),Ada只是一个简单的procedure。begin 和 end 都一样使用Put_Line有分号semicolon,和C,C++相似

Ada Compute

with Ada.Text_IO, Ada.Integer_Text_IO;use Ada.Text_IO, Ada.Integer_Text_IO;procedure Compute is procedure Double(Item : in out Integer) is begin -- procedure Double. Item := Item * 2; end Double; X : Integer := 1; -- Local variable X of type Integer.begin -- procedure Compute loop Put(X); New_Line; Double(X); end loop;end Compute;

1. 制作了X local variable,Integer用于想储存某signed integers。这里不会在意 integers 的minimum and maximum range 2. Double函数把取值乘了2 3. Put 把数值显示出来,New_Line使数值内容走向下一页 4. When a computation (such as doubling) cannot be performed, Ada raises an `exception’.

现在我们对 Ada 程序长的什么样已有了基本的认识,下面需要了解几个术语。一个 Ada 程序是由 一个或多个程序单元组成(programunit)。

一个程序单元可以为: 1. 子程序(subprogram),定义一些可执行运算。过程(procedure)和函数(function)都是子程序。 2. 程序包(package),定义一些实体(entity)。程序包是 Ada 中的主要分组机制,类似于 C 的函数 库,Modula 的”module”。 3. 任务单元(taskunit),与线程类似,定义一些计算,然后并发执行。 4. 保护单元(protectedunit),在并发计算中协调数据共享,这在 Ada83 中不存在。 5. 类属单元(genericunit),帮助构建可重用组建,和 C++ 的模板类似。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表