Logout

3.1.2 Describe the function of high-level language translators.

(No teaching notes from the syllabus.)

Sample Question:

Outline one difference between the functioning of an interpreter and a compiler. [2 marks]

JSR Notes:

- The translators should be limited to interpreters and compilers.

- Most important is compiling versus Interpreting, during the translation of high level languages into low level machine code.

Most of the JSR Notes in this case are just re-stating what is generally well done in the yellow and red text book:

And though I only infrequently copy and paste from webopedia or wikipedia, in this case, it's hard to state it better. So from Wikepedia.org:

Interpreted language

From Wikipedia, the free encyclopedia
Jump to: navigation, search

Interpreted language is a programming language in which programs are 'indirectly' executed ("interpreted") by an interpreter program. This can be contrasted with a compiled language which is converted into machine code and then 'directly' executed by the host CPU. Theoretically, any language may be compiled or interpreted, so this designation is applied purely because of common implementation practice and not some essential property of a language. Indeed, for some programming languages, there is little performance difference between an interpretive- or compiled-based approach to their implementation.

Many languages have been implemented using both compilers and interpreters, including BASIC, C, Lisp, Pascal, and Python. While Java is translated to a form that is intended to be interpreted, just-in-time compilation is often used to generate machine code.

 

Note that translation is "parsing", or changing from one form (human words written in a language like Java) to, ultimately - through various steps - the machine code of 0s and 1s specific for a specific kind of computer architecture. The key difference between compiled languages and interpreted languages is that with compiling, the "parsing" is done ahead of time to the whole program all at once, down to the actual machine code which is ready to be executed, whereas with interpretation, the parsing and execution are done by the interpreter when the program is run, one instruction at a time.

Also note that an interpreted program needs an interpreter on any computer that wishes to run it, whereas the compiled file is a complete, totally stand-alone file, like an .exe Windows file, not requiring a specific interpreter.

One interesting thing not mentioned in class is that Java can be both interpreted and compiled. How is this possible? You can refer to the Morelli text, pages 45-49, but basically, Java (along with the even newer C# - pronounced "C-sharp") are not languages that compile all the way to machine code native to a particular kind of computer, as C and C++ do; rather they compile to general byte code, which is then, in turn, is interpreted in a specific way by their respective Java Virtual Machines (VM). So, in this case, you'll note that the Java VM is the "interpreter".

(If I get a chance, I'll do a "Hello World" applet, and insert it here: The fact that I can, and you'll all be able to run it on your computer - no matter what kind of a computer you have - demonstrates this distinct advantage of Java: the ability to do the final interpretation stage in a specific way on each specific computer - assuming that you have the Java Virtual Machine running on your computer, which you almost certainly do.) (I did, but will have to do it again, as it is causing freezing in Firefox.... will do another one some time.)

 

Linking: This is worth expanding upon a bit. When you compile a Java file, after it's been parsed to "object code" (simplified, compacted code accomplished though the "lexical analysis" stages), it then needs to have all of the Java libraries you've taken advantage of linked to the file. So things like System.out.println, and Math.random need to be included in the overall file.

So for Java, the various stages (all the way from the code you write to the actual executable file on a specific computer) are:

1. Writing the source code - what you write(in NotePad, Netbeans, or whatever)
2A. Compiling your code - when you comile the program in Netbeans or whatever, the compiler checks for syntax correctness, and then makes tokens etc out of the statement you have written.
2B. Linking libraries to your code - in Netbeans, this happens when you run the program; both your lines and the lines of needed external libraries are compiled to an intermediary stage of byte-code. With Java a compressed format .jar file is produced.
3. Interpetation of the byte-code by a specific JVM of a particular computer. (That also happens when you run in Netbeans, but it happens slightly differently on each platform the program runs on.)

 

JSR To Do: Better yet would be a link to a java file working through a GlassFish server that will not only allow java files to be executed on any computer, but to be done so with the capability of storing information on a server, just like Stroodle does with php and a mySql database. I’m not quite sure how the GlassFish server works, but you can imagine my delight in getting as far as I did in just half an hour or so; this opens up a whole new world of possibilities for what your programs can do: :8080/WebApplication3/ ...Actually, not sure about this one; it's working when I have Netbeans open; it has to "deploy"; I'm a little nervous to keep it deployed until I know a bit more about it - particularly security issues. So I'll show you in class; it's pretty interesting.