Evaluation and analysis of ALGOL, PASCAL and ADA

DilankaDias 1,830 views 19 slides May 17, 2017
Slide 1
Slide 1 of 19
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19

About This Presentation

Evaluation and analysis of ALGOL, PASCAL and ADA


Slide Content

1

Programming Languages and Design Concept
Assignment 2


Evaluation and Analysis of ALGOL, PASCAL
and ADA Programming Languages



IT15071576
M.A.P.D.Dias

Introduction

Algol
In the mid1950s it became apparent to many scientists that a universal, machine independent
programming language would be valuable. Therefore Algol 58 was developed which greatly
influenced many other languages. In the sense that most modern languages are "algol-like", it
was possibly the most successful of the four high-level programming languages with which it
was compared to (FORTRAN, Lisp, and COBOL). Moreover, it was the first programming
language which gave serious attention to formal language definition and through the
ALGOL-60 Report introduced Backus-Naur Form, a principal notation for language
design.The ALGOL-60 was a very simple and clear language.
Niklaus Wirth based his own ALGOL W on ALGOL 60 before developing Pascal. [3]

Pascal
Pascal is a historically influential imperative and proceduralprogramming language, designed
and published around 1970 by Niklaus Wirth as a small and efficient language intended to
encourage good programming practices using structured programming and data structuring.
It has evolved significantly since that day, with a lot of contributions by the various compiler
constructors (Notably: Borland). PASCAL is a programming language named after the 17th
century mathematician Blaise Pascal. Pascal provides a teaching language that highlights
concepts common to all computer languages. It also standardizes the language in such a way
that it makes programs easy to write. Strict rules make it difficult for the programmer to write
bad code.
Ada
Ada is a high-level Pascal descended language whose development was initiated in 1975 by
the Department of Defense. Ada was intended to be a common language that could be used
on the department's computers, which were produced by many different manufacturers. The
first version of the language specification was completed in 1979. Ada was named after Ada
Lovelace (1815–1852), who is credited as being the first computer programmer, Ada is
similar to Pascal but Ada has not been widely spread in programs other than those of the
Department of Defense screaming to get out from inside its vast, elephantine bulk.It has built-
in language support for explicit concurrency, offering tasks, synchronous message passing,
protected objects, and non-determinism.

Major contributions to modern languages

Algol

Algol is one of the major milestones in programming language development. This is partly
reflected in the terms it added to the programming language vocabulary, which includes type,
formed parameter, actual parameter, and block call by value, call by name, scope, dynamic
analysis and global and local variables.
Eventually almost all the programming languages became "Algol-like" that is, block-
structured, nested, recursive, and free form.
One of the major contributions of ALGOL-60 wasthat it used a hierarchical structure
throughout itsdesign.


Pascal

This contains many additional features that are convenient for the development of large-scale
programs.Pascal is influential on software development because of its wide use as a "learning
language." Aspects of Pascal are also seen in other languages. For example, the Oracle
database procedural programming language PL/SQL has always felt eerily similar to Pascal.
One might argue that Pascal's influence is felt more today indirectly via languages such as
PL/SQL than via direct use. Mostly Pascal offers numerous advantages as a "learning
language." Ada is also a language that’s been inspired or influenced by Pascal.


Ada

Ada has advanced programming facilities which are not available in modern languages as
well. But also features found in existing programming languages such as PASCAL, Algol 60,
and Fortran are there as well.Ada supports new and changing technologies,facilitates
development of complex programs andhelps make code readable and portable.Ada is used
throughout a number of major industries to design software that protects businesses and lives.

Features

Algol

1. Program structure

Algol programs are hierarchically structured.
One of the primary characteristics and important contributions of Algol is its use of
Hierarchical structure, or nesting, throughout its design.
An Algol program is composed of number of nested environments;


begin
integer N;
Read int (N);
begin
real array Data [1:N];
real sum, avg;
integer i;
sum i = 0;
for i = 1 step 1 until N do
begin real val;
Read Real (val);
Data [i] := if val < 0 then -val else val;
end;
for i := 1 step 1 until N do
sum := sum + Data[i];
avg := sum/N;
Print Real (avg)
end
end

2. Variable declaration

Variables are declared as TYPE var, var, var;
Where TYPE is INTEGER, REAL, ARRAY, STRING. Another type allowed is called a
SWITCH declaration. This allows you to define a range of values to be stored in a variable,
where the values are actually labels (as used in GOTO statements). This was used similarly
to a switch or case statement in later languages but was far more primitive and was replaced
by a true CASE statement in ALGOL 68. ALGOL 68 also introduced the UNION to the
ALGOL languages.

Arrays are declared with both the reserved word array and [range] notation. If no type is
provided, arrays default to REAL. The range allows you to specify the starting and ending
indices for the array. Thus, arrays are not limited to 0..num-1 as in C, or 1..num as in
FORTRAN. Instead, you might specify [0:99] or [1:100] or [-50:49]. Arrays with common
sizes can be declared with a single range as follows:

