campus.murraystate.educampus.murraystate.edu/academic/faculty/wlyle/415/2013/vargas.docx · web...

27
Research Project CSC 415 Programming Languages Fall 2013 Name: Christian Vargas Professor: Dr. William F. Lyle

Upload: duongnhi

Post on 27-May-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

Research ProjectCSC 415

Programming LanguagesFall 2013

Name: Christian VargasProfessor: Dr. William F. Lyle

Table Of ContentI. History of Ada

II. Overview of Ada’s Design, Syntax and Semantics

a. Names, Binding, and Scopes

b. Data Types

c. Expression and Assignment Statements

d. Statement-level Control Structures

e. Sub programs

f. Abstract Data Types and Encapsulation Constructs

g. Support for Object-Oriented Programming

h. Concurrency

i. Exception Handling and Event Handling

III. Language Evaluationa. Readability

b. Writability

c. Reliability

IV. Appendices

V. Bibliography and References

I. History of Ada“Ada is a structured, statically typed, imperative, wide-spectrum, and object-

oriented high-level computer programming language, extended from Pascal and

other language” as defined by Wikipedia. It was a language created in the 1970

for the purpose of the US Department of defense. They came to this decision

because they had realized that there were many languages used by the US

Department of Defense and created this program to supersede the many different

languages they were using.

The programming language was named after the first credited programmer Ada

Lovelace. In the 1970s, the US Department of Defense was concerned by the

number of different programming languages being used for its embedded

computer system projects, many of which were obsolete or hardware-dependent,

and none of which supported safe modular programming which was said by the

authors of the information given by wikipedia.

In 1975, a working group, the High Order Language Working Group also known

as “HOLWG”, was formed with the intent to reduce this number by finding or

creating a programming language generally suitable for the department's

requirements. The result was Ada. The total number of high-level programming

languages in use for such projects fell from over 450 in 1983 to 37 by 1996. As

this language progressed and developed the language became broader and became

useful for more applications rather than just that of the US Department of

Defense.

Ada attracted much attention from the programming community as a whole

during its early days. Its backers and others who predicted that it might become a

dominant language for general purpose programming and not just defense-related

work. Ichbiah publicly stated that within ten years, only two programming

languages would remain and these were Ada and Lisp.

II. Overview of Ada’s Design, Syntax and Semanticsa. Names, Binding, and Scopes

- Name, binding and scopes vary across different programing languages. Each

programming language has its specific guidelines and its own way in which they

are coded and written. Names are for the human programmer to read what a

program is doing. In Ada names are used for different things such as variables,

arrays and other parts of the code. Names are evaluated at run time in the general

case; name refers to objects, containing value, or to other entities such as

subprograms and types.

Binding is the act of associating properties with names. In Ada this is where the

names given to a specific part of the program in described with its properties. The

scope of the name is the part of a computer program where the name can be used

to find the referred entity. Modern high-level programming languages allow us to

define names with a limited scope of visibility, to reuse them in different contexts

and also to overload them; It is responsibility of the compiler to keep track of

scope and binding information about names. For this purpose the compilers

generally use a separate Symbol Table structure. In the case of GNAT, there is no

separate symbol table. Rather, semantic information concerning program entities

is stored directly in the Abstract Syntax Tree

b. Data Types- Data types of a programming language are the different types of input and

symbols that a programming language can read and work with. The data types are

what the program works with to get a specific output and give the desired action

that the programmer wants. According to the article about data types in the

Wikipedia library, Ada's type system is not based on a set of predefined primitive

types but allows users to declare their own types. This declaration is not based on

the internal representation of the type but on describing the goal which should be

received. This allows the compiler to determine a suitable memory size for the

type, and to check for violations or errors of the type definition at compile time

and run time.

Ada supports numerical types defined by a range, modulo types, aggregate types,

which includes records and arrays, and enumeration types. Below is a table of all

the data types that can exist in the Ada programming language and their ranges.

Type RangeInteger -2,147,483,648 to 2,147,483,647Natural 0 to Integer'lastPositive 1 to Integer'lastLong_Integer -2**63 to (2**63)-1Short_Integer -128 to 127Float,Short_Float

Real numbers with anapproximate range of 8.43E-37 to 3.37E+38 and an accuracy of about 6 decimal digits

Long_Float Real numbers with anapproximate range of 4.19E-307 to 1.67E+308 and an accuracy of about 15 decimal digits

Boolean An enumeration type with the values (False, True)Character A character in the ANSI (8-bit) character set.Wide_Character A character in the UNICODE (16-bit) character setUnsigned_Integer 0 to 4,294,967,295Byte_Integer Integer values in the range of -128 to 127Unsigned_Byte_Integer Integer values in the range of 0 to 255

Word_Integer Integer values in the range of -32768 to 32767Unsigned_Word_Integer Integer values in the range of 0 to 65535Dword_Integer Integer values in the range of -2,147,483,648 to 2,147,483,647Unsigned_Dword_Integer Integer values in the range of 0 to 4,294,967,295Qword_Integer -2**63 to (2**63)-1Byte_Boolean An enumeration type with the values (False, True)Word_Boolean An enumeration type with the values (False, True)Dword_Boolean An enumeration type with the values (False, True). Useful when interfacing

with C code.

c. Expression and Assignment Statements-Expression is the fundamental means of specifying computations in a

programming language. To grasp the concept of expressions and expression

evaluation, you need to be familiar with the order of operator and the operand

evaluation. Operator evaluation order is dictated by associativity and precedence.

Other issues in expression semantics are type mismatches, coercions, and short

circuit evaluation. When it comes to assignment statement, the purpose of it is to

change the value of a variable. Simple assignment statement specifies an

expression to be evaluated and a target location in which to place the result of the

expression evaluation.

When it comes to Ada, statements are executed at run time to cause an action to

occur. Expressions are evaluated at run time to produce a value of some type.

Declarations are elaborated at run time to produce a new entity with a given

name. Many expression and subtype constraints are statically known. The Ada

compiler is required to evaluate certain expression and subtype at compile time.

The language defines a mechanism that allows Ada compiler to pre-elaborate

certain kinds of units.

An assignment statement causes the value of a variable to be replaced by that of

an expression of the same type. Assignment is normally performed by a simple bit

copy of the value provided by the expression. However, in the case nonlimited

controlled types, assignment can be redefined by the user.

In this part of the Ada language the For loops, infinite loops, If Then Else, and

case statements are also included. Here are some simple examples of expression

statements:

Character next_vowel := ‘o’;

Float delta_v_sq := (v2-v1) **2;

Delta_sum := (delta_v_sq + delta_h_sq) * 0.10;

angle := 2.0 * pi * float(p) / 360.0;

integer i := i + 1;

natural new_value := abs(any_value) + mod(old_value, 10);

string my_string := “ “ & packname(j) & “-“;

d. Statement-level Control Structure-A control structure is a control statement and the statement whose execution it

controls. A control structure is a primary concept in most high level programming

languages. In its simplest sense, it is a block of code. More specifically, control

structures are blocks of code that dictate the flow of control. In other words, a

control structure is a container for a series of function calls, instructions and

statements.

Ada is a structured programming language, meaning that the flow control is

structured into standard statements. All standard constructs and deep level early

exit are supported so the use of the also supports ‘go to’ commands is seldom

needed.

Here is a sample code that gives examples of statement level control structure:

with Ada.Text_IO, ADa.Integer_Text_IO;use Ada.Text_IO, Ada.Integer_Text_IO;

procedure Example is

Year : INTEGER;

begin for Age in 0..21 loop Put("In"); Put(Age + 1938,5); Put(", I was"); Put(Age,3); Put(" years old"); case Age is when 5 => Put(", and started school"); when 17 => Put(", and graduated from high school"); when others => null; end case; Put("."); New_Line; end loop;end Example;

e. Sub programs-Subprograms are the most important concept in programming language design.

Subprogram contains many parts which include the subprogram definition, the

subprogram call, the subprogram header, the parameter profile, the protocol, the

prototypes and the subprogram is active state. Each part of the subprogram plays

an important part in the subprogram and what it does.

In Ada programming language subprogram consist of several different topics

which include parameter modes, functions, procedure and recursion. When we

talk about the parameters of subprogram, it is referring to the three parameter

modes which are IN, OUT and INOUT parameters. Below is a table that displays

the subprogram and their distinct parameter mode:

Parameter Mode Functions Procedure DescriptionIN Yes Yes Passed into the subprogram, are

constants in the subprogram, and may not be changed in the

subprogramOUT No Yes Passed out of the subprogram, a

parameters value is defined inside the subprogram

INOUT No Yes Passed into the subprogram, and may be changed by the

subprogram, and the parameters value is passed out of the

subprogram

When it comes to functions in Ada, they are mainly used to return a single value

to the calling program using the ‘Return’ statement. The default parameter mode

is the ‘IN’ as shown in the table above, which means “n : Integer” is equivalent to

“n : IN Integer.” Any variables declare locally within a function have their scope

limited to within the function. If these variables are use outside of the function

your program will not compile and will not run.

A procedure on the other hand is a different type of sub programming within the

Ada programming language. Procedures do not return values using the return

statement. The parameter mode can be “IN” for an input parameter, “OUT” for an

output parameter and “INOUT” for a parameter whose mode is both input and

output. Variables declared locally within the procedure have their scope limited

within the procedure.

Another type of sub programming within the Ada programming language is

recursion. A recursion subprogram is a subprogram that calls itself. Both

functions and procedures can be recursive. Each instance of the recursive

