SPARKS語言

SPARKS語言

SPARKS 語言是一種算法描述語言,這種語言具有精簡易懂的特點,適用於模組化程式設計過程中對於各模組的算法進行描述交流,通過使用SPARKS 語言,在模組細化的過程中,可以忽略模組的細節而將關鍵的算法思想表達出來。

基本介紹

  • 中文名:SPARKS語言
  • 外文名:SPARKS language
  • 類型:算法描述語言
數據類型,命名規則,賦值語句,邏輯運算符,關係運算符,多維數組,主要語句,條件語句,case語句,循環語句,輸入和輸出,函式(過程),寫法,算法,

數據類型

整型(integer)
實型(real)
布爾型(boolean)
字元型(char)
例: integer x, y; char ch;

命名規則

以字母開頭,不允許使用特殊字元,不允許與保留字重複

賦值語句

變數<---- 表達式

邏輯運算符

and , or , not

關係運算符

< ,≤,=,≠,>, ≥

多維數組

任意整數下界和上界的多維數組
例: integer A(1:10); real B(1:3 , 1:4);

主要語句

條件語句

if 條件 then s1
endif
if 條件 then s1
else s2
endif

case語句

case
: 條件 1: s1

: 條件 n: sn
: else : sn+1
endcase

循環語句

(1)while 條件 do
S
repeat
(2)loop
S
until 條件 repeat
(3)for 變數初值 to 終值 by 變數增值 do
S
repeat

輸入和輸出

read(參數表);print(參數表);

函式(過程)

procedure NAME(<參數列表>)
<說明部分>
S
return(<表達式>)
end NAME

寫法

procedure MAX(A, n, j)
parameters real A(1:n);
parameters integer n, j;
real xmax;
local integer i;
xmaxA(1);
for i2 to n do
if A(i)>xmax then
xmaxA(i); ji;
endif
repeat
return(xmax);
end MAX
procedure MAX(A, n, j)
float A(1:n); int n, j;
global float xmax;
int i;
xmax=A[1];
for( i=2; i<=n; i++)
if (A[i]>xmax)
{ xmax=A[i]; j=i; }
return(xmax);
end MAX

算法

變數的另一種劃分方法: in、out、inout
邊界效應:
將改變其參變數或全程變數的過程叫做具有邊界效應。
Notes:約定只準寫沒有邊界效應的函式過程或純過程。

相關詞條

熱門詞條

聯絡我們