144 lines
5.0 KiB
HTML
144 lines
5.0 KiB
HTML
<html>
|
|
<head>
|
|
<link rel=stylesheet type="text/css" href="styles.css">
|
|
</head>
|
|
<body>
|
|
<H2>
|
|
paxCompiler for Delphi. Evaluate expression.
|
|
</H2>
|
|
<hr>
|
|
|
|
|
|
<blockquote>
|
|
|
|
<pre>
|
|
<font color="blue"><b>unit</b></font> Unit1;
|
|
|
|
<font color="blue"><b>interface</b></font>
|
|
|
|
<font color="blue"><b>uses</b></font>
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|
Dialogs, StdCtrls, PaxCompiler;
|
|
|
|
<font color="blue"><b>type</b></font>
|
|
TForm1 = <font color="blue"><b>class</b></font>(TForm)
|
|
Button1: TButton;
|
|
Button2: TButton;
|
|
<font color="blue"><b>procedure</b></font> Button1Click(Sender: TObject);
|
|
<font color="blue"><b>procedure</b></font> Button2Click(Sender: TObject);
|
|
<font color="blue"><b>procedure</b></font> FormCreate(Sender: TObject);
|
|
<font color="blue"><b>private</b></font>
|
|
{ Private declarations }
|
|
arr_x, arr_y: <font color="blue"><b>array</b></font>[1..3] <font color="blue"><b>of</b></font> Double;
|
|
h_norm, h_x, h_y: Integer;
|
|
|
|
buff: <font color="blue"><b>array</b></font>[1..4096] <font color="blue"><b>of</b></font> Byte;
|
|
<font color="blue"><b>public</b></font>
|
|
{ Public declarations }
|
|
<font color="blue"><b>end</b></font>;
|
|
|
|
<font color="blue"><b>var</b></font>
|
|
Form1: TForm1;
|
|
|
|
<font color="blue"><b>implementation</b></font>
|
|
|
|
{$R *.dfm}
|
|
|
|
<font color="blue"><b>function</b></font> Norm(x, y: Double): Double;
|
|
<font color="blue"><b>begin</b></font>
|
|
result := Sqrt(x * x + y * y);
|
|
<font color="blue"><b>end</b></font>;
|
|
|
|
<font color="blue"><b>procedure</b></font> TForm1.Button1Click(Sender: TObject);
|
|
<font color="blue"><b>var</b></font>
|
|
PaxCompiler1: TPaxCompiler;
|
|
PaxPascalLanguage1: TPaxPascalLanguage;
|
|
PaxProgram1: TPaxProgram;
|
|
I: Integer;
|
|
<font color="blue"><b>begin</b></font>
|
|
PaxCompiler1 := TPaxCompiler.Create(<font color="blue"><b>nil</b></font>);
|
|
PaxPascalLanguage1 := TPaxPascalLanguage.Create(<font color="blue"><b>nil</b></font>);
|
|
PaxProgram1 := TPaxProgram.Create(<font color="blue"><b>nil</b></font>);
|
|
|
|
<font color="blue"><b>try</b></font>
|
|
PaxCompiler1.Reset;
|
|
PaxCompiler1.RegisterLanguage(PaxPascalLanguage1);
|
|
|
|
h_norm := PaxCompiler1.RegisterRoutine(0, <font color="Red">'Norm'</font>, _typeDOUBLE, _ccREGISTER);
|
|
PaxCompiler1.RegisterParameter(h_norm, _typeDOUBLE, Unassigned);
|
|
PaxCompiler1.RegisterParameter(h_norm, _typeDOUBLE, Unassigned);
|
|
|
|
h_x := PaxCompiler1.RegisterVariable(0, <font color="Red">'x'</font>, _typeDOUBLE);
|
|
h_y := PaxCompiler1.RegisterVariable(0, <font color="Red">'y'</font>, _typeDOUBLE);
|
|
|
|
<font color="blue"><b>if</b></font> PaxCompiler1.CompileExpression(<font color="Red">'Norm(x, y)'</font>, PaxProgram1) <font color="blue"><b>then</b></font>
|
|
<font color="blue"><b>begin</b></font>
|
|
PaxProgram1.SaveToBuff(buff);
|
|
ShowMessage(<font color="Red">'Compiled expression has been created!'</font>);
|
|
<font color="blue"><b>end</b></font>
|
|
<font color="blue"><b>else</b></font>
|
|
<font color="blue"><b>for</b></font> I:=0 <font color="blue"><b>to</b></font> PaxCompiler1.ErrorCount - 1 <font color="blue"><b>do</b></font>
|
|
ShowMessage(PaxCompiler1.ErrorMessage[I]);
|
|
<font color="blue"><b>finally</b></font>
|
|
PaxCompiler1.Free;
|
|
PaxPascalLanguage1.Free;
|
|
PaxProgram1.Free;
|
|
<font color="blue"><b>end</b></font>;
|
|
<font color="blue"><b>end</b></font>;
|
|
|
|
<font color="blue"><b>procedure</b></font> TForm1.Button2Click(Sender: TObject);
|
|
<font color="blue"><b>var</b></font>
|
|
PaxProgram1: TPaxProgram;
|
|
ResValue: Double;
|
|
I: Integer;
|
|
<font color="blue"><b>begin</b></font>
|
|
{$O-}
|
|
<font color="blue"><b>if</b></font> h_x <> 0 <font color="blue"><b>then</b></font>
|
|
<font color="blue"><b>begin</b></font>
|
|
PaxProgram1 := TPaxProgram.Create(<font color="blue"><b>nil</b></font>);
|
|
<font color="blue"><b>try</b></font>
|
|
PaxProgram1.LoadFromBuff(buff);
|
|
|
|
PaxProgram1.SetAddress(h_norm, @norm);
|
|
|
|
<font color="blue"><b>for</b></font> I:=1 <font color="blue"><b>to</b></font> 3 <font color="blue"><b>do</b></font>
|
|
<font color="blue"><b>begin</b></font>
|
|
PaxProgram1.SetAddress(h_x, @arr_x[I]);
|
|
PaxProgram1.SetAddress(h_y, @arr_y[I]);
|
|
|
|
PaxProgram1.Run;
|
|
|
|
ResValue := Double(PaxProgram1.ResultPtr^);
|
|
ShowMessage(FloatToStr(ResValue));
|
|
<font color="blue"><b>end</b></font>;
|
|
|
|
<font color="blue"><b>finally</b></font>
|
|
PaxProgram1.Free;
|
|
<font color="blue"><b>end</b></font>;
|
|
<font color="blue"><b>end</b></font>
|
|
<font color="blue"><b>else</b></font>
|
|
ShowMessage(<font color="Red">'Press the first button to create compiled script.'</font>);
|
|
<font color="blue"><b>end</b></font>;
|
|
|
|
<font color="blue"><b>procedure</b></font> TForm1.FormCreate(Sender: TObject);
|
|
<font color="blue"><b>begin</b></font>
|
|
h_x := 0; h_y := 0; h_norm := 0;
|
|
arr_x[1] := 4.2; arr_y[1] := -5.2;
|
|
arr_x[2] := -0.4; arr_y[2] := 3.2;
|
|
arr_x[3] := 2.0; arr_y[3] := 3;
|
|
<font color="blue"><b>end</b></font>;
|
|
|
|
<font color="blue"><b>end</b></font>.
|
|
</pre>
|
|
</blockquote>
|
|
|
|
|
|
<p>
|
|
<HR>
|
|
<font size = 1 color ="gray">
|
|
Copyright © 2006-2009
|
|
VIRT Laboratory. All rights reserved.
|
|
</font>
|
|
</body>
|
|
</html>
|