跳轉到內容

軟體工程師手冊/語言詞典/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 程式設計/控制#loops

輸出語句

[編輯 | 編輯原始碼]

<描述如何輸出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 程式設計/型別/訪問

物理結構

[編輯 | 編輯原始碼]

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

<請包括便於從其他語言切換到此語言的提示。>

網路參考

[編輯 | 編輯原始碼]

書籍和文章

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