INTEGER ARRAY A, B, C[5:10];

Local variables are generally called local variables in ALGOL 68. Variables must be declared
before use. In traditional ALGOL 68, variables must be declared before any labels: in a
compound-clause.

The declaration of a variable, without assigning a value takes the form:
<typename><variablename>;

Ex:int j;


It is possible to initialize variables with expressions having known values when they are
defined.
The syntax follows the form: <typename><variablename> := <initializing expression>;

Ex: SHORT INT b1 := 2500;

3. Data types and structures

There are three main data types in Algol: integer, real and string.

Data structures

Primitive scalars: integer, real, boolean

Constructor: array

Array bounds and dimensions are unconstrained. (the Zero-One-Infinity Principle.)
Ex:

integer array aMatrix[-10:10, 0:20];

Arrays are dynamic: space is allocated at block entry time and fixed until block exit.
Ex:

begin
integer array aList[lowest:highest];
. . .
end

E.g.,

begin
integer i;
procedure f(x);
real x; x := 0;
integer array days[ 0: i ];
begin
. . .
end
begin
i := 7;
f(x);
. . .
i := 30;
f(x);
. . .
end
end

4. Control structures

All other Algol imperatives alter the flow of control in the program. The most obvious of
these is the goto statement, which transfers to a labeled statement. Algol has a conditional
statement, the if-then-else and an iterative statement, the for-loop which is an elaboration of
Fortran’s Do loop.

Some of the control structures in Algol are:
 goto
 if-then-else
 for loop
 switch
GOTO: like Fortran's, except for scope rules for labels (can only go to a label at the same
lexical level, or an enclosing lexical level)
if-then-else: both statement and expression forms
y := if x=3 then 5 else 6;

for loop: definite, indefinite iterations. In general, a for-loop generates a sequence of values
to be assigned successively to the controlled variable.

For loop have a number of variants:
for i := 1 step 2 until N do
a[i] := b[i];

for newGuess := Improve( oldGuess )
while abs( newGuess - oldGuess ) > 0.0001 do
oldGuess := newGuess;

for days := 31,
if mod( year, 4 ) = 0 then 29 else 28,
31, 30, 31, 30, 31, 31, 30, 31, 30, 31 do
. . .

for i := 3, 7,
11 step 1 until 16,
i ÷ 2 while i >= 1,
2 step i until 32 do
print( i );

switch statement: supports a kind of computed goto; now obsolete (case statement is better)

5. Parameter passing mechanisms

The two best known parameter passing methods are pass by value(call-by-value)and pass by
reference(call-by-reference).

Pass by value(call-by-value):

The default parameter passing method was pass by value, which, like inC, means that
parameter values are copied into the formal parameters from which pointthe formal
parameters act like local variables.

Pass by name:

The way this worked is through a thunk -- a parameter less function which would perform a
textual substitution of the formal parameter name with that of the actual parameter. So in
effect, pass by name is merely a form of substitution that then has the program access non-
local variables. This is confusing and dangerous and while it can lead to some interesting
code, it is far more dangerous than pass by reference or pass by result.

Here is the original code before the thunk executes:

begin
integer idx; // variable available in the main code
real procedure sum (i, lo, hi, term); // function, i and term passed by name
value lo, hi; // function declarations
integer i, lo, hi;
real term;
begin // begin of sum function
real temp;
temp := 0;
for i := lo step 1 until hi do
temp := temp + term;
sum := temp
end;
print (sum (idx, 1, 100, 1/idx)) // main code contains function call
end

The above code becomes the following:

begin
integer idx;
real sum;
begin // pass by name unfolds the code so that
real temp; // hi becomes 100, lo becomes 1 and term
temp := 0; // becomes idx
for idx := 1 step 1 until 100 do
temp := temp + 1/idx;
sum := temp
end;
print (sum)
end

Pass by reference:

Reference to the actual parameter is copied into the formal parameter.

Pass by result:

In pass by result formal parameter acts as an un-initialized local variable which is given a
value during the execution of the procedure.
On leaving the procedure, the value of the formal parameter is assigned to the actual
parameter which must be a variable.

Pascal

1. Program structure
A Pascal program basically consists of the following parts:
 Program name
 Uses command
 Type declarations
 Constant declarations
 Variables declarations
 Functions declarations
 Procedures declarations
 Main program block
 Statements and Expressions within each block
 Comments
Following format shows the basic syntax for a Pascal program:
program {name of the program}
uses {comma delimited names of libraries you use}
const {global constant declaration block}
var {global variable declaration block}

function {function declarations, if any}
{ local variables }
begin
...
end;

procedure { procedure declarations, if any}
{ local variables }
begin
...
end;

