paxPascal implements a subset of Object Pascal. For example, the following script is admissible:
program P; type TMyClass = class; TMyArray = array[1..3] of String; TMyClass = class(TObject) private function GetProp: Integer; public function MyFunc(U: Integer; V: Integer): Integer; procedure MyProc; property MyProp: Integer read GetProp; end; TMyRec = record X, Y: Integer; end; function GlobalFunc: Integer; forward; function TMyClass.MyFunc(U: Integer; V: Integer): Integer; begin result := U + V + GlobalFunc; end; procedure TMyClass.MyProc; begin writeln('here'); end; function TMyClass.GetProp: Integer; begin result := 11; end; function GlobalFunc: Integer; begin result := 700; end; var X: TMyClass; A: TMyArray; R: TMyRec; begin X := TMyClass.Create; A[1] := 'abc'; A[2] := 'pqr'; A[3] := 'uv'; R.X := 100; writeln(X.MyFunc(4, 5)); X.MyProc; writeln(X.MyProp); writeln(R.X); end;
From another hand, paxPascal has a few extra features which are absent in the Object Pascal.
A paxPascal program is the list of statements. In this relation, paxPascal is more similar with
VBScript or JavaScript.
For example, the following script
Program Structure
contains four executable statements:
program P;
type
TMyRec = record
X, Y: Integer;
end;
var
R: TMyRec;
begin
print R;
end.
program P;
Creates namespace P.
type
TMyRec = record
X, Y: Integer;
end;
Creates record type TMyRec.
var
R: TMyRec;
Creates variable R.
print R;
Printes variable R.
Declaration of Variables
is equivalent to
function MyFunc(X);
var Y;
begin
Y := Random(100);
result := X + Y + Y;
end;
function MyFunc(X: Variant): Variant;
var Y: Variant;
begin
Y := Random(100);
result := X + Y + Y;
end;
procedure MyProc;
var
X: Integer = Random(100);
Y = 54.3;
begin
..................
end;
Class Types
type
TFoo = class (TObject)
class var X: String;
class function F(): Integer;
class procedure P();
end;
type
TMyClass = class(TObject)
X: Integer = 100;
S: String = 'abc';
constructor Create;
........................
end;
Note, that you cannot use nested routines in such case. If you want to use the nested routines
inside of the method body, you must define such method outside of the class declaration.
type
TMyForm = class(TForm)
constructor Create(Owner: TComponent);
begin
inherited;
Top := 100;
Left := 200;
Caption := 'MyForm';
end;
end;
Record Types
Note, that you cannot use nested routines in such case. If you want to use the nested routines
inside of the method body, you must define such method outside of the record declaration.
type
TPoint = record
private
function GetNorm: Integer;
begin
result := X*X + Y*Y;
end;
public
X, Y: Integer;
property Norm: Integer read GetNorm;
end;
type
TRandomPoint = record
X: Integer = Random(100);
Y: Integer = Random(100);
end;
type
TRandomPoint = record
X, Y: Integer;
procedure Initialize;
begin
X := Random(100);
Y := Random(100);
end;
end;
type
TRandomCircle = record (TRandomPoint)
R: Integer = Random(100);
end;
Array Types
The native array is multi-dimensional zero-based array with elements of Variant type.
var A[10, 2];
This kind of arrays is derived from native arrays at compile-time. For example, declaration
type
TMyArray[1..2, 3..5] of TPoint;
is equivalent to
type
TMyArray = array [3..5] of Integer;
type TMyArray = record
var L = 3;
var H = 5;
var fItems[H - L];
procedure Initialize;
var
I: Integer;
begin
for I:=L to H do
fItems[I - L] := 0;
end;
function GetItem(I: Integer): Integer;
begin
result := @ fItems[I - L];
end;
procedure SetItem(I: Integer; Value: Integer);
begin
fItems[I - L] := Value;
end;
property Items[I: Integer]: Integer; read GetItem write SetItem; default;
end;
procedure P(N: Integer);
var
A: array[3..N] of Double;
begin
...............
end;
Namespaces
paxPascal supports namespaces. For example:
namespace Shapes
type
TPoint = class(TObject)
X, Y: Integer;
constructor Create(X, Y: Integer);
begin
inherited Create;
Self.X := X;
Self.Y := Y;
end;
end;
TCircle = class(TPoint)
R: Integer;
constructor Create(X, Y, R);
end;
constructor TCircle.Create(X, Y, R);
begin
inherited Create(X, Y);
Self.R := R;
end;
end;
var
Point = Shapes.TPoint.Create(3, 5);
Circle = Shapes.TCircle.Create(3, 5, 7);
begin
print Point, Circle;
end.
Regular Expressions
paxPascal supports the regular expression literals. For example:
Output:
var r = /[_a-zA-Z\d\-\.]+@[_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+/g;
s = 'My e-mails are ab@virtlabor.donbass.com and ppusr154@ints.net';
repeat
if r.exec(s).length = 0 then
Break
else
begin
writeln(r[0]);
writeln(r.MatchPos[0]);
writeln(r.MatchLen[0]);
writeln(r.LastIndex);
end;
until false;
ab@cable.netlux.org
16
24
41
ppusr154@ints.net
45
17
63
Strings
Double quoted string constants are allowed.
You can use backslasges to represent special characters:
const s: String = "My name is 's' ";
Long string literals are allowed:
const z: String = 'Two \n lines';
You can use string literals with parameters. For example:
const s: String = """This
is a long
string literal""";
It is equivalent to:
print '''
First Name: %s
Last Name: %s
''' with ['Ivan', 'Sidorov'];
print Format ('''
First Name: %s
Last Name: %s
''', ['Ivan', 'Sidorov'] );
Forward Declarations
You need no to use forward declarations in paxPascal. In another words, you can use a function
call before declaration of the function. For example:
Fact(5);
function Fact(N: Integer): Integer;
begin
if N = 1 then
result := 1
else
result := N * Fact(N - 1);
end;
Control Structures
The Break statement permits optional label that causes the flow of control to
exit an outer for, while, or repeat statement and continue at the next statement.
Output:
var
I, J: Integer;
label
Outer;
begin
print 'Start';
Outer:
for I:=1 to 3 do
for J:=1 to 4 do
begin
if (I = 2) and (J = 3) then
Break Outer;
print I, J;
end;
end;
The Continue statement permits optional label that causes
the flow of control to proceed to the next iteration of the outer for, while, or repeat statement.
11
12
13
14
21
22
Output:
var
I, J: Integer;
label
Outer;
begin
print 'Start';
Outer:
for I:=1 to 3 do
for J:=1 to 4 do
begin
if (I = 2) and (J = 3) then
Continue Outer;
print I, J;
end;
end;
11
12
13
14
21
22
31
32
33
34
Embedding Scripts into Html Pages
paxScript is consecutively developing in the direction of the internet programming. You can embed your
paxPascal scripts into html pages as easy as PHP scripts. Click here to see a demo.
Operator Overloading
paxPascal allows you to overload operators "+", "-", "*", "/", "mod", "shl", "shr", "=", "<>", ">", "<",
">=", "<=". Click here, to see an example.
LISPPA
Like other paxScript languages, paxPascal supports LISPPA technology (List
Processing based on the Polymorphic Arrays), a new technology of the processing dynamic data structures
without using pointers.
Syntax
Remember, that paxPascal program is list of statements. Therefore you can disregard Object Pascal
synax rules to make your scripts more laconic. For example, the following scripts are admissible:
print "Hello, world!";
type
TMyRec = record
X, Y: Integer;
end;
var
R: TMyRec;
begin
R.X := 10;
Y.Y := 12;
end;
(this is equivalent of the script above).
record TMyRec
X, Y: Integer;
end;
var
R: TMyRec;
R.X := 10;
Y.Y := 12;
Copyright © 1999-2006
VIRT Laboratory. All rights reserved.