Changes

Jump to navigation Jump to search
m
no edit summary
Line 1: Line 1: −
'''Pascal''' is a computer programming language created by Prof. Nicholas Wirth in 1970. It became widely popular with the release of Borland's Turbo Pascal, an integrated editor and compiler for Pascal on MSDOS, in 1981. Pascal was eventually made an ISO standard (ISO 7185).
+
[[File:Niklaus Wirth.jpg|right|200px|thumb|Prof. Niklaus Wirth.]]
 +
'''Pascal''' is a [[computer]] [[programming language]] created by Prof. Niklaus Wirth, and published in 1970. It became widely popular with the release of Borland's [[Turbo Pascal]], an integrated editor and compiler for Pascal on [[MS DOS]], in 1981. Pascal was eventually made an ISO standard (ISO 7185).
 +
 
 +
== Description ==
 +
Pascal uses a series of ''statements'', which, like [[BASIC (programming language)|BASIC]], are English-like words.
 +
Statements can wrap onto multiple lines, and each statement is terminated by a semi-colon or the reserved word '''end'''.
 +
 
 +
Statements may be simple or compound.
 +
A simple assignment statement is:
 +
 
 +
{{tt|1=a:=3;}}
 +
 
 +
A loop statement that appends characters to a string might look like the following:
 +
 
 +
{{tt|1=for i:=1 to 6 do s:=s+' more';}}
 +
 
 +
The {{tt|for}} statement executes the assignment statement each time through the loop.
 +
If the loop is to execute more than one statement, they are incorporated into a compound statement, bracketed by {{tt|begin}} and {{tt|end}} reserved words:
 +
 
 +
<code>
 +
  for i:=1 to 6 do
 +
  begin
 +
    s:=s+' more';
 +
    count:=count+1;
 +
    y:=y-3;
 +
  end;
 +
</code>
    
==Technical Summary==
 
==Technical Summary==
Pascal, as defined by Wirth, is a general-purpose programming language with the following '''reserved words''': array, begin, case, const, do, downto, else, end, file, for, function, goto, if, label, nil, of, packed, procedure, program, record, repeat, set, then, to, type, until, var, while, with.  The following reserved words are '''operators''': and, or, not, div, mod, in.  Built in simple '''data types''': integer, char, boolean, real.  In addition, arrays of data types, files of data types, and records (structures) can be defined, as well as enumerations (called scalars).  Unique among major programming languages is the support of '''sets'''.  Built-in '''functions''': abs, arctan, chr, cos, eof, eoln, exp, ln, odd, ord, pred, round, sin, sqr, sqrt, succ, trunc.  Build-in '''procedures''': dispose, get, new, put, read, readln, reset, rewrite, write, writeln.  '''Operators''': + - * ( ) < > = <> >= <=
+
Pascal, as defined by Wirth, is a general-purpose programming language with the following '''reserved words''': array, begin, case, const, do, downto, else, end, file, for, function, goto, if, label, nil, of, packed, procedure, program, record, repeat, set, then, to, type, until, var, while, with.  The following reserved words are '''operators''': and, or, not, div, mod, in.  Built in simple '''data types''': integer, char, boolean, real.  In addition, arrays of data types, files of data types, and records (structures) can be defined, as well as enumerations (called scalars).  Unique among major programming languages is the support of '''sets'''.  Built-in '''functions''': abs, arctan, chr, cos, eof, eoln, exp, ln, odd, ord, pred, round, sin, sqr, sqrt, succ, trunc.  Build-in '''procedures''': dispose, get, new, put, read, readln, reset, rewrite, write, writeln.  '''Operators''': + - * ( ) < > = <> <= >=  
    +
A major fault in the original definition of Pascal was the lack of string support.  Namely, strings are packed arrays of chars, with minimal string-specific support.  This shortcoming has been addressed by every modern Pascal compiler, which provide well-supported native string data types.
   −
A major fault in the original definition of Pascal was the lack of string supportNamely, strings are packed arrays of chars, with minimal string-specific supportThis shortcoming has been addressed by every modern Pascal compiler, which provide well-supported native string data types.
+
== Sets ==
 +
 
 +
In Pascal, a '''set''' is a collection of ordinal values of the same type.
 +
Operators can test for the existence of a value in a set, ''and'' or ''or'' two sets together, compare sets, and do other operations.
 +
The following code shows an example of declaring and using a set, in this case of the days of the month that are Sundays.
 +
type
 +
  DaysOfMonthSet = set of 1..31; {Declare type as a set representing the days of a month}
 +
 +
 +
procedure Demo;
 +
var  SundaysInMonth: DaysOfMonthSet;  {Declare variable of type DaysOfMonthSet}
 +
      DaysWorked:    DaysOfMonthSet;  {And another}
 +
      Day: Byte;  {Declare 8-bit variable to hold a day of the month}
 +
begin
 +
  SundaysInMonth:=[2,9,16,23,30];    {Allocate the 2nd, 9th, etc. of month to the set SundaysInMonth.}
 +
  DaysWorked:=[10..14, 17..21];      {Allocate two ranges of dates to the set DaysWorked.}
 +
  ...
 +
  if Day in SundaysOfMonth          {'in' operator tests for a value in a set.}
 +
    then writeln('Day is a Sunday')
 +
    else writeln('Day is not a Sunday');
 +
  ...
 +
  if DaysWorked * SundaysInMonth = []    {'*' operator ''ands'' both sets together'[]' is an empty set.}
 +
    then writeln('No Sunday shifts worked.');
 +
end;
    
==References==
 
==References==
*[http://www.cacs.louisiana.edu/~mgr/404/burks/language/oberon/obhist/history.htm A brief History of Pascal]
   
*[http://www.bitwisemag.com/2/Delphi-Study-Guide.html Delphi Study Guide]
 
*[http://www.bitwisemag.com/2/Delphi-Study-Guide.html Delphi Study Guide]
 
*Jensen, K. and Wirth, N., Pascal User Manual and Report, Springer-Verlag, 1976.
 
*Jensen, K. and Wirth, N., Pascal User Manual and Report, Springer-Verlag, 1976.
 
*ISO 7185:1990
 
*ISO 7185:1990
   −
[[Category:Information technology]]
+
[[Category:Programming Languages]]
[[Category:computer science]]
+
[[Category:Computers]]
SkipCaptcha
292

edits

Navigation menu