begin { main program block starts}
...
end. { the end of main program block }

2. Variable declaration

All variables must be declared before we use them in Pascal program. All variable
declarations are followed by the var keyword. A declaration specifies a list of variables,
followed by a colon (:) and the type.

Syntax of variable declaration is:

var
variable_list : type;

Here this type must be a valid data type such as character, integer, real, boolean, or any user-
defined data type and variable_list should consist of one or more identifiers separated by
commas.



3. Data types


Type Description

 Character Typically a single octet (one byte). This is an integer type.
 Integer The most natural size of integer for the machine.
 Real A single-precision floating point value.
 Boolean Specifies true or false logical values. This is also an integer type.
 Enumerated Specifies a user-defined list.
 Subrange Represents variables, whose values lie within a range.
 String Stores an array of characters.

4. Controls structures

Programming languages provide various control structures that allow for more complicated
execution paths.
Pascal programming language provides the following types of loop constructs to handle
looping requirements.

Loop Types

 while-do loop Repeats a statement or group of statements while a given
condition is true. It tests the condition before executing the loop body.

 for-do loop Executes a sequence of statements multiple times and abbreviates
the code that manages the loop variable.It allows only +/- 1 increments in the loop
variable

 repeat-until loop Like a while statement, except that it tests the condition at the end
of the loop body.

 nested loops You can use one or more loop inside any another while, for or
repeat until loop


5. Parameter passing mechanisms

There are two ways to pass information which are call by value (pass-by-value) and call by
reference (pass-by-reference).

Call by value:

This method copies the actual value of an argument into the formal parameter of the
subprogram. In this case, changes made to the parameter inside the subprogram have no
effect on the argument.
By default, Pascal uses call by value to pass arguments. In general, this means that code
within a subprogram cannot alter the arguments used to call the subprogram.


Call by reference:

This method copies the address of an argument into the formal parameter. Inside the
subprogram, the address is used to access the actual argument used in the call. This means
that changes made to the parameter affect the argument.
In order to pass the arguments by reference, Pascal allows to define variable parameters. This
is done by preceding the formal parameters by the keyword var.


For example

procedureswap(vara:integer, varb:integer)
var t;
begin
t := a; a := b; b := t
end

Where the var formal parameters a and b are passed by reference ( var t declares a local
variable).

Ada

1. Program structure

ADA syntax is similar to Pascal
ADA uses a keywords convention to improve readability
ADA has four categories of constructs:
 declarations
 expressions
 statements
 types
The type system in ADA is stronger as it consistently uses name equivalence.

Simple Ada program:

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

The two most important facilities provided by
ADA:
 the package
 the task
The package and the task supportinformation hiding
Packages can be used as libraries, shared data areas (data structures but noprocedures), data
structure managers.

2. Variable declaration

Before using a variable, have to declare it. To do this has various options. To declare a
variable, in the line under procedure, use the following formula:
VariableName :DataType;
The declaration starts with the name of the variable:
 The name of a variable must be in one word
 It must start with a letter
 It can include a combination of letters, digits, and underscores
 It must not contain special characters
The above formula is used to declare one variable. You can use it to declare various
variables, each on its own line. This would be:
VariableName1, VariableName2 : DataType1;
If declaring more than one variable but those variables uses the same data type, declare them
on the same line, separating their names wit commas. This would be done as follows:

VariableName1 : DataType1;
VariableName2 : DataType1;
Ada uses some words that you must not use to name the variables. These are referred to as
reserved words. They are:


3. Data types

Ada's type system is not based on a set of predefined primitive types but allows users to
declare their own types. This declaration in turn is not based on the internal representation of
the type but on describing the goal which should be achieved. This allows the compiler to
determine a suitable memory size for the type, and to check for violations of the type
definition at compile time and run time.
Ada supports numerical types defined by a range, modulo types, aggregate types (records and
arrays), and enumeration types. Access types define a reference to an instance of a specified
type; untyped pointers are not permitted. Special types provided by the language are task
types and protected types.
For example a date might be represented as:
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;
abort abs Abstract accept access
aliased all And array at
begin body case constant declare
delay delta Digits do else
elsif end Entry exception exit
for function Generic goto if
in interface Is limited loop
mod new Null not of
or others Out overriding package
pragma private procedure protected raise
range record Rem renames requeue
return reverse Select eparate subtype
synchronized tagged Task terminate then
type until use when while
with xor

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

4. Controls structures

Ada is a structured programming language, meaning that the flow of control is structured into
standard statements. All standard constructs and deep level early exit are supported so the use
of the also supported 'go to' commands is rarely needed.

Example of a use of the control structure in Ada:

-- while a is not equal to b, loop.
while a /= b loop
Ada.Text_IO.Put_Line ("Waiting");
end loop;

