Contoh Program Dengan Analisis Leksikal

Teknik Kompilasi UIGM

Latihan :

Contoh program :

#include <iostream.h>
#include <conio.h>
Void main ()
{
Int pil;
Cout<<“===============================”<<endl;
Cout<<“1. SENIN 2. SELASA 3. RABU 4. KAMIS 5. JUMAT 6. SABTU 7. MINGGU”<<endl;
Cout<<“===============================”<<endl;
Cout<<endl;
Cout<<“masukan sebuah huruf (1..7):”;
Cin>>pil;
Switch (pil)
{
Case 1 : cout<<“HARI SENIN”<<endl;
Break;
Case 2 : cout<<“HARI SELASA”<<endl;
Break;
Case 3 : cout<<“HARI RABU”<<endl;
Break;
Case 4 : cout<<“HARI KAMIS”<<endl;
Break;
Case 5 : cout<<“HARI JUMAT”<<endl;
Break;
Case 6 : cout<<“HARI SABTU”<<endl;
Break;
Case 7 : cout<<“HARI MINGGU”<<endl;
Break;
Default : cout<<“tidak terdapat namaa hari”<<endl;
}
Getch();
}

_________________TOKENS___________________

Keyword (#include) operator (<) keyword (iostream.h) operator (>) keyword (#include) operator (<) keyword (conio.h) operator (>) keyword (void) keyword (main) funtuation (()) keyword ({) keyword (int) literal (pil) functuation (;) keyword (cout) operator (<<) functuation (“) operator (===========) functuation (“) operator (<<) keyword (endl) functuation (;) keyword (cout) operator (<<) functuation (“) literal (1) functuation (.) Literal (senin) Literal (2) functuation (.) literal (selasa) literal (3) functuation (.) Literal (rabu) literal (4) functuation (.) Literal (kamis) literal (5) functuation (.) Literal (jumat) literal (6) functuation (.) Literal (sabtu) literal (7) functuation (.) Literal (minggu) functuation (“) operator (<<) keyword (endl) functuation (;) keyword (cout) operator (<<) functuation (“) operator (============) functuation (“) operator (<<) keyword (endl) functuation (;) keyword (endl) functuation (;) keyword (cout) operator (<<) functuation (“) literal (masukan) literal (sebuah) literal (huruf) functuation ( ( ) literal (1) functuation (..) literal (7) functuation ( ) ) operator (:) functuation (“) functuation (;) keyword (cin) operator (>>) literal (pil) functuation (;) keyword (switch) functuation ( ( ) literal (pil) keyword ( ) ) keyword ({) keyword (case) literal (1) operator (:) keyword (cout) operator (<<) functuation (“) literal (hari) literal (senin) functuation (“) operator (<<) keyword (endl) functuation (;) keyword (break) functuation (;) keyword (case) literal (2) operator (:) keyword (cout) operator (<<) functuation (“) literal (hari) literal (selasa) functuation (“) operator (<<) keyword (endl) keyword (break) functuation (;) keyword (case) literal (3) operator (:) keyword (cout) operator (<<) functuation (“) literal (hari) literal (rabu) functuation (“) operator (<<) keyword (endl) functuation (;) keyword (break) functuation (;)keyword (case) literal (4) operator (:) keyword (cout) operator (<<) functuation (“) literal (hari) literal (kamis) functuation (“) operator (<<) keyword (endl) functuation (;) keyword (break) functuation (;)keyword (case) literal (5) operator (:) keyword (cout) operator (<<) functuation (“) literal (hari) literal (jumat) functuation (“) operator (<<) keyword (endl) functuation (;) keyword (break) functuation (;)keyword (case) literal (6) operator (:) keyword (cout) operator (<<) functuation (“) literal (hari) literal (sabtu) functuation (“) operator (<<) keyword (endl) functuation (;) keyword (break) functuation (;)keyword (case) literal (7) operator (:) keyword (cout) operator (<<) functuation (“) literal (hari) literal (minggu) functuation (“) operator (<<) keyword (endl) functuation (;) keyword (break) functuation (;) keyword (default) operator (:) keyword (cout) operator (<<) functuation (“) literal (tidak) literal (terdapat) literal (nama) literal (hari) functuation (“) operator (<<) keyword (endl) functuation (;) keyword (}) keyword (getch) functuation (()) functuation (;) keyword (})


Silahkan masukan alamat surel untuk mendapatkan informasi menarik dan terbaru lainnya.



Balasan