Imperative programming languages and tools


Информатика, кибернетика и программирование

LGOL gretly influenced mny other lnguges its mjor contribution is being the root of the tree tht gve rise to mny other progrmming lnguges including BCPL B Pscl PL I Simul C C nd Jv. Niklus Wirth bsed his own LGOL W on LGOL 60 before developing Pscl. This led to the doption of smller nd more compct lnguges such s Pscl...



56.5 KB

0 чел.

Lecture 5. Imperative programming languages and tools. Part 2.

5.1 Algol1

ALGOL (short for ALGOrithmic Language) is a family of imperative computer programming languages. ALGOL was developed jointly by a committee of European and American computer scientists in a meeting in 1958 at ETH Zurich (cf. ALGOL 58). It specified three different syntaxes: a reference syntax, a publication syntax, and an implementation syntax. The different syntaxes permitted it to use different keyword names and conventions for decimal points (commas vs periods) for different languages.

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 and the lack of interest in the language by large computer vendors other than Burroughs Corporation. ALGOL 60 did however become the standard for the publication of algorithms and had a profound effect on future language development.

In the sense that most modern languages are “algol-like”, it was arguably the most successful of the four high-level programming languages with which it was roughly contemporary: Fortran, Lisp, and COBOL. It was designed to avoid some of the perceived problems with FORTRAN. ALGOL greatly influenced many other languages – its major contribution is being the root of the tree that gave rise to many other programming languages, including BCPL, B, Pascal, PL/I, Simula, C, C++, and Java.

ALGOL introduced code blocks and the begin and end pairs for delimiting them and it was also the first language implementing nested function definitions with lexical scope. 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 (BNF), a principal notation for language design.

There were three major specifications:

  •  ALGOL 58 – originally proposed to be called IAL (for International Algebraic Language).
  •  ALGOL 60 – first implemented as X1 ALGOL 60 in mid-1960 – revised 1963
  •  ALGOL 68 – revised 1973 – introduced new elements including flexible arrays, slices, parallelism, operator identification, and various extensibility features.

Niklaus Wirth based his own ALGOL W on ALGOL 60 before developing Pascal. Algol-W was intended to be the next generation ALGOL but the ALGOL 68 committee decided on a design that was more complex and advanced rather than a cleaned simplified ALGOL 60. The official ALGOL versions are named after the year they were first published.

ALGOL 60 as officially defined had no I/O facilities; implementations defined their own in ways that were rarely compatible with each other. In contrast, ALGOL 68 offered an extensive library of transput (ALGOL 68 parlance for Input/Output) facilities.

ALGOL 60 allowed for two evaluation strategies for parameter passing: the common call-by-value, and call-by-name. Call-by-name had certain limitations in contrast to call-by-reference, making it an undesirable feature in imperative language design. For example, it is impossible in ALGOL 60 to develop a procedure that will swap the values of two parameters if the actual parameters that are passed in are an integer variable and an array that is indexed by that same integer variable. Think of passing a pointer to swap(i, A[i]) in to a function. Now that every time swap is referenced, it’s reevaluated. Say i := 1 and A[i] := 2, so every time swap is referenced it'll return the other combination of the values ([1,2], [2,1], [1,2] and so on). Another problematic situation is passing a random function.

ALGOL 68 was defined using a two-level grammar formalism invented by Adriaan van Wijngaarden and which bears his name. Van Wijngaarden grammars use a context-free grammar to generate an infinite set of productions that will recognize a particular ALGOL 68 program; notably, they are able to express the kind of requirements that in many other programming language standards are labelled “semantics” and have to be expressed in ambiguity-prone natural language prose, and then implemented in compilers as ad hoc code attached to the formal language parser.

Algol 68 is substantially different from Algol 60 but was not well received, so that in general “Algol” means Algol 60 and dialects thereof. Fragments of ALGOL-like syntax are sometimes still used as pseudocode.

Code sample comparisons

ALGOL 60. The way the bold text has to be written depends on the implementation, e.g. ‘INTEGER’ (including the quotation marks) for integer; this is known as stropping.

