Lesson Notes By Weeks and Term - Senior Secondary School 1

Translators

TERM: 2nd Term

WEEK: 4

CLASS: S.S. 1

DATE:

SUBJECT: Computer Science
TOPIC: Translators

Introduction

Translators are highly developed programs capable of converting high level language to machine language, low level language to machine language. A translator is a computer program that performs the translation of a program written in a given programming language into a functionally equivalent program in a different computer language, without losing the functional or logical structure of the original code (the “essence” of each program).

Types of translators

  • Assembler
  • Compiler
  • Interpreter
    • If the translator translates a high level language into another high level language, it’s called a translator or source-to-source compiler. Examples include Haxe, FORTRAN-to-Ada translators, CHILL-to-C++ translators, PASCAL-to-C translators, COBOL (DialectA)-to-COBOL(DialectB) translators.
    • If the translator translates a high level language into a lower level language it is called a compiler. Notice that every language can be either translated into a (Turing-complete) high level or assembly language.
    • If the translator translates a high level language into an intermediate code which will be immediately executed it is called an interpreter.
    • If the translator translates target/machine code to source language it is called a decompiler. Example: DCC, Boomerang Decompilers and Reverse Engineering Compiler(REC).
    • If the translator translates assembly language to machine code it is called an assembler. Examples include MASM, TASM and NASM.
    • If the translator translates machine code into assembly language it is called a disassembler. Examples include gdb, IDA Pro and OllyDbg.
    • Translators that translate from a human-readable design specified in terms of rules and high level functions, into the equivalent logic gates and chip layout needed to achieve its manufacture, belong to electronic design automation and hardware description language categories.
  1. Assembler: This is a translator that is capable of converting low level language to machine language directly.Anassembler translates assembly language into machine code. Assembly language consists of mnemonics for machine opcodes so assemblers perform a 1:1 translation from mnemonic to a direct instruction.
    For example: LDA #4 converts to 0001001000100100

Advantages of using an Assembler:

Very fast in translating assembly language to machine code as 1 to 1 relationship

Assembly code is often very efficient (and therefore fast) because it is a low level language

Assembly code is fairly easy to understand due to the use of English-like mnemonics
Disadvantages of using Assembler:

 Assembly language is written for a certain instruction set and/or processor

 Assembly tends to be optimised for the hardware it’s designed for, meaning it is often incompatible with different hardware

 Lots of assembly code is needed to do relatively simple tasks, and complex programs require lots of programming time

  1. Compiler: This is a translator that is capable of converting high level language to machine language directly.ACompiler is a computer program that translates code written in a high level language to a lower level language, object/machine code. The most common reason for translating source code is to create an executable program (converting from a high level language into machine language).

Advantages of using a compiler

Source code is not included, therefore compiled code is more secure than interpreted code

Tends to produce faster code than interpreting source code

Produces an executable file, and therefore the program can be run without need of the source code
Disadvantages of using a compiler

 Object code needs to be produced before a final executable file, this can be a slow process

 The source code must be 100% correct for the executable file to be produced

  1. Interpreter:An interpreter program executes other programs directly, running through program code and executing it line-by-line. As it analyses every line, an interpreter is slower than running compiled code but it can take less time to interpret program code than to compile and then run it — this is very useful when prototyping and testing code. Interpreters are written for multiple platforms, this means code written once can be run immediately on different systems without having to recompile for each. Examples of this include flash based web programs that will run on your PC, MAC, games console and Mobile phone.

Advantages of using an Interpreter

Easier to debug(check errors) than a compiler

Easier to create multi-platform code, as each different platform would have an interpreter to run the same code

Useful for prototyping software and testing basic program logic
Disadvantages of using an Interpreter

 Source code is required for the program to be executed, and this source code can be read making it insecure

 Interpreters are generally slower than compiled programs due to the per-line translation method

Stages of programming

There are six stages in developing a good program.

  1. Program analysis
  2. Program design
  3. Program coding
  4. Program verification
  5. Program documentation
  6. Program maintenance

Flow chart: This is the pictorial or graphical representation of steps in writing a program.

Flow Chart

A logarithm is the step by step procedure in solving a problem or task

Basic programming language

The programming language must have the following basics

  1. Language syntax: This involves codes which are understood by computer compiler of the computer language. Example “20” is a Hausa syntax. Compiler has its own syntax and it includes
  • Print
  • REM
  • Input
  • Output
  • Tab
  1. Variable: Also known as identifier, which contains some known or unknown quantity of information referred to as a value.
  2. Constant: These are data items which do not change during program execution.

Examples include:

1, 2, 3 ……..

A, B, C, .…..

  1. Operator: This can be arithmetic, relational or logic.

Examples:

Arithmetic operators include (arithmetic language)

+ = addition

– = subtraction

x = multiplication

/ = division

؈ or ** = Exponent

Relational operators include

= for equality

> = greater than

< = less than

≤ = less than or equal to

≥ = greater than or equal to

Logical operations

True or false

Yes or no

OR or AND

Every program must have

  1. Beginning
  2. End
  3. Body

ASSESSMENT

  1.  ____ converts high level or low level language to machine language
    (a) transmitter
    (b) translator
    (c) transferrer
    (d) transducer
  2. One of these is not a type of translator
    (a) assembler
    (b) compiler
    (c) interpreter
    (d) silicon
  3. If the translator translates target/machine code to source language it is called a
    (a) machiner
    (b) languager
    (c) decompiler
    (d) congester
  4. ______ is capable of converting high level language to machine language directly.
    (a) assembler
    (b) compiler
    (c) interpreter
    (d) silicon
  5. How many stages are involved in developing a good program.
    (a) 4
    (b) 5
    (c) 6
    (d) 7

ANSWERS

  1. a
  2. d
  3. c
  4. a
  5. c

 



© Lesson Notes All Rights Reserved 2023