Professional Documents
Culture Documents
Chapter 3.2 - Functions and Purposes of Translators (Cambridge AL 9691)
Chapter 3.2 - Functions and Purposes of Translators (Cambridge AL 9691)
Chapter 3.2 - Functions and Purposes of Translators (Cambridge AL 9691)
1. A translator program converts source code written in a high level programming language to
machine code.
This is because:
How errors in the reserved words used in high level language instructions are recognized by
the translator program?
1. Translator program maintains a dictionary of reserved words and compares the reserved word
used in the program with those words in the dictionary
2. If the reserved word used in the program is not found in the dictionary then an error has been
made
How errors in the variables used in high level language instructions are recognized by the
translator program?
2. Translator tries the rules against the variable names used. If the variable name used does not
follow the rules then an error has been made
What is compiler?
A compiler translates source code written in a high level programming language to object code
which can be saved as an object code file and later run to execute the program. Compiler does
this by scanning through the source code in one run.
What is interpreter?
2
An interpreter converts source code written in a high level programming language to machine
language line by line and executes each line.
What is assembler?
Object code is the product obtained when source code is translated by a compiler. Object code
may almost be machine code or close to machine code.
2. Produces an error message as soon as an error is encountered and indicates the line of
source code where the error occurred
3. Interpreter is useful in program development because errors can be found and corrected as
soon as they are encountered.
1. Program executes slowly because each line of the source code has to be translated
whenever the program has to be executed
2. Object code is not produced which can be run later to execute the program fast
Advantages of compiler
3
2. Once the object code is created it is saved as a separate file which is executed subsequently
when the program has to be executed
Disadvantages of compiler
2. When an error in a program occurs it is difficult to indicate exactly the line of source
code where the error occurred
Source Code
Lexical Analysis
Syntax Analysis
Semantic Analysis
Intermediate Language
Code Generation
Code Optimization
Object Code
1. The compiler replaces groups of characters by tokens and converts the source code into a
stream of tokens
2. The compiler creates a symbol table which is accessed by using a hashing algorithm. In this
stage the symbol table contains only the variable names
3. The compiler removes the redundant characters, white spaces, tabs and comments
4. The compiler creates some error diagnostics such as illegal variable names
4
2. The compiler parses the program to find out whether the correct number of brackets has been
used in expressions and determine the priorities of the arithmetic operators.
4. Data types and scope of variables are added to the symbol table
1. The compiler optimizes the code by removing any duplicate or redundant instructions which
increases the speed of execution and reduces the size of object code