Professional Documents
Culture Documents
Language Design and Translation: Programming Languages
Language Design and Translation: Programming Languages
Translation
Programming Languages
Chapter 3
There are two methods to implement
programming languages
Interpretation method
Programming Languages
Chapter 3 2
Compilation (Translation)
Compiler
Programming Languages
Chapter 3 3
Compilation
Better performance
Fast execution
Slow translation
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
optimization
Object code
Optimized int. code Executable
generation
code
phase
for compiling
Programming Languages
Chapter 3 7
Interpretation
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)
Programming Languages
Chapter 3 9
Hybrid implementation systems
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