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

  • GeoGebra 6.0.417.0 16 Januari 2018
    GeoGebra is a free dynamic mathematics software tool for all levels of advanced education. The application combines geometry, algebra, spreadsheets, graphing, statistics and calculus and bundles them into one easy-to-use package. Users can use G...
  • dbForge Studio for MySQL 7.3.137 15 Januari 2018
    dbForge Studio for MySQL is the universal MySQL and MariaDB front-end client for database management, administration and development. It provides utilities to compare, synchronize, and backup MySQL databases with scheduling, and gives possibility t...
  • NTLite Free 1.5.0.5930 15 Januari 2018
    NTLite Free is an app for Windows administrators that allows you to edit Windows installation images, either 'offline' or 'live'. The 'live' edit mode is a unique feature that lets you modify already installed Windows OS' without re-installation. Al...
  • MKVToolNix 20.0.0 15 Januari 2018
    MKVToolNix is a set of tools that include mkvmerge, mkvinfo, mkvextract, mkvpropedit and mmg, which allow you to to create, manipulate and inspect Matroska (.MKV) files in several ways. With MKVToolNix you can create, split, edit, mux, demux, mer...
  • Total Excel Converter 5.1.0.245 15 Januari 2018
    If you work with Excel, then an app like Total Excel Converter is a really useful tool to have in your kit. Total Excel Converter is able to convert nearly any type* of table into any almost any type** of format you need. Key Features includ...

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: