program Scanner1;
uses wincrt;
var
hrf:array [1..1000] of char;
token:array [1..50]of string;
nama_token:array[1..50]of string;
ch:set of char;
huruf:set of char;
j,k,l,m,n:integer;
txt:text;
chr:char;
procedure baca;
begin
assign (txt,'scanner2.txt');
reset(txt);
end;
procedure tampil;
begin
m:=0;
repeat
read(txt,chr);
m:=m+1;
write(chr);
hrf[m]:=chr;
until (chr='.');
j:=m;
end;
procedure cek_token;
begin
ch:=['a'..'z']+['A'..'Z']+['0'..'9']+['+']+['-']+['*']+['/']+[':']+[';']+['='];
reset(txt);
token[1]:='';
k:=0;
m:=1;
huruf:=['a'..'z']+['A'..'Z'];
for m:=1 to j do
begin
while hrf[m] in ch do
begin
k:=k+1;
if hrf[m] in huruf then
nama_token[k]:='Tident'
else
nama_token[k]:='Tbilbulat';
repeat
token[k]:=token[k]+hrf[m];
m:=m+1;
until not(hrf[m] in ch);
if hrf[m]='.' then
begin
token[k+1]:=hrf[m];
nama_token[k+1]:='Ttitik';
end;
end;
end;
k:=k+1;
end;
procedure cek_nama_token;
begin
l:=1;
for m:=1 to k do
begin
if token[m]= 'mulai' then
nama_token[m]:='Tmulai';
if token[m] = 'beda' then
nama_token[m] := 'Tbeda';
if token[m] = '*' then
nama_token[m] := 'Tkali';
if token[m] = '/' then
nama_token[m] := 'Tbagi';
if token[m] = '+' then
nama_token[m] := 'Ttambah';
if token[m]='Jika' then
nama_token[m]:='Tjika';
if token[m]='=' then
nama_token[m]:='Tsama';
if token[m]='Maka' then
nama_token[m]:='Tmaka';
if token[m]=':=' then
nama_token[m]:='Tmasukan';
if token[m]='div' then
nama_token[m]:='Tdiv';
if token[m]='Beda' then
nama_token[m]:='Tbeda';
if token[m]='mod' then
nama_token[m]:='Tmod';
if token[m]=';' then
nama_token[m]:='Ttkoma';
if token[m]='Selesai' then
nama_token[m]:='Tselesai';
if token[m]='.' then
nama_token[m]:='Ttitik';
end;
end;
procedure tampil_token;
begin
clrscr;
gotoxy(25,1);writeln(' keyword | Token');
gotoxy(25,2);writeln(' ******* | *****');
n:=3;
for m:=1 to k do
begin
gotoxy(25,n);
writeln(token[m]:10,' = ',nama_token[m]);
n:=n+1;
end;
end;
begin
baca;
tampil;
cek_token;
cek_nama_token;
tampil_token;
end.
0 komentar:
Post a Comment
Tinggalkan Komentar Disini