La 5 Pl Translator


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

La 5 Pl Translator

  1. 1. PROGRAMMING LANGUAGES 5.1.4 TRANSLATOR 08042008 Prepared by: Norhasimah Mohamed, SMK Sungai Pusu, Gombak Selangor. 08042008
  2. 2. Learning Outcomes <ul><li>5.1.4 Translator </li></ul><ul><li> Describe the translation method of programming using </li></ul><ul><li>i) assembler, </li></ul><ul><li>ii) interpreter, </li></ul><ul><li>iii) compiler </li></ul>Prepared by: Norhasimah Mohamed, SMK Sungai Pusu, Gombak Selangor. 04042008
  3. 3. TRANSLATOR <ul><li>Sometimes two people cannot understand each other because they don’t speak the same language. So they need the help of a third person who understands both languages. This third person is known as a translator . </li></ul><ul><li>All software packages or programs are written in high-level languages, for example, C++, Visual Basic and Java. </li></ul><ul><li>However, in order for the computer to be able to carry out the instructions, the high-level languages must be translated into machine language before the computer can understand and execute the instructions in the program. </li></ul><ul><li>The translation of high level languages to machine language is performed by a translator. </li></ul>
  4. 4. TRANSLATOR <ul><li>A programmer will write a source code which consists of the instructions </li></ul><ul><li>needed to run a program. Then the compiler or interpreter with assembler will translates the source code into machine language which is made of a sequence of bits (eg. 01100011). </li></ul><ul><li>The computer will load the machine code and run the program. </li></ul>
  5. 5. ASSEMBLER <ul><li>An assembler is a computer program for translating assembly language — essentially, a mnemonic representation of machine language — into machine language. </li></ul><ul><li>For example in intel 80836, the assembly language for the ’no operation’ command is NOP and its machine code representation is 10010000. </li></ul><ul><li>Example of assemblers are MACRO-80 Assembler and Microsoft MASM. </li></ul>
  6. 6. ASSEMBLER <ul><li>an assembler is used to translate assembly language statements into the target computer's machine code. </li></ul><ul><li>The assembler performs a more or less isomorphic translation (a one-to-one mapping) from mnemonic statements into machine instructions and data. (This is in contrast with high-level languages, in which a single statement generally results in many machine instructions. A compiler, analogous to an assembler, is used to translate high-level language statements into machine code; or an interpreter executes statements directly.) </li></ul><ul><li>Many sophisticated assemblers offer additional mechanisms to facilitate program development, control the assembly process, and aid debugging. In particular, most modern assemblers include a macro facility (described below), and are called macro assemblers . </li></ul>
  7. 7. INTERPRETER <ul><li>Interpreter is used to interpret and execute program directly from its source without compiling it first. The source code of an interpreted language is interpreted and executed in real time when the user execute it. </li></ul><ul><li>The interpreter will read each codes converts it to machine code and executes it line by line until the end of the program. </li></ul><ul><li>Examples of interpreter-based language are BASIC, Logo and Smalltalk. </li></ul>
  8. 8. INTERPRETER <ul><li>an interpreter normally means a computer program that executes, i.e. performs , instructions written in a programming language. </li></ul><ul><li>While interpretation and compilation are the two principal means by which programming languages are implemented, these are not fully distinct categories, one of the reasons being that most interpreting systems also perform some translation work, just like compilers. An interpreter may be a program that either : </li></ul><ul><li>1. executes the source code directly </li></ul><ul><li>2. translates source code into some efficient intermediate representation (code) and immediately executes this </li></ul><ul><li>3. is invoked to explicitly execute stored precompiled code made by a compiler which is part of the interpreter system </li></ul><ul><li>Perl, Python, MATLAB, and Ruby are examples of type 2, while UCSD Pascal and the Java virtual machine are type 3: Java source programs are compiled ahead of time and stored as machine independent code, which is then linked at run-time and executed by an interpreter (virtual machine). Some systems, such as Smalltalk, and others, may also combine 2 and 3. </li></ul><ul><li>The terms Interpreted language or Compiled language merely mean that the canonical implementation of that language is an interpreter or a compiler; a high level language is basically an abstraction which is (ideally) independent of particular implementations. </li></ul>
  9. 9. COMPILER <ul><li>The source code (in text format) will be converted into machine code which is a file consisting of binary machine code that can be executed on a computer. If the compiler encounters any errors, it records them in the program-listing file. </li></ul><ul><li>When a user wants to run the program, the object program is loaded into the memory of the computer and the program instructions begin executing. </li></ul><ul><li>A compiled code generally runs faster than programs based on interpreted language. Several programming languages like C++, Pascal and COBOL used compilers as their translators. </li></ul>
  10. 10. COMPILER <ul><li>A compiler is a computer program (or set of programs) that translates text written in a computer language (the source language ) into another computer language (the target language ). </li></ul><ul><li>The original sequence is usually called the source code and the output called object code . Commonly the output has a form suitable for processing by other programs (e.g., a linker), but it may be a human-readable text file. </li></ul><ul><li>The most common reason for wanting to translate source code is to create an executable program. </li></ul><ul><li>The name &quot;compiler&quot; is primarily used for programs that translate source code from a high-level programming language to a lower level language (e.g., assembly language or machine language). A program that translates from a low level language to a higher level one is a decompiler . </li></ul><ul><li>A program that translates between high-level languages is usually called a language translator , source to source translator , or language converter . A language rewriter is usually a program that translates the form of expressions without a change of language. </li></ul><ul><li>A compiler is likely to perform many or all of the following operations: lexical analysis, preprocessing, parsing, semantic analysis, code generation, and code optimization. </li></ul>