Programming Languages CS 3723
Popular in Course
verified elite notetaker
Popular in ComputerScienence
verified elite notetaker
This 6 page Class Notes was uploaded by Mireya Heidenreich on Thursday October 29, 2015. The Class Notes belongs to CS 3723 at University of Texas at San Antonio taught by Jeffery Ronne in Fall. Since its upload, it has received 10 views. For similar materials see /class/231369/cs-3723-university-of-texas-at-san-antonio in ComputerScienence at University of Texas at San Antonio.
Reviews for Programming Languages
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 10/29/15
101m Xy72 3 X gtU lt3Altgtsyxltlt e 3gt x y ASSune 1 77 at 35 f5 41quot im 9 47 55une fyJe 04 5 4 9 inf 91quot l Cmsfmiab 90ml nmcmlion r 1 75 V 4139 COASTraim39S 90 Q 15 1 39911L u 9 5 us Uzi fql f79y VHL 14 9l1 l vgt f V in f w gtv 39 inf3 n in r w M M P 14739 Fm r emf39 S in The yp 7 K s I39Af fl3947 9 Af CS 3723 SUPPLEMENTAL NOTES ON COMPILERS AND INTERPRETERS 2142008 Compilers and Interpreters Most programs a written in high level programming languages that are not di rectly implemented by any real hardware machine So it is not possible to simply dump the source code onto a computer and expect it to run There are two basic approaches to bridge the gap between high level programming languages and machine code compilation and interpretation Traditional Compilation With compilation some source program P written in some source language L is translated into an equivalent program P in some target language L The program that does this translation is called a compiler Typically the source language L is some high level programming language eg C and the target language L is the machine code of some hardware machine The output program P would then be an executable that can run directly on the hardware In this way P is both the output of the compiler program and a program itself After compilation P can be executed independently of the compiler to process input and produce output S P P Traditional Machine Code ource rogram compiler Program P Interpretation An alternative approach to program execution is interpretation An interpreter is a program that executes another program P written in some programming language L 1W simulating L and directly performing the tasks required by the statements in P while P is running With an interpreter there is no independent executable output P The interpreter itself is the only program that runs directly on L It knows how to simulate the execution each kind of statement in L and so it can be used to perform the tasks for each of the statements in P as they would be performed on L For a non interactive program P the interpreter can be seen as taking two inputs P and the input for P and directly producing an output This output must be the same as P would produce if it were executing directly on L Source Program P H Interpreter Comparison of Compilation and Interpretation Compilations happens once each time the source is modified whereas interpretation continues throughout every execution of a program So for long running programs compilation is almost always faster In addition many compilers expend effort to analyze pro grams and rearrange and optimize the code so that it runs even faster A good interpreter might execute a program about 20X slower than the compiled and optimized machine code for the same program On the other hand this translation and optimization takes time so if you are developing a program you might get faster turnaround time with a interpreter In addition with a optimizing compiler the program that gets executed does not always perform operations in the order that they appear in the program whereas interpretation executes each statement as it appears in the program Thus interpreted programs are often easier to debug Another issue is the amount of runtime overhead required to implement various features Languages like Lisp SmallTalk and most scripting languages tend to require a lot of decisions and actions to take place in the background that are not explicitly mentioned in the code One example of this we ve already dis cussed is garbage collection but other example include the way variable names are mapped to their contents complex built in data types dynamic loading of new program code and re ection In general the runtime performance overhead of these features is the same whether the program is compiled or interpreted so in more dynamic languages where lots of these decisions occur at runtime in terpretation will not be significantly slower than compilation These languages are typically implemented with an interpreter and are sometimes called quotinter preted languagesquot even though a compiler could be written for them On the other hand languages that can be analyzed easily and for which many decisions can be decided during compilation eg Fortran C C benefit from compi lation these are often called quotcompiled languagesquot even though an interpreter could be written for them Virtual Machines Modern execution environments however blur the distinction between com pilers and interpreters On the one hand modern compilers process provide an ability to separately compile various program modules and operating sys tems provide facilities for dynamically loading and linking the modules together when the program starts or even as the program runs On the other hand in terpreters have evolved into complex virtual machines that can improve perfor mance by selectively compiling parts of the program that it is executing In addi tion a hybrid compilation interpretation process is often used where the source program is first compiled to an intermediate bytecode which is then interpreted and or compiled by a virtual machine As a concrete example consider Java or more specifically Sun s reference im plementation of the Java the Java platform standard edition There are exe cutable programs that are of interest javac and java javac stands for Java com piler but it does not produce executable machine language instead it translates from the Java source programming language into a bytecode for the Java Virtual Machine1 A separate stream of bytecode instructions is created for each method and the bytecode for all of the methods in a given class are collected into a Java class file These class files are the output of compilation but they are also the input to the Java Virtual Machine the jaw executable From the outside the Java Virtual Machine JVM looks a lot like our standard interpreter but instead of having a source programming language as input it has bytecode as input JVM java Source Code 09mp39ler BytECOIJe Javac Class Flle Internally though things are even more complicated The Java Virtual Machine loads class files into memory on a class by class basis but then executes Mite code stored in the classes on a method by method basis It usually interprets the bytecode for a method the first few times the method is called After a method is called many times however the virtual machine will decide to compile that method to native machine code and then execute that machine code directly 1Although at one point Sun did actually build a computer chip that could run Java Bytecode as its native machine code instruction set This process of compiling parts of the program as needed while the program is running is known as ust in time JIT compilation Class Loader I Input Java Virtual Machine Machine Code for a Method Re ection Byiecode 39 JIT Com Iler Interpreter of a Method Garbage Colledion Output In addition to a compiler and or interpreter a Java Virtual Machine also includes other runtime facilities that support features such as dynamic class loading re ection and garbage collection Dynamic Loading and Eval One of the more interesting facilities provided by the Java Virtual Machine is the ability to load class files into the virtual machine and link them dynamically to a running program This dynamic class loading happens automatically the first time each class is used but can also be explicitly requested by the running program to for example download a new plugin over the internet and integrate into the running program Slightly less exible versions of dynamic loading and linking are provided for traditional compiled languages eg C 1W most modern operating systems eg Linux and through calls to system libraries eg dlopen An even more exible version of dynamic loading is available in many inter preted languages Lisp Scheme provides an eval function This function takes a list containing Lisp Scheme code as an argument let code cons cons 1 cons 1 cons code eval code will evaluate to 1 1 2 CS 3723 A CALCULS REFERENCE SH EET 1312008 Modified 22108 Notation Three kinds of A terms 1 variables x y z 2 application function call MN 3 abstraction function definition MLM Free Variables PV x x PV MLM PV M 7 x PV MN PV M u PV N Theory 1 tx equivalence tx renaming MLM a AyVle 2 B reduction AxMN a Nxw 3 B equivalence AxMN Nxw MM 15 MMW 4 eqivalence not very important M 7 LXMX N XM represents the substution of N for all of the free occurences of X in M These rules may be applied to individual subterms of a larger term TerminologyConcepts ChurchRosser Theorem con uence M N 3ZMgt gt ZANgt gt Z normal form result of reducing a A term until it cannot be reduced anymore currying simulating multiple arguments with a higher order function that takes one argument and returns a function that takes the next argument
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'