pascal programming language

Available in 1970, over 50 years ago, this is version 3.2.0

this is work in progress, not complete

Learn from examples

1. Program to output a string, integer,  and floating point

  expa1.p source code

{expa1.p  example  print string, character, integer 32, integer 64,}
{                        real, boolean}
program expa1;
var
   s : string;
   c : char;
   i : integer;
   l : int64;
   x : real;
   bt : boolean;
   bf : boolean;
begin
   writeln('expa1.p  running');
   s := 'my string';
   c := 'a';
   i := 1;
   l := 1000000000000;
   x := 3.0e+11;
   bt := true;
   bf := false;
   writeln('string  s = '+s);
   writeln('char    c = '+c);
   {writeln('integer i = '+i);}
   write('integer i = ');
   writeln(i);
   {write('int64   l = '+l);}
   write('int64   l = ');
   writeln(l);
   {writeln('real    x = '+x);}
   write('real    x = ');
   writeln(x);
   {writeln('boolean bt = '+bt);}
   write('boolean bt = ');
   writeln(bt);
   write('boolean bf = ');
   writeln(bf);
   writeln(' ');
   writeln('expa1.p  ends');
end.



  Output from execution:

expa1.p  running
string  s = my string
char    c = a
integer i = 1
int64   l = 1000000000000
real    x =  3.0000000000000000E+011
boolean bt = TRUE
boolean bf = FALSE
 
expa1.p  ends



2. commands to execute the source code
   at a minimum, Windows, Linux, MacOSX.

{expa2.p  commands to execute source code}
program expa2;
   
begin
   writeln('expa2.p  running');
   writeln('pascal can be downloaded and installed, I have 3.2.0');
   writeln('The downloads seem to have the name  fpc  in them ');
   writeln('Windows: ');
   writeln('  I created file  pascal.bat');
   writeln('  "\FPC\3.2.0\bin\i386-win32\ppcrossx64.exe" %1');
   writeln(' ');
   writeln('Linux: ');
   writeln('  I downloaded .tar  for amd linux');
   writeln('  I run ~/fpc-3.2.0/bin/x86_64-linux$/ppcrossarm');
   writeln(' ');
   writeln('MacOSX ');
   writeln('  not tried yet ');
   writeln('expa2.p  ends');
end.

expa2.p  running
pascal can be downloaded and installed, I have 3.2.0
The downloads seem to have the name  fpc  in them 
Windows: 
  I created file  pascal.bat
  "\FPC\3.2.0\bin\i386-win32\ppcrossx64.exe" %1
 
Linux: 
  I downloaded .tar  for amd linux
  I run ~/fpc-3.2.0/bin/x86_64-linux$/ppcrossarm
 
MacOSX 
  not tried yet 
expa2.p  ends


3. You must be able to declare  vector and matrix of various types.

  expa3.p source code

{expa3.p  example  declare and print vector, matrix}
program expa3;
  const
    size = 100;
  type
     vector = array[1..size] of real;
     matrix = array[1..size,1..size] of real;
  var
    v1 : vector;
    MB : matrix;
    i,j,nv,nrow,ncol : integer;
procedure prtvec(var v: vector; var n:integer);
  var
    i: integer;
  begin
    for i:= 1 to n do
      begin
        write('v['); write(i); write(']=');
        writeln(v[i]);
      end;
    writeln(' ');
  end;

procedure prtmat(var A:matrix; var nr:integer; nc:integer);
  var
    i,j: integer;
  begin
    for i:= 1 to nr do
      begin
	for j:=1 to nc do
	  begin
	    write('m['); write(i); write(','); write(j);write(']=');
            writeln(A[i,j]);
	  end
      end;
    writeln(' ');
  end;

begin {main expa3}
   writeln('expa3.p  running');
   v1[1] := 1.0;
   write('v1['); write(1); write(']=');
   writeln(v1[1]);
   v1[2] := 2.0;
   v1[3] := 3.0;
   nv := 3;
   prtvec(v1,nv);
   nrow := 3;
   ncol := 4;
   for i:= 1 to nrow do
     begin
       for j:=1 to ncol do
         begin
	    MB[i,j] := (i*ncol+j)*1.0;
	 end
     end;

   prtmat(MB,nrow,ncol);

   writeln(' ');
   writeln('expa3.p  ends');
end.


Execution output:

expa3.p  running
v1[1]= 1.0000000000000000E+000
v[1]= 1.0000000000000000E+000
v[2]= 2.0000000000000000E+000
v[3]= 3.0000000000000000E+000
 
m[1,1]= 5.0000000000000000E+000
m[1,2]= 6.0000000000000000E+000
m[1,3]= 7.0000000000000000E+000
m[1,4]= 8.0000000000000000E+000
m[2,1]= 9.0000000000000000E+000
m[2,2]= 1.0000000000000000E+001
m[2,3]= 1.1000000000000000E+001
m[2,4]= 1.2000000000000000E+001
m[3,1]= 1.3000000000000000E+001
m[3,2]= 1.4000000000000000E+001
m[3,3]= 1.5000000000000000E+001
m[3,4]= 1.6000000000000000E+001
 
expa3.p  ends



4. You need to be able to have loops, iteration statements

  expa4.p source code

{expa4.p loops and iteration statements }
{ logical operators <  >  =  <>  }
{ logical operators  and  or   not  }   
{ logical constants true  false }
program expa4;
var
   i,j : integer;
   
begin

   writeln('expa4.p  running');
   for i:=1 to 3 do writeln(i);
   writeln(' ');
   for i:=1 to 3 do
     begin
	j := 2*i;
	writeln(j);
     end;
   writeln(' ');
   j := 3;
   while j>0 do
     begin
       writeln(j);
       j := j-1;
     end;
   writeln(' ');
   i:=3;
   repeat i:=i-1; until ( i = 0);
   writeln('i='); writeln(i);
   repeat
     i:= i+1;
     writeln(i);
     if i=3 then { finish early }
       break;
   until (i=5);
      
   writeln(' ');
   writeln('expa4.p  ends');
end.


Execution output:

expa4.p  running
1
2
3
 
2
4
6
 
3
2
1
 
i=
0
1
2
3
 
expa4.p  ends



5. You need  if then else  conditional statements

  expa5.p source code




Execution output:

expa5.p running

expa5.p ends



6. You need to be able to create functions, procedures,
   subroutines.

  expa6.p source code



Execution output:

expa6.p running

expa6.p ends
  

7. You need to be able to read and write files in various formats.

  expa7.p source code


Execution output:

expa7.p running
expa7.p ends



8. You need to be able to use a number of files combined to
   build a program. This may include packages, libraries,
   operating system commands, header files, etc.

  expa8.p source code

{expa8.p  include stuff}
program expa;
   
begin

   writeln('expa8.p  running');

   writeln(' ');
   writeln('expa8.p  ends');
end.


Execution output:

expa8.p  running
 
expa8.p  ends

Other source files with output, you may be interested in

test_math.p source code
test_math_p.out output
Sort.p source code
Sort_p.out output
SortQ.p source code
SortQ_p.out output
mystring.p source code
mystring_p.out output

  
Last updated 3/1/2021