Professional Documents
Culture Documents
Language Processors Intro
Language Processors Intro
Instructor: JayaKrishna
Cabin: CSE/FC-36
Mob:9035669570
Mail: jayakrishnaa.r@gmail.com
jayakrishna.r@manipal.edu
Language is a
purely human and non-instinctive method
of communicating
ideas, emotions, and desires
by means of a system
of voluntarily produced symbols.
By JayaKrishna, Dept.,of CSE, MIT
Do you Know, How many Languages are there?
people.
To provide a means for realising a stated process
computer science
• grammar
• semantics By JayaKrishna, Dept.,of CSE, MIT
Prerequisite
Must have thorough Knowledge on
– Programming Languages
– Machine Architecture
– Formal Languages and Automata
– Algorithms
– Software Engineering
What is a Compiler ?
A program that takes a source program in one language
and translates it into a target language.
Artificial Languge
Human Machine
Artificial Compiler Machine
Languge Languge
Machine Languge
string over Σ
finite sequence of elements chosen from Σ : word,
sentence, utterance
formal language λ
set of strings over a vocabulary Σ
λ⊆Σ*
By JayaKrishna, Dept.,of CSE, MIT
Chomsky Hierarchy/Theory of
Languages
formal grammar G = (N, Σ, P, S)
nonterminal symbols N
terminal symbols Σ
production rules P ⊆ (N ∪ Σ)* N (N ∪ Σ)* × (N ∪ Σ)*
start symbol S ∈ N
Grammar classes
type-0, unrestricted
type-1, context-sensitive: (aAc, abc)
type-2, context-free: P ⊆ N × (N ∪ Σ)*
type-3, regular: (A, x) or (A, xB)
By JayaKrishna, Dept.,of CSE, MIT
Chomsky Hierarchy/Theory of
Languages
• Finite automata and Regular expressions are closely
related to Context Free Grammar(CFG) of chomsky’s
type 3 grammar.
Human Machine
Artificial Parse Generate Meachine
Language AST Language
C
h
e
c
k
Errors
Human Parse
Machine
Artificial Generate Meachine
Language analyse AST Language
Example: Java
Linker
• Both Compilers and Assemblers often rely on a program
called Liker.
• Linker collects code separately compiled or assembled in
different object files into a file that is directly executable.
• It also connects an object program to the code for
standard library functions and to resources supplied by
the OS of the computer, such as memory allocators and
input and output devices.
Editors
• Compilers, editors and other programs are merged into
IDE(Interactive Development Environment).
• Such editors are called structure based and includes
with some of the operations of a compiler
Profilers
• It is a program that collects statistics on the behavior of
an object program during execution.
• Typical statistics are number of times each procedure is
called, percentage of execution time.
By JayaKrishna, Dept.,of CSE, MIT
Programs related to Compilers
Project Managers
• If a project is developed by team of s/w engineers
where each module needs to be integrated.
a identifier
[ left bracket
Index identifier
] right bracket
= assignment
4 Number
+ Plus Sign
2 Number
By JayaKrishna, Dept.,of CSE, MIT
The Translation Process
The Parser
It Receives the source code in the form of tokens from the scanner
and performs Syntax Analysis, which determines the structure of
the program.
expression = expression
Subscript-expression Additive-expression
Identifier Identifier
a index Number number
4 2
Subscript-expression Additive-expression
Identifier Identifier
a index Number number
4 2
Assign-expression
Subscript-expression Additive-expression
Identifier Identifier
a index Number number
4 2
Array of integers integer
integer integer
Subscript-expression Number
6
integer
Identifier Identifier
a index
Array of integers integer
Ex:
t=4+2
a[index]=t
The representation of data will play a major role, such as how many
bytes or words variables of integer and floating-point data types occupy in
memory.
Ex:
MOV R0,index //value of index ->R0
MUL R0,2 //double value in R0
MOV R1,&a //address of a ->R1
ADD R1,R0 //add R0 to R1
MOV *R1,6 //constant 6 -> address in R1
By JayaKrishna, Dept.,of CSE, MIT
The Translation Process
The target code optimizer
The compiler attempts to improve the target code
generated by the code generator.
MOV R0,index
SHL R0
MOV &a[R0],6 By JayaKrishna, Dept.,of CSE, MIT
The Translation Process