procedure Absmax(a) Size:(n, m) Result:(y) Subscripts:(i, k);

   value n, m; array a; integer n, m, i, k; real y;

comment The absolute greatest element of the matrix a, of size n by m

is transferred to y, and the subscripts of this element to i and k;

begin integer p, q;

   y := 0; i := k := 1;

   for p:=1 step 1 until n do

   for q:=1 step 1 until m do

       if abs(a[p, q]) > y then

           begin y := abs(a[p, q]);

           i := p; k := q


end Absmax

ALGOL 68. The following code sample is ALGOL 68 version of the above ALGOL 60 code sample. ALGOL 68 reuses ALGOL 60’s stropping. In ALGOL 68’s case tokens with the bold typeface are reserved words, types (modes) or operators.

proc abs max = ([,]real a, ref real y, ref int i, k)real:

comment The absolute greatest element of the matrix a, of size a by 2a

is transferred to y, and the subscripts of this element to i and k; comment


  real y := 0; i := a; k := 2a;

  for p from a to a do

    for q from 2a to 2a do

      if abs a[p, q] > y then

          y := abs a[p, q];

          i := p; k := q





end # abs max #

Though Algol implemented some novel concepts, such as recursive calling of functions, the next version of the language, Algol 68, became bloated and difficult to use. This lead to the adoption of smaller and more compact languages, such as Pascal.

5.2 Pascal2

Pascal was begun as an extension to ALGOL in 1968 by Niklaus Wirth, and was first published in 1970. The language is named after the famous 17th-century French mathematician and philosopher Blaise Pascal.

Development of Pascal was mainly out of necessity for a good teaching tool. In the beginning, the language designers had no hopes for it to enjoy widespread adoption. Instead, they concentrated on developing good tools for teaching such as a debugger and editing system and support for common early microprocessor machines which were in use in teaching institutions.

Wirth’s intention was to create an efficient language (regarding both compilation speed and generated code). Pascal is a highly-structured, strongly-typed programming language. Pascal was designed in a very orderly approach, it combined many of the best features of the languages in use at the time, COBOL, FORTRAN, and ALGOL. While doing so, many of the irregularities and oddball statements of these languages were cleaned up, which helped it gain users. The combination of features, input/output and solid mathematical features, made it a highly successful language.

Pascal has its roots in the ALGOL 60 language, but also introduced concepts and mechanisms which (on top of ALGOL’s scalars and arrays) enabled programmers to define their own complex (structured) datatypes, 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. Similar mechanisms are standard in many programming languages today.

Pascal also added a CASE statement, that allowed instructions to branch like a tree in such a manner:

CASE expression OF


              statements to execute...


              statements to execute...


Pascal, like many programming languages of today (but unlike most languages in the C family), allows nested procedure definitions to any level of depth, and also allows most kinds of definitions and declarations inside subroutines (procedures and functions). This enables a very simple and coherent syntax where a complete program is syntactically nearly identical to a single procedure or function (except for the heading, which has one of these three keywords).

Wirth later created a successor to Pascal, Modula-2, but by the time it appeared, C was gaining popularity and users at a rapid pace.

The Pascal language has been extended many times by different groups. Borland Turbo Pascal is among the better known extensions, featuring one of the fastest compilers for PCs at the time. Turbo Pascal also popularized the usage of object oriented programming in the Pascal language.

In the 1970’s and 80’s, Pascal became very popular, particularly in the academic field. However, its popularity started to wane when many universities and businesses began using the newly created UNIX operating system, which was programmed in the C language. Many university classes and other users switched from Pascal to C to take advantage of the new system. Another major user of Pascal, Apple, would also eventually switch to C and Objective-C.

5.2.1 Borland Turbo Pascal3

Turbo Pascal is a complete development system that includes a compiler and an Integrated Development Environment (IDE) for the Pascal programming language running mainly on MS-DOS, developed by Borland under Philippe Kahn’s leadership. The name Borland Pascal was generally reserved for the high end packages (with more libraries and standard library source code) while the original cheap and widely known version was sold as Turbo Pascal. The name Borland Pascal is also used more generically for Borland’s dialect of Pascal.

