Passnownow

Rated 4.8/5 by parents & students

Classwork Series and Exercises {Computer – SS1}: Translators

Computer Science SS1 Second Term

Week 4:

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. An assembler 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:

plus pointVery fast in translating assembly language to machine code as 1 to 1 relationship
plus pointAssembly code is often very efficient (and therefore fast) because it is a low level language
plus pointAssembly code is fairly easy to understand due to the use of English-like mnemonics
Disadvantages of using Assembler:
minus point Assembly language is written for a certain instruction set and/or processor
minus point Assembly tends to be optimised for the hardware it’s designed for, meaning it is often incompatible with different hardware
minus point Lots of assembly code is needed to do relatively simple tasks, and complex programs require lots of programming time

2. Compiler: This is a translator that is capable of converting high level language to machine language directly. A Compiler 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

plus pointSource code is not included, therefore compiled code is more secure than interpreted code
plus pointTends to produce faster code than interpreting source code
plus pointProduces an executable file, and therefore the program can be run without need of the source code
Disadvantages of using a compiler
minus point Object code needs to be produced before a final executable file, this can be a slow process
minus point The source code must be 100% correct for the executable file to be produced

3. 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

plus pointEasier to debug(check errors) than a compiler
plus pointEasier to create multi-platform code, as each different platform would have an interpreter to run the same code
plus pointUseful for prototyping software and testing basic program logic
Disadvantages of using an Interpreter
minus point Source code is required for the program to be executed, and this source code can be read making it insecure
minus point 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.

[fusion_builder_container hundred_percent=”yes” overflow=”visible”][fusion_builder_row][fusion_builder_column type=”1_1″ background_position=”left top” background_color=”” border_size=”” border_color=”” border_style=”solid” spacing=”yes” background_image=”” background_repeat=”no-repeat” padding=”” margin_top=”0px” margin_bottom=”0px” class=”” id=”” animation_type=”” animation_speed=”0.3″ animation_direction=”left” hide_on_mobile=”no” center_content=”no” min_height=”none”]

Flow Chart
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 complier of the computer language. Example “20” is a Hausa syntax. Complier 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

For more notes, visit: http://passnownow.com/classwork-support/

[/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top