Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
6Activity
0 of .
Results for:
No results containing your search query
P. 1
Intermediate Languages

Intermediate Languages

Ratings:

4.0

(1)
|Views: 1,203|Likes:
Published by sgganesh
see www.joyofprogramming.com
see www.joyofprogramming.com

More info:

Published by: sgganesh on Jun 02, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

01/26/2013

pdf

text

original

 
 Intermediate Languages
Intermediate languages are with us for quite a long time. Most of thecompilers employ them in one-way or another. The way of usingintermediate languages have also sometimes contributed to thesuccess of the languages like Pascal, Java and recently C# (with .NETinitiative in general). Even some tools like MS-Word makes use of anintermediate language (p-code). Intermediate languages have made abig difference in achieving portability of code. This article explores theconcept of intermediate languages and their use in achieving completeportability and language interoperability.In 1950s itself, this idea of having an intermediate language wasexperimented with the introduction of UNCOL [1]. Later Pascal becamewidely available because of p-code. Not until recently did Javaemployed the same technology with its promise of portability tobecome a big success. Now Microsoft's .NET initiative is also based onthis approach, but the keyword is language interoperability. A closerlook reveals that all are based on same idea: use of intermediate code,and that is the current trend in the language translation technology.
Approaches in Language Translation
Two major approaches towards language translation are compilationand interpretation. In compilation, since the native code is generated,different compilers are needed for different platforms. An interpreter isalso particular to the platform, but its specifics are abstracted makingonly the behavior of the program transparent as the code is translatedand executed 'on-the-fly'.Neither of them is ‘the’ best approach - both boasts of significantadvantages and also suffer from some serious disadvantages.The advantages of compilation mostly overweigh its disadvantages andthat is why it is preferred in most of the languages. The translationand optimization needs to be done only once, and native code ensuresefficiency of execution. However as native code is generated, it isplatform specific.Interpretation has some very good advantages that compilationdoesn’t have. In particular, they can achieve full portability. Also it canprovide better interactive features and diagnostic (error) messages.But one problem that cripples interpretation is performance. Since
 
translation needs to be done every time (and for the same reason,optimization is less attractive) execution becomes generally very slow(10 to 100 times) compared to the equivalent compiled code.You can think of an interpreter as the one that implements a virtualmachine. So, it can be inferred that the 'machine language' of thatvirtual machine is the high-level language for which the interpreter iswritten!Interpreters provide many advantages including greater flexibility,better diagnostics and interactive features like debugging. True powerof interpretation is generally underestimated. To illustrate, you canthink of printf library routine in C as a tiny interpreter for formattedoutput - depending on the requirement it parses the format string,gets the arguments, computes the format on the fly, prints it to theoutput along with facilities like padding, aligning, specific notations etc.Interpretation allows the code to be generated or modify itself "on thefly" and execute it. For example, interpreted languages like Lisp oreven partly interpreted languages like Java or C# provides suchfacilities (although not recommended to use such facilities for practicalprogramming). Note that few language features like reflection are onlypossible with interpretation. This is the reason why compilers cannotbe written for some languages and interpretation is the only option.So, instead of restricting to pure compilation or interpretation, you caninfer that a combination of the both is better to enjoy the advantagesof these approaches.It seems to be very simple to use both compilation and interpretation.For that itself, various languages use different approaches.Few languages provides options for both interpretation and compilationand can be used depending on the requirement. For example, fordevelopment and debugging, Microsoft Visual Basic uses an interpreterand for deployment, it employs a compiler.As already stated, writing compilers for the languages that are meantfor interpretation is sometimes not possible. In such cases, it ispossible to bundle the source code with the whole interpreter as anexecutable file and distribute it. Java Native Interface (JNI) follows asimilar approach by embedding a Java interpreter in an executablecode created by a C/C++ source code, and run the Java code through
 
it. This solution is feasible because the Java interpreter’s size is notvery big.A very interesting approach towards combining compilation andinterpretation through hardware support was widely used in as earlyas 1960s in IBM chips. IBM released chips that incorporated theinterpreter software burnt into chips (nothing but firmware) thatsupported a general instruction set. The main advantage being thatthe same instruction set (of the interpreter) shall be used acrossdifferent processor architectures. Since, the compilers would generatethe code just for that one instruction set, the effort is minimized.Later, the advent of VLSI design with RISC architecture obviated thismicroprogramming approach.The very popular and widely used approach that combines thecompilation and interpretation is making use of intermediate codedirectly. Since its use in Java this approach seems to have receivedwidespread acceptance, even though its idea was used long back inPascal and in many other languages. Languages following thisapproach are sometimes referred to as p-code languages since p-codeof Pascal is one of the first intermediate codes to follow this approachsuccessfully. Few of important p-code languages are Python, Perl, Javaand now, C# (.NET framework). The idea is to use a compiler togenerate the intermediate language code. The intermediate code canbe moved on to other platforms or even across the network where aninterpreter (also called as virtual machine) for that platform will takeover to interpret the code.The usage of intermediate code in compilers is not a new idea. Thereare various phases in a compiler and they can be grouped generally asthe front-end and the back-end. The analysis and translation of thecode (in general 'parsing') is done by the front end and the synthesisof the code is taken care by the back-end. The information in the formof intermediate languages is represented that is generally independentany particular architecture and thus serves as a link to transfer theinformation from front-end to the back-end. The advantage with thisapproach is that, the front-end can be same and only the back-endneeds to be changed to support new architectures and hence the effortis limited only in rewriting the back-end of the compiler. Intermediatelanguages also help in general optimization of the code that are notparticular to any platform and provides many related advantages. Somost of the compilers employ intermediate code.

Activity (6)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
sblushing liked this
Arthi Selvam liked this
Pardeep Jindal liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->