CD Unit I Part I Introduction
CD Unit I Part I Introduction
CD Unit I Part I Introduction
Dr.S.Gopi Krishna
Professor in CSE
Agenda
01 UNIT I : PART I
1. Language Processors
2. Structure of a Compiler
3. Evolution of Programming
Languages
4. The Science of building a
Compiler
5. Applications of Compiler
Technology
6. Programming Language
Basics
Agenda
01 UNIT I : PART I
1. Language
Processors
2. Structure of a Compiler
3. Evolution of Programming
Languages
4. The Science of building a
Compiler
5. Applications of Compiler
Technology
6. Programming Language Basics
Agenda UNIT I : PART I
01
1.Language
Processors
Compiler
Language Processing
System
Language Processors
1. Preprocessor
2. Compiler
3. Assembler
4. Linker/Loader
1. Preprocessor
1.Language
Processors
Compiler
Language Processing
System
…. Thank you
Agenda
01 UNIT I : PART I
1. Language Processors
2. Structure of a
Compiler
3. Evolution of Programming
Languages
4. The Science of building a
Compiler
5. Applications of Compiler
Technology
6. Programming Language Basics
Agenda UNIT I : PART I
01
2. Structure of a
Compiler
Analysis - Synthesis
Phases of a Compiler
Structure of a compiler
1. Analysis and
2. Synthesis.
1. Analysis
The analysis part often called the front end of the compiler,
Representation of the assignment statement, after lexical analysis as the sequence of tokens
(id,1) (=) (id, 2) (+) (id, 3) (*) (60)
2 Syntax Analysis
The second phase of the compiler is syntax analysis or
parsing (Parser).
A syntax tree for the token stream is shown as the output of the syntactic analyzer. This tree
shows the order in which the operations in the assignment position = initial + rate * 60
are to be performed.
3 Semantic Analysis
2. Structure of a
Compiler
Analysis - Synthesis
Phases of a Compiler
…. Thank you
Agenda
01 UNIT I : PART I
1. Language Processors
2. Structure of a Compiler
3. Evolution of
Programming
Languages
4. The Science of building a
Compiler
5. Applications of Compiler
Technology
6. Programming Language Basics
Agenda
01 UNIT I : PART IV
Evolution of
Programming
Languages
The Move to Higher-level
Languages
Impacts on Compilers
The Evolution of Programming Languages
The first electronic computers appeared in the 1940's and were programmed in machine
language by sequences of 0's and 1's that explicitly told the computer what operations to
execute and in what order.
Needless to say, this kind of programming was slow, tedious, and error prone. And once
written, the programs were hard to understand and modify.
A major step towards higher-level languages was made in the latter half of the 1950's with
the development of FORTRAN for scientific computation, COBOL for business data
processing, and LISP for symbolic computation.
1. Classification is by generation.
First-generation languages are the machine languages
3. Scripting languages are interpreted languages with high-level operators designed for
"gluing together" computations.
These computations were originally called "scripts." Awk, JavaScript, Perl, PHP,
Python, Ruby, and Tel are popular examples of scripting languages.
Programs written in scripting languages are often much shorter than equivalent
programs written in languages like C.
1. The Move to Higher-level Languages
3. Scripting languages are interpreted languages with high-level operators designed for
"gluing together" computations.
These computations were originally called "scripts." Awk, JavaScript, Perl, PHP,
Python, Ruby, and Tel are popular examples of scripting languages.
Programs written in scripting languages are often much shorter than equivalent
programs written in languages like C.
2. Impacts on Compilers
Since the design of programming languages and compilers are intimately related, the
advances in programming languages placed new demands on compiler writers.
They had to devise algorithms and representations to translate and support the
new language features.
A compiler must translate correctly the potentially infinite set of programs that
could be written in the source language.
The problem of generating the optimal target code from a source program is
undecidable in general; thus, compiler writers must evaluate tradeoffs about what
problems to tackle and what heuristics to use to approach the problem of
generating efficient code.
Agenda
01 UNIT I : PART IV
Evolution of
Programming
Languages
The Move to Higher-level
Languages
Impacts on Compilers
… Thank You
Agenda
01 UNIT I : PART I
1. Language Processors
2. Structure of a Compiler
3. Evolution of Programming
Languages
4. The Science of
building a Compiler
5. Applications of Compiler
Technology
6. Programming Language Basics
Agenda
01 UNIT I : PART I
The Science of
building a Compiler
Modelling in Compiler Design
and Implementation
The Science of Code
Optimization
The Science of Building a Compiler
Also among the most fundamental models are context-free grammars, used to
describe the syntactic structure of programming languages such as the nesting of
parentheses or control constructs.
1 Modeling in Compiler Design and Implementation
1. The optimization must be correct, that is, preserve the meaning of the
compiled program,
2. The optimization must improve the performance of many programs,
3. The compilation time must be kept reasonable, and
4. The engineering effort required must be manageable.
Agenda
01 UNIT I : PART I
The Science of
building a Compiler
Modelling in Compiler Design
and Implementation
The Science of Code
Optimization
… Thank You
Agenda
01 UNIT I : PART I
1. Language Processors
2. Structure of a Compiler
3. Evolution of Programming
Languages
4. The Science of building a
Compiler
5. Applications of
Compiler
Technology
6. Programming Language Basics
Agenda
01 UNIT I : PART I
Applications of
Compiler
Technology
Implementation of High-Level
Programming Language
Optimizations for Computer
Architectures
Design of New Computer
Architectures
Program Translations
Software Productivity Tools
Applications of Compiler Technology
Generally, higher-level programming languages are easier to program in, but are less
efficient, that is, the target programs run more slowly.
Programmers using a low-level language have more control over a computation and
can, in principle, produce more efficient code.
Unfortunately, lower-level programs are harder to write and — worse still — less
portable, more prone to errors, and harder to maintain.
The rapid evolution of computer architectures has also led to an insatiable demand for new
compiler technology.
Almost all high-performance systems take advantage of the same two basic techniques:
2. Memory hierarchies are a response to the basic limitation that we can build very fast
storage or very large storage, but not storage that is both fast and large.
3 Design of New Computer Architectures
i. Binary Translation
Compiler technology can be used to translate the binary code for one machine to that
of another, allowing a machine to run programs originally compiled for another
instruction set.
Binary translation technology has been used by various computer companies to
increase the availability of software for their machines.
Hardware designs are typically described at the register transfer level (RTL), where
variables represent registers and expressions represent combinational logic.
Unlike compilers for programming languages, these tools often take hours optimizing the
circuit. Techniques to translate designs at higher levels, such as the behavior or functional
level, also exist.
4 Program Translations
Inputs to a simulator usually include the description of the design and specific input
parameters for that particular simulation run.
Dataflow analysis can find errors along all the possible execution paths, and not just
those exercised by the input data sets, as in the case of program testing.
• Type Checking
Type checking is an effective and well-established technique to catch
inconsistencies in programs.
It can be used to catch errors, for example, where an operation is applied to the
wrong type of object, or if parameters passed to a procedure do not match the
signature of the procedure.
Program analysis can go beyond finding type errors by analyzing the flow of data
through a program. For example, if a pointer is assigned null and then immediately
dereferenced, the program is clearly in error.
5 Software Productivity Tools
• Bounds Checking
It is easier to make mistakes when programming in a lower-level language than a
higher-level one.
For example, many security breaches in systems are caused by buffer overflows in programs
written in C. Because C does not have array bounds checks, it is up to the user to
ensure that the arrays are not accessed out of bounds.
Failing to check that the data supplied by the user can overflow a buffer, the program may
be tricked into storing user data outside of the buffer.
An attacker can manipulate the input data that causes the program to misbehave and
compromise the security of the system. Techniques have been developed to find buffer
overflows in programs, but with limited success.
5 Software Productivity Tools
• Memory-Management Tools
Garbage collection is another excellent example of the trade off between
efficiency and a combination of ease of programming and software
reliability.
Various tools have been developed to help programmers find memory management
errors. For example, Purify is a widely used tool that dynamically catches
memory management errors as they occur. Tools that help identify some of
these problems statically have also been developed.
Agenda
01 UNIT I : PART I
Applications of
Compiler
Technology
Implementation of High-Level
Programming Language
Optimizations for Computer
Architectures
Design of New Computer
Architectures
Program Translations
Software Productivity Tools
… Thank You
Agenda
01 UNIT I : PART I
1. Language Processors
2. Structure of a Compiler
3. Evolution of Programming
Languages
4. The Science of building a
Compiler
5. Applications of Compiler
Technology
6. Programming
Language Basics
Agenda
01 UNIT I : PART I
Programming Language
Basics
The Static/Dynamic Distinction
Environments and States
Static Scope and Block
Structure
Explicit Access Control
Dynamic Scope
Parameter Passing Mechanisms
Aliasing
1 The Static/Dynamic Distinction
2. On the other hand, a policy that only allows a decision to be made when
we execute the program is said to be a dynamic policy or to require a
decision at run time.
It may be less clear that the location denoted by x can change at run time.
3 Static Scope and Block Structure
Most languages, including C and its family, use static scope.
Later languages, such as C++, Java, and C#, also provide explicit control
over scopes through the use of keywords like
1. public
2. private
3. protected.
If p is an object of a class with a field (member) x, then the use of x in p.x refers to field
x in the class definition.
5 Dynamic Scope
The term dynamic scope, however, usually refers to the following policy:
• a use of a name x refers to the declaration of x in the most recently called
procedure with such a declaration.
All programming languages have a notion of a procedure, but they can differ in how
these procedures get their arguments.
It is possible that two formal parameters can refer to the same location; such
variables are said to be aliases of one another.
As a result, any two variables, which may appear to take their values from two
distinct formal parameters, can become aliases of each other, as well.
Agenda
01 UNIT I : PART I
Programming Language
Basics
The Static/Dynamic Distinction
Environments and States
Static Scope and Block
Structure
Explicit Access Control
Dynamic Scope
Parameter Passing Mechanisms
Aliasing
…. Thank You
Agenda 01 END OF
UNIT I : PART I
1. Language Processors
2. Structure of a Compiler
3. Evolution of Programming
Languages
4. The Science of building a
Compiler
5. Applications of Compiler
Technology
6. Programming Language
Basics
….. THANK YOU