0% found this document useful (0 votes)
11 views19 pages

Lec 04

Uploaded by

Ambreen Raja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views19 pages

Lec 04

Uploaded by

Ambreen Raja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Theory of Programming

Languages
LECTURE#4
Implementation Methods

Two of the primary components of a computer are its:


 internal memory and
 processor
Implementation Methods

 The internal memory is used to store programs and data.


 The processor is a collection of circuits that provides a realization of a
set of primitive operations, or machine instructions, such as those for
arithmetic and logic operations.
Implementation Methods

Programming languages can be implemented by any of three general


methods.
 Compiler
 Interpreter
 Hybrid
Compilation

 Programs can be translated into machine language, which can be


executed directly on the computer. This method is called a compiler
implementation.
 Very fast program execution.
 Most production implementations of languages, such as C, COBOL, and
C++, are by compilers.
Compilation

 The language that a compiler translates is called the source


language.
 The process of compilation and program execution takes place in
several phases, the most important of which are shown as:
Compilation

 The lexical analyzer gathers the characters of the source program


into lexical units.
 The lexical units of a program are identifiers, special words, operators,

and punctuation symbols.


 The lexical analyzer ignores comments in the source program because
the compiler has no use for them.
 The syntax analyzer takes the lexical units from the lexical analyzer
and uses them to construct hierarchical structures called parse trees.
Compilation

 The parse trees represent the syntactic structure of the program.


 In many cases, no actual parse tree structure is constructed; rather, the
information that would be required to build a tree is generated and
used directly.
 The intermediate code generator produces a program in a different
language, at an intermediate level between the source program and the
final output of the compiler: the machine language program.
Compilation

 The semantic analyzer is an integral part of the intermediate code


generator.
 The semantic analyzer checks for errors, such as type errors, that are
difficult, if not impossible, to detect during syntax analysis.
 Optimization, which improves programs (usually in their intermediate
code version) by making them smaller or faster or both.
 The code generator translates the optimized intermediate code
version of
the program into an equivalent machine language program.
Compilation

 The symbol table serves as a database (type and attribute


information
of each user-defined name) for the compilation process.
Pure Interpretation

 Programs are interpreted by another program called an interpreter.


 allow easy implementation
 For example, if an array index is found to be out of range, the error
message can easily indicate the source line of the error and the name
of the array.
Pure Interpretation

 It has a disadvantage that execution is 10 to 100 times slower than in


compiled systems.
 Some early languages of the 1960s (APL, SNOBOL, and Lisp) were
purely interpreted.
 In recent years, pure interpretation has made a significant comeback
with some Web scripting languages, such as JavaScript and PHP, which
are now widely used.
 The process of pure interpretation is shown as:
Pure Interpretation
Hybrid Implementation Systems

 Some language implementation systems are a compromise between


compilers and pure interpreters; they translate high-level language
programs to an intermediate language designed to allow easy
interpretation.
 This method is faster than pure interpretation because the source
language statements are decoded only once. Such implementations are
called hybrid implementation systems.
 The process used in a hybrid implementation system is shown as:
Hybrid Implementation Systems

 Instead of translating intermediate language code to machine code, it


simply interprets the intermediate code.
 Perl is implemented with a hybrid system.
 Initial implementations of Java were all hybrid.
 Java Virtual Machine
Preprocessors

 A preprocessor is a program that processes a program just before the


program is compiled.
 Preprocessor instructions are commonly used to specify that the code
from another file is to be included.
 For example, the C preprocessor instruction
#include "myLib.h“
causes the preprocessor to copy the contents of myLib.h into the
program at the position of the #include.
Programming Environment

 A programming environment is the collection of tools used in the


development of software. This collection may consist of only a file
system, a text editor, a linker, and a compiler.
 UNIX is an older programming environment, first distributed in the
middle 1970s.
 Microsoft Visual Studio .NET is a relatively recent step in the evolution
of software development environments.
 NetBeans is a development environment that is primarily used for Java
application development.

You might also like