Sunteți pe pagina 1din 4

organization of compiler

compiler

-analysis-------->ir-------->synthesis

get scorce program and convert it to tree and this tree is called IR(intgermadit
e represerntation). then the ir is converted to machine code

structure of compiler

soruce program ----------> front end ------> ir --------->

backend

the foront end done analysis, check either it is leagel or illeagle (error e.t.c
).
the back end done converting ir to terget code

source progra---------------->scanner ---tokens----> parcer


-----synthetic
structure------> semantic routlines ---abstract synthasis----> ir code genra
tor ------>(( optimazer)its belong to ir) ------> codegenarator ----- targert m
achine code
(all the uper cart belong sto "symbolic tuble and atributes table(it keeps the r
ecord of every step like log. it is data sturucture.)")

1)
2)
3)

lexical analyser
symnthic analysir
sementic analysir

ir code
three address cod
opprend 1. oprator. opprend 2

1) lexical analyesis

1)
2)
3)
4)
5)
6)
7)
8)
9)
10)

it is the 1st phase of compiler


it read charecter by charecter form sourcce code.
group each characters and form lexeme.
it is also called scanner
it take sorce program and convert ist lexeme(word).
it genrate tokens for each lexeme
lexeme is creted at the basis of reguler expression of automata
token is created at basis of NFA AND DFA
lexeme is backily a orginal part of sorce program.
token has name, attribute , value

lexeme
tv
vcr

token
application

chire
table

furnature

football

sports

passe tree:
E -> E+E
E -> E*E
E -> id

rule 1
rule 2
rule 3

input string

id+id*id

LMD (Lift Most Diravation)


E -> E+E
using step 1
-> E*E+E
using step
-> id*E+E
using step
-> id*id+E
using step
-> id*id+id using step

Ambiguity

2
3
3
3

1)
2)

if a grammer has more one fasse tree for at least one string.
it is also called inherently ambiguis
the soloution of it is 1)
2)

associtivity
presedence

Associativity:
(orpreand)oprator(orpreands)
1)
if operand has operator on both side the side on which the opera
tors taken this operand is decided by associativity of the operators.
2)
if operaton is left-associativity then operand will be taken by
left-operators.e.g (+, -, *, /,)
(id op id op id)
(id op id )op id
3)
other then that upper types the all other will be right associti
vity like log, e.t.c

procedence:
two different operators share common perand, preadence will pecides whic
h will take the operand
2+3*4
(2+3)*4
or
2+(3*4)
under the maths rules the 2nd wi
ll be cerrect
left recurrison:
a -> A(alfa sing)/(beta sing)
problematic situation for top-down parser.

Home task S->A(alfa sing)/(Beta sing)


A-> Sd
left factoring:
if more then one grammer production rule has common prfix string
-problum to take which productuion to passe the string
-technique used to remove this confusion called left factoring

parsing:
top-down
top-up
types of top down parsing
1) recursive descent parser:
- recussively passe input to make passe tree
- back-tracking
- we want to remove the back-tracking
- commen prefix can be heindle easly, while usin
g this technuque if left recurgsig occour that will
lead to infinte loop
2) preductive parsser:
- it is the spical type of recursive desent pars
er:
- it handle left recursion problum with out back
tracking
- it in advance gusses the preduction can be use
d.

S-ar putea să vă placă și