domingo, noviembre 06, 2005

Ejercicios 6.3 y 6.5 (Libro Aho)

Ejercicios 6.3 y 6.5 (Libro Aho)

6.3)      P ( D ; E
     D ( D1 ; D2
     D ( id : T { añadetipo(id.entrada,T.tipo) }
     T ( char { T.tipo := char }
     T ( integer { T.tipo := integer }
     T ( list of T1 { T.tipo := agregarLista(T1.tipo) }
     E ( literal { E.tipo := char }
     E ( num { E.tipo := integer }
     E ( id { E.tipo := buscar(id.entrada) }
     E ( ( L ) { E.tipo := L.tipo }     
     L ( E , L1 { L.tipo := if E.tipo=integer and L1=integer then integer
                                  else if E.tipo=char and L1=char then char
                    else error_tipo()  }
     L ( E { L.tipo := E.tipo }

6.5)
  1. c: char; i:integer;
     c mod i mod 3

     P( D ; E
     D( D ; D
     D( id : T { añadetipo(id.entrada,T.tipo) }
     E ( E1 mod L { E.tipo := if E1.tipo=integer and L.tipo=integer then integer
                      else error_tipo() }
     E( literal { E.tipo := char }
     E ( num { E.tipo := integer }
     E ( id { E.tipo := buscar(id.entrada) }
     L( E1 mod E2 { L.tipo := if E1.tipo=integer and E2.tipo=integer then integer
                      else error_tipo()  }
     T ( char { T.tipo := char }
     T ( integer { T.tipo := integer }

  1. P: ↑integer; a:array[10] of integer;
     a[↑p]

     P( D ; E
     D( D ; D
     D( id : T { añadetipo(id.entrada,T.tipo) }
     E ( num { E.tipo := integer }
     E ( id { E.tipo := buscar(id.entrada) }
     E ( E1 [ E2 ] { E.tipo := if E2.tipo =integer and E1.tipo=array(s,t) then t
                                      else error_tipo() }
     E ( E1↑ { E.tipo := if E.tipo=pointer(t) then t
                               else error_tipo() }
     T ( integer { T.tipo := integer }
     T ( ↑T1 { T.tipo := pointer(T1.tipo) }
     T ( array [ num ] of T1{ T.tipo:= array(1..num.value, T1.tipo) }





  1. f:integer ( boolean;
     i;integer; j:integer; k:ineger;
     while f(i) do
          k := i;
          i := j mod i;
          j := k

P( G ; D ; E
     G( id : T ( T { añadetipo(id.entrada,T.tipo) }
     D( D ; D
     D( id : T { añadetipo(id.entrada,T.tipo) }
     E( while E1 ( E2 ) S { E.tipo := if E2=integer then true                         
                          else false }
     E ( num { E.tipo := integer }
     E ( boolean { E.tipo := boolean }
     E ( id { E.tipo := buscar(id.entrada) }
     E ( E1 mod E2 { E.tipo := if E1.tipo=integer and E2.tipo=integer then integer
                      else error_tipo() }
     S( S ; S
     S( id := E
     T ( char { T.tipo := char }
     T ( integer { T.tipo := integer }
     T ( boolean { T.tipo :=  boolean }


No hay comentarios.: