Lenguajes y autómatas II

Generacion de codigo intermedio:

instrucciones de control

- ACEVEDO MALDONADO JOSUÉ.
- MORALES MARTINEZ MARÍA.
- OLIVERA ROSAS LUIS MIGUEL.
- PÉREZ CARRERA CARLOS FRANCISCO.
- RUIZ GONZALEZ ALEXANDER

- VASQUEZ LOAEZA ALAN

Las condiciones deben expresarse de manera lo más 
sencilla posible de tal forma que puedan evaluarse 
en cortocircuito.

Denota la semántica de algunos operadores booleanos en 
algunos lenguajes de programación.

Si el primer argumento de la función AND evalúa y el 
resultado es falso, el valor total debe ser falso.

Si el primer argumento de la función OR evalúa y el 
resultado es verdadero, el valor total tiene que ser verdadero.

    x and y 
    if x then y else false
    
    x or y
    if x then true else y
    int numerador = 5, denominador = 0;
    if (denominador && numerador/denominador) {
         ………..
    }
    
    
    if (true || false ) {
         ………..
    }
    if (a > b) {
     c = a + b;
    }else {
     c = a * b;
    }
  1. (>, a, b) 
  2. (jump falso, (1), (6))
  3. (+, a, b)
  4. (=, c, (3))
  5. (jump, ,(8))
  6. (*, a, b)
  7. (=, c,(6))
  8. ………..
  1. (>, a, b, T1)
  2. (jump falso, T1, (5), )
  3. (+, a, b, c)
  4. (jump, ,(6), )
  5. (*, a, b, c)
  6. …….

Text

L0			L4		    IMUL        68
ICONST_3	06	ILOAD 1	     15	    ISTORE 3	36
ISTORE 1	36	ILOAD 2	     15	    L6
L1			IADD	     60	    RETURN	B1
ICONST_4	07	ISTORE 3     36
ISTORE 2	36	L5
L2			GOTO L6	     A7
ILOAD 1	        15	L3 	
ILOAD 2	        15	ILOAD 1      15
IF_ICMPLE L3	A4	ILOAD 2	     15

Text

Triplo 
 

    If (x>y) then z=x  
    1)(>, x, y) 
    2)(Saltar si falso, (1), (4)) 
    3)(=, z, x) 
    4)….

Text


 Cuádruplo

     If x>y then z=x  
    1)(>, x, y) 
    2)(Saltar si falso, (1), (4)) 
    3)(=, z, x) 
    4)….

 Generacion de codigo p
 

    
    If (x>y) then z=x 

WHILE

se puede expresar como:

inicio: if a < b goto B.true
        goto B.false
B.true: instruccion
        goto inicio 
B.false: ...

WHILE

Exemplo

    i=0
    c=1
    
    while i<10
      x=c+i
      i=i+1
    end

WHILE

Tripletas

1.(=,i,0)
2.(=,c,1) 
3.(<,i,10)
4.(jump falso, (3), (10))
5.(+,c,i)
6.(=,x,(5))
7.(+,i,1)
8.(=,i,(7))
9.(jump,,(3))
10. ...

WHILE

1.(=,0,,i)
2.(=,1,,c) 
3.(<,i,10,t1)
4.(jump falso,t1,(8),)
5.(+,c,i,x)
6.(+,i,1,i)
7.(jump,,(3),)
8. ...

Cuadruplas

WHILE

loada i
loadc 0		    label w1
storage		    load i<10
clr		    fjump w3
loada c		    loada x
loadc 1		    load c
storage		    load i
clr	            addi
	            storage
		    loada i
	            load i
		    loac 1
	            addi
	            storage
                    clr
	            jump w1
	            label w3

    

Codigo p

DO-WHILE

B.true: instruccion 
if a < b goto B.true
        goto B.false
B.false: ...

se puede expresar como:

Exemplo

    i=0
    c=1
    
    do{
      x=c+i
      i=i+1
    } while i<10

DO-WHILE

Tripletas

1.(=,i,0)
2.(=,c,1) 
3.(+,c,i)
4.(=,x,(3))
5.(+,i,1)
6.(=,i,(7))
7.(<,i,10)
8.(jump falso, (7), (10))
9.(jump,,(3))
10. ...

DO-WHILE

1.(=,0,,i)
2.(=,1,,c) 
3.(+,c,i,x)
4.(+,i,1,i)
5.(<,i,10,t1)
6.(jump falso,t1,(8),)
7.(jump,,(3),)
8. ...

Cuadruplas

DO-WHILE

loada i		    label w2
                    clr
loadc 0		    loada x
storage		    load c
clr		    load i
loada c		    addi
loadc 1		    storage
storage	            loada i
clr	            load i
	            loac 1
	            addi
	            storage
	            load i>10
		    fjump w2

Codigo p

DO-WHILE

Repeat-until >>

lenguajes y autómatas II

By neomatrix

lenguajes y autómatas II

  • 682