Function of a Translator - Translates the instruction(s) of one programming language into the instruction(s) of another programming language
without the loss of original meaning.
Function of a compiler - Transforms source code written in a programming language into another computer language,
often having a binary form. Generally, transforming source code to create an executable program.
Interpreter vs Compiler
Interpreters convert program into a machine-executable form each time the program is executed.
They analyze and execute each line of the source program from the start to end. So the interpreter processes the code as it executes it.
Characteristics:
• Relatively little time is spent analyzing and processing the program
• Intermediate code is produced as a result.
• The intermediate code is interpreted by another program
• Executing the program is fairly slow.
Compilers translate high-level language into machine language. Compilers analyze all the statements in the source code and creates the Object program.
After the source program is compiled, it can be executed one instruction at a time.
Characteristics:
• Much time is spent analyzing and processing program
• Resulting executable is some form of machine-specific binary code
• Computer hardware interprets and executes the resulting code
• Program execution is fairly fast
A compiler would translate the source code once, while interpreters would translate the code every time a program is executed.