You are on page 1of 38

Unit– 2– 4

Unit
Pushdown
Overview of Language
Processor
Automata
Prof. Dixita Kagathara
dixita.kagathara@darshan.ac.in

Unit
System
–– 22Programming
System
Unit :: Overview
Overview of
Programming of(2150708)
Language
Language Processor
(2150708) Processor 11 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Topics to be covered
• Overview of Language Processors
• Programming Languages and Language Processors
• Language Processing Activities
• Fundamentals of language processor
• Symbol tables
• Data Structures for Language Processing: Search Data structures,
Allocation Data Structures.

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 22 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
What do you see?
10101001 00000000 10101001 00000000
10101001 00000000 10101001 00000000
10000101 0000000 110101001 00000000 Binary
10101001 00000010 10101001 00000010 program
10000101 00000010 10101001 00000010
10100000 00000000 10101001 00000010
10101001 0000000 110101001 00000010
What does it
10010001 00000001 10000101 00000000 mean????
10000101 00000001 10101001 00000010
10101001 00000010 10101001 00000010
10101001 00000010 10101001 00000010

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 33 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
What do you see?

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 44 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Semantic gap

10101001 00000000 10101001 00000000


10101001 00000000 10101001 00000000
10000101 0000000 110101001 00000000
10101001 00000010 10101001 00000010
10000101 00000010 10101001 00000010
Semantic
10100000 00000000 10101001 00000010
Low level Gap High level
10101001 0000000 110101001 00000010
10010001 00000001 10000101 00000000

Actual Data Human perception

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 55 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Example: Semantic gap between domains
Reservation system
Semantic Gap

Reservation
Data
CPU registers,
It represents the Memory, I/O
difference between the devices
Query
semantic (rules) of two
domains.
Book
CPU
Cancel Instructions

Application Domain Execution Domain


Thehasdesigner
The ideas of designer, expresses the
to be interpreted ideas related
in terms in termsto the
related tosystem.
execution domain of computer application domain of the software.

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 66 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Semantic gap between domains
Gap between application & Gap between programming
programming language domain language & execution domain

Specification Gap Execution Gap

Reservation
Data CPU
Data registers
Structures Memory I/O
Query
devices

Book
CPU
Cancel Functions
Instructions

Application Domain Programming Language Domain Execution Domain

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 77 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Semantic gap

Semantic gap = Specification gap + Execution gap

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 88 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Language processor
• Language processor is a software which bridges a specification
and/or an execution gap.

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 99 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Basic definitions
• Language translator: Language translator bridges an execution gap
between programming language and machine language of a
computer system.
Examples: Compiler, Interpreter, Assembler
• De-translator: It bridges the same execution gap as language
translator, but in the opposite direction.
• Preprocessor: It is a language processor which bridges an
execution gap but is not a language translator.
• Language migrator: It bridges the specification gap between two
programming languages.

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 10
10 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Language processing activity

Unit
System
–– 22Programming
System
Unit :: Overview
Overview of
Programming of(2150708)
Language
Language Processor
(2150708) Processor 11
11 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Language processing activity
Language processing activity

Program Program
generation execution

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 12
12 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Program generation activity
• A program generation activity aims an automatic generation of a
program.
• Program generator is a software, which accepts the specification
of a program and generates a program in target language that
fulfills the specification.

Errors

Program Program in target


Program specification language
generation

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 13
13 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Language processing activity
Language processing activity

Program Program
generation execution

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 14
14 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Program execution
• Two models for program execution are:
1. Program Translation
2. Interpretation

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 15
15 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Program execution (Program translation)
• The program translation model bridges the execution gap by
translating a program written in programming language (PL),
called source program, into an equivalent machine program or
assembly language, called target program.

Error Data

Source M/C language


Translator Results
Program program

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 16
16 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Practical arrangement of language processors

Skeletal
Source Source Assembly
Program Program Program Machine
Preprocessor Compiler Assembler language
Program

Linker

Data

M/C language
Loader
program

Results

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 17
17 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Program execution (Interpretation)
• The interpreter reads the source
program and stores it in its memory.
• The CPU uses the program counter Memory
(PC) to note the address of the next Program Source
instruction to be executed. counter Program
• Steps for interpretation cycle are: +
Data
1. Fetch the statement. Errors

2. Analyze the statement and


determine what operation to be Interpretation
performed and which operands
are their. Detect errors, if any.
3. Perform the operations.

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 18
18 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Fundamental of language
processing

Unit
System
–– 22Programming
System
Unit :: Overview
Overview of
Programming of(2150708)
Language
Language Processor
(2150708) Processor 19
19 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Fundamental of language processing
Language processing = Analysis of Source Program
+
Synthesis of Target Program

Language processor

Source Analysis Synthesis Target


Program Phase Phase Program

Errors Errors

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 20
20 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Phases of language processor (Toy compiler)

Analysis phase Synthesis phase

Lexical analysis
Intermediate Memory
code allocation
Syntax analysis generation
Code
Semantic analysis generation

Front end Back end

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 21
21 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Lexical analysis
• Lexical analysis identifies the lexical A = B + C
unit in a source statement.
• Lexical unit is called a token. Lexical analysis
• Categories of Tokens are:
Id#1 Op#1 Id#2 Op#2 Id#3
1. Identifier
2. Keyword
3. Operator
Symbol Type Length Address
4. Constant
A (id#1)
• Format of token is: B (id#2)
• Lexical analyzer alsoCode builds C (id#3)
#no symbol
table.

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 22
22 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Syntax analysis
A=B+C
• Syntax analysis processes the string
Id#1 Op#1 Id#2 Op#2 Id#3
of token to determine its grammatical
structure and builds the tree
Syntax analysis
structure.
=

A +

B C

Symbol Type Length Address


A (id#1)
B (id#2)
C (id#3)

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 23
23 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Semantic analysis
• Semantic analysis determines the =
meaning of a statement by applying +
A, real
the semantic rules to the structure of
the statement. B,real C, int
• While processing a declaration
statement, it adds information Semantic analysis
concerning the type and length of a
=
symbol to the symbol table.
A, real +
Symbol Type Length Address
A (id#1) Real 1 B,real C*, real
B (id#2) Real 1
C (id#3) Int 1
C*(id#4 Real 1 =
)temp Real 1
(id#5) A, real temp, real
Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 24
24 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Intermediate code generation
• Following two important properties of intermediate code are:
1. It should be easy to produce.
2. Easy to translate into target program.

Symbol Type Length Address


A (id#1) Real 1 Convert (Id#3) to real, giving (Id#4)
B (id#2) Real 1 Add (Id#2) to (Id#4), giving (Id#5)
C (id#3) Int 1
Store (Id#5) in (Id#1)
C*(id#4 Real 1
)temp Real 1
(id#5)

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 25
25 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Memory allocation
 The memory requirement of an Symbol Type Length Address
identifier is computed from its type, A Real 1 2000
B Real 1 2001
length and dimensionality,
C Int 1 2002
accordingly memory is allocated to it.
• The address of the allocated memory
area is entered in the symbol table.

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 26
26 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Code generation
• Two key decisions involved in generating good quality target code
are:
1. Which instructions should be used for each of the actions in
the intermediate code?
2. Which CPU registers should be used for evaluating
expressions?

CONV_R AREG, C CONV_R converts value of C to real and stores the result into AREG

ADD_R AREG, B Adds the content of AREG and B


MOVEM AREG, A Moves the content of AREG to memory area allotted to A

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 27
27 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Pass structure

Unit
System
–– 22Programming
System
Unit :: Overview
Overview of
Programming of(2150708)
Language
Language Processor
(2150708) Processor 28
28 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Language processor pass
• One complete scan of a source program is called pass.
• A pass includes reading an input file and writing to the output file.
• A language processor pass is the processing of every statement in
a source program, or in its equivalent representation to perform
language processing function.

Source Front end Back end Target


Program (Pass I) (Pass II) Program

Intermediate
representation

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 29
29 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Language processor pass
Pass I
• Perform analysis of the source program and note relevant
information.
Pass II
• Perform synthesis of the target program.

Source Front end Back end Target


Program (Pass I) (Pass II) Program

Intermediate
representation

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 30
30 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Symbol table
• A language processor uses the symbol table to maintain the
information about attributes used in a source program.
• Language processor performs following operations on the symbol
table:
1. Add a symbol and its attributes: Make a new entry in the
symbol table.
2. Locate a symbol’s entry: Find a symbol’s entry in the symbol
table.
3. Delete a symbol’s entry: Remove the symbol’s information
from the table.
4. Access a symbol’s entry: Access the entry and set, modify or
copy its attribute information.

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 31
31 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Data structures for symbol table
• Following data structures can be used for organizing symbol
table’s entries:
1. Linear data structure: Entries in the symbol table occupy
contiguous areas of memory.
2. Nonlinear data structure: Entries in the symbol table do not
occupy contiguous areas of memory.

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 32
32 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Symbol table entry formats
Attributes of different classes of symbols:
Symbol Class Attributes
Variable Type, length, number and bounds of dimensions
Procedure Number of parameters, address of parameter list

Function Number of parameters, address of parameter list , type of


returned value, length of returned value
Label formats of theStatement
Entry number
symbol table:
1. Fixed length entries: Each entry in the symbol table has fields for all
attributes specified in the programming language.
2. Variable-length entries: the entry occupied by a symbol has fields only
for the attributes specified for symbols of its class.
3. Hybrid entries: Combination of previous two.

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 33
33 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Search data structures

Unit
System
–– 22Programming
System
Unit :: Overview
Overview of
Programming of(2150708)
Language
Language Processor
(2150708) Processor 34
34 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Search data structures
• Search data structures (Search structure) are used to create and
organize various tables of information and mainly used during the
analysis of the program.
• Types of search data structures are:
1. Sequential search organization
2. Binary search organization
3. Hash table organization
4. Linked list and tree structure organization

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 35
35 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Allocation data structures

Unit
System
–– 22Programming
System
Unit :: Overview
Overview of
Programming of(2150708)
Language
Language Processor
(2150708) Processor 36
36 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
Allocation data structures
• Allocation strategy is an important factor in efficient utilization of
memory.
• Types of allocation data structures are:
1. Stack allocation
2. Heap allocation

Unit –– 22Programming
System
Unit
System :: Overview
Overview of
Programming Language
Language Processor
of(2150708)
(2150708) Processor 37
37 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology
End of Unit - 2

Unit
System
–– 22Programming
System
Unit :: Overview
Overview of
Programming of(2150708)
Language
Language Processor
(2150708) Processor 38
38 Darshan
Darshan Institute
Institute of
of Engineering
Engineering &
& Technology
Technology

You might also like