Evaluation and Analysis of ALGOL

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 26
At a glance
Powered by AI
The report discusses and compares three programming languages: ALGOL, Pascal, and Ada.

The three programming languages discussed are ALGOL, Pascal, and Ada.

Some of the features discussed for each language include program structure, variable declaration, data types, control structures, and parameter passing mechanisms.

Programming Languages and Design Concept

Languages Evaluation Assignment 1


3rd Year (2015)

Evaluation and Analysis of ALGOL, PASCAL


and ADA Programming Languages
Evaluation and Analysis of ALGOL, PASCAL & ADA
Programming Languages

Summary

In this report my main goal is to present a more informative discussion about three important
programming languages. These three languages are ALGOL, PASCAL & ADA. Through this
report I’m going to evaluate and analyze these languages by comparing their strengths,
weaknesses, features such as program structure, variable declaration, data types, data
structures, controls structures, parameter passing mechanisms etc. and major contribution to
modern languages.

ii
Table of Content

1. Summary ii
2. Introduction 1
3. Major contributions to modern languages 2
4. Features -- ALGOL--
4.1 Program structure 3
4.2 Variable declaration 4
4.3 Data types and structures 5
4.4 Control structures 6
4.5 Parameter passing mechanisms 7
5. Features – PASCAL--
5.1 Program structure 9
5.2 Variable declaration 10
5.3 Data types and structures 11
5.4 Control structures 12
5.5 Parameter passing mechanisms 13
6. Features –ADA--
6.1 Program structure 14
6.2 Variable declaration 15
6.3 Data types and structures 16
6.4 Control structures 17
6.5 Parameter passing mechanisms 18

7. Strengths and Weaknesses


7.1 Algol 19
7.2 Pascal 20
7.3 Ada 21

8. Conclusion 22
9. References 23

iii
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 procedural programming 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.

Pascal introduced concepts and mechanisms which enabled programmers to define their own
structured data types, and also made it easier to build dynamic and recursive data structures
such as lists, trees and graphs. Important features included for this were records,
enumerations, subranges, dynamically allocated variables with associated pointers, and sets.
To make this possible and meaningful, Pascal has a strong typing on all objects, which means
that one type of data cannot be converted or interpreted as another without explicit
conversions. [2]

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. [1]

1
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 was that it used a hierarchical structure
throughout its design.

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 and helps make code readable and portable. Ada is used
throughout a number of major industries to design software that protects businesses and lives.

2
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

3
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;

4
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

5
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)

6
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 in C, means that
parameter values are copied into the formal parameters from which point the formal
parameters act like local variables.

Pass by name:

Is powerful, Can be confusing and Expensive to Implement.

However, ALGOL also introduced pass by name which gave the programmer the ability to
change a formal parameter's value and thus affect the actual parameter.

The way this worked is through a thunk -- a parameterless 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

7
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.

8
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 }

9
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.

Some valid variable declarations are:

age, weekdays : integer;


initials, grade: char;
name, surname : string;

10
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.

11
4. Controls structures

Programming languages provide various control structures that allow for more complicated
execution paths.

A loop statement allows us to execute a statement or group of statements multiple times and
following is the general form of a loop statement in most of the programming languages:

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.

12
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).

The call by value method of passing arguments to a subprogram copies the actual value of an
argument into the formal parameter of the subprogram. In this case, changes made to the
parameter inside the function have no effect on the argument.

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

procedure swap( var a: integer, var b: 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).

13
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 support information hiding
Packages can be used as libraries, shared data areas (data structures but no procedures), data
structure managers.

14
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:

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

15
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;
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

Types can have modifiers such as limited, abstract, private etc. Private types can only be
accessed and limited types can only be modified or copied within the scope of the package
that defines them.

16
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;

for aWeekday in Weekday'Range loop -- loop over an enumeration


Put_Line ( Weekday'Image(aWeekday) ); -- output string representation of an
enumeration
if aWeekday 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;

17
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 call by
reference.

For example

procedure shift(a:out integer, b:in out integer, c:in integer) is


begin
a := b; b := c;
end shift;

Where a is passed out, b is passed in and out, and c is passed in.

in mode 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.

out mode 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 out mode 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.

18
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.

19
Pascal

Strengths
The basic elements have been kept through the years:

 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. Other languages just use parentheses or curly braces – that is one letter.
Editor functions like "match-corresponding parentheses/brace" or in Pascal-context "match
corresponding begin/end" are harder to find.

 Pascal was devised as a teaching language a few years before C but was very limited
with poor string and file handling

20
Ada

Strengths
Ada is a carefully designed, general-purpose programming language. 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.

 Flexibility
 Avoidance of “Namespace Pollution”
 Data Abstraction and Information Hiding
 Methodology neutrality
 Real-time support
 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.

Ada has built-in constructs called tasks, protected objects, and partitions that provide elegant
support for capabilities that are becoming increasingly vital for modern systems. Ada also has
low-level representation clauses, which are valuable when interfacing to physical devices or
communicating across networks.

Weaknesses
 Ada is not appropriate for writing some concurrent programs like concurrent versions
of divide and conquer algorithm.
 Hard to write parallel numerical computations.
 Tasks can’t determine their identities which prevents easy expression of certain types
of paradigms.
 Task types can’t be parameterized.
 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.

21
Conclusion

Although Ada is based upon Pascal, it is quite a different type of language. Pascal is excellent
as an educational tool but is inappropriate for major commercial or real-time projects. Ada is
more complex than Pascal but has a capability for large systems. Ada has a set of unique
technical features that make it highly effective for use in large, complex and safety-critical
projects.
Algol was used mostly by research computer scientists in the United States and in Europe. Its
use in commercial applications was hindered by the absence of standard input/output
facilities in its description.
Although in Algol there were many other problems, the entrenchment of Fortran among users
and the lack of support by IBM were probably the most important factors in ALGOL 60’s
failure to gain widespread use.

The choice of a language for a project is very important. Currently both languages are
restricted to long-term projects because of the absence of production quality compilers and
there are more advance languages available now.

22
References

[1] Wikipedia – http://en.wikipedia.org/wiki/Ada_%28programming_language%29


[2] Wikipedia-http://en.wikipedia.org/wiki/Pascal_%28programming_language%29
[3] Wikipedia –“http://en.wikipedia.org/wiki/ALGOL”
[4] Website –“http://www.adacore.com/adaanswers/benefits-and-features”
[5] Book- “Principles of programming languages by B.J. MacLennan”
[6] Book- “Concepts of programming languages by Robert W. Sebesta”

23

You might also like