Borland has released three versions of Turbo Pascal for free: versions 1.0, 3.02 and 5.5.

Motivation for Turbo Pascal.

Philippe Kahn first saw an opportunity for Borland, his newly formed software company, in the field of programming tools. Historically, the vast majority of programmers saw their work flow in terms of the edit/compile/link cycle, with separate tools dedicated to each task. Programmers wrote code in a text editor, a compiler created object code from source (often requiring multiple passes), and a linker combined object code with runtime libraries to produce an executable program. This cycle was the result of limited computer power and small amounts of memory.

In the IBM PC market of the early 1980s, the major programmer tool vendors included IBM, Microsoft, and Lattice. They all made C compilers (and some made Pascal compilers), which all worked in a similar fashion. For example, the Microsoft Pascal system consisted of two compiler passes and a final linking pass (which could take minutes on systems with only floppy disks for secondary storage). This process was the cumbersome product of the extremely limited resources of the early IBM PC models. Vendors of software development tools aimed their products at professional developers, and the price for these basic tools plus ancillary tools like profilers ran into the hundreds of dollars.

Kahn’s idea was to integrate these separate functions in a programming toolkit, have it run with much better performance, and charge one low price for it all. Instead of selling the kit through established sales channels (retailers or resellers), his new tool would be sold inexpensively via mail-order. Turbo Pascal is generally considered to be the first popular Integrated Development Environment (IDE) of any type.

As an additional selling point against the bigger vendors, Turbo Pascal disks came with no copy protection of any sort. Turbo Pascal came with the famous “Book License”: “You must treat this software just like a book ... may be used by any number of people ... may be freely moved from one computer location to another”. Since the first versions didn't have online help, copy protection was effectively enforced by possession of the Turbo Pascal reference manual.

Turbo Pascal v1.0. Turbo Pascal 1.0 was very fast compared to other microcomputer Pascal compilers. Turbo Pascal 1.0 was not only fast but also compact due to the lack of EXE support — the compiler was a single COM file, about 38 kilobytes long. This file included the editor, compiler, linker, and all of the library routines. The edit/compile/run cycle was fast compared to other Pascal implementations, because everything related to building the program was stored in RAM. Writing a built program to disk was an additional menu option.

When the first version of Turbo Pascal appeared on November 20 1983, the type of IDE it used was relatively new. On its debut in the American market, Turbo Pascal retailed for USD$49.99. The integrated Pascal compiler also was of very good quality compared to other Pascal products of the time and was affordable above all. The “Turbo” name alluded to its compilation speed as well as the speed of the executables it produced. The speed of these “com” executable files was a revelation for developers whose only previous experience programming the PC was with Microsoft’s BASIC.

The IDE was incredible for its day, a day of extremely limited resources for the typical IBM PC. It was simple and intuitive, and it had a menu system that was well organized. Early versions used the WordStar control key layout, which was the de facto standard because of WordStar's wide use. Later versions of the IDE, designed for later PCs with more disk space and memory, had the ability to instantly look up the definitions of the keywords of the language just by putting the cursor over a keyword and hitting the help button. The definitions also frequently included example code that used the keyword. This enabled the inexperienced programmer to learn Pascal simply by using the IDE, without actually requiring help from a book.

Later versions. Beginning with version 4.0, released in 1987, the compiler could generate executables in native EXE format under MS-DOS. (Previous versions could generate only COM files.) Along with this, support for the increasingly outdated CP/M operating system was dropped. This version also introduced the first full-screen user interface with pull-down menus. Prior to 4.0, the product had a text-based menu screen and a separate full-screen editor.

Version 5.x introduced the familiar Borland blue screen, which would be the trademark of the company’s MS-DOS compiler tools until the end of this line in the middle 1990s.

Later versions had the ability to easily integrate assembly language within Pascal. The addition of in-line assembly was desirable because assembly provides the lowest human-readable interface to the machine, and allowed a talented assembly programmer to replace the built-in Pascal functions with code that was smaller or faster (or both). The user could single step through a program quite easily, and when they got to an assembler block, they could single step through that too. The user could add watches on variables and registers in an IDE window. Programs using IBM PC graphics mode could flip between graphics and text mode automatically or manually.

On top of all of the previous features, the IDE included a code profiler that could report on which parts of the program were using the most time. The books included with Borland Pascal had detailed descriptions of the Intel assembler language, going so far as to provide the clock cycles required of each instruction. Overall this system, as a whole, made for a relatively pleasant experience when trying to optimize code; the user never had to leave the IDE. This all worked ‘out of the box’ and was put together so simply that a high school student could use it.

Units. Over the years, Borland enhanced not only the IDE, but also the programming language. Borland’s dialect of Pascal became a de facto industry standard (and is still implemented by modern variants like Free Pascal), since ISO standard Pascal proved inadequate for real-world application development.

From version 4.0, the language introduced the concept of Units. Units were used as external function libraries, like the object files used in other languages such as C, but a little more high level (the programmer was able to define what will be visible outside the unit and what not).

Units in Borland’s Pascal were similar to Modula-2’s separate compilation system. In 1987 when Turbo Pascal 4.0 came out, Modula-2 was making inroads as an educational language which could replace Pascal. Borland, in fact, had a Turbo Modula-2 compiler, but this product ran only on CP/M and was never ported to MS-DOS (its user interface was almost identical to that of Turbo Pascal 3.x and earlier). Instead of porting their Modula-2 compiler to MS-DOS, Borland elected to implement separate compilation in their popular Pascal product. Separate compilation was not part of the standard Pascal language, but was already available in UCSD Pascal, which was very popular on 8-bit machines. Turbo Pascal syntax for units appears to have been borrowed from UCSD Pascal. With earlier versions of Turbo Pascal, which ran on primitive PCs, the complexity of software written with the package did not demand it; but with the new ability to generate EXE files, programs of significant complexity were now possible which needed separate compilation.

Object oriented programming. From version 5.5 onwards some object oriented programming features were introduced: classes (confusingly called “objects”), inheritance, and constructors and destructors. The IDE was already augmented with an object browser interface showing relations between objects and methods and allowing the programmer to navigate the modules easily. Some people call these extensions Object Pascal although that is more commonly used as a name for the language underlying Delphi (which has two totally separate OOP systems).

Turbo Pascal 7 and Borland Pascal 7. The last version released was version 7. Borland Pascal 7 contained an IDE and compilers for creating DOS, extended DOS and Windows 3.x programs. Turbo Pascal 7 on the other hand could only create standard DOS programs. It also had a graphical API (the Graph unit) which supported multiple external drivers (BGI files - standing for Borland's Graphics Interface) and provided a mechanism to link these drivers with the EXE, but as it was quite slow and caused unpleasant flickering, interchangeable visual pages were used, which caused overfilling the video memory. Some third party drivers, such as SVGA drivers, were made by fans, but they never gained big popularity, since next-generation tools like Borland C++ and Delphi were on their way at that time.

Windows versions. Two versions of Turbo Pascal for Windows 3.x were released: Turbo Pascal for Windows 1.0 (based on Turbo Pascal 6 but released about 2 years later), and 1.5 (released after Turbo Pascal 7). The Windows compiler included in Borland Pascal 7 was entitled Borland Pascal for Windows' but presumably was from the same code base as TPW 1.5.

All versions built Windows-compatible programs, and featured a Windows-based IDE, as opposed to the traditional DOS-based IDE in Turbo Pascal. The IDE and editor commands conformed with Microsoft Windows user interface guidelines, instead of the classic TP user interface. The support for Windows programs required the use of the ObjectWindowslibrary, similar but different from (the first release of) the Borland C++ sister, radically different from the DOS Turbo Vision environment, and was launched quite late (1992), so it never achieved wide popularity, and was later eclipsed by Delphi.

Mac version.

Borland released Turbo Pascal for Macintosh in 1985. Much like the PC version, it was written in very tight assembly language and had a very powerful IDE, but not a good debugger. Borland did not support this product very well. They did issue a version 1.1, patched to run on the 32-bit clean Macintosh II. The product was dropped not long after.

Sample Code.

Historically, Pascal comments are indicated { like this }, or (* like this *), but later versions of Borland Pascal also supported C++-style comments // like this. The line uses crt; is a Borland specific extension to Pascal. Borland’s Pascal is not case sensitive. This simple program prints the words “Hello World” on the screen.


WriteLn('Hello World');


This asks for a person’s name and prints it on the screen.

program WriteName;


Name:string; { This declares the variable Name as a string }


Write('Please give your name: ');

Readln(Name); { Readln reads the string printed on the screen }

WriteLn('Hello ', Name);


5.2.2 Implementations

1) Delphi. Embarcadero Delphi is a proprietary IDE which uses a dialect of Object Pascal, a much more developed object oriented dialect than that used in Borland Turbo Pascal.

2) Free Pascal. Free Pascal is a free and open source implementation which supports a wide variety of platforms. It features its own Object Pascal dialect similar to that of Delphi, as well as Delphi, Turbo, and Mac Pascal compatibility. The project also develops two IDEs: the text-based FreeVision IDE, and the Delphi-like Lazarus IDE.

3) Code Typhon is a Pascal IDE built as extended version of Lazarus with a lot of packages shipped and scripts to build FPC cross compilers provided. Code Typhon was designed in free pascal and supports Object Pascal, Turbo Pascal and Delphi too. Programmers could build any program for any device.

4) GNU Pascal. GNU Pascal is another free and open source Pascal implementation, maintained as part of the GNU project and built upon GCC. It focuses more on supporting the ISO Pascal standards, with several features from ISO Standard and Extended Pascal which other modern Pascal dialects like Free Pascal and Delphi do not support. The Dev-Pascal IDE supports the GNU Pascal dialect.

5) Kylix was a descendant of Delphi, with support for the Linux operating system and an improved object library. It is no longer supported. Compiler and IDE are available now for non-commercial use.

5.3 C4

C is an imperative (procedural) language. It was designed to be compiled using a relatively straightforward compiler, to provide low-level access to memory, to provide language constructs that map efficiently to machine instructions, and to require minimal run-time support. C was therefore useful for many applications that had formerly been coded in assembly language, such as in system programming.

Despite its low-level capabilities, the language was designed to encourage cross-platform programming. A standards-compliant and portably written C program can be compiled for a very wide variety of computer platforms and operating systems with few changes to its source code. The language has become available on a very wide range of platforms, from embedded microcontrollers to supercomputers.

C was developed in 1972 by Dennis Ritchie while working at Bell Labs in New Jersey. The origin of C is closely tied to the development of the Unix operating system. At that year a great part of Unix was rewritten in C. By 1973, with the addition of struct types, the C language had become powerful enough that most of the Unix kernel was now in C. The new language was named “C” because its features were derived from “B”, which was a stripped-down version of the BCPL programming language.

The transition in usage from the first major languages to the major languages of today occurred with the transition between Pascal and C. All of the features of Pascal, including the new ones such as the CASE statement are available in C. C uses pointers extensively and was built to be fast and powerful at the expense of being hard to read. But because it fixed most of the mistakes Pascal had, it won over former-Pascal users quite rapidly.

C and Unix go hand in hand. Unix was one of the first operating system kernels implemented in a language other than assembly. Unix gives C such advanced features as dynamic variables, multitasking, interrupt handling, forking, and strong, low-level, input-output. Because of this, C is very commonly used to program operating systems such as Unix, Windows, the MacOS, and Linux.

C is one of the most widely used programming languages of all time, and C compilers are available for the majority of available computer architectures and operating systems. Many later languages have borrowed directly or indirectly from C, including D, Go, Rust, Java, JavaScript, Limbo, LPC, C#, Objective-C, Perl, PHP, Python, Verilog (hardware description language), and Unix's C shell. These languages have drawn many of their control structures and other basic features from C. Most of them (with Python being the most dramatic exception) are also very syntactically similar to C in general, and they tend to combine the recognizable expression and statement syntax of C with underlying type systems, data models, and semantics that can be radically different. C++ and Objective-C started as compilers that generated C code; C++ is currently nearly a superset of C, while Objective-C is a strict superset of C.

Before there was an official standard for C, many users and implementers relied on an informal specification contained in a book by Dennis Ritchie and Brian Kernighan. In 1978, Brian Kernighan and Dennis Ritchie published the first edition of The C Programming Language. This book, known to C programmers as “K&R”, served for many years as an informal specification of the language. The version of C that it describes is commonly referred to as K&R C. The second edition of the book covers the later ANSI C standard. In 1989 the American National Standards Institute published a standard for C (generally called “ANSI C” or “C89”). The next year, the same specification was approved by the International Organization for Standardization as an international standard (generally called “C90”). ISO later released an extension to the internationalization support of the standard in 1995, and a revised standard (known as “C99”) in 1999. The current version of the standard (now known as “C11”) was approved in December 2011.

Sample program.

The “hello, world” example, which appeared in the first edition of K&R, has become the model for an introductory program in most programming textbooks, regardless of programming language. The program prints “hello, world” to the standard output, which is usually a terminal or screen display.

The original version was:



   printf("hello, world\n");


A standard-conforming “hello, world” program is:

#include <stdio.h>


int main(void)


   printf("hello, world\n");


1 http://en.wikipedia.org/wiki/ALGOL

2 https://wiki.installgentoo.com/index.php?title=Pascal

3 http://borlandpascal.wikia.com/wiki/Borland_Pascal

4 http://en.wikipedia.org/wiki/C_(programming_language)


А также другие работы, которые могут Вас заинтересовать

55174. Об’єднання текстів, введення колонтитулів, розміщення тексту на сторінках 906.5 KB
  Короткі теоретичні відомості Створені документи зберігаються у файлах і відповідних папках. Через деякий час може виникнути потреба у роботі над вже готовим документом. Щоб відкрити потрібний документ необхідно виконати такі дії:...
55175. Довідково-інформаційні документи 32 KB
  Пресреліз. Що таке пресреліз Які є види пресрелізів 3. Назвіть основні реквізити пресрелізів. Які існують вимоги до написання пресрелізів 5.
55176. Приватизация и структурная перестройка в переходной экономике 24.9 KB
  Переход к рыночной экономике – это как бы двусторонний процесс. С одной стороны, прежде всего необходимо сформировать собственно «рынок», систему рыночных связей: обеспечить свободное ценообразование, свободу торговли, конкурентные отношения...
  В каждом варианте задания необходимо определить требуемые входные и выходные данные , для вычисления предложенных функций составить схемы алгоритмов и программы решения задач. Предусмотреть печать всех входных и выходных данных.
55178. Створення документу зі складним обрамленням за допомогою редактора Word 82.5 KB
  Мета: Формувати уміння і навички обрамлення окремих частин таблиці виділення заголовків обєднання чарунок таблиці. Постановка загальної проблеми: Як при допомозі текстового редактора Word створювати таблиці із складним обрамленням І.
  Цена и ценовая политика в комплексе маркетинга туристского предприятия. Методы ценообразования. Виды скидок в туризме. Ценовые стратегии туристского предприятия.
55181. Вставка в текстовий документм Word таблиці із складним обрамленням, списків та схем для створення накладних 67.5 KB
  Мета: Формувати уміння і навички вставки сітки таблиці для створення документів в яких текст розташований в декілька стовпчиків. Пересуваючись вздовж або поперек таблиці можна обстежити деяку групу комірок встановлювати курсор на будьяку комірку таблиці вносити в неї нову інформацію або редагувати існуючу.