1 / 74

Ada Programming Language

In the Name of God. Modularity And Data Abstraction. Ada Programming Language. Chapter 7. The software crisis & reliable programming. Software Crisis. 1970 software cost increase without bound Dijkstra difficulty of producing a program program length 2.

sandra_john
Download Presentation

Ada Programming Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. In the Name of God Modularity And Data Abstraction Ada Programming Language Chapter 7

  2. The software crisis & reliable programming Software Crisis • 1970 software cost increase without bound • Dijkstra difficulty of producing a program program length2 But this proportion must become linear

  3. Parnas’s Principle • Control of complexity of a large program Modularization • Modules are independent of each other in debug, understand & maintain. • Parna’s principle : There should be one module for each difficult design decision in the program. • If the decision changed, the corresponding module will be changed. Information Hiding

  4. Abstract Data Types • Data structure representation A common design decision • stack implementation : array or linked list • set implementation : array of values or bit string • Any manipulation must be through procedures. • Users must do abstract operations on the DS. • Modules provides this abstract operations. Abstract Data Types Abstract operation : push & pop on the stack DS Concrete operation : pointer operations

  5. Experimental Abstract Type Languages • 1973 : Languages that support data types and modules. • Alphard, CLU, Mesa, Euclid, Modula • Many of them has the construct of a class, first included in Simula67. • These experiences were important for the development of Ada.

  6. DoD Saw the Need for a New Language • 1970 : the need for a new PL for military services in embedded (or mission critical) computer applications. Embedded : the computer is integrated with some larger system. Nonembedded : i.e. scientific & data processing applications. • DoD spent a lot of money for embedded applications, but because of multiple PLs much of them has the portability & reuse problem • HOLWG group was created. Higher Order Language Working Group

  7. A Series of specifications • HOWLG published a series of specifications, each more detailed & specific than the previous • 1975 Strawman • 1975 Woodenman • 1976 Tinman • 1978 Ironman • 1979 Steelman

  8. Information Hiding, Verification, concurrency • General requirements on the language design • Readability • Simplicity • More specific requirements • Module facility to support information hiding • Concurrent programming • Verification of program correctness • Concrete requirements • Character set • Commenting conventions

  9. Several competing designs winner : Ada • 26 existing languages was studied, none is usable • At first,16 proposals • The winner named Ada • Augusta Ada, A mathematician and Charles Babbage’s first programmer • A tradition of naming PLs after mathematicians • Become an ISO standard in 1987

  10. No Subset or Superset • Portability purpose :No subset or superset • Register the ‘Ada’ name as trademark. • No subset & superset can legally named Ada How to understand which compiler implements the spec? Validation Procedure, comprising over 2500 tests, attempts to ensure no more & no less than the standard language

  11. Ada Has Been Revised • 1983 : 1st version, Ada83 • 1988 : new version, Ada95 • 1990 report : 41 requirement & 22 new topics. • 1995 : resulting revision & includes ideas from 5th generation OO PLs.

  12. Ada95 • A language that specify all the specification was very detailed. 1. core languages 2.sixspecial need annexes • must be implemented • Optional extensions for particular application areas (system programming, information systems, real-time systems, numerical programming, distributed systems, safety & security) Ada95

  13. Design: Structural Organization • Syntax quite similar to Pascal’s • Keywords in lowercase • Others mixed (lower & upper) Declarations Expressions Ada’s constructs Statements Types

  14. Ada’s constructs • Expressions & statements similar to Pascal • Types also similar but more flexible & less problem • Declarations are very different object type subprogram package task

  15. package Tables is type Table is array (Integer range < > ) of float; procedure BinSearch (T: Table; Sought: Float; Location: out Integer; Found: out Boolean) is subtype Index is Integer range T’First .. T’Last; Lower: Index := T’First; Upper: Index := T’Last; Middle: Index := (T’First+ T’Last)/2; begin loop if T (Middle)=Sought then location:=middle; Found:=true; return; elsif Upper<Lower then Found:=false; return; elsif T (Middle)>Sought then Upper := Middle-1; else Lower:=Middle+1; end if; Middle:=(Lower+ Upper)/2; end loop; end BinSearch; end Tables;

  16. Declarations • Object same as Pascal’s constant & variable declarations. • Subprogram same as Pascal’s function & procedure declarations & also operator overloading. • Package & Tasksmost important facilities declare modules. Tasks can execute concurrently. Basic blocks of Ada programs.

  17. modules • Communication through interfaces. specification body (definition) Implements information hiding principle

  18. Ada Compiler • Syntactic analyzer (parser) More complicated than Pascal Some have syntax-directed editor Generates parse tree • Semantic analyzer Type checking Process generic declarations & overloaded operators More complex than Pascal’s Generates program tree • Optimizer • Code generator

  19. Design: Data structure & typing • The numeric types are generalized. • Integer type : like Pascal, plus range constraint. • type coordinate is range -100 .. 100 • Real Floating point Type coefficient is digits 10 range -1.0e10 .. 1.0e10 Fixed point • If the computer has single or double • precision the compiler selects between them.

  20. Numeric Types… Short_Float • Float • Programmers are encouraged to use digit constraint rather than the above types to be more machine independent. Preservation of information principle • Floating-point arithmetic : • Maximum precision & then rounded. Long_Float

  21. Fixed point Floating point Absolute error bound It fell into disuse after introducing Floating points. The rule of early computers. Still in use for commercial programming More complicated arithmetic Ada must support it, because in some embedded systems peripheral devices (i.e. ADC) use this method. Approximate Arith. with a relative error bound

  22. Fixed point Numbers type Dollars is delta 0.01 range 0.00 .. 1_000_000.00 • Values of Dollars are multiples of 0.01 16.75=1675*0.01 2=200*0.01 • Min Number of bits: • If delta a power of 2 : left or right shift • Compiler sometimes do this itself Absolute error bound

  23. Data Structure & Typing • Constructors Are Based on Pascal’s • Similar to Pascal’s • Name equivalence is used. • 2 reasons • Repeating a type definition means logical difference. • Structural equivalence isn’t well defined. • 2 new concepts : subtype & derived type

  24. Subtypes • Constraints defines the subtype of the base type. • Arithmetic operations are allowed. • Compatible with its base type & other subtypes of its base type (with runtime constraint check) Subtype Index is Integer range 1 .. 100 keyword

  25. Derived Types Type percent is new Integer range 0 .. 100 • It inherits all of the functions (user defined or built-in) from base type. • We can define abstractly-different derived type. • Conversion can be done explicitly between base/derived.

  26. Constraints replace subranges • Replacement of Pascal subrange constructor constraint • Range constraint • Accuracy constraint • Discriminant constraint • Index constraint

  27. 1.Range constraint Integer range 1..100 • The same implementation as Pascal’s • Runtime expressions are allowed

  28. Accuracy constraint Float digits 10 range -1e6 .. 1e6

  29. Discriminant constraint Person (Male) is a type [person is a variant record of Male , Female] • A runtime check is necessary in the assignment of a Person to a Person (Male)

  30. Index constraint • 2 problems of Pascal’s arrays • Static indexes • Passing arrays with different sizes to a function (i.e. sum) • These problems are solved Type Vector is array (integer range < >) of float Data: Vector (1..100) Days : Vector (1 .. 365) Function sum (V : vector) return Float is …

  31. Index constraint • The compiler must pass actual bounds of the array as Hidden parameter V’First , V’Last , V’Range Name of the array For I in V’Range loop Total := Total + V(I) End loop;

  32. Enumerations can be overloaded • Pascal doesn’t allow overlap of the elements of the enumeration types. Type primary is ( Red, Blue, Green ) Type StopLight ( Red, Yellow, Green ) • the Red identifier overloaded to 2meaning • Ada uses context to determine which Red is meant • In many situations programmers are required to specify. Primary (Red), StopLight (Red)

  33. Why we need overloaded enumerations? • Convenience • In natural languages, one word has several meanings. • Ada character set : enumeration type • Characters may be repeated in different enumerations

  34. Ada character set : enumeration type Type Discode is (‘A’,’B’,’C’,’D’,’E’,’F’,’G’, ’H’,’I’,’J’,’K’,’L’,’M’,’N’,’O’,’P’,’Q’,’R’,’S’, ’T’,’U’,’V’,’W’,’X’,’Y’,’Z’,’0’,’1’,’2’,’3’,’4’, ’5’,’6’,’7’,’8’,’9’,’+’,’-’,’.’)

  35. 7:4 Design: Name Structures • The primitives are those of Pascal • Constant • Variable • Type • Procedure • Function • Task • Package

  36. Variable declaration • One of the simplest declaration is the variable declaration • It allows initialization • Eliminates a common error: using an uninitialized variable • It causes a program to be more readable • The initial value is not restricted to be a constant. It can be an expression

  37. Constant declaration • It is more general than a Pascal constant • Its value can be computed during the execution of the program • This facility aids program maintenance • Example: • Feet_Per_Mile: constant Integer := 5280; • PI: constant := 3.14159_26535_89793

  38. Ada 83 allows the type to be omitted if it is a numeric type, and if the expression on the right involve only: • Literals • Names of numeric literals • Calls of the predefined function ABS • Parenthesized literal expression • Predefined arithmetic operation

  39. This feature is included to allow constants of type universal integer and universal real to be named • These types • Have the maximum possible precision • Are not normally accessible to programmers • This kind of declaration permits the programmer to name a type- and precision independent numerical constant

  40. Specifications and definitions • Information hiding was supported by the ability to divide declarations into two parts: • Interface • Implementation • Since subprograms form most of the interface to a package subprogram specification is very important

  41. Global Variables Considered Harmful • Problems with block structure: • Side effects: • Result from hidden access to a variable • Indiscriminate access: • The problem of indiscriminate access is the inability to prevent access to a variable

  42. Vulnerability: • Means a program segment can not preserve access to a variable • No overlapping definitions: • The need for this arises from attempts to modularize large systems • We can not control share access to variables

  43. Side Effects • Example: Integer procedure Max (x,y); integer x, y; begin count := count + 1; Max := if x>y then x else y; end • It makes it very difficult to determine the effects of a procedure from the form of a call of the procedure

  44. Indiscriminate Access • Example: begin integer array s[1:100]; integer top; procedure Push(x); integer x; begin top := top + 1; s[top] := x; end; top := 0; … uses of Push … end

  45. Vulnerability • Under certain circumstances it is impossible to preserve access to a variable • The basic problem is that new declarations can be interposed between the definition and use of a variable

  46. Example: Begin integer x; …… many lines of code …… begin real x; …… many lines of code …… x := x + 1; ……………………………………… end; end;

  47. No Overlapping Definitions • Example: begin array DA[…]; array DB[…]; procedure p1; ….; procedure p2; ….; procedure p3; ….; procedure p4; ….; … end

  48. Attributes of an Alternative • The default should not be to extend the scope of a variable to inner blocks • The right to access a name should be by the mutual consent of the creator and accessor of the name • Access right to a structure and its substructures should be decoupled.

  49. It should be possible to distinguish different types of access • Declaration of definition ,name access,and allocation should be decoupled

  50. Two Important Principles of Information Hiding • One must provide the intended user with all the information needed to use the module correctly and nothing more • One must provide the implementer with all the information needed to complete the module and nothing more

More Related