Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
24Activity
0 of .
Results for:
No results containing your search query
P. 1
Modul Peraktikum Teknik Kompilasi II

Modul Peraktikum Teknik Kompilasi II

Ratings: (0)|Views: 532|Likes:
Published by cyberjack30

More info:

Published by: cyberjack30 on Jan 18, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

05/15/2013

pdf

text

original

 
 Modul Peraktikum MTBTeknik Kompilasi (T.Informatika)
MODUL PERAKTIKUM TEKNIK KOMPILASI II
PROGRAM SCANNER LANJUT (KOMPLEKS)*****************************************************
Berikut ini adalah program scanner yang menerima input suatu file kodesumber dalam bahasa pascal, kemudian menghasilkan suatu file text yang berisidaftar token-token yang terdapat dalam program.
PROGRAM SCANNER;USES CRT;TYPETOKENTYPE = ( TNONE,TIDENTIFIER,TINTEGER,TREAL,TCHARCONSTANT,TSTRING,TPLUS,TMIN,TMULT,TDIV,TASSIGMENT,TTITIKDUA,TRANGE,TKOMA,TTITIK,TTITIKKOMA,TEQUAL,TINEQUAL,TLESS,TLESSEQU,TGREATER,TGREATEREQU,TKURUNGSIKUBUKA,TKURUNGSIKUTUTUP,TKURUNGBUKA,TKURUNGTUTUP,TKEYAND,TKEYARRAY,TKEYBEGIN,TKEYCASE,TKEYCONST,TKEYDIV,TKEYDO,TKEYDOWNTO,TKEYELSE,TKEYEND,TKEYFILE,TKEYFOR,TKEYFUNCTION,TKEYGOTO,TKEYIF,TKEYIN,TKEYLABEL,TKEYMOD,TKEYNIL,TKEYNOT,TKEYOF,TKEYOR,TKEYPACKED,TKEYPROCEDURE,TKEYPROGRAM,TKEYRECORD,TKEYREPEAT,TKEYSET,
 
 Modul Peraktikum MTBTeknik Kompilasi (T.Informatika)
TKEYTHEN,TKEYTO,TKEYTYPE,TKEYUNTIL,TKEYVAR,TKEYWHILE,TKEYWITH);SCANERRORTYPE = (ERRNONE,ERRSCANUNEXPCHAR,ERRSCANFLOAT,ERRSCANINT,ERRSCANAPOSTEXP,ERRSCANUNEXPEOF);CONSTENDFILE = #26;JMLKEYWORD = 44;KEYWORD : ARRAY [1..JMLKEYWORD] OF STRING[9] = ('AND', 'ARRAY','BEGIN', 'BOOLEAN', 'CASE','CONST', 'CHAR', 'DIV', 'DO', 'DOWNTO','ELSE', 'END', 'FILE', 'FOR','FUNCTION','GOTO', 'IF', 'IN','INTEGER', 'GOTO', 'IF', 'IN','INTEGER', 'LABEL','MOD', 'NIL', 'NOT','OF', 'OR', 'PACKED', 'PROCEDURE','PROGRAM', 'REAL', 'RECORD', 'REPEAT', 'SET','STRING', 'THEN', 'TO', 'TYPE', 'UNTIL','VAR', 'WHILE','WITH');EMAX = 38;EMIN = -38;JMLSIGDGT = 5;VALMAX = 16383;MAXINFO = 128;VARSCANSTR : STRING;TOKEN : TOKENTYPE;INUM : LONGINT;RNUM : REAL;CC : CHAR;FILESOURCE,FILERES : STRING;INFILE,RESFILE : TEXT;ERRCOUNTER : INTEGER;LINECOUNTER : INTEGER;LOKASI : ARRAY [1..MAXINFO] OF STRING;JINFO : INTEGER;FUNCTION OPENFILE:BOOLEAN;VARI : INTEGER;OPEN1,OPEN2 : BOOLEAN;BEGINWRITELN;WRITE('FILE WILL BE PARSED (.PAS) : ');READLN(FILESOURCE);I:=POS('.',FILESOURCE);IF I<>0 THEN FILESOURCE:=COPY(FILESOURCE,1,I-1);WRITE('OUTPUT FILE (.TXT) : ');READLN(FILERES);WRITELN;I:=POS('.',FILERES);IF I<>0 THEN FILERES:=COPY(FILERES,1,I-1);OPENFILE:=TRUE;ASSIGN(INFILE,FILESOURCE+'.PAS');RESET(INFILE);IF IORESULT <> 0 THENBEGINWRITELN('FILE ',FILESOURCE,'.PAS DOESN''T EXIST...');
 
 Modul Peraktikum MTBTeknik Kompilasi (T.Informatika)
OPENFILE:=FALSE;ENDELSEBEGINASSIGN(RESFILE,FILERES+'.TXT');REWRITE(RESFILE);IF IORESULT <> 0 THENBEGINWRITELN(FILERES,'.TXT CAN''T BE MADE...');OPENFILE:=FALSE;ENDEND;END;FUNCTION UPPERCASE(STR:STRING):STRING;VARI : INTEGER;BEGINFOR I := 1 TO LENGTH(STR) DOSTR[I] := UPCASE(STR[I]);UPPERCASE:=STR;END;PROCEDURE INCLINE(VAR LINECOUNTER : INTEGER);BEGINGOTOXY(1,WHEREY);LINECOUNTER:=LINECOUNTER+1;WRITE('PROCESSING LINE : ',LINECOUNTER);END;PROCEDURE READCHAR;BEGINREAD(INFILE,CC);END;PROCEDURE PROSERR(ERR:SCANERRORTYPE);BEGINGOTOXY(25,WHEREY);WRITE('*ERROR :');CASE ERR OFERRSCANUNEXPCHAR : BEGIN WRITE('UNEXPECTED CHARACTER ', CC);READCHAR;END;ERRSCANAPOSTEXP : WRITE(#39' EXPECTED');ERRSCANUNEXPEOF : BEGIN WRITE('UNEXPECTED END OF FILE ');READLN; HALT;END;ERRSCANFLOAT : WRITE('FLOATING POINT FORMAT ERROR');ERRSCANINT : WRITE('INTEGER VALUE ERROR');END;READLN;END;PROCEDURE WRITEFILE;VARI : INTEGER;ADAINFO : BOOLEAN;BEGINWRITE(RESFILE,' ');WRITE(RESFILE,ORD(TOKEN):2);WRITE(RESFILE,' ');CASE TOKEN OFTIDENTIFIER:BEGINADAINFO := FALSE;I := 0;REPEATI := I + 1;IF LOKASI[I] = SCANSTR THEN ADAINFO := TRUE;UNTIL (ADAINFO) OR (I > JINFO);

Activity (24)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Sankala Tertawa liked this
Dodik Krisd liked this
Dodik Krisd liked this
Dodik Krisd liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->