TEKNIK KOMPILASI 1

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

Transcript of TEKNIK KOMPILASI 1

Page 1: TEKNIK KOMPILASI 1

Teknik Kompilasi I

1/45Ernastuti & Sulistyo

TEKNIK KOMPILASI

Ernastuti & Sulistyo

Page 2: TEKNIK KOMPILASI 1

Teknik Kompilasi I

2/45Ernastuti & Sulistyo

Page 3: TEKNIK KOMPILASI 1

Teknik Kompilasi I

3/45Ernastuti & Sulistyo

MATERI

Page 4: TEKNIK KOMPILASI 1

Teknik Kompilasi I

4/45Ernastuti & Sulistyo

ARTI KATA TEKNIK KOMPILASI

Page 5: TEKNIK KOMPILASI 1

Teknik Kompilasi I

5/45Ernastuti & Sulistyo

TRANSLATOR:COMPILER & INTERPRETER

Page 6: TEKNIK KOMPILASI 1

Teknik Kompilasi I

6/45Ernastuti & Sulistyo

COMPILER & INTERPRETER

Page 7: TEKNIK KOMPILASI 1

Teknik Kompilasi I

7/45Ernastuti & Sulistyo

COMPILER

Page 8: TEKNIK KOMPILASI 1

Teknik Kompilasi I

8/45Ernastuti & Sulistyo

KENAPA PERLU TRANSLATOR ?

Page 9: TEKNIK KOMPILASI 1

Teknik Kompilasi I

9/45Ernastuti & Sulistyo

LATAR BELAKANG

Page 10: TEKNIK KOMPILASI 1

Teknik Kompilasi I

10/45Ernastuti & Sulistyo

Bagaimana dengan orang yang tidakmengerti bahasa mesin?

Page 11: TEKNIK KOMPILASI 1

Teknik Kompilasi I

11/45Ernastuti & Sulistyo

Page 12: TEKNIK KOMPILASI 1

Teknik Kompilasi I

12/45Ernastuti & Sulistyo

Page 13: TEKNIK KOMPILASI 1

Teknik Kompilasi I

13/45Ernastuti & Sulistyo

Page 14: TEKNIK KOMPILASI 1

Teknik Kompilasi I

14/45Ernastuti & Sulistyo

BAHASA TINGKAT TINGGI

Pemrograman bisa menggunakan Bahasa Tingkat Tinggi.

Page 15: TEKNIK KOMPILASI 1

Teknik Kompilasi I

15/45Ernastuti & Sulistyo

Bahasa Tingkat Tinggi adalah:

Page 16: TEKNIK KOMPILASI 1

Teknik Kompilasi I

16/45Ernastuti & Sulistyo

Page 17: TEKNIK KOMPILASI 1

Teknik Kompilasi I

17/45Ernastuti & Sulistyo

Jenis Translator: ASSEMBLER

Page 18: TEKNIK KOMPILASI 1

Teknik Kompilasi I

18/45Ernastuti & Sulistyo

Jenis Translator: COMPILER

Page 19: TEKNIK KOMPILASI 1

Teknik Kompilasi I

19/45Ernastuti & Sulistyo

Jenis Translator: Interpreter

Page 20: TEKNIK KOMPILASI 1

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.

Page 21: TEKNIK KOMPILASI 1

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?

Page 22: TEKNIK KOMPILASI 1

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.

Page 23: TEKNIK KOMPILASI 1

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.

Page 24: TEKNIK KOMPILASI 1

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

Page 25: TEKNIK KOMPILASI 1

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

Page 26: TEKNIK KOMPILASI 1

Teknik Kompilasi I

26/45Ernastuti & Sulistyo

Page 27: TEKNIK KOMPILASI 1

Teknik Kompilasi I

27/45Ernastuti & Sulistyo

Page 28: TEKNIK KOMPILASI 1

Teknik Kompilasi I

28/45Ernastuti & Sulistyo

Page 29: TEKNIK KOMPILASI 1

Teknik Kompilasi I

29/45Ernastuti & Sulistyo

Contoh Source Program ke dalam Kode Mesin:

Page 30: TEKNIK KOMPILASI 1

Teknik Kompilasi I

30/45Ernastuti & Sulistyo

Contoh Source Program ke dalam Kode Mesin

Page 31: TEKNIK KOMPILASI 1

Teknik Kompilasi I

31/45Ernastuti & Sulistyo

Konsep dan Notasi Bahasa

Page 32: TEKNIK KOMPILASI 1

Teknik Kompilasi I

32/45Ernastuti & Sulistyo

Konsep dan Notasi Bahasa

Page 33: TEKNIK KOMPILASI 1

Teknik Kompilasi I

33/45Ernastuti & Sulistyo

Konsep dan Notasi Bahasa

Page 34: TEKNIK KOMPILASI 1

Teknik Kompilasi I

34/45Ernastuti & Sulistyo

Contoh Tata Bahasa Sederhana

Page 35: TEKNIK KOMPILASI 1

Teknik Kompilasi I

35/45Ernastuti & Sulistyo

Tabel Aturan Produksi

Page 36: TEKNIK KOMPILASI 1

Teknik Kompilasi I

36/45Ernastuti & Sulistyo

Hirarki CHOMSKY

Page 37: TEKNIK KOMPILASI 1

Teknik Kompilasi I

37/45Ernastuti & Sulistyo

Page 38: TEKNIK KOMPILASI 1

Teknik Kompilasi I

38/45Ernastuti & Sulistyo

ATURAN PRODUKSI

Page 39: TEKNIK KOMPILASI 1

Teknik Kompilasi I

39/45Ernastuti & Sulistyo

Page 40: TEKNIK KOMPILASI 1

Teknik Kompilasi I

40/45Ernastuti & Sulistyo

DIAGRAM STATE

Page 41: TEKNIK KOMPILASI 1

Teknik Kompilasi I

41/45Ernastuti & Sulistyo

Notasi BNF (Backus Normal Form)

Page 42: TEKNIK KOMPILASI 1

Teknik Kompilasi I

42/45Ernastuti & Sulistyo

DIAGRAM SYNTAX

Page 43: TEKNIK KOMPILASI 1

Teknik Kompilasi I

43/45Ernastuti & Sulistyo

DIAGRAM SYNTAX

Page 44: TEKNIK KOMPILASI 1

Teknik Kompilasi I

44/45Ernastuti & Sulistyo

Kualitas dari Compiler:

Page 45: TEKNIK KOMPILASI 1

Teknik Kompilasi I

45/45Ernastuti & Sulistyo

Lanjut ke TEKNIK KOMPILASI II.ppt