Está en la página 1de 4

tema 1

Escriba la propuesta de código de tres direcciones estándar para:

EXP in [val1,val2,val3,valn]

codigo 3d

if EXP == val1 then goto l1


if EXP == val2 then goto l1
if EXP == val3 then goto l1
if EXP == valn then goto l1
goto l2
l1:
<sentencia verdadera>
l2:
<sentencia falsa>

exp in [val1..va2,val3..val4]
if exp <val1 then goto l2
if exp <=val2 then goto l1
if exp <val3 then goto l2
if exp <=val4 then goto l1
goto l2:
l1:
<sentencia verdadera>
l2:
<sentencia falsa>

Escriba el código de tres direcciones de las siguientes expresiones


condiciones con base en la propuesta del inciso anterior, indique las etiquetas que son

------B in [ A,D,C]

if B==A then goto l1


if B==D then goto l1
if B==C then goto l1
goto l2
l1:
<sentencia verdadera>
l2:
<sentencia falsa>

----------B in [ 1..10]

if B <1 then goto l2

1
if B <=10 then goto l1
goto l2
l1:
<sentencia verdadera>
l2:
<sentencia falsa>

--------------B in [ A, D, 1..10, C]
if B==A then goto l1
if B==D then goto l1

if B <1 then goto l2


if B <=10 then goto l1

if B==C then goto l1


goto l2
l1:
<sentencia verdadera>
l2:
<sentencia falsa>

-------------B < C or H in [ K+D*F, P, L*D] and J > L

if B<C then goto l1


goto l2

t1=D*F
t2=k+t1
if H ==t2 then goto l3
if H==p then goto l3
t3=L*D
if H==t3 then goto l3
goto l5

l3: if j>l then goto l4


goto:l5
l1:
l4:
<sentencia verdadera>

l2:
l5:
<sentencia falsa>

Para las producciones que reconocen las expresiones relacionales escriba un esquema
de traducción que genere el código propuesto en el inciso (a) y el código de tres
direcciones de las expresiones del inciso (b).

2
s->ID "in" {listaexp.Hid=id.lex;
lista_exp.HEV=new etiqueta()}
lista_exp.HEF=new etiqueta()}
"[" lista_exp "]"{gen("goto "+lista_exp.EF);s.EV=lista_exp.EV; S,EF=lista_exp.EF}

lista_exp->{listaexp1.Hid=lista_exp.Hid;
lista_exp1.HEV=lista_exp.HEV;
lista_exp1.HEF=lista_exp.HEf} lista_exp "," | {exp.Hid=lista_exp.Hid;
exp.HEV=lista_exp.HEV;
exp.HEF=lista_exp.HEf} exp {

lista_exp.EV=lista_exp.HEV;
lista_exp1.EF=lista_exp.HEf}

| {exp.Hid=lista_exp.Hid;
exp.HEV=lista_exp.HEV;
exp.HEF=lista_exp.HEf} exp { lista_exp.EV=lista_exp.HEV;
lista_exp1.EF=lista_exp.HEf}

exp-> E {gen("if"+exp.Hid+"=="+E.dir "then goto"+exp.HEV)}


|E..E{gen("if"+exp.Hid+"<"+E.dir "then goto"+exp.HEF);
gen("if"+exp.Hid+"<="+E1.dir "then goto"+exp.HEV);}

E->E*E
|E+E
|E/E
|E-E
|(E)
|num {E,dir=num.lexema}
|ID {E,dir=id.lexema}

tema 2:

Switch {
Case val1: Sentencias 1
Case val2: Sentencias 2
:
:
Case valn: Sentencias n
} (Var)

-------------- como la variable "var" esta la final del switch utilice una varaible auxiliar para
poder igualarla al final -------
l1://inicio
3
if tempswitch == val1 goto l4
goto l5
l4:
<sentencia1>
goto l2
l5:
if tempswitch == val2 goto l6
goto l7
l6:
<sentencia2>
goto l2
l7:

if tempswitch == valn goto l8


goto l9
l8:
<sentencian>
goto l2
l9:

l2:
tempswitch=Var
goto l1
l3: ://salida

También podría gustarte