subprogram has its own version of the calling parameter and all items, which

include variables, arrays, etc. declare in the body of the subprogram.

f. Abstract Data Types and Encapsulation Constructs- An abstract data type is a user-defined data type that satisfies two conditions.

These two condition are the representation of, and operation on, object of the type

are defined in a single syntactic unit and the representation of objects of the type

is hidden from the program unit that use these objects, so the only operation

possible are those provided in the type’s definition.

When it comes to term with the Ada programming language, the encapsulation

construct is called packages. This includes the specification package and the body

package, which implementation of the entities named in the specification. Ada

also supports information hiding. The representation of type appears in a part of

the specification called the private part which is more restricted form with limited

private types.

Packages support information hiding in the sense that the user of the package

cannot depend on the implementation detail that appear in the package body.

Private types provide additional information-hiding capability. By declaring a

type and its operation in the visible part of a package specification, the user can

create a new abstract data type. The advantage of supporting private and

information hiding means that the information with the package is safe and cannot

be modified. It gives the package a more structured state within the package.

g. Support for Object-Oriented Programming

- Although the Ada language primary use was for the US Department of Defense,

it does support object oriented programming. Programming with GUI is possible,

and not difficult for a programmer to write. It does have use interface with

buttons, images, audio, and other source of input. According to the book

“Introducing Ada 95” written by John Barnes, Ada 95 gives flexibility of

programming that allows programs to be maintained at a lower cost. According to

Barnes, modern software development practices call for building programs from

reusable parts, and for extending existing systems. Ada supports such practices

through object oriented programming features. The basic principle of object

oriented programming is to be able to define one part of a program as an

extension of another, pre-existing, parts.

Abstract data types may be defined in Ada using packages and private types.

Types may be extended by adding new packages, deriving from existing types,

and adding new operations to derived types. For non-tagged types, such extension

is "static" in the sense that the compiler determines which operations apply to

which objects according to the typing and overloading rules.

For tagged types, however, operation selection is determined at run time, using

the tag carried by each such object. This allows easy extension of existing types.

To add a new tagged type, the programmer derives from an existing tagged parent

type, possibly adding new record components. The programmer may override

existing operations with new implementations. Then, all calls to the existing

operation will automatically call the new operation in the appropriate cases; there

is no need to change or even to recompile such pre-existing code. For tagged

types, it is possible to write class-wide operations by defining subprograms that

take parameters of a class-wide type. Class-wide programming allows the

programmer to avoid redundancy in cases where an operation makes sense for all

types in a class, and where the implementation of that operation is essentially the

same for all types in the class as according to Barnes. (Introducing Ada95)

h. Concurrency-Concurrent computation makes programming much more complex. In a

concurrent program, several steams of operation may execute concurrently. Each

stream of operation executes as it would in a sequential program except for the

fact that streams can communicate and interfere with one another. Ada has

language support for task based concurrency. A major feature of the Ada

programming language is the facilities it provides for concurrent programming.

In concurrency task are executed in parallel. Concurrent programs can be

executed on a single processor by interleaving the execution steps of each in a

time-slicing way, or can be executed in parallel by assigning each computational

process to one of a set of processors that may be closed or distributed across a

network. Tasks are specified into two parts that includes the task declaration

which defines the task interface and the task body which specifies the

implementation of the task. Depending on the implementation, Ada tasks are

either mapped to operating system task or processes, or are scheduled internally

by the Ada runtime. Here is a diagram to better illustrate how concurrency in Ada

works.

Ready <------+ | ^ Task | | Scheduled | | | | | | | | Completed <---- Running | Message (for ACCEPT) | | | | | | Delay time has passed | | ACCEPT | | | DELAY | | | | \/ | | Terminated <--- Blocked ----->+

i. Exception Handling and Event Handling-Every programming language must have a way to handle errors or a way to

modify the error display message so that the user knows what they did wrong or if

it is something simple that went wrong. This is what exception handling is.

Exception handling is the process of responding to the occurrence, during

computation, of exceptions often changing the normal flow of program execution.

An exception is used to name a particular kind of error situation. Some exceptions

are predefined by the language and others may be defined by the user. Exceptions

are declared in the same way as other entities

Buffer_Full_Error : exception;

When the exceptional situation happens, the exception is raised. Exception

handling can be made for any errors that can be raised. The more exception

handling created the better responsive a program becomes to errors.

Here is a sample of exception handling in Ada code:

begin ...

exception when Buffer_Full_Error => Reset_Buffer; when Error: others => Put_Line("Unexpected exception raised:"); Put_Line(Ada.Exceptions.Exception_Information(Error));end;

III. Language Evaluation a. Readability

-When it comes to the readability of the Ada language there are many features in

the programming language that makes it easier for a person to both read and code

a program. Spelling is something of an advantage for Ada programming because