if a > b then
Ada.Text_IO.Put_Line ("Condition met");
else
Ada.Text_IO.Put_Line ("Condition not met");
end if;

for i in 1 .. 10 loop
Ada.Text_IO.Put ("Iteration: ");
Ada.Text_IO.Put (i);
Ada.Text_IO.Put_Line;
end loop;

loop
a := a + 1;
exit when a = 10;
end loop;

case i is
when 0 => Ada.Text_IO.Put ("zero");
when 1 => Ada.Text_IO.Put ("one");
when 2 => Ada.Text_IO.Put ("two");
-- case statements have to cover all possible cases:
when others => Ada.Text_IO.Put ("none of the above");
end case;

foraWeekday in Weekday'Range loop -- loop over an enumeration
Put_Line( Weekday'Image(aWeekday) ); -- output string representation of an
enumeration

ifaWeekday in Working_Day then -- check of a subtype of an enumeration
Put_Line ( " to work for " &
Working_Hours'Image (Work_Load(aWeekday)) ); -- access into a lookup table
end if;
end loop;




5. Parameter passing mechanisms

Ada uses different designations: IN, OUT, IN OUT.

For scalar data types (such as integers), IN is the same as call by value, OUT is the same as
call by result, and IN OUT is the same as call by value result. In addition, IN parameters are
local constants therefore can't assign into them.
For compound data types such as arrays, these can be implemented as above, or using callby
reference.

For example

procedureshift(a:out integer, b:inout integer,c:in integer) is
begin
a := b; b := c;
endshift;

Where ais passed out, b is passed in and out, and cis passedin.

inmode parameters can be read but not written in the subroutine. This is the default when no
mode is given. The actual parameter is an expression.

outmode parameters can be written but not read in the subroutine. The formal parameter can
be read and written. (In Ada 83 out parameters were write-only.)


in outmode parameters can be read and written in the subroutine. The actual parameter goes
into the call and may be redefined. The formal parameter is a variable.

Strengths and Weaknesses
Algol
Strengths
ALGOL 58 introduced the concept of data type, although only variables that were not
floating-point required explicit declaration. It added the idea of compound statements, which
most subsequent languages incorporated.
In Algol 60 the concept of block structure was introduced. This allowed the programmer to
localize parts of programs by introducing new data environments, or scopes.
Every imperative programming language designed since 1960 owes something to ALGOL
60. It was the first language that was designed to be machine independent. It was also the first
language whose syntax was formally described. This successful use of the BNF formalism
started several important fields of computer science: formal languages, parsing theory, and
BNF-based compiler design.
Finally, the structure of ALGOL 60 affected machine architecture.
Weaknesses
For one thing, some of the features of ALGOL 60 turned out to be too flexible; they made
understanding difficult and implementation inefficient. The best example of this is the pass-
by-name method of passing parameters to subprograms.

The lack of input and output statements in the language was another major reason for its lack
of acceptance. Implementation-dependent input/output made programs difficult to port to
other computers.

Pascal

Strengths
The basic elements of pascal:
 Easy syntax, rather verbose, yet easy to read. Ideal for teaching.(Readability)
 Strongly typed.
 Procedural.
 Case insensitive.
 Allows nested procedures.
 Easy input/output routines built-in.
 Well structured
 Supports OOP(Object Oriented Programming)

Weaknesses
 Reduced popularity
Finding people for software projects who already have experience in Pascal could be
difficult. It could be harder to find suitable library solutions for specific problems.
 More usage of reserved words than reserved characters
Sometimes writing all the reserved words (like "begin", "end", "then",...) feels uncomfortable.
 Pascal was devised as a teaching language a few years before C but was very limited
with poor string and file handling

Ada

Strengths
Ada is the first internationally standardized object oriented programming(OOP)language.
Ada encourages good programming practices by incorporating software engineering
principles with strong typing, modularity, portability, reusability and readability. These
features reduce costs in software development, verifying, debugging, and maintenance that
typically puts strain on an organization's resources over the life of the software.
 Avoidance of “Namespace Pollution”
 Data Abstraction and Information Hiding
 Methodology neutrality
 Real-time support
 Flexibility
 Safety-critical support
 Ada uses compiler checking effectively;[4]
To eliminate many common errors that cause painful, time-consuming debugging efforts that
characterize and slow down many software development projects. Various language features,
such as strong typing and separate (but not independent) compilation, make this checking
process possible. Other features, such as the way pointers (called access values) are used, also
contribute to the avoidance of many typical difficulties
 Ada has built-in support for concurrency and distribution.
Weaknesses
 Hard to write parallel numerical computations.
 Tasks can’t determine their identities which prevents easy expression of certain types
of paradigms..
 Buffer, register and interrupt address can’t be specified dynamically.
 Entry families cannot be associated with a set of interrupts &doesn’t give programmer
sufficient control over the task scheduling algorithm.