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

  • Save To Pocket 2.1.48 19 Oktober 2017
    The Save to Pocket Extension for Chrome is one of the best ways to save articles, videos and other important content. Using the extension is really easy; when you find something in Chrome that you want to view later, put it in Pocket! The Save to Poc...
  • SaferPass 6.3.3 19 Oktober 2017
    SaferPass Password Manager makes life easy by ensuring you never forget another password! With SaferPass you have the ability to generate strong password, which you don't have to remember. SaferPass is able to secure your online accounts and aut...
  • Google Translate 2.0.7 19 Oktober 2017
    The Google Translate extension will allow you to view numerous languages easily as you browse the web. Simply highlight or right-click on a portion of text and then click on Translate icon next to it to translate it to the language that you need. If ...
  • Google Calendar 2.8 19 Oktober 2017
    If you use Google's Chrome browser and you use Google's Calendar then, quite simply, you need to install the free Google Calendar extension for Chrome. With the Google Calendar extension installed, you will be able to access your Google Calendar ap...
  • Notepad3 2.17.1016.610 19 Oktober 2017
    Notepad3 is a revamp of the standard, vanilla offering Windows Notepad that comes with Microsoft’s operating system. Notepad3 is a fast and lightweight Scintilla-based text editor with syntax highlighting capability. Although it has a small footpri...

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: