TP 1
TP 1
TP 1
Fecha: March 2, 2021
1 rec ( n ) {
2 var f ;
3 i f ( n ==0) {
4 f =1;
5 }
6 else {
7 f = n * rec (n -1) ;
8 }
9 return f ;
10 }
Snippet 2: Recursive program
TIP gramárica. La gramática para TIP esta dada por las siguientes reglas
ISIS-1106 Lenguajes y máquinas
TP 1
Fecha: March 2, 2021
1 foo (p , x ) {
2 var f , q ;
3 i f (* p ==0) { f = 1; }
4 else {
5 q = malloc ;
6 * q = (*( p ) -1;
7 f =(* p ) *(( x ) (q , x ) ) ;
8 }
9 return f ;
10 }
12 main () {
13 var n ;
14 n = input ;
15 return foo (& n , foo ) ;
16 }
Snippet 3: Complicated program
Expresiones.
E → intconst
→ id
→ E + E | E − E | E ∗ E | E / E | E > E | E == E
→ (E)
→ input
Declaraciones.
S → id = E
→ output E
→ SS
→ if (E) { S }
→ if (E) { S } else { S }
→ while (E) { S }
→ var id1 , . . . , idn
ISIS-1106 Lenguajes y máquinas
TP 1
Fecha: March 2, 2021
Funciones.
Apuntadores.
E → &id
→ malloc
→ ∗E
S → ∗id = E; //asignación de valores
E → (E)(E, . . . , E) //generalización de llamado a funciones
Programas.
P → F ... F