Presentation is loading. Please wait.

Presentation is loading. Please wait.

Compiled vs Interpreted A tradeoff of flexibility vs efficiency.

Similar presentations


Presentation on theme: "Compiled vs Interpreted A tradeoff of flexibility vs efficiency."— Presentation transcript:

1 Compiled vs Interpreted A tradeoff of flexibility vs efficiency

2 Similarity The function of a compiler or interpreter is to translate a Higher Level Language (HLL) and execute it. HLL Compiler or Interpreter Output

3 Major Difference Timing Amount of code translated before executing Oversimplified example –Translate a book -> Then read the book –Translate a statement -> Read statement (REPEAT) –Statement(word) at a time or do entire translation first.

4 Environments (extremes) Compiled –translate into object code –link –execute g++ is a script which hides steps –g++ -c HelloW.C creates HelloW.o –g++ -o HelloW HelloW.o links/creates HelloW

5 Environments (continued) Interpreted –Read line, translate, execute –Repeat unix basic calculator (bc) program America>bc a = 12 + 4 a 16 b = a + 2 b 18 quit America>

6 Other languages Lots of languages are interpreted –Basic –Smalltalk –APL –java –Our Tannenbaum machine language

7 Target code Compilers –HLL -> Machine language of the executing machine Interpreters –HLL -> intermediate code –program reads those codes, translates by executing lots of machine language instructions

8 Example (Tannenbaum) A compiler would translate the pascal program directly into ML. If there was a real machine, what you see in ML would be the result of compilation. Target is native ML. –A := 4; -> LOCO 4 STOD A Instead, this is a virtual machine. The resulting ML requires us to execute hundreds of c++ instructions in our simulator and each of those c++ instructions requires multiple real ML instructions on the Sun. E.g. –A;=4 -> 2 ML (tann) -> 30 c++ -> 100 ML (sun)

9 Binding Times Compilers –Make decisions as early as possible –Results are more efficiently implemented Interpreters –make decisions late –Results less efficient –PROGRAMMERS more FLEXIBILITY

10 XML – delaying decisions cs260 Prof. Game Announcement Test on Wednesday! cs260 Prof. Game Announcement Test on Wednesday! versus

11 Binding Time example Compiler: a:=4; Decide where to store the variable and simple translation like what we saw in the Tannenbaum example. A few ML instructions. Interpreter: a:=4; a:=“Hello”; Requires a RUN-TIME DESCRIPTOR. (see next slide). Code must check: if (numeric) … else if (string) … else...

12 Descriptor A B C int45 float12.456 string5 Hello type lengthvalue Managed during execution. Examined at each reference!

13 Now do B:=‘xyz’ A B C int45 string5 Hello type lengthvalue B had it’s value changed, so descriptor also changed. Not as simple as STOD B. string3 xyz

14 Most languages are a combination Pascal/Tannenbaum example –A:=4; -> direct translation in ML –writeln(A); -> must interpret with a procedure. Java –byte codes for virtual machine –JIT (just in time) compiler to translate parts of it for the purpose of efficiency Grey areas

15 How do we use this categorization? Think of it more in terms of features rather than the entire language. Tradeoff is Efficiency vs Flexibility This gives us a sense of whether the feature or language executes to provide optimal performance or perhaps optimizes other factors such as flexibility of target/platform such as in java.


Download ppt "Compiled vs Interpreted A tradeoff of flexibility vs efficiency."

Similar presentations


Ads by Google