there are many ways you can go about spelling out names of variables and

procedures to make it very straight forward to read. You can use underscore to

separate words in a compound name or you can make reserved words and other

element of the program visually distinct from each other.

You can also use naming a variable as an advantage for reading the language

better. You can choose names that are as self-documenting as possible or you can

give a variable a name that is more self-explanatory of what the variable will do

but you need to avoid naming more than one variable the same identifier. You can

also use nouns for non- Boolean function and you can also name the functions to

whatever is the main purpose of the function.

One of the most helpful features of Ada that help a lot while writing a program or

reading a program is using comments to explain what each particular part of the

code is doing or describing . You can put comments in a program wherever you

feel it necessary to explain a variable or even a subprogram. Having comments

makes it a lot easier to read and a lot easier to follow code within the program.

Comments are one of the main features of Ada and of any other programming

language to make it better to read.

b. Writability-The writability of Ada is much more user friendly than that of most of other

programming language. The program structure of Ada and the names given to the

different functions of Ada makes it a program that is very much easy to be

written. Code in Ada is more self-explanatory than that of other language. A

simple ‘put(“Hello”)’ will output hello on the output of a program. To display a

message as simple as that isn’t that easy in other languages and may entail a lot

more than just one line of code.

One of the main features that make this language easier to write and to understand

is that the language is not case sensitive. This means that while writing the code

you don’t need to be concern with the fact that every variable that has an upper

case letter within it or in the beginning of the word has to be repeated all the way

down to the end of the program. This makes it easier to write although it does

open the door for bad habits in writing code. Other programming languages are

not that lenient when it comes to case sensitivity. Some programming languages

will not even compile and will raise errors for every word that is not the same as

the original variable. Bottom line is that this language is not case sensitive and it

makes it a lot easier to write.

c. Reliability-The reliability of this programming language is high. The programming language

Ada is often used in air traffic control, banking and other high-risked industries

because of its reliability, the Ada programming language has become even more

flexible and secure since the beginning of its life. The latest version of Ada offers

a feature commonly referred to as “contract-based programming.” Found in very

few languages, it significantly strengthens programmes against bugs and

malicious use.

Since then, the language has been revised to increase flexibility and extensibility,

and give more control and wider support. The 2012 version further enhances its

capability and expressiveness, as well as the dependability, safety and security of

programmes using the language. This is critical as Ada is often used in industries

where security and dependability are crucial. Examples include aviation and air

traffic control, satellites, medical and banking sectors, railway and subway

systems, and the military, to name a few. The language was originally made and

commissioned by the US department of Defense which required a high level of

reliability.

This means that when it comes to reliability, the Ada language is on top of its

game.

IV. Appendices

Hello world program in Ada:

with Ada.Text_IO; use Ada.Text_IO;procedure Hello isbegin Put_Line ("Hello, world!");end Hello;

Example of Data types:type Day_type is range 1 .. 31;type Month_type is range 1 .. 12;

type Year_type is range 1800 .. 2100;type Hours is mod 24;type Weekday is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday); type Date is record Day : Day_type; Month : Month_type; Year : Year_type; end record;

Code that uses Array:procedure Arr1 is A: array(1..5) of Integer; -- Array subscripts 1 to 5. I: Integer;begin -- Read 'em in. for I in 1..5 loop Put("> "); Get(A(I)); end loop;

-- Put 'em out in reverse order. Put("["); for I in reverse A'Range loop Put(A(I)); if I > A'First then Put(' '); end if; end loop; Put_Line("]");end Arr1;

Example of exception handling:with Ada.Text_IO; use Ada.Text_IO;procedure ReadOut is S: String(1..100); -- Input line (up to 100 chars) N: Integer; -- Number of characters read.begin -- Issue the lovely decoration. Put_Line("-----------------------------------------------------" & "-----------");

-- Copy lines like there's no tomorrow. loop Get_Line(S, N); Put_Line(S(1..N)); end loop;

exception when End_Error =>

-- When reaching end of file, issue the closing lovely decoration and -- return from the procedure. Put_Line("-----------------------------------------------------" & "-----------"); return;end ReadOut;

V. Bibliography and ReferenceInformation from each source was used throughout the research and information from these sources were quoted and placed within the research paper. Most information for this research was received from the following references which include both books and internet sites.

Book sources include:Barnes J. (1995). Introducing Ada 95: The language for a complex world. Reading, England.

Riehle R. (2003) Ada Distilled: Introduction to Ada programming for experienced computer programmers. Monterey, CA: AdaWorks Software Engineering.

Online sources include:Introductory Ada Summary. Just the Basics. Retrieved from http://www.seas.gwu.edu/~csci51/fall99/ada_note.html#statements

Ada (programming language). Retrieved from http://en.wikipedia.org/wiki/Ada_(programming_language).