How a Translator Works
CS 222: Programming Languages
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
CS 222: Programming Languages
The job of a tr translator is to convert data in a source language to an equivalent form in a target language.
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
compiled.
interpreted.
immediately executed
Just-in in-ti time me (JIT) compilati tion
3
High-level language Machine code of physical processor High-level language Machine code of virtual machine
The runtime behavior of a translated form must be that described by the input being translated.
Both syntax (form) and semantic (use) errors should be identified and reported at the earliest possible point in the translation process.
type che hecki king ng.
Statically typed languages type check at translation time
Dynami mically typed languages type check at execution time
A translator must ensure that a translated form makes sensible and efficient use
A translator should be designed so that it can be ported to a new execution environment with a minimum of effort.
4
5
Analysis Synthesis
character stream Final Translated Form Source Program
6
Analysis Synthesis Syntax Checking Semantic Analysis
character stream Final Translated Form Source Program
7
Analysis Synthesis Syntax Checking Semantic Analysis
Lexical analysis Syntax analysis character stream Final Translated Form Source Program
8
Analysis Synthesis Syntax Checking Semantic Analysis
Lexical analysis Syntax analysis character stream token stream Final Translated Form Source Program
To Tokenizer Pa Parser
9
Analysis Synthesis Syntax Checking Semantic Analysis
Lexical analysis Syntax analysis character stream token stream Final Translated Form Source Program
To Tokenizer Pa Parser
Syntax Tree Symbol Table
10
Analysis Synthesis Syntax Checking Semantic Analysis
Lexical analysis Syntax analysis character stream token stream Syntax Tree Symbol Table Final Translated Form Source Program
To Tokenizer Pa Parser
Se Semantic c Cod Code Ch Checker
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
To Tokenizer Pa Parser
Ob Object Cod
Gen Gener erator
Se Semantic c Cod Code Ch Checker
In Inter ermed media iate e Co Code Generator