Teknik Pendeskripsian Semantik Bahasa Pemrograman (dengan Contoh)

A. Operational Semantic

Operational Semantic adalah pendekatan yang menggunakan operasi matematika dalam bahasa pemrogramannya, contoh :

(Dalam QBasic)

CLS
‘Program Perhitungan Luas dan Keliling Persegi Panjang
INPUT “Panjang : “, pjg
INPUT “Lebar : “, lbr
L = pjg * lbr
K = 2 * (pjg + lbr)

PRINT
PRINT “Luas Persegi Panjang adalah”; L
PRINT “Keliling Persegi Panjang adalah”; K
END

==========================================================

B. Denotational Semantic

Denotational Semantic adalah pendekatan yang menggunakan suatu fungsi pemetaan program-program komputer, contoh :

(dalam PASCAL)

uses crt;
var
a,b,c:integer;
j,k:integer;

function jumlah:integer;
begin
clrscr;
writeln(‘program jumlah’);
write(‘angka1 = ‘); readln(a);
write(‘angka2 = ‘); readln(b);
j:=a+b;
write(j);
readln;
end;

function kali:integer;
begin
clrscr;
writeln(‘program kali’);
write(‘angka1 = ‘); readln(a);
write(‘angka2 = ‘); readln(b);
k:=a*b;
write(k);
readln;
end;

begin
kali;
jumlah;
end.

==========================================================

C. Axiomatic Semantic

Axiomatic Semantic adalah pendekatan yang menggunakan logika seperti AND, OR, NOT, contoh :

(dalam QBasic)

CLS
INPUT “Nilai UTS : “, A
INPUT “Nilai UAS : “, B
c = (A + B) / 2
IF c >= 90 THEN
grade$ = “A”
ELSEIF c >= 75 AND c <= 89 THEN
grade$ = “B”
ELSEIF c >= 60 AND c <= 74 THEN
grade$ = “C”
ELSEIF c < 60 THEN
grade$ = “D”
END IF
PRINT
PRINT “Nilai Akhir :”; c
PRINT “Grade : “; grade$
END

==========================================================

D. Algebraic Semantic

Algebraic Semantic adalah pendekatan yang menggunakan fungsi Boolean (True or False). Contoh :

(dalam QBasic)

DIM Numbers(5) AS INTEGER
DIM SearchNum AS INTEGER
DIM X AS INTEGER
DIM found AS INTEGER

CLS

FOR X = 1 TO 5
INPUT “Enter Number: “, Numbers(X)
NEXT X

CLS

INPUT “Search Number: “, SearchNum

PRINT
PRINT

found = 0

FOR X = 1 TO 5
IF SearchNum = Numbers(X) THEN
found = 1
END IF
NEXT X

IF found = 1 THEN
PRINT “The Number Is In The Array”
ELSE
PRINT “The Number Is Not In The Array”
END IF

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s