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 berkata:

    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 berkata:

    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

  • Bandicam 3.4.0.1227 27 April 2017
    With Bandicam screen recorder you can video record a certain area on a PC screen, or you can record a program which uses the DirectX/OpenGL graphic technologies. Bandicam screen recorder works with a high compression ratio, whilst keeping the video...
  • LibreOffice 5.3.3 RC 1 27 April 2017
    LibreOffice is the free power-packed Open Source personal productivity suite for Windows, Macintosh and Linux, that gives you six feature-rich applications for all your document production and data processing needs. Writer is the word processor insi...
  • LibreOffice 5.3.3 RC 1 64-bit 27 April 2017
    LibreOffice is the free power-packed Open Source personal productivity suite for Windows, Macintosh and Linux, that gives you six feature-rich applications for all your document production and data processing needs. Writer is the word proc...
  • Dropbox 24.4.17 27 April 2017
    Dropbox is the easiest way to store, sync and share files online. File Sync 2GB of online storage for free, with up to 100GB available to paying customers. Sync files of any size or type. Sync Windows, Mac and Linux computers. Automaticall...
  • EaseUS Partition Master Free 12.0 27 April 2017
    As Partition Magic alternative, EASEUS Partition Master Home Edition is a FREE ALL-IN-ONE partition solution and disk management utility. It allows you to extend partition (especially for system drive), manage disk space easily, settle low disk space...

RSS detikInet

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

RSS detikOto

%d blogger menyukai ini: