Program Konversi Infix ke Postfix dengan Pascal

6

4 Januari 2012 oleh Rizky Zakaria

Listing Koding Infix ke Postfix:

program KONVERSI_INFIX_KE_POSTFIX;

uses crt;

const Max_Elemen = 255;

type S255 = string[Max_Elemen];

Tumpukan = record

Rinci : S255;

Atas : 0..Max_Elemen

end;

var Infix : S255;

Lagi : char;

 

function VALENSI (Tanda_Op : char) : integer;

begin

case Tanda_Op of

‘$’ : VALENSI := 3;

‘*’, ‘/’ : VALENSI := 2;

‘+’, ‘-‘ : VALENSI := 1;

‘(‘ : VALENSI := 0

end

end;

procedure PUSH (var T : Tumpukan; Elemen : char);

begin

T.Atas := T.Atas + 1;

T.Rinci[T.Atas] := Elemen

end;

function POP (var T : Tumpukan) : char;

begin

POP := T.Rinci[T.Atas];

T.Atas := T.ATas – 1

end;
procedure KONVERSI_CETAK (Infix : S255);

var I : integer;

Operator : set of char;

Temp, Kar : char;

T : Tumpukan;

Test : boolean;

begin
Operator := [‘$’]+[‘*’]+[‘/’]+[‘+’]+[‘-‘];
for I := 1 to length(Infix) do

begin

Kar := Infix[I];
if Kar = ‘(‘ then PUSH(T, Kar)
else if Kar = ‘)’ then

begin

while T.Rinci[T.Atas] <> ‘(‘ do

write(POP(T):2);

Temp := POP(T)

end
else if Kar in Operator then

begin

while (T.Atas <> 0) and (VALENSI(Kar) <= VALENSI(T.Rinci[T.Atas])) do

write(POP(T):2);

PUSH(T, Kar)

end
else if Kar <> ‘ ‘ then

write(Kar:2)

end;

if T.Atas <> 0 then
repeat

write(POP(T):2)

until T.Atas = 0;

end;

begin

clrscr;

writeln(‘—————————————–‘);

writeln(‘| PROGRAM KONVERSI INFIX MENJADI POSTFIX |’);

writeln(‘—————————————–‘);

writeln;

repeat
write(‘Masukkan Ungkapan Infix: ‘);

readln(Infix); writeln;

write(‘Ungkapan Postfixnya Adalah: ‘);
KONVERSI_CETAK (Infix);

writeln; writeln;

write(‘Akan mencoba lagi? Y/T: ‘);

readln(Lagi);

writeln

until not (Lagi in [‘Y’, ‘y’])

end.

(Disarankan memakai Turbo Pascal versi 7.1 karena apabila Anda memakai Free Pascal akan tidak jalan programnya dikarenakan variabel (Operator = set of char) set of-nya dikatakan salah pendeklarasian, sebenarnya itu sudah benar.

Untuk Outputnya:

6 thoughts on “Program Konversi Infix ke Postfix dengan Pascal

  1. daga mengatakan:

    low di dev pas set of char pake apa gan??

  2. […] Menggarap Klip Nasional (Taboo Band)Ruang Ganti City ‘Sangat Argentina’, Tevez pun BetahProgram Konversi Infix ke Postfix dengan Pascal .set-header:after{ background-image: […]

  3. sandy mengatakan:

    Untuk free pascal, deklarasi set of char nya tidak dengan titik dua (:)
    contoh :
    Var : set of char;

    Tetapi dengan tanda sama dengan (=)
    contoh :
    Var = set of char;

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

Masukkan alamat surat elektronik Anda untuk mengikuti blog ini dan menerima pemberitahuan tentang tulisan baru melalui surat elektronik.

Bergabunglah dengan 1 pengikut lainnya

My Profile

Tanggal/Bulan/Tahun

Januari 2012
S S R K J S M
« Nov   Mar »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

7zip (Alternatif Selain WinRAR)

RSS detiksepakbola

RSS File Hippo

  • Spotify 1.0.44.100 9 Desember 2016
    With Spotify, it’s easy to find the right music for every moment – on your phone, your computer, your tablet and more. There are millions of tracks on Spotify. So whether you’re working out, partying or relaxing, the right music is always at your fi...
  • StressMyPC 2.91 9 Desember 2016
    If you need to test your computer's performance to ensure it is running at optimal capacity, then it is a good idea to run a stress test and analyze the results. StressMyPC is a small, lightweight and useful tool for the job. It actually does not req...
  • Calibre 2.74.0 64-bit 9 Desember 2016
    Calibre is a complete e-book library manager that lets you totally organize your collection. With Calibre you can convert your books to multiple formats, and then sync with all of your devices. KEY FEATURES INCLUDE: Library management. Calibre ...
  • Calibre 2.74.0 32-bit 9 Desember 2016
    Calibre is a complete e-book library manager that lets you totally organize your collection. With Calibre you can convert your books to multiple formats, and then sync with all of your devices. KEY FEATURES INCLUDE: Library management. Calibre...
  • LastPass: Free Password Manager 4.1.34 9 Desember 2016
    LastPass is an award-winning password manager that can save your passwords and provide you with secure access from every computer and mobile device you have. With LastPass you need only remember one password - your LastPass master password. With t...

RSS detikInet

  • Sebuah galat telah terjadi; umpan tersebut kemungkinan sedang anjlok. Coba lagi nanti.

RSS detikOto

  • Sebuah galat telah terjadi; umpan tersebut kemungkinan sedang anjlok. Coba lagi nanti.
%d blogger menyukai ini: