1 / 15

Compiled vs Interpreted

Compiled vs Interpreted. A tradeoff of flexibility vs efficiency. Similarity. The function of a compiler or interpreter is to translate a Higher Level Language (HLL) and execute it. Compiler or Interpreter. Output. HLL. Major Difference. Timing

lorin
Download Presentation

Compiled vs Interpreted

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. Compiler or Interpreter Output HLL

  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 <note> <to>cs260</to> <from>Prof. Game</from> <heading>Announcement</heading> <body>Test on Wednesday!</body> </note> versus cs260 Prof. Game Announcement Test on Wednesday!

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

  12. Descriptor int 45 A B C float 12.456 Hello string 5 length value type Managed during execution. Examined at each reference!

  13. Now do B:=‘xyz’ int 45 A B C xyz string 3 Hello string 5 length value type B had it’s value changed, so descriptor also changed. Not as simple as STOD B.

  14. Grey areas • 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

  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.

More Related