How a Translator Works CS 222: Programming Languages Translators - - PowerPoint PPT Presentation

how a translator works
SMART_READER_LITE
LIVE PREVIEW

How a Translator Works CS 222: Programming Languages Translators - - PowerPoint PPT Presentation

How a Translator Works CS 222: Programming Languages Translators The job of a tr translator is to convert data in a source language to an equivalent form in a target language. translator Assemblers Assembly language Machine code Decrement


slide-1
SLIDE 1

How a Translator Works

CS 222: Programming Languages

slide-2
SLIDE 2

Translators

The job of a tr translator is to convert data in a source language to an equivalent form in a target language.

  • Assemblers

2

translator DEC B 00000101 Decrement the B processor register by one: Load AL register with 61 hexadecimal value: MOV AL, 61h 10110000 01100001 Assembly language Machine code

slide-3
SLIDE 3

More Translators

  • Compilers
  • Programs in the source language are co

compiled.

  • Produces executable program
  • Ex: GCC is a compiler for C, C++, Objective-C, Fortran, Ada
  • Interpreters
  • Programs in the source language are in

interpreted.

  • Parses the source code into intermediate representation which is

immediately executed

  • Ex: Thonny is an interpreter for Python
  • Combination thereof
  • Ex: Ju

Just-in in-ti time me (JIT) compilati tion

  • Java compiler translates source code to byte code to be executed by JVM
  • JVM can compile byte code to machine code

3

High-level language Machine code of physical processor High-level language Machine code of virtual machine

slide-4
SLIDE 4

Four Translator Design Principles

  • 1. Correctness Principle

The runtime behavior of a translated form must be that described by the input being translated.

  • 2. Early-warning Principle

Both syntax (form) and semantic (use) errors should be identified and reported at the earliest possible point in the translation process.

  • Type errors are identified via type

type che hecki king ng.

  • St

Statically typed languages type check at translation time

  • Ex: Java, C, C++
  • Dy

Dynami mically typed languages type check at execution time

  • Ex: Python, Ruby, Lisp
  • 3. Efficiency Principle

A translator must ensure that a translated form makes sensible and efficient use

  • f the computational resources in the execution environment.
  • 4. Portability Principle

A translator should be designed so that it can be ported to a new execution environment with a minimum of effort.

4

slide-5
SLIDE 5

Phases of Translation

5

Analysis Synthesis

character stream Final Translated Form Source Program

  • creates-
slide-6
SLIDE 6

Phases of Translation

6

Analysis Synthesis Syntax Checking Semantic Analysis

character stream Final Translated Form Source Program

  • creates-
slide-7
SLIDE 7

Phases of Translation

7

Analysis Synthesis Syntax Checking Semantic Analysis

Lexical analysis Syntax analysis character stream Final Translated Form Source Program

  • creates-
slide-8
SLIDE 8

Phases of Translation

8

Analysis Synthesis Syntax Checking Semantic Analysis

Lexical analysis Syntax analysis character stream token stream Final Translated Form Source Program

  • creates-

To Tokenizer Pa Parser

slide-9
SLIDE 9

Phases of Translation

9

Analysis Synthesis Syntax Checking Semantic Analysis

Lexical analysis Syntax analysis character stream token stream Final Translated Form Source Program

  • creates-

To Tokenizer Pa Parser

Syntax Tree Symbol Table

  • creates-
  • creates-
slide-10
SLIDE 10

Phases of Translation

10

Analysis Synthesis Syntax Checking Semantic Analysis

Lexical analysis Syntax analysis character stream token stream Syntax Tree Symbol Table Final Translated Form Source Program

  • creates-
  • creates-
  • creates-

To Tokenizer Pa Parser

Se Semantic c Cod Code Ch Checker

slide-11
SLIDE 11

Phases of Translation

11

Analysis Synthesis Syntax Checking Semantic Analysis

Lexical analysis Syntax analysis Intermediate Code Generation Object Code Optimization character stream token stream Syntax Tree Intermediate Code Symbol Table Final Translated Form Source Program

  • creates-
  • creates-
  • creates-
  • creates-

To Tokenizer Pa Parser

Ob Object Cod

  • de

Gen Gener erator

Se Semantic c Cod Code Ch Checker

In Inter ermed media iate e Co Code Generator