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

  • mp3tag 2.83 25 Juni 2017
    Mp3tag is a universal media tag editor. It is an easy to use app for conveniently editing tags in audio files such as the information about artist, album, title, and album art. The app supports batch tag editing of ID3v1, ID3v2.3, ID3v2.4, iTunes ...
  • Video Booth 2.8.1.6 24 Juni 2017
    Video Booth is a great little application if you like to edit your own video for fun. It gives you the ability to take snapshots and video clips both quickly and with minimal fuss. Not only can you take snapshots and video but Video Booth also has a ...
  • Seafile 6.0.7 23 Juni 2017
    Seafile is a cloud storage and data synchronization platform that lets you store your data and files on a central server and then synchronize them with your computers and mobile devices. It work by synchronizing your data between Seafile’s servers ...
  • Xinorbis 8.0.15 23 Juni 2017
    Xinorbis is a simple but powerful hard disk, folder and storage analyser. It uses a mix of graphs, tables and tree displays to provide the user with a complete overview of the contents of any hard disk, folder, removable drive or network drive. ...
  • Maxthon Cloud Browser 5.1.0.1700 Beta 23 Juni 2017
    Maxthon Cloud Browser is a powerful web browser which has a highly customizable interface. The browser has multiple tools that make your web experience more enjoyable, such as resource sniffer, screen capture tool, night mode and cloud functionality...

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: