• Tidak ada hasil yang ditemukan

TEKNIK KOMPILASI. Sulistyo Puspitodjati.

N/A
N/A
Protected

Academic year: 2021

Membagikan "TEKNIK KOMPILASI. Sulistyo Puspitodjati."

Copied!
27
0
0

Teks penuh

(1)

TEKNIK KOMPILASI

Sulistyo Puspitodjati

sulistyo@staff.gunadarma

Sumber: Compiler Construction by Vana Doufexi users.ece.northwestern.edu/~boz283/cs-322-original/01.ppt

(2)

JADWAL KELAS

Sulistyo P

Senin 1/2/3 D661 4IA16 Teknik Kompilasi **

Senin 4/5/6 D348 4IA17 Teknik Kompilasi **

Selasa 3/4/5 G128 4IA07 Teknik Kompilasi **

Selasa 7/8/9 G244 4IA11 Teknik Kompilasi **

(3)

PELAKSANAAN

pelaksanaan perkuliahan semester PTA 2020/2021 secara Daring,

Perkuliahan dimulai pada hari Senin, 28 September 2020.

jadwal kuliah daring berlangsung sesuai jadwal kuliah yang telah diinfokan pada website BAAK.

Mekanisme

(4)

PELAKSANAAN

Mekanisme:

Virtual Class seperti biasa = 7 kali  dilaksanakan pada minggu keempat perkuliahan

google meet atau platform cloud meeting = 7 kali serta virtual class sebanyak 7 kali  3 minggu pertama

Dosen menyiapkan materi sesuai dengan RPS / SAP

Dosen menginformasikan jadwal pelaksanaan perkuliahan sinkron menggunakan google meet atau platform

meetingnya lainnya melalui studentsite atau nomor kontak (nomor HP) ketua kelas/perwakilan kelas.

Daftar hadir mahasiswa dapat dibuat dan dilakukan sesuai dengan keperluan masing-masing Dosen.

Daftar Hadir Dosen pada google form yang sudah disediakan melalui link https://forms.gle/673iVpwENXvsFAxq6

(5)

Mode Kelas

7 Google Meeting

Info link melalui vclass

WA ketua/wakil kelas

Student site

7 VClass

Materi ppt/pdf

Tugas kecil

Tugas besar  bertahap

UTS

Nilai 50% Tugas besar

UAS

** = Praktikum Penunjang

(6)

Compiler?

program yang membaca program yang ditulis dalam suatu bahasa dan di terjemahkan ke program yang ditulis dalam bahasa lain

Modula-2 to C

Java to bytecodes

C++ to C

Bagian dari translator

Translator :

Interpreter

Compiler

(7)

7

TRANSLATOR

What is a compiler?

a program that translates an executable program in one language into an executable program in another language

A compiler is a computer program that transforms code written in a high-level programming language into the machine code

convert the code into machine code (create an exe) before program run

What is an interpreter?

a program that reads an executable program and produces the results of running that program

which coverts each high-level program statement into the machine code.

Interpreters convert code into machine code when the program is run

(8)

8

Compiler vs Interpreter

Tugas baca: Kunjungi dan pelajari

https://www.guru99.com/difference-compiler-vs-interpreter.html

(9)

Pentingkah belajar COMPILER?

Untuk contoh aplikasi yang keren dari teori-teori yg sudah didapat sebelumnya

Data Structures

Teori Bahasa dan Otomata

Algorithms

Computer Architecture

Pengalaman merekayasa SW

Better understanding of programming languages

(10)

Fitur compiler

Correctness

preserve the meaning of the code

Kecepatan target code

Kecepatan Kompilasi

Bagusnya penangan dan pelaporan error

Tingkat Cooperation dengan debugger

Support compilation terpisah

(11)

Compiler structure

Pakai IR (intermediate representation = representasi antara)

Why?

source code

target Front End IR Back End code

Fase: Analisa Sintesa 2-Pass

(12)

Struktur Compiler

Front end

Mengenl legal/illegal programs

melaport/menangani errors

Generate IR (intermedite representtion)

Process dapat diotomatisasi

Back end

Translate IR ke target code

instruction selection

register allocation

instruction scheduling

lots of NPC (Non Programmable Character) problems -- use approximations

(13)

Struktur Compiler

Optimization

tujuan

improve running time of generated code

improve space, power consumption, etc.

bagaimana?

perform a number of transformations on the IR

multiple passes

perhatikan: preserve meaning of code  tidak ambigu

(14)

The Front End

Scanning (a.k.a. lexical analysis)

Mengenal "words" (tokens)

Parsing (a.k.a. syntax analysis)

check syntax

Semantic analysis

Mengartikan (examine meaning ) (e.g. type checking)

Other issues:

symbol table manager (menelusuri identifiers)

error detection/reporting/recovery

(15)

Scanner

Its job:

Dari untaian karakter yang diberikan  dikenali kata (token) yang terlibat

Mis. x = 1 dikenal sebagai IDENTIFIER EQUAL INTEGER

Mengumpulkan informasi identifier information

Contoh: IDENTIFIER berhubungan dengan lexeme (susunan huruf yang membentuk token  x), type (berdasarkan deklarasi identifier x).

Mengabaikan white space dan comments

Melaporkan kesalahan

Good news

the process can be automated

(16)

Parser

Its job:

Check dan verifikasi syntax berdasarkan specifikasi aturan syntax

Mis. IDENTIFIER LPAREN RPAREN memebentuk EXPRESSION.

context-free grammars specify syntax

Report errors

Build IR

Dapat berupa syntax tree

Good news

the process can be automated

(17)

Contoh syntax in C++

// function returning the max between two numbers int max(int num1, int num2) {

// local variable declaration int result;

if (num1 > num2) result = num1;

else

result = num2;

return result;

}

(18)

Semantic analysis

Its job:

Check arti program (coding/script)

Mis x=y, apakah y terdefinisi sebelum digunakan?

Sudahkah dideklarasi ?

Mis x=y, typenya x dan y sesuai ?

Makna script tergantung context

Report errors

Contoh:

Kucing menendang bola vs Bola menendang kucing

(19)

IR (intermediate representation)

Graphical

parse tree, DAG

Linear

three-address code

Hybrid

linear for blocks of straight-line code, a graph to connect blocks

Low-level or high-level

(20)

Summary

(21)
(22)

> 2 pass

(23)

AGENDA

Sesuai RPS (SAP) lihat sap.gunadarma.ac.id

(24)

The scanning process

Main goal: recognize words

How? by recognizing patterns/pola

Contoh: identifier berbentuk susunan huruf atau digits yang diawali dengan huruf

Pola lexical membentuk bahasa regular

Regular languages dapat dirumuskan menggunakan regular expressions (REs)

Dapatkan RE recognizer diotomatisasi?

Yes!

(25)

The scanning process

Definition: Regular expressions (over alphabet Σ)

ε is an RE denoting {ε}

If α∈Σ, then α is an RE denoting {α}

If r and s are REs, then

(r) is an RE denoting L(r)

r|s is an RE denoting L(r)∪L(s)

rs is an RE denoting L(r)L(s)

r* is an RE denoting the Kleene closure of L(r)

Property: REs are closed under many operations

This allows us to build complex REs.

(26)

The scanning process

Definition: Deterministic Finite Automaton

a five-tuple (Σ, S, δ, s0, F) where

Σ is the alphabet

S is the set of states

δ is the transition function (S×Σ→S)

s0 is the starting state

F is the set of final states (F ⊆ S)

Notation:

Use a transition diagram to describe a DFA

DFAs are equivalent to REs

Hey! We just came up with a recognizer!

(27)

The scanning process

Goal: automate the process

Idea:

Start with an RE

Build a DFA

How?

We can build a non-deterministic finite automaton (Thompson's construction)

Convert that to a deterministic one (Subset construction)

Minimize the DFA (Hopcroft's algorithm)

Implement it

Existing scanner generator: flex

Referensi

Dokumen terkait

Sistem distribusi tiga fasa dengan empat kawat , Pada tipe ini, sisi sekunder (output) trafo distribusi terhubung star,dimana saluran netral diambil dari titik

Berdasarkan latar belakang dan rumusan masalah diatas maka masalah yang hendak dijawab dalam penelitian ini adalah Peran Warna Kemasan, Desain Kemasan dan Bahan Kemasan

Therefore the aim of this study is to assess the differential and correlation between Atherogenic Index of Plasma (AIP), ratio of small dense low density

Penelitian ini bertujuan untuk mengetahui sikap pengunjung Dolly terhadap penayangan iklan kondom di televisi serta situasi dan kondisi apa saja yang menentukan sikap pengunjung

Pegawai Negeri Sipil adalah unsur aparatur negara, abdi negara dan abdi masyarakat yang harus menjadi teladan yang baik bagi masyarakat dalam tingkah laku, tindakan dan

Kata Kunci : Internet Financial Reporting, Content, Timeliness, Technology, User Support, Bank Umum Syariah, Indonesia,

Dalam dongeng “Bunga Melati yang Baik Hati” terdapat pesan yang patut kita contoh.. Tulislah pesan yang terkandung dalam dongeng

penelitian ini dilakukan di perusahaan yang tergabung dalam Jakarta Islamic.. Index (JII) yang terdaftar di Bursa Efek Indonesia dengan waktu penelitian