跳到內容

軟體工程師手冊/語言詞典/Ada

來自華夏公益教科書,開放的書籍,開放的世界

Ada 是一種 強型別 多正規化 程式語言,適用於 嵌入式系統裝置驅動程式 和其他形式的 系統程式設計

Ada 是一種完整的 多正規化 程式語言,實現了以下正規化:併發分散式泛型 (模板 超程式設計)、命令式面向物件 (基於類的) 程式設計。

執行入口點

[編輯 | 編輯原始碼]

入口點的過程名稱可以自由選擇。

通用語法

[編輯 | 編輯原始碼]

典型的語句以分號結尾。將 b 賦值給 a 使用

a := b ;
-- this is an inline comment.  Everything after the -- is a comment.

變數宣告

[編輯 | 編輯原始碼]

宣告可以出現在塊的開頭。

將 i 宣告為整數

declare 
  I : Integer ; 
begin
  -- program
end ; 

以下是將 i 宣告為整數併為其賦予初始值 0 的兩種方式

declare 
  I : Integer := 0 ; 
begin
  -- program
end ;

方法宣告/實現

[編輯 | 編輯原始碼]

過程和函式分別由關鍵字過程函式 宣告。有關詳細資訊,請參閱 Ada 程式設計/子程式

procedure A_Test (A, B: in Integer; C: out Integer) is
begin
   C := A + B;
end A_Test;
function Minimum (A, B : Integer) return Integer is
begin
   if A <= B then
      return B;
   else
      return A;
   end if;
end Minimum;

類方法是與類記錄在同一範圍內宣告的原始操作(過程和函式)。有關詳細資訊,請參閱 Ada_Programming/面向物件

範圍由包的使用來宣告,包可能包含三個部分:公共規範()、私有規範(私有)和主體( 主體).

package Package_With_Body is

   type Basic_Record is private;

   procedure Set_A (This : in out Basic_Record;
                    An_A : in     Integer);

   function Get_A (This : Basic_Record) return Integer;

private

   type Basic_Record is 
      record 
         A : Integer;
      end record ;

end Package_With_Body;
package body Package_With_Body is

   procedure Set_A (This : in out Basic_Record;
                    An_A : in     Integer)
   is
   begin
      This.A := An_A;
   end Set_A;

   function Get_A (This : Basic_Record) return Integer is
   begin
      return This.A;
   end Get_A;

end Package_With_Body;

有關詳細資訊,請參閱 Ada_Programming/包

條件語句

[編輯 | 編輯原始碼]

<用文字描述條件語句並展示

檔案:range_1.adb (檢視純文字下載頁面瀏覽所有)
      if A < Range_Type'Last then
         T_IO.Put (",");
      else
         T_IO.New_Line;
      end if;

有關詳細資訊,請參閱 Ada_Programming/控制#if-else

迴圈語句

[編輯 | 編輯原始碼]

<用英語描述迴圈語句並展示程式碼示例。>

檔案:range_1.adb (檢視純文字下載頁面瀏覽所有)
   for A in Range_Type loop
      I_IO.Put (Item  => A,
                Width => 3,
                Base  => 10);

      if A < Range_Type'Last then
         T_IO.Put (",");
      else
         T_IO.New_Line;
      end if;
   end loop;

有關詳細資訊,請參閱 Ada 程式設計/控制#迴圈

輸出語句

[編輯 | 編輯原始碼]

<描述如何輸出Hello world!,包括帶或不帶回車的換行符。>

檔案:hello_world_1.adb (檢視純文字下載頁面瀏覽所有)
with Ada.Text_IO;

procedure Hello is
begin
   Ada.Text_IO.Put_Line("Hello, world!");
end Hello;

有關詳細資訊,請參閱 Ada_Programming/庫/Ada.Text_IO

錯誤處理/恢復

[編輯 | 編輯原始碼]

<描述錯誤處理和恢復。根據需要提供示例。>

有關詳細資訊,請參閱 Ada_Programming/異常

以下預定義的包現在可以在 Ada 中原生使用(自 Ada 2005 起)

這些是確定版本的 - 每個區域的非確定版本也提供。所有容器都是無界的。

演算法

[編輯 | 編輯原始碼]

<列出此語言原生提供的演算法或演算法列表的參考。列出如果演算法不是該語言的原生部分,則如何將演算法合併。或者,如果不可用,請說明。>

垃圾收集

[編輯 | 編輯原始碼]

垃圾收集可以是手動或自動的 - 請參閱您的編譯器手冊。如果提供自動收集,則 pragma Controlled () 可以停用對命名訪問型別的自動收集。

對於手動釋放,包 Ada.Unchecked_Deallocation 用於釋放。

有關詳細資訊,請參閱 Ada 程式設計/型別/訪問

物理結構

[編輯 | 編輯原始碼]

<描述檔案、庫和部分的典型劃分和排列方式。>

<請包含使從其他語言切換到此語言更容易的提示。>

網路參考資料

[編輯 | 編輯原始碼]

書籍和文章

[編輯 | 編輯原始碼]
華夏公益教科書