As we have seen, the commands that we have written (the "source program") must be converted to something that the computer understands (an "executable" program).
If we choose a low-level language such as "assembly", such translation is simple, and is made using tools called assemblers.
If we choose a high level language, the translation is more complex, and it might also involve collecting multiple source programs or including "libraries". The tools for such tasks are called compilers.
The executable program created by the compiler or the assembler can run be run on another computer, even if that computer has no compiler or assembler in it.
For example, the program that greets us using Pascal language, we would type those commands and save them in a source file named SALUDO.PAS. This file would be useless on a computer with no Pascal compiler. But after we compile it, we would get SALUDO.EXE (supposing we are on MsDos or Windows), which can be run on any computer with the same operating system, even if it has no Pascal compiler. This program would not run in other operating systems (such as Linux or Mac OS X, for example).
An interpreter is a similar tool, but it does not create any "executable" file which can be run on its own. This way, if we want to distribute our program to someone else, we must give the program source and also the interpreter which is able to understand it.
When the program is run, the interpreter converts each high-level statement into machine code commands, one at a time. If one statement is run 1000 times, it will be analyzed and translated 1000 times, so interpreted programs use to be slower than compiled programs.
Nowadays there is another alternative, halfway between a compiler and an interpreter. Some languages are not compiled to an executable for a certain computer, but to a "generic" executable, which can be run on different kinds of computers, provided that in such computer there is a "virtual machine" capable of understanding these executable programs. This happens with Java language: Java source programas are text files with ".java" extension, and executable programs are files with ".class" extension. These ".class" files can be run in any computer that has a "Java Virtual Machine" installed in it (and such virtual mahines are available for most operating systems). The same idea applies in C#, based on a virtual machine called "Dot Net Framework".
No comments:
Post a Comment