ImageVerifierCode 换一换
格式:PPT , 页数:63 ,大小:133.50KB ,
资源ID:378026      下载积分:2000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
注意:如需开发票,请勿充值!
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-378026.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Ada95- A brief History.ppt)为本站会员(Iclinic170)主动上传,麦多课文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文库(发送邮件至master@mydoc123.com或直接QQ联系客服),我们立即给予删除!

Ada95- A brief History.ppt

1、ada-typesI- 1,Ada95: A brief History,1975-1979: strawman-steelman requirements, Pascal is base 1981 : Green wins, becomes preliminary Ada 1983 : ANSI Standard, first validated compiler 1987 : ISO Standard 1990-1994 : Revision Process 1995 : ANSI - ISO Ada 95 Standard 1995 : First validated GNAT comp

2、iler,ada-typesI- 2,Design principles,Software Engineering: programming in the large Readability over writability Rigorous standard for portability Precise semantics Built-in concurrency Strong-Typing: all unsafe code is explicit,ada-typesI- 3,Ada, C+ and Java,Big languages winstrong typing : Ada, C+

3、 JavaGenerics : Ada C+Concurrency : Ada JavaPackages: Ada C+ and JavaAhead of its time in designOut of step in implementationBetween language generations,ada-typesI- 4,Key Goals,Readability : between COBOL and APLstrong typing : compile, dont debugProgramming in the large: package itException Handl

4、ing: Murphy is always rightData abstraction : apples are not orangesObject orientation : Dispatch and inheritTasking : walk, chew gum, etc.Generic units : the easiest reuse is to copyInterfacing : play well with others,ada-typesI- 5,The canonical example,with Text_Io; use Text_Io; procedure example

5、is beginPut_Line (“easier than we thought!”); end;,ada-typesI- 6,A small package,Package Math_Functions isfunction Sqrt (X : Float) return Float;function Exp (Base : Float; Exponent : Float) return Float; end Math_Functions;,ada-typesI- 7,Using the package,with Math_Functions; with Gnat_IO; use Gnat

6、IO; procedure Example2 isVal : Float; beginget (Val);put (“Sqrt (“); put (Val); put (“) = “);put (Math_Functions.Sqrt (Val);new_line; end;,ada-typesI- 8,Implementing the package,Package body Math_Functions isEpsilon : constant := 1.0e-7;function Sqrt (X : Float) return Float isResult : Float := X /

7、 2.0;beginwhile abs (Result * Result - X ) Epsilon loopResult := 0.5 * (X / Result + Result);end loop;return Result;end Sqrt;. end Math_Functions;,ada-typesI- 9,Abstraction at its best: enumeration types,Trivial Implementation: literals are mapped into successive integersVery common abstraction: lis

8、t of names, propertiesExpressive of real-world domain, hides machine representation type suit is (hearts, diamonds, spades, clubs) ; type direction is (east, west, north, south, lost);Order of list implies that spades hearts, etc.,ada-typesI- 10,Enumeration types and strong typing,type Fruit is (App

9、le, Orange, Grape, Apricot);type Vendor is (Apple, IBM, Compaq);My_PC : Vendor;Dessert : Fruit;My_PC := Apple;Dessert := Apple;Dessert := My_PC; - ERROR,ada-typesI- 11,Built-in enumeration types,type Boolean is (False, True);type Character is (. - full ASCII.- not expressible in Adatype Wide_Charact

10、er is ( - Unicode, or ISO646,ada-typesI- 12,Array Types,Index is typed:type weekday is (Mon, Tue, Wed, Thu, Fri);type workhours is array (Weekday) of integer;Predefined array:type String is array (Positive range ) of Character;,ada-typesI- 13,Record Types,conventional named fields:type Buffer is rec

11、ordsize : Positive;contents : String (1 100);end record;B1 : Buffer; - can use B1, B1.size, B1.contents (10).,ada-typesI- 14,Access Types,Typed pointers, for type safety and to minimize aliasing:type Handle is access Buffer;Ptr : Handle := new Buffer;Ptr.all is a Buffer.Can write Ptr.size, Ptr.conte

12、nts, etc.,ada-typesI- 15,Abstraction mechanisms,Packages Private types Objects and Inheritance Classes, polymorphism, dynamic dispatching Generic units Concurrency : tasks and protected types,ada-typesI- 16,Packages,A related set of types, constants, and subprogramsSeparate declaration (interface) a

13、nd implementationSupports privacy and data hidingThe single most important idea in software engineering,ada-typesI- 17,A package for stacks,package Stacks istype Stack is private;procedure Push (It : Character; On : in out Stack);procedure Pop (It : Character; From : in out Stack);function Empty (S

14、 Stack) return Boolean; privatetype Stack is recordtop : Integer := 0;contents : String (1 80) := (others = *);end record;end Stacks;,ada-typesI- 18,Object-oriented Programming,Type extension Inheritance and overriding Run-time dispatching Polymorphism Class-wide programming Abstract types and subp

15、rograms,ada-typesI- 19,Type Extension,Mechanism to define new types by enrichment:type Point is tagged recordX_Coord, Y_Coord : Integer;end record;type Pixel is new Point with recordR, G, B : Integer;end record;,ada-typesI- 20,Inheritance,A type has primitive operations: operations that involve the

16、type as a parameter or a returned value. A type extension inherits the primitive operations of its parent. A primitive operation can be redefined and overridden for a descendant type.,ada-typesI- 21,Polymorphism,A class is a family of types with the same ancestor. An object of the class is identifie

17、d at run-time by its tag. Dynamic dispatching uses the tag of the object to determine the operation that applies. A classwide operation applies uniformly to all member of the class:procedure Examine (Thing : in out TClass);,ada-typesI- 22,Generic Units,The basic tool for software reuse. Parameters c

18、an be types, objects, subprograms, packages. Akin to C+ templates. Absence from Java is incomprehensible,ada-typesI- 23,A Generic Package,Generictype T is private; package Stacks istype Stack is private;procedure Push (Thing : T ; On : in out Stack); privatetype Arr is array (1 100) of T;type stack

19、is recordTop : Integer := 100;contents : Arr;end record; end Stacks;,ada-typesI- 24,A Generic Subprogram,Generictype T is private;type Arr is array (Integer range ) of T;with function “ (X, Y : T) return Boolean; procedure Sort (Table : in out Arr);,ada-typesI- 25,The Type Model,Types and Subtypes D

20、eclarations and their scope Objects, constants and variables Scalar types Array types Record types Access types,ada-typesI- 26,Types and Subtypes,A type is a set of values and a group of operations A type declaration specifies static properties of objects A subtype declaration specifies dynamic prop

21、erties of values. Types with different names are distinct and incompatible: name equivalence everywhere, instead of structural equivalence. Subtypes of the same base type are compatible.,ada-typesI- 27,Compile-time vs. run-time,Type properties are enforced by the compiler:x : integer := false; - pro

22、gram rejectedx : positive := f (z); - if f returns an integer, need to check value at run-time,ada-typesI- 28,Built-in subtypes,type Integer is - implementation defined subtype Positive is integer range 1 IntegerLast; - useful attribute subtype Natural is integer range 0 IntegerLast; X : integer :=

23、500; Y : Positive := 2 * X; Z : Natural := - Y; - legal, raises constraint error,ada-typesI- 29,Declarations and Scope,Declarations are elaborated in order Entities become visible at the end of their declaration (usually) Block structure allows arbitrary nesting of declarative regions. Declarations

24、can appear in subprograms packages blocks .,ada-typesI- 30,Blocks,DeclareX : Integer := F (5);Y : Integer := 2 * X;Z : Integer := Y * Z; - Error: prematureX : Float ; - Error: duplicate begindeclareX : Float := Float (Y); - hides outer X beginPut_Line (FloatImage (X);end;end;,ada-typesI- 31,Variable

25、s and Constants,Variable declaration:Limit : Integer := 25;Offset : Integer range 1 20;Constant declaration:Sqrt2 : constant float := Sqrt (2.0); - not static Always : constant Boolean := True; - static valueNever : constant Boolean := not Always; - static expression,ada-typesI- 32,Variables must be

26、 constrained,Subtype is constrained:First_Name : String (15) := “Ralph”;but not necessarily static:Last_Name : String (1 X * 2);else subtype is indefinite but initial value provides bounds:Comment : String := “this is obvious”; - bounds are 1 15,ada-typesI- 33,Multiple Declarations,This, That : T :=

27、 F (1, 2, 3); Is equivalent toThis : T := F (1, 2, 3);That : T := F (1, 2, 3);F is called twice. Important if expression has side-effect:type Ptr is access R;P1, P2 : Ptr := new R;two Rs are allocated.,ada-typesI- 34,Number Declarations,Pi : constant := 3.14159265; - type deduced from valueHalf_Pi :

28、 constant := Pi / 2; - mixed arithmetic OKBig : constant := 2 * 200; - legalOne : constant := 2 * Big / (Big + Big); - must be exact,ada-typesI- 35,Scalar Types,Discrete types Integer types Enumeration Types Real types Floating-point types Fixed_point types,ada-typesI- 36,Integer Types,Several prede

29、fined types: Integer, Long_Integer, Short_IntegerSpecific bounds of type must be static:type My_Int is range -2 * 16 2 * 16 - 1;type Tiny is range 0 10; By giving explicit bounds, program is more portable: each compiler will figure out what hardware type correspondsModular types:type Byte is mod 2 *

30、 8;,ada-typesI- 37,Integer Operations,Comparison Operators: = /= = Addition Operators: + - Unary operators + - Multiplying operators * / mod rem Highest precedence Operators: * abs,ada-typesI- 38,Boolean Operations,All attributes of discrete typesBoolean binary operators : and or xorBoolean unary op

31、erators : notShort-circuit operations : and then or else Membership operations : in not inWhen in doubt, parenthesize!,ada-typesI- 39,Attributes,Attributes denote properties of a type, or type-specific properties of a value BooleanSize - 1, because single bit charactersize - 8 bits monthpos (Jul) -

32、involves type and literal tablelength (1) - specify array and dimension Could be written as a function, but functions dont take types as arguments = need new syntax.,ada-typesI- 40,Attributes on Discrete Types,ByteFirst, Long_IntegerLast - applies to type or subtype WeekdaySucc (Today) - like functi

33、on call IntegerSucc (X*Y) - like adding one BooleanPred (True) - Yields False BooleanSucc (True) - Exception WeekdayPos (Mon) - Yields 0 WeekdayVal (3) - Yields Thu PositiveMax (X, Y) - function with two args,ada-typesI- 41,Real Types,All computations are approximate: Fixed point type: absolute boun

34、d on error: type temp is delta 2 * (-16) range -100.0 100.0; Floating point type: relative bound on error:type Angle is digits 7 range -2.0 2.0; Predefined floating point types: Float, Long_Float, etc.,ada-typesI- 42,Derived Types,A general mechanism for creating new types with the properties of exi

35、sting ones: type Like_T is new T; - same set of values, same operations.type Small_Int is range 1 10; equivalent totype Anon is new Integer;subtype Small_Int is Anon range 1 10; and all arithmetic operations are inherited,ada-typesI- 43,Array Types,Index types can be of any discrete type Component t

36、ype must be definite:type class_list is array ( 1 100) of String (110); - OKtype class_list is array ( 1 100) of String; - Error Subtype constrains all indices or none:type Matrix is array(positive range , positive range ) of Long_Float;subtype Table is Matrix;subtype Rotation is Matrix (1 3, 1 3);,

37、ada-typesI- 44,Anonymous Array Types,Grades : array (1 Num_Students) of Natural;type of Grades has no name: distinct from any other array types.Ar1, Ar2 : array (1 10) of Boolean;Ar1 := Ar2; - Error: different (anonymous) types. If type is useful, it deserves to have a name.,ada-typesI- 45,Array Att

38、ributes,type Matrix is array (Positive range , Positive range )of Float;subtype Rect is Matrix (1 3, 1 5);M3 : Rect;M3First (1) - Yields 1M3First - same.Rectlength (2) - Yields 5 (applies to type)M3range (2) - equivalent to 15StringLength - ERROR: unconstrained,ada-typesI- 46,Array Aggregates,Expres

39、sion that yields an array value:A := (1, 2, 3, 10); - positionalA := (1, others = 0); - notation for default.A := (13 = 1, 4 = -999); - component associationsDefault can only be used if bounds are known:A : String (1 10) := (others = ?); - OKA : String := (others = ?); - Error : unknown bounds.,ada-

40、typesI- 47,Aggregates and Qualification,Aggregate may be ambiguous:type Vector is array (1 3) of Float;procedure Display (V : vector);type Assay is array (1 3) of Float;procedure Display (A : assay);Display (1.0, 1.2, 1.5); - ambiguousDisplay (Vector (1.0, 1.2, 1.5); - OK.,ada-typesI- 48,Multidimens

41、ional Arrays,Aggregates given in row-major order with subaggregates:type Square is array (1 3, 1 3) of Integer;Unit : constant Square := ( (1, 0 ,0), (0, 1, 0), (0, 0, 1);Two-dimensional array is NOT array of arrays:type vector is array (1 3) of Integer;type V3 is array (1 3) of vector; - not conver

42、tible to Square,ada-typesI- 49,Operations on One_Dimensional Arrays,Boolean operations extend pointwise:type Set is array (1 Card) of Boolean;S1, S2,S3 : Set;S3 := S1 and S2; - Intersection lexicographic comparisons on arrays of discrete types:S1 := (T, T, T);S2 := (T, T, F);S2 S1 - yields True,ada-

43、typesI- 50,Concatenation and Slicing,Both operations yield the base type:type Table is array (110) of Integer;T1, T2 : Table;T1 T1 & T2 , T1 (X Y) are of type Anon,ada-typesI- 51,Specifying a range,subtype Sub is Positive range 2 4; Label : String (110) := “transcends” ; Label (2 4) - Yields “ran”La

44、bel (Integer range 2 4) - SameLabel (Sub) - DittoAlso used in loops and case statements.,ada-typesI- 52,Control Structures,Conventional sequential constructs: If-Statement Loop Case statement Goto and labelsMore novel forms for task communication.,ada-typesI- 53,If-Statement,If Done (X, Y) thenSucce

45、ss;Close_Up; elsif Almost_Done (X) then - the only keyword that isnt EnglishHurry (Y); elseif X = 0 then Call_For_Help (X) else Panic; end if; end if;,ada-typesI- 54,Loops,Infinite loop:loopPut_Line (“Forever”);end loop;In general, better to stop:loopPut_Line (“Still_Going”);exit when Time_Is_Up; -

46、must be boolean valueend loop;,ada-typesI- 55,Loops over discrete ranges,for J in 1 1000 loop - declares Jfor K in 1 0 loop - empty rangefor Month in Feb Nov loopfor Month in Months range Feb Nov loopfor K in Positive loop - might take a long timefor Num in reverse 1 1000 loop - descending order,ada

47、typesI- 56,While-Loops,while abs (Result * Result - X ) Epsilon loopResult := 0.5 * (X / Result + Result);end loop;Effect of Until can be obtained with while and exit statements.,ada-typesI- 57,Named Loops,search : while X 0 loopX := F(X, Y);refine: for J in 1 N loopY := G (Z);exit search when X =

48、0.0;end loop refine;if T 20 then exit; end if; - alternate formend loop search;.,ada-typesI- 58,Case Statements,Most programs are interpreters for some abstract machine = case statement is most useful control structure!Works naturally with discrete types, in particular enumerations.Case alternatives must cover all values of the range,

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1