Documente Academic
Documente Profesional
Documente Cultură
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
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
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)
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
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.
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.