Pascal Regina Bellamy Katitia Eaddy Corinthia Cunningham Anthony Mancuso
Problem Domain Designed to be efficient and concise First developed for instructional use Later extended for more wide-spread use
Historical Context Developed by Nicklaus Wirth after Algol-W passed up for Algol-68 Named after Blaise Pascal, a French mathematician Direct descendent from Algol-60 and Algol-W in 1971 Used from the late 60s to the late 80s for teaching programming, which it was originally designed for
Evolution of the Language Pascal was extended to better support the needs of programmers Pascal-P (Portable) was created to allow code to be ported to various operating systems (virtual machine!) Borland and Apple created object-oriented extensions in the 1990s Borland then created Delphi, which uses Pascal as its programming language ML and Modula are descended from Pascal
Language Concepts Case-insensitive Semicolon as a separator Functions and procedures Variable-length strings vs. arrays of characters Record (borrowed from COBOL) Repeat..until (do..while in C) In
Example 1 – A Sample Program Program ArithFunc; const Sentinel = 0.0; var X : Real; begin writeln(‘Enter a real number, 0.0 to stop’); writeln; writeln(‘X’, ‘Trunc(x)’ :16, ‘Round(x)’ :10, ‘Sqrt(Abs(X))’ :15); readln(X); while X <> Sentinel do begin writeln(Trunc(X) :17, Round(X) :10, Abs(X) :10:2, Sqrt(X) :10:2); readln(X) end end. Reference:
Example 2 – Using Procedures Program Something; procedure DoSomethingElse(x : real); begin writeln(‘Displaying half of your number: ’, x / 2) end; procedure DoSomething; var x : real; begin writeln(‘Enter a number.’); readln(x); DoSomethingElse(x) end; begin DoSomething end.
Example 3 – While Version Program FactorialWhile; var n, fact : integer; begin writeln(‘Enter n to compute n!.’); readln(n); fact := 1; while n > 1 do begin fact := fact * n; n := n – 1 end end.
Example 3 – Repeat Version Program FactorialRepeat; var n, fact : integer; begin writeln(‘Enter n to compute n!.’); readln(n); if n > 0 then begin fact := 1; repeat fact := fact * n; n := n – 1; until n = 0; end end.
Example 3 – Downto Version Program FactorialFor; var n, i, fact : integer; begin writeln(‘Enter n to compute n!.’); readln(n); fact := 1; for i := n downto 1 do fact := fact * i end.
Comparison to Algol Designed to be simpler than its ancestor Algol-60 was the first block-structured language Foundation provided by Algol-W
Comparison to C Record vs. struct Variable-length string vs. char[] Begin..end vs. { } Pascal is more strongly typed Pascal allows nested function definitions