Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 14

Language Design and

Translation
Programming Languages
Chapter 3
There are two methods to implement
programming languages

 Compilation (translation) method

 Interpretation method

In some instances the two methods may be


mixed to implement a language

Programming Languages
Chapter 3 2
Compilation (Translation)

 The compiler translates the source program


(HLL) into a target program (machine
language
 Object code = machine language
source program

Compiler

Input Target program Output

Programming Languages
Chapter 3 3
 Compilation
Better performance
Fast execution
Slow translation

 Compiled languages include:


 – C, C++, FORTRAN, Pascal and Ada.
 – Their runtime routines are limited to supporting a
few operations without a close analogue in the
machine language (e.g., input/output)

Programming Languages
Chapter 3 4
Programming Languages
Chapter 3 5
Source program Structure of a compiler

Lexical analysis
Lexical tokens Source
Symbol table program
and Syntax analysis recognition
other tables phase
Parse tree

Semantic analysis Object code


Intermediate code from library files

optimization
Object code
Optimized int. code Executable
generation
code
phase

Code generation Object Linking


code

compilation Programming Languages


Chapter 3
loading 6
Important tools related to compilation

 Compiler = translate HLL to assembly


language or machine language
 Assembler = translate assembly language

into machine language


 Linker = to merge appropriate library

routines into the final program


 Preprocessor = perform work in preparation

for compiling

Programming Languages
Chapter 3 7
Interpretation

 The interpreter reads and executes


statements of the program one at a time
Source Program

interpreter Output

Input

Programming Languages
Chapter 3 8
 Interpretation leads to greater flexibility and
better diagnostics
• No translation
• platform independence (Java's byte code, for example)
• dynamic typing
• smaller executable program size
• Slow execution ( the main disadvantage)

 Interpreted languages include:


– LISP, ML, Perl, Postscript, Prolog and Smalltalk.
– The translator produces an intermediate form
of the program which the executor can interpret
quickly.

Programming Languages
Chapter 3 9
 Hybrid implementation systems

 Most language implementation include a


mixture of both compilation & interpretation
 Small translation cost
 Medium execution speed

Programming Languages
Chapter 3 10
Source program

Translator

Intermediate program
Virtual machine Output

Input

Programming Languages
Chapter 3 11
C++ compilation

Programming Languages
Chapter 3 12
Java compiled or interpreted?
 Java incorporates both interpretation and
compilation
 Java source code is first compiled into

‘bytecode’
 The bytecode is interpreted by java virtual

machine
 The compilation step allows for some degree

of optimization
 JVM interpretation allows for portability

Programming Languages
Chapter 3 13
Bytecode
loader
Bytecodes
move
Java source through
code network or Bytecode
filesystem verifier

Java
compiler
Interpreter
Code
generator
Java
bytecode Runtime

hardware

Programming Languages
Chapter 3 14

You might also like