Introduciona a ada

Páginas: 6 (1463 palabras) Publicado: 3 de septiembre de 2010
Instrumentación de Tiempo Real
UNIVERSIDAD DE CANTABRIA

Introducción al Lenguaje de Programación Ada
Mario Aldea Rivas Departamento de Electrónica y Computadores Universidad de Cantabria
GRUPO DE COMPUTADORES Y TIEMPO REAL DPTO. DE ELECTRÓNICA Y COMPUTADORES

© Mario Aldea Rivas
5/Mar/06

1

1. El lenguaje Ada

UNIVERSIDAD DE CANTABRIA

Ada (en honor de Lady Augusta Ada Byron) •Lenguaje inspirado en Pascal • Creado en 1983 (Ada 83) por el DoD de los EEUU - Lenguaje de propósito general - pero orientado a sistemas empotrados de tiempo real - detecta muchos errores en tiempo de compilación: facilita la creación de programas fiables Revisión en 1995 (Ada 95): • versión mejorada, incluye programación orientada al objeto Nueva versión a punto de salir (Ada 06) • mejoras entodos los aspectos (también en tiempo real)
GRUPO DE COMPUTADORES Y TIEMPO REAL DPTO. DE ELECTRÓNICA Y COMPUTADORES

© Mario Aldea Rivas
5/Mar/06

2

Comparación con Pascal: Estructura de un programa
Ada:
procedure Mi_Programa is Max_Empleados : constant := 50; type T_Empleados is range 1 .. Max_Empleados; Num_Empleados : T_Empleados := 10; procedure Un_Proc is begin ...; -- instruccionesend Un_Proc; begin ...; -- instrucciones end Mi_Programa;
GRUPO DE COMPUTADORES Y TIEMPO REAL DPTO. DE ELECTRÓNICA Y COMPUTADORES

UNIVERSIDAD DE CANTABRIA

Pascal:
program Mi_Programa; const Max_Empleados = 50; type T_Empleados=1..Max_Empleados; var Num_Empleados : T_Empleados; procedure Un_Proc; begin ...; (* instrucciones *) end; begin ...; { instrucciones } end.
© Mario Aldea Rivas5/Mar/06

3

Comparación con Pascal: Instrucciones de control
Ada:
if I < 0 then Negativo := True; I := Abs (I); else Negativo := False; end if; for I in 1..100 loop Suma := Suma + I; end loop; loop Anadir_Gota; Medir_Nivel (En_Nivel_Mx); exit when En_Nivel_Mx; end loop;
GRUPO DE COMPUTADORES Y TIEMPO REAL DPTO. DE ELECTRÓNICA Y COMPUTADORES

UNIVERSIDAD DE CANTABRIA

Pascal:
if I < 0then begin Negativo := True; I := Abs (I); end else Negativo := False; for I:=1 to 100 do Suma := Suma + I;

repeat Anadir_Gota; Medir_Nivel (En_Nivel_Mx); until En_Nivel_Mx;

© Mario Aldea Rivas
5/Mar/06

4

Comparación con Pascal: Procedimientos y funciones
Ada:
procedure (A, B : S : begin S := A end Suma; Suma in Integer; out Integer) is + B;

UNIVERSIDAD DE CANTABRIA

Pascal:procedure (A, B : S : begin S := A end; Suma Integer; var Integer); + B;

function Area (R : Float) return Float is PI : constant := 3.141592; begin return PI * R * R; end Area;

function Area (R : Real): Real; const PI : 3.141592; begin Area := PI * R * R; end;

GRUPO DE COMPUTADORES Y TIEMPO REAL DPTO. DE ELECTRÓNICA Y COMPUTADORES

© Mario Aldea Rivas
5/Mar/06

5

Comparación conPascal: Entrada/Salida
Ada:
with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

UNIVERSIDAD DE CANTABRIA

Pascal:

program Mi_Programa; var procedure Mi_Programa is N : Integer; N : Integer; begin begin Write (‘Introduce número...‘); Put ("Introduce número..."); Readln (N); Get (N); Skip_Line; Writeln (‘Has escrito el ‘, Put ("Has escrito el "); N); Put (N);end. New_Line; -- o también: Put_Line ("Has escrito el " & Integer'Image(N)); end Mi_Programa;

GRUPO DE COMPUTADORES Y TIEMPO REAL DPTO. DE ELECTRÓNICA Y COMPUTADORES

© Mario Aldea Rivas
5/Mar/06

6

Tipos numéricos
Definición de tipos:

UNIVERSIDAD DE CANTABRIA

type Nota_Examen is range 0 .. 10; type Nota_Con_2_Decimales is digits 2 range 0.0 .. 10.0;

Declaración devariables y constantes
I : Integer; Precio : Float; Nota : Nota_Examen; Nota_Inicial : Nota_Examen := 5; Nota_De_Corte : constant Nota_Con_2_Decimales := 5.0;

Ejemplos de uso:
I := I + 1; Precio := 10.0 * Float (I);

GRUPO DE COMPUTADORES Y TIEMPO REAL DPTO. DE ELECTRÓNICA Y COMPUTADORES

© Mario Aldea Rivas
5/Mar/06

7

Arrays
Definición de tipos:

UNIVERSIDAD DE CANTABRIA

type...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Adaed
  • ADAE
  • introducion
  • INTRODUCION
  • Introducion
  • introducion
  • ---Ada
  • De ada

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS