Computer assignment for grade 9

829 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
829
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Computer assignment for grade 9

  1. 1. Computer assignment for grade 9 Bereket SolomunCompiler and interpreter, both basically serve the same purpose. They convert one level oflanguage to another level. A compiler converts the high level instructions into machinelanguage while an interpreter converts the high level instruction into some intermediateform and after that, the instruction is executed.CompilerA compiler is defined as a computer program that is used to convert high level instructionsor language into a form that can be understood by the computer. Since computer canunderstand only in binary numbers so a compiler is used to fill the gap otherwise it wouldhave been difficult for a human to find info in the 0 and 1 form.Earlier the compilers were simple programs which were used to convert symbols into bits.The programs were also very simple and they contained a series of steps translated by handinto the data. However, this was a very time consuming process. So, some parts wereprogrammed or automated. This formed the first compiler.More sophisticated compliers are created using the simpler ones. With every new version,more rules added to it and a more natural language environment is created for the humanprogrammer. The complier programs are evolving in this way which improves their ease ofuse.There are specific compliers for certain specific languages or tasks. Compliers can bemultiple or multistage pass. The first pass can convert the high level language into alanguage that is closer to computer language. Then the further passes can convert it intofinal stage for the purpose of execution.InterpreterThe programs created in high level languages can be executed by using two different ways.The first one is the use of compiler and the other method is to use an interpreter. High levelinstruction or language is converted into intermediate from by an interpreter. Theadvantage of using an interpreter is that the high level instruction does not goes throughcompilation stage which can be a time consuming method. So, by using an interpreter, thehigh level program is executed directly. That is the reason why some programmers useinterpreters while making small sections as this saves time.
  2. 2. Almost all high level programming languages have compilers and interpreters. But somelanguages like LISP and BASIC are designed in such a way that the programs made usingthem are executed by an interpreter. Difference between compiler and interpreter • A complier converts the high level instruction into machine language while an interpreter converts the high level instruction into an intermediate form. • Before execution, entire program is executed by the compiler whereas after translating the first line, an interpreter then executes it and so on. • List of errors is created by the compiler after the compilation process while an interpreter stops translating after the first error. • An independent executable file is created by the compiler whereas interpreter is required by an interpreted program each time.What is the main difference between aninterpreter and a compiler?Computer Programming QuestionsAnswerThe execution of a program can happen either natively -- the intructions are actual CPUinstructions, or it can happen through an interpreter. The interprer thus takes instructions (whichare typically not native CPU instructions), and performs the actions associated with theinstruction (open a file, write a character to the screen, etc). The interpreter is thus in charge ofthe execution of the program instructions.Now consider a program written in spoken English. It is obvious that the CPU does notunderstand spoken English. We can either use an interpreter to execute this program, or we cantranslate to "another form" (typically machine code specific to a particular CPU) -- using acompiler. This "other form" may require additional things to happen, so the compiler may insertextra instructions to cater for these things. The end result is our spoken English program, in
  3. 3. another form -- either native, which can be executed by the CPU, or an a form which requiresthat an interpreter be used to execute it.The interested reader is encouraged to read Allan Turings groundbreaking paper on computingmachines entitled "On computable numbers: With an application to the Entscheidungsproblem".You can find this easily by simply searching for this title with your favourite search engine.Another AnswerWe usually prefer to write computer programs in languages we understand rather than inmachine language, but the processor can only understand machine language. So we need a wayof converting our instructions (source code) into machine language. This is done by aninterpreter or a compiler.An interpreter reads the source code one instruction or line at a time, converts this line intomachine code and executes it. The machine code is then discarded and the next line is read. Theadvantage of this is its simple and you can interrupt it while it is running, change the programand either continue or start again. The disadvantage is that every line has to be translated everytime it is executed, even if it is executed many times as the program runs. Because of thisinterpreters tend to be slow. Examples of interpreters are Basic on older home computers, andscript interpreters such as JavaScript, and languages such as Lisp and Forth.A compiler reads the whole source code and translates it into a complete machine code programto perform the required tasks which is output as a new file. This completely separates the sourcecode from the executable file. The biggest advantage of this is that the translation is done onceonly and as a separate process. The program that is run is already translated into machine code sois much faster in execution. The disadvantage is that you cannot change the program withoutgoing back to the original source code, editing that and recompiling (though for a professionalsoftware developer this is more of an advantage because it stops source code being copied).Current examples of compilers are Visual Basic, C, C++, C#, Fortran, Cobol, Ada, Pascal and soon.You will sometimes see reference to a third type of translation program: an assembler. This islike a compiler, but works at a much lower level, where one source code line usually translatesdirectly into one machine code instruction. Assemblers are normally used only by people whowant to squeeze the last bit of performance out of a processor by working at machine code level.CompilerA Compiler is a program that translates code of a programming language in machine code*****Translated source code into machine code***** .A compiler is a special program that processes statements written in a particular programminglanguage and converts them into machine language, a "binary program" or "code," that acomputer processor uses.
  4. 4. A compiler works with what are sometimes called 3GL and higher-level languages (3rd-generation languages, such as Java and CInterpreterInterpreters translate code one line at time, executing each line as it is "translated," much the waya foreign language interpreter would translate a book, by translating one line at a time.Interpreters do generate binary code, but that code is never compiled into one program entity.Interpreters offer programmers some advantages that compilers do not. Interpreted languages areeasier to learn than compiled languages, which is great for beginning programmers. Aninterpreter lets the programmer know immediately when and where problems exist in the code;compiled programs make the programmer wait until the program is complete.Interpreters therefore can be easier to use and produce more immediate results; however thesource code of an interpreted language cannot run without the interpreter.Compilers produce better optimized code that generally run faster and compiled code is selfsufficient and can be run on their intended platforms without the compiler present

×