TEKNIK KOMPILASI - Gunadarma...

45
Teknik Kompilasi I 1/45 Ernastuti & Sulistyo TEKNIK KOMPILASI Ernastuti & Sulistyo

Transcript of TEKNIK KOMPILASI - Gunadarma...

Teknik Kompilasi I

1/45Ernastuti & Sulistyo

TEKNIK KOMPILASI

Ernastuti & Sulistyo

Teknik Kompilasi I

2/45Ernastuti & Sulistyo

Teknik Kompilasi I

3/45Ernastuti & Sulistyo

MATERI

Teknik Kompilasi I

4/45Ernastuti & Sulistyo

ARTI KATA TEKNIK KOMPILASI

Teknik Kompilasi I

5/45Ernastuti & Sulistyo

TRANSLATOR:COMPILER & INTERPRETER

Teknik Kompilasi I

6/45Ernastuti & Sulistyo

COMPILER & INTERPRETER

Teknik Kompilasi I

7/45Ernastuti & Sulistyo

COMPILER

Teknik Kompilasi I

8/45Ernastuti & Sulistyo

KENAPA PERLU TRANSLATOR ?

Teknik Kompilasi I

9/45Ernastuti & Sulistyo

LATAR BELAKANG

Teknik Kompilasi I

10/45Ernastuti & Sulistyo

Bagaimana dengan orang yang tidakmengerti bahasa mesin?

Teknik Kompilasi I

11/45Ernastuti & Sulistyo

Teknik Kompilasi I

12/45Ernastuti & Sulistyo

Teknik Kompilasi I

13/45Ernastuti & Sulistyo

Teknik Kompilasi I

14/45Ernastuti & Sulistyo

BAHASA TINGKAT TINGGI

Pemrograman bisa menggunakan Bahasa Tingkat Tinggi.

Teknik Kompilasi I

15/45Ernastuti & Sulistyo

Bahasa Tingkat Tinggi adalah:

Teknik Kompilasi I

16/45Ernastuti & Sulistyo

Teknik Kompilasi I

17/45Ernastuti & Sulistyo

Jenis Translator: ASSEMBLER

Teknik Kompilasi I

18/45Ernastuti & Sulistyo

Jenis Translator: COMPILER

Teknik Kompilasi I

19/45Ernastuti & Sulistyo

Jenis Translator: Interpreter

Teknik Kompilasi I

20/45Ernastuti & Sulistyo

Why study compilers?Most CS students do not go on to write a commercial compiler someday, but that's not why we study compilers. We study compiler construction for the following reasons:

Writing a compiler gives experience with large-scale applications development. Your compiler program may be the largest program you write as a student. Experience working with really big data structures and complex interactions between algorithms will helpyou out on your next big programming project.

Compiler writing is one of the shining triumphs of CS theory. Itdemonstrates the value of theory over the impulse to just "hack up" a solution.

Compiler writing is a basic element of programming language research. Many language researchers write compilers for the languages they design.

Many applications have similar properties to one or more phases of a compiler, and compiler expertise and tools can help an application programmer working on other projects besides compilers.

Teknik Kompilasi I

21/45Ernastuti & Sulistyo

There is no software development method for writing large programs that doesn't involve pain: pain is inevitable in software development (Berry's Theorem).

There is no way to learn the skills necessary for writing big programs without pain. A good CS course includes pain, and teaches pain management and minimization.

The questions we should ask, then, are:

(a) should CS majors be required to spend a lot of time becoming really good programmers? (b) are we providing students with the assistance and access to the tools and information they need to accomplish their goals with the minimal doses of inevitable pain that are required?

Teknik Kompilasi I

22/45Ernastuti & Sulistyo

What Are They and What Kinds of Compilers are Out There?

• The purpose of a compiler is:to translate a program in some language (the source language) into a lower-level language (the target language).

The compiler itself is written in some language, called the implementation language.

To write a compiler you have to be very good at programming in the implementation language, and have to think about and understand the source language and target language.

Teknik Kompilasi I

23/45Ernastuti & Sulistyo

Several major kinds of compilersNative Code CompilerTranslates source code into hardware (assembly or machine code) instructions. Example: gcc.

Virtual Machine CompilerTranslates source code into an abstract machine code, for execution by a virtual machine interpreter. Example: javac.

JIT Compiler Translates virtual machine code to native code. Operates within a virtual machine. Example: Sun's HotSpot java machine.

PreprocessorTranslates source code into simpler or slightly lower level source code, for compilation by another compiler. Examples: cpp, m4.

Pure interpreterExecutes source code on the fly, without generating machine code. Example: Lisp.

Teknik Kompilasi I

24/45Ernastuti & Sulistyo

Phases of a CompilerLexical Analysis:

Converts a sequence of characters into words, or tokens

Syntax Analysis:Converts a sequence of tokens into a parse tree

Semantic Analysis:Manipulates parse tree to verify symbol and type information

Intermediate Code Generation:Converts parse tree into a sequence of intermediate code instructions

Optimization:Manipulates intermediate code to produce a more efficient program

Final Code Generation:Translates intermediate code into final (machine/assembly) code

Teknik Kompilasi I

25/45Ernastuti & Sulistyo

PenganalisaLeksikal

(scanner)

PenganalisaSintaks(parser)

PenganalisaSemantik

PembangkitKode antara

Pembentukkode

Pengoptimalkode

ProgramSumber

ProgramSumber

ProgramSasaranProgramSasaran

TABELSIMBOLTABEL

SIMBOL

ANALISA SINTESA

Bagan pokok proses kompilasi

Blok Diagram

Teknik Kompilasi I

26/45Ernastuti & Sulistyo

Teknik Kompilasi I

27/45Ernastuti & Sulistyo

Teknik Kompilasi I

28/45Ernastuti & Sulistyo

Teknik Kompilasi I

29/45Ernastuti & Sulistyo

Contoh Source Program ke dalam Kode Mesin:

Teknik Kompilasi I

30/45Ernastuti & Sulistyo

Contoh Source Program ke dalam Kode Mesin

Teknik Kompilasi I

31/45Ernastuti & Sulistyo

Konsep dan Notasi Bahasa

Teknik Kompilasi I

32/45Ernastuti & Sulistyo

Konsep dan Notasi Bahasa

Teknik Kompilasi I

33/45Ernastuti & Sulistyo

Konsep dan Notasi Bahasa

Teknik Kompilasi I

34/45Ernastuti & Sulistyo

Contoh Tata Bahasa Sederhana

Teknik Kompilasi I

35/45Ernastuti & Sulistyo

Tabel Aturan Produksi

Teknik Kompilasi I

36/45Ernastuti & Sulistyo

Hirarki CHOMSKY

Teknik Kompilasi I

37/45Ernastuti & Sulistyo

Teknik Kompilasi I

38/45Ernastuti & Sulistyo

ATURAN PRODUKSI

Teknik Kompilasi I

39/45Ernastuti & Sulistyo

Teknik Kompilasi I

40/45Ernastuti & Sulistyo

DIAGRAM STATE

Teknik Kompilasi I

41/45Ernastuti & Sulistyo

Notasi BNF (Backus Normal Form)

Teknik Kompilasi I

42/45Ernastuti & Sulistyo

DIAGRAM SYNTAX

Teknik Kompilasi I

43/45Ernastuti & Sulistyo

DIAGRAM SYNTAX

Teknik Kompilasi I

44/45Ernastuti & Sulistyo

Kualitas dari Compiler:

Teknik Kompilasi I

45/45Ernastuti & Sulistyo

Lanjut ke TEKNIK KOMPILASI II.ppt