Saturday, March 15, 2014

Translating High-level Language to machine language

Since computers understand only machine language, it is necessary to convert the highlevel
language programs into machine language codes. This is achieved by using language
translators or language processors, generally known as compliers, interpreters or other routines
that accepts statements in one language and produces equivalent statements in another language.

Compiler

A compiler is a kind of translator that translates a program into another program, known
as target language. Usually, the term compiler is used for language translator of high-level
language into machine language. The complier replaces single high-level statement with a series
of machine language instruction. A compiler usually resides on a disk or the storage media.
When a program is to be complied, its complier is loaded into main memory. The compiler
stores the entire high-level program, scans it and translates the whole program into an equivalent
machine language program. During the translation process, the compiler reads the source
program and checks the syntax (grammatical) errors. If there is any error, the compiler generates
an error message, which is usually displayed on the screen. In case of errors, the compiler will
not create the object code until all the errors are rectified.
Once the program has been compiled, the resulting machine code is saved in an
executable file, which can be run on its own at any time. To be precise, once the executable is
generated, there is no need for the actual source code file. Anyway, it is worthwhile to keep the
source file(s) because if the source code is modified, it is necessary to recompile the program
again to regenerate the executable file containing amendments.

Compiler is a program which translates source code written in a particular programming language into computer-readable machine code that can be directly loaded and executed. For each high-level language, a separate compiler is required. For example, a complier for C language cannot translate a program written in FORTRAN. Hence, to execute both language programs, the host computer must have the compilers of both languages.

 Interpreter

Unlike compilers, an interpreter translates a statement in a program and executes the
statement immediately, before translating the next source language statement. When an error is
encountered in the program, the execution of the program is halted and an error message is
displayed. Similar to compilers, every interpreted language such as BASIC and LISP has its
own interpreters.

No comments:

Post a Comment