program scanner;
uses wincrt;
var
ch : char;
f : text;
token,Ttoken : string;
procedure baca;
begin
read (f,ch);
end;
procedure tampil;
begin
write (token:8,'--',Ttoken)
end;
procedure scan;
begin
clrscr;
assign(f,'Scan.txt');
reset(f);
write (' Token--Ttoken');
writeln;
while ch <> '.' do
baca;
case ch of
'A'..'Z','a'..'z':
repeat
token:= token+ch;
baca;
until (not( ch in ['A'..'Z','a'..'z']))
end;
Ttoken := 'Tident';
if token = 'dan' then Ttoken := 'Tdan';
if token = 'atau' then Ttoken := 'Tatau';
if token = 'mulai' then Ttoken := 'Tmulai';
if token = 'selesai' then Ttoken := 'Tselesai';
if token = 'div' then Ttoken := 'Tdiv';
if token = 'mod' then Ttoken := 'Tmod';
if token = 'bila' then Ttoken := 'Tbila';
if token = 'maka' then Ttoken := 'Tmaka';
if token = 'beda' then Ttoken := 'Tbeda';
if token = 'dari' then Ttoken := 'Tdari';
if token = 'sampai' then Ttoken := 'Tsampai';
if token = 'lakukan' then Ttoken := 'Tlakukan';
if token = 'tidak' then Ttoken := 'Ttidak';
if token = 'peubah' then Ttoken := 'Tpeubah';
if token = 'true' then Ttoken := 'Tboolkon';
tampil;
token := ''
end;
begin
case ch of
'+','-','/','*','=','>','<',';','.':
begin
repeat
token := token+ch;
baca;
until(not(ch in['+','-','/','*','=','>','<',';','.']));
if token = '+' then Ttoken := 'Ttambah';
if token = '-' then Ttoken := 'Tkurang';
if token = '/' then Ttoken := 'Tbagi';
if token = '*' then Ttoken := 'Tkali';
if token = '=' then Ttoken := 'Tsama';
if token = '>' then Ttoken := 'Tbesar';
if token = '<' then Ttoken := 'Tkecil';
if token = '>' then Ttoken := 'Tbsama';
if token = '<' then Ttoken := 'Tksama';
if token = '>=' then Ttoken := 'Tbsama';
if token = '<=' then Ttoken := 'Tksama';
if token = '<>' then Ttoken := 'Ttsama';
if token = '->' then Ttoken := 'Ttipe';
if token = '<-' then Ttoken := 'Tmasuk';
if token = ';' then Ttoken := 'Tkoma';
if token = '.' then Ttoken := 'Ttitik';
tampil;
token:=''
end;
end;
case ch of '0'..'9':
begin
repeat
token := token+ch;
baca;
until(not(ch in ['0'..'9']));
Ttoken := 'Tbulatkon';
tampil;
token :='';
end;
end;
case ch of
'A'..'Z','a'..'z','''':
begin
repeat
token := token+ch;
baca;
until(not(ch in ['A'..'Z','a'..'z','''']));
Ttoken := 'Tkarkon';
tampil
;
end;
end;
case ch of
'0'..'9','.':
begin
repeat
token := token+ch;
baca;
until(not(ch in['0'..'9','.']));
Ttoken := 'Tdeskon';
tampil;
token :='';
end;
end;
end.
0 komentar:
Post a Comment
Tinggalkan Komentar Disini