home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
PASTUT34
/
ADA&C.TXT
next >
Wrap
Text File
|
1993-06-12
|
5KB
|
123 lines
PASCAL AND ITS RELATION TO OTHER LANGUAGES.
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
It has already been indicated that Pascal was developed from Algol, in
as much as it is a structured, typed language using free-format. Other
languages have retained these features, whilst attempting to improve on
weaknesses.
In the 1970s, it was recognised that the difficulty of producing programs
seemed to increase with the square of the program length (not linearly)
and this led to the concept of modularization to reduce the difficulty
and hence the cost of programs. The Turbo Pascal Unit illustrates this
concept. The language MODULA, amongst others, is another example of
modularization, whilst Ada (1980) was the winner of a language design
competition initiated by a working group for the US Department of
Defense.
In Ada, expressions, statements and types are very similar to Pascal
but the declaration part is different, particularly as regards 'package'
and 'task', both of which declare modules. Tasks are distinguished from
packages in their ability to execute concurrently with other tasks.
Ada also uses a fully bracketed syntax, so that the different compound
structures have distinguishable starts and finishes, instead of the
standard 'begin' and 'end' of Pascal. Typical examples are:
loop...end loop
if...end if
case...end case
record...end record
The main disadvantage to Ada is its size, coupled to the fact that the
US Department of Defense will not allow a subset of the language, on
the grounds that this would mitigate against portability. This could
well limit the use of this language, even though it will undoubtedly
influence the developers of future languages.
Further information on Ada and other languages such as FORTRAN, Algol,
Pascal, LISP, Smalltalk and PROLOG can be found in 'Principles of
Programming Languages' by Bruce J. MacLennan, published by Holt,
Rinehart and Winston (1983).
Perhaps the most attractive alternative language to a Pascal programmer
is C. It is a structured, typed language with free-format, but unlike
Ada it is a very small language. It was developed by Dennis Ritchie at
the Bell Laboratories in 1972, and was based on another language called
B, itself derived from BCPL (Basic Combined Programming Language).
The language C is associated with the operating system UNIX, which is
recommended by government and much used by universities. Both UNIX and
the C compiler are designed for portability. Although UNIX itself
requires a larger memory than the 640KB of ordinary PCs, UNIX (or XENIX)
could well become the operating system of the future for 386 machines
with 4 MB of memory.
C is a very flexible language, because any program is composed of
functions which can be easily modified and extended and then stored on
disk for use by other programs.
Although the syntax of C is different to Pascal, the style is similar
and all statements are terminated by semi-colons (;). Braces, { and },
are used to indicate the start and end of the statements within a
function, instead of the begin and end used in Pascal. Comments are
placed within /* and */ instead of the braces used in Pascal.
As with Pascal, control loops eliminate the need to use GOTO statements.
They are similar to Turbo Pascal as indicated below:
if (expression) statement1; else statement2;
while (expression) statement;
or in the case of compound statements
while (expression)
{
statement1;
...
statementr;
}
for(expression1; expression2; expression3) statement;
where expression1 relates to the initial condition expression2 relates to the end condition
and expression3 act as the adjuster or counter.
There is also a 'Switch-Case' statement similar to the Case statement in
Pascal.
Each function, including an obligatory one called 'main', must have open
and closing brackets following the function name, e.g. main() and then
have braces enclosing the statements of that function. The brackets may
enclose parameters, but must still be used even if there are no
parameters.
The data types in C are:
int float char short long double
These are declared as shown below:
int a,b,c;
char z;
etc.
Unsigned integers, arrays and pointers may also be used. The size and
precision of data types is machine dependent. Assignments are indicated
with the equal sign only (=), whilst == indicates 'equal to'.
There are a number of other operators, such as ++ which is used to
increment a variable, so that ++a means a = a + 1 . % is used for
modulus, whilst && means logical and.
Appropriate references should be consulted for further details, but for
a modest text that enables a Pascal programmer to convert to C, 'The Big
Red Book of C' by Kevin Sullivan, published by Sigma Press (1983) is
recommended. The definitive text is 'C Programming Language 2nd Ed.'
by Kernighan and Ritchie, published by Prentice-Hall.
ADA&C.TXT
1.3.90