,,,
.
.
, : , , , .
.
, .
.......................................................................................................... 4
1. ............................................................................. 8
1.1. .......... 8
1.2. ............................................................ 10
1.3. .......................... 12
1.3.1 ...... 13
1.3.2. ................ 15
1.3.2.1. ................................... 15
1.3.2.2. ......................................................................... 16
1.3.2.3. ...................................................................... 17
1.3.2.4. ........................................................................ 18
1.3.2.5. . 4
1.3.2.6. ......................................... 4
1.3.2.7. ................................................................... 5
1.4. ...................... 6
1.5. ................. 8
1.6. ........................................................... 8
2. ............................................................................. 10
2.1. -................. 10
2.2. ........................................................ 10
2.2.1. ................................................... 11
2.2.1.1. ................................................... 11
2.2.1.2. ............................................................ 12
2.2.1.3. ............................................. 13
2.2.1.4. ...................................................... 15
2.2.1.5. ............................................................ 15
2.3. .......................................................................... 16
2.3.1. ........................................... 18
2.3.2. .......................................... 19
2.4. , ............... 19
2.4.1. TPrologVariable, TPrologVariables, TPrologVariableList, TPrologVariableStruct.................................................................................... 19
2.5.2. ................................................... 21
2.6. - ........................... 21
2.7. ................................................................................... 23
2.8. . 25
3. .............................................................................. 28
3.1. ............. 28
3.2. ................................................................................. 28
3.3. . 29
3.3.1. .............................................................................. 29
3.3.2. , ....................................... 29
3.3.3. -................................................. 29
3.3.4. ..................................... 34
3.3.5. ...................................................................................... 35
3.4. , . 38
3.5. ...................................................... 39
3.6. - ................ 39
3.7. ....................................................... 40
3.8. .................................................................................. 43
4. - .................................................... 45
4.1. ......................... 45
5. ................................................ 47
5.1. ................................................................................................. 47
5.2. ............................................................................... 48
5.2.1. ....................................................................... 48
5.2.2. .............................................. 50
5.3. , ................................................................................ 52
5.3.1. ................................. 53
5.3.2. , ............................................................................. 54
5.3.3. ........................................................................... 55
5.3.4. ....................... 56
5.3.5 .................................................................. 57
5.3.6. ........................................................ 58
5.3.7. ............................... 58
5.3.8. ..................................... 59
5.4. , ......... 60
5.4.1 , , ........... 60
5.4.1.1. . 61
5.4.1.2. ............................................. 61
5.4.1.3. ...................................... 61
5.4.2. , , . 62
5.4.2.1. ( ).............................................. 62
5.4.2.2. ( , ).......................................................................................... 62
5.4.2.3. ( , )....................................................................................................... 63
5.5. , ............... 63
.................................................................................................... 66
.................................................................................................... 67
................................................................................................... 68
1................................................................................................ 68
2................................................................................................ 73
3................................................................................................ 81
4................................................................................................ 87
, , .
, . , , , , , . - , , . , . , -. SQL, , .
, . , , - , .
, . , . . .
- , . , , , .
:
1. , ;
2. , , -;
3. , , , , , -[1].
. . , , . , , . , , . , , , .
, , . , . , .
. , , . , , , , - . . , , . , , .
. , . , . , -. ( ).
, , , . , . , , .
, . . , . , , .
, , .
, , , ( ) . [5].
, . , , . , , .
, - . , . , , - . , , .[1]
. , :
;
;
.
. (, ) , . . , , , . , , . , , .
, . . , . .[1]
-.
1. . , , . , . . , . , .
2. . , ( ). , . , .
3. . , . , . .
, . , , . , , , , .
, .
, , , . , . : () , , , , .
, , . ( ) , , . , , .
. , . , .
, . . , . , . - , , , . , . .
. ( ) , , .[3]
, . , , - .
, , , . , . .
, , . , , . .
, , . . , , . , T F , . , , , , , .[2]
, , .
, , . . , , , , .
, , , . , , .
, . , .
P, . , . , , . , P , , . , : . , . , , . , . ( ) , - - , , , .
, , , . , .
, , . - , . , , . , "" .
, W S . , . .
. , - , . , , , , .[2]
, W S . W S, , , , ~W S. , , W S.
x ( ), W ( x ) S . , , , , x. , S, , , "".
, , , . , . , , .[1]
. S, S , R. R , R(R(S))=R2(S), .. , R(S), R2(S), . , . : , .[2]
, . , , . , .
.
, ( ), , , , .
.
( ) , , S. . , E , E(7,3), , , S , E(x,y) ~E(x,y).
- T, , . - F, .[2]
.
, , . ,
- ,
- ,
-
- .
S, S, S, . , , , .[2]
, , . , , . S S , C. , .
, C, , " C". , .. , n nil.
, , . , , , , . , , , C.[2]
AF-. AF-, :
1. ;
2. , ;
3. , A B, B A ( ).
AF-: 1, 2. . .[2]
1.1. AF-.
, K S, S-K . , K , . , K . , , , , , , .
S-K , , AF-, K. , , , AF-.[2]
, , , . , , . . R(S), R2(S) .. n, , , .
. , .. , . , . , , - .. - , , . .
, . , . , , .
. , , , . , .[2]
.
(CProlog). . 32- UNIX. DEC-10 . . :
Call -
Back To -
Exit -
Fail - .[2]
(Quintus Prolog). Quintus Computer Systems Inc. UNIX VMS. , EMACS. , .[2]
-2. Expert Systems Int. MS-DOS. , , . - , . . .[2]
(Arity Prolog). Arity Corp. MS-DOS . . , .[2]
(Turbo Prolog). Borland Int. MS-DOS. , . : , , . .[6]
Visual Prolog. Prolog Development Center. Windows 3.1 . . Windows . .
, , , . , , , , , -.
. , , , , ., .
, , .
:
1. ;
2. ;
3. .
, , :
1. ;
2. - ;
3. ;
4. .
++ . ( Delphi) ++ . Delphi 4 , .
Delphi 4 , , , .
Borland Delphi 4 Windows 95, 98 NT. .
::= <>
::=,
::=._
:- ._
if ._
::=
<, >._
::=
::=
<, >
::=|
_::=, [6]
:
;
.
. :
;
;
( );
.
.
:
.
. , .
, , .
. , Delphi 4 2 . , Enter . , .
, , . , , .
, , ( , , ..). , , . , . , . , . , .
, .
, , , .
.
. : . , .
. , .
:
(1, 2, ) if
1(11, 12, ),
2(21, 22, ),
N(N1, N2, ).
, -, . ( ) if. , , , .
. :
;
;
( ) .
:
, - ;
, - ;
- .
, .
, .
, , .
, , . :
1. *,/
2. +,-
3. >,<.>=,<=,<>
4. and,or
5. =
, . : , , . .
, , . , .
.
: A=5+func(6+C,D,E)/E-4
2.1. .
. , , , . , .
, :
,
,
,
.
, , , .
, . , .
, , . , .
, .
, . , .
, , . , .
:
1. [1, 2, , N]
2. [|]
.
, , .
, .
. - , . , . , , . , . , , . , , . , , .
TPrologProgram.ExecutePredicate, . TStackNode, , , . ExecutePredicate , , . InputParameters.
, ExecutePredicate, :
1. . ( FindNamedAreas), . .
2. . .
3. , . , TSubStackNode, : , . , TSubStackNode , .
4.
,
TStackNode . ,
,
ExecuteExtDataPredicate, , -
ExecuteStandardPredicate, ,
ExecutePredicate.
- ,
ExecuteArithmeticTerm.
5. False, . TSubStackNode, .
6. , . , 1 , .
7. , False.
SQL-.
SQL- .
SQL-
SELECT <1>,,<N>
FROM < >
WHERE
<1>=<1> and
<2>=<2> and
<N>=<N>
-, .
, .
.
( ) SQL- , , Next .
, , -.
, , .
, .
, , , .
, . ( , ).
(, , , , , ) TPrologVariable. iType. Data , . (, , , ) . . . :
1. procedure CreateVariable(DomainType:string; vName:string) - DomainType vName;
2. procedure DestroyVariable - ( , , )
3. function CreateCopy:TPrologVariable - ;
4. procedure AssignVariable (v:TPrologVariable) - .
TPrologVariableList, , , ( -), , TPrologVariable, .
(TPrologVariableStruct) , .
, TPrologVariable, , . Name - .
TPrologVariables :
1. procedure AddVariable(v:TPrologVariable) - ;
2. function AddNewVariable:TPrologVariable - ;
3. procedure DeleteVariable(n:integer) procedure DeleteVariable(vName:string) procedure DeleteLastVariable - , ;
4. function VariableByName(vName:string):TPrologVariable - ;
5. property Variables[ind:integer]:TPrologVariable - , .
.
:
TStdFunction=function (Args:TPrologVariables):TPrologVariable;
Args .
TPrologVariable.
, :
TStdPredicate=function (VarPacket:TPrologVariables; BackTracking:Boolean):Boolean;
VarPacket
BackTracking , True, .
, .
- TPrologTerm, TPredicateClause TProgramPredicate.
TPrologTerm . (, , ), -, (Data) (TSubTermPredicate, TSubTermExtData, TSubTermExpression).
TSubTermPredicate -. :
1. Name :String - ;
2. StandardPredicate :Boolean - True - ;
3. Params :TVariablesArray - ;
4. NoInverse :Boolean - .
TSubTermExtData TSubTermPredicate , StandardPredicate.
TSubTermExtData . LeftHand RightHand . :
1. Operation :TExpressionOperation - ;
2. FuncName :String - , Operation=eoFunction;
3. Operand :TPrologVariable - , Operation=eoVariable;
4. LeftHand :TSubTermExpression - ;
5. RightHand :TSubTermExpression -
6. FuncParams :array of TSubTermExpression - , Operation=eoFunction.
TPredicateClause . Params, - Terms.
TProgramPredicate . , . (Name), , , , .
TPrologProgram -:
(Domains);
(ExtData);
(TProgramPredicate);
(Stack);
(BreakPoints);
(StartPredicate);
(OnTheRun).
CompileUnit. - - TPrologProgram, , : TStackNode TSubStackNode. CompileUnit .
ProgramClasses. , TPrologProgram, TStackNode TSubStackNode :
TLexemRecord - , ;
TPrologVariable - -.
TPrologVariableList - , TPrologVariable, ;
TPrologVariableStruct - , TPrologVariable, ;
TPrologVariables - , TPrologVariable ;
TSubTermPredicate - TPrologTerm ;
TSubTermExtData - TPrologTerm ;
TSubTermExpression - TPrologTerm ;
TPrologTerm - TSubTermPredicate, TSubTermExtData, TSubTermExpression ;
TPredicateClause - TPrologTerm TPrologVariable ;
TProgramDomain - TPrologProgram ;
TProgramExtData - TPrologProgram ;
TProgramPredicate - TPrologProgram ;
TPrologFile - TPrologProgram ;
PrologRunTime TRunTimeError, .
MainFormUnit - TMainForm;
ProgFormUnit - TProgForm;
DomConstrFormUnit - TExtDataForm;
ExtDataFormUnit - TExtDataForm;
PredicateConstrFormUnit - TPredicateConstrForm;
EditorFormUnit - TEditorForm
ConsoleUnit - TConsole;
ErrorsFormUnit - TErrorsForm;
StackFormUnit - TStackForm;
RunTimeDebugFormUnit - TRunTimeDebugForm;
BreakPointsFormUnit - TBreakPointsForm;
ProjectOptionsFormUnit - .
, . ( , , , , , , , , CD-ROM ).
.
("Configs.db"), .
2.1.
Task | String[33] | |
Frequency | Integer[4] | |
Processor | String[17] | |
Memory | Integer[4] | |
VideoMemory | Integer[4] | |
HDD | Integer[4] | |
MonitorSize | Integer[4] | |
Addition1Name | String[17] | 1- |
Addition1Value | String[9] | 1- |
Addition2Name | String[17] | 2- |
Addition2Value | String[9] | 2- |
Addition3Name | String[17] | 3- |
Addition3Value | String[9] | 3- |
Addition4Name | String[17] | 4- |
Addition4Value | String[9] | 4- |
("DeviceClass.db"). , .
2.2.
TypeName | String[17] | |
SubType | String[33] | |
SubTypeIndex | Real |
, : , , , , , , .
ReadParameters _ReadParameters StringList.
SelectProcessor . , . , , , .
AddNewAddition . . , . , DeviceClass.
ChooseConfig , , . , . .
.
Pentium 16 . :
- 1.5 ;
( Borland Database Engine) - 10 .
Microsoft Windows 95, Windows 98, Windows NT.
3.5" 1.44 .
, Windows "Setup.exe", . .
, .
, Borland Database Engine . BDE , .
- "Prolog", "Prolog.exe" "Prolog with databases", help- "readme.txt".
.
"", "", "Prolog". , , "Prolog with databases".
"" .
:
1. , .
2. .
3.
4. , , "".
.
:
1. ;
2. ;
3. ;
4. ;
5. ;
6. ;
7. ;
8. ;
9. ;
10. ;
11. .
.
, .
3.1. .
: .
: , .
3.2. .
: "", " " "". "" " " , .
. : "", "", " ". , . "" . , ( )
) )
. 3.3. : ) ;
)
. "". . , . , , . , , . , , " " ( ). , . , . "" .
. 3.4.
.
. , .
, .
. . , , . , F1.
. 3.5. .
Windows. Windows, , . :
Shift - , , , , Home, End - ;
Ctrl-Insert Ctrl-C - ;
Shift-Insert Ctrl-V - ;
Shift-Del Ctrl-X - .
( ) . , .
. 3.6. .
3.3.4
"" "" . . "". , . , .
, . "" "" , , , . : .
"" , , , .
. 3.7. .
"" . . . , , .
: " n1 : n2", n1 - , n2 - .
.3.8. .
, :
.
- .
- Windows :
.3.9. .
, , - . , .
- , , -. .
- . , , .
- . .
- , , . , . . "" . :
< >
DOMAINS
< >
ALIAS
< Borland Database Engine, >
DATABASES
< >
PREDICATES
< >
GOAL
< >
CLAUSES
< >
- .
:
;
;
;
;
;
.
:
- , , , .
- - .
. , .
:
- help- .
- .
, , .
. , , . , . , . , , . , . . , .
, .
3.5
Turbo Prolog .
:
Integer - ;
Real - ;
String - ;
Boolean - ( True - False - ).
:
- . .
- . .
- .
.
:
Paradox 7 ( );
DBase IV DBase for Windows;
Fox Pro;
MS Access.
(, InterBase Oracle) .
Borland Database Engine, , - .
, "". , .
, , -.
- , . , . . , . - .
. .
.
ReadString(< >) - . . .
ReadInteger(< >) - .
ReadReal(< >) - .
.
Write (< >, ...) - . . . . , .
WriteLn (< >, ...) - . .
Nl - .
.
IsInteger(<>) - , - .
IsReal(<>) - , .
IsNumeric(<>) - , , , . IsNumeric , IsInteger IsReal, (, ).
IsString(<>) - , .
IsBoolean(<>) - , .
IsList(<>) - , .
IsStruct(<>) - , .
IsFree(<>) - , .
.
, , ( , ) .
DBAppendZ(< >:String, <1>, ... , <N>) - . . .
DBAppendA(< >:String, <1>, ... , <N>) - . . .
DBDelete(< >:String, <1>, ... , <N>) - . . , , - nil. , ( nil).
DBClear(< >:String) - .
.
.
, .
FileOpenRead(< >:String, < >:Integer) - . . .
FileOpenWrite(< >:String, < >:Integer) - . . .
FileRead(< >:Integer,<>) - . , " ".
FileWrite(< >:Integer,<>:String) - .
FileClose(< >:Integer) - . , .
EOF(< >:Integer) - . , .
.
StringToList (String, <>) - , , <>.
Fail - .
.
Sin (<Integer, Real>):Real - . , . .
Cos (<Integer, Real>) :Real - .
Tan (<Integer, Real>) :Real - .
Exp (<Integer, Real>) :Real - .
Ln (<Integer, Real>) :Real - .
Int (<Integer, Real>) :Integer - . .
Frac (<Integer, Real>) :Real - .
Abs(<Integer, Real>):<Integer, Real> - .
.
SubStr(String, N1:Integer, N2:Integer):String - , N1 N2 .
FindStr(S1:String, S2:String):Integer - S2 S1 S1. S1 S2, 0.
Chr(Integer):String - , ASCII.
Asc(String):Integer - ASCII- .
NumbToStr(<Integer Real>):String -
StrToNumb(String):<Integer Real> - , . . , . , .
.
Not(Boolean):Boolean - . (: , "~")
:
/, 堠 (4.1)
L - , .,
nn - , , ,
- ,
- ,
- .
L = 10000
nn = 50
= 25
= 0.8
= 0.7
, :
Tn = (100000.80.7)/(2550) = 4.5 /
/ :
460 .
20% , 92 .
, , 38.5% , 212.52 .
/:
460+92+212.52=764.52 .
:
=0.25460=115 .
, :
S=S1+S+S.
- 8 . - 20000 . 0.2 /.
8 :
S1=20000/(812228)=1.18 /.
0.1 /, :
S=0.10.2=0.02 .
20% :
S=0.21.18=0.17.
S=1.18+0.2+0.17=1.37 /.
:
,
- , , ./.,
- , , .,
- , .,
= 0.5 - .
764.524.5+84.51.37250.5= 4056.84 .
5
, , -, , - .
. .
, , , , .
.
. , . , .
, , .
, , , , , . , , .
, , , , , , , . , 5.4.
, , , , , , .
, , , , . , .
. . , , , :
(),
,
- .
, , - . , , , . , , , , .
5.1.
- | , | ||
, , | |||
- | , | ||
, , | |||
- | , | ||
, , | - | , | |
, | |||
, , , .
. .
. . - .
3 12.1.007-76 ( . ).
1.5 / L=18000 3/.
.
:
Q=5 3/,
r=1.3 /3,
m=42.2×10-6 ×,
d50 lgs=0.77,
r=1300 / .
h=0.9 .
:
1. -24 w D. 1: w=4.5 /.
2. D() =0.3015 .
. D=0.3 .
3. :
=4.76 /,
n=1 .
4. :
=67,
k1=0.93 ;
k2=0.9 ;
=80 500 , C=80 /.
5. :
=971 /.
6. :
,
- x, :
.
=8.5 , =0.308.
:
=87,
: DT=0.6 , r=1930 /3, mT=22.2*10-6 *, wT=3.5 /.
x, 6 =0.8413.
=0.0921.
, , .
, , , :
:
;
, ;
;
;
;
;
.
:
;
;
;
, , .
: , . , , , , , , , , .
:
;
;
( , , , ; ; );
( , , , ).
12.1.003-83. 5.2
, | , | |||||||||
31.5 | 63 | 125 | 250 | 500 | 1000 | 2000 | 4000 | 8000 | ||
, | ||||||||||
86 | 71 | 61 | 54 | 49 | 45 | 42 | 40 | 38 | 50 |
220, . .
:
, ;
, .. ;
, , ;
.
:
1. ;
2. ;
3. , ;
4. .
, :
;
;
;
.
, .
, , , , , , , , , .
.
, . , , , , .
, , .
, . .
, , . , , .
, , :
;
;
: , , , .
, , , .
, , .
848-70 :
1. 20 / 100 -30 5 / 30-300 ;
2. 5 / 100 -1.5.
:
1. ;
2. .
, , . .
, .
, , , .
11-4-79 ( V) ( VII).
. , (: ..) . . , 11-4-79 0.3 .
. . , . . , .
:
1. : +6-15 ; 045 ;
2. ;
3. 11-4-79.
:
1. , ;
2. , %;
3. , /.
- (I ), .. , , . 12.1.005-76 , 5.3.
5.3.
, | , % | , / | |
20-23 | 60-40 | 0.1 | |
22-25 | 60-40 | 0.1 |
0.2 /2 2 .
. , , . ; .
, , .
, .
, . . , ( , - ) , ( ).
, , - .
:
- . , .
. ( / ) - .
. - . , , .
:
, . .
, . , .
, , , .
. , .
5.4.2 ,
,
, . , :
, . .
:
ࠠ 400-500 %;
蠠 50%.
: , (, ) .
. .
:
堠 70-80%
堠 99.6%
⠠ 97.3%
ࠠ 450-550%
蠠 55%
: 97.2% ( 2.8%) . , , .
, , .
.
:
堠 99.9%;
堠 99.9%;
100%;
堠 99.6%;
⠠ 99.3%;
ࠠ 950-990%;
蠠 68%.
. , 10 , .
5´10´4 .
dL = L - L,
L
L 12.1003-83.
L=L + 10Lg(S(X/Si) + 4/B),
i 1 m, m , 2;
X , r r1, r=1.5; r1=3.4 X=1.
Si , i , S1=14.12 S2=72.62;
B , B=B1000*M, B1000 1000 ( 2000 3 B1000=102) M .
5.3:
5.3.
|
||||||||
63 | 125 | 250 | 500 | 1000 | 2000 | 4000 | 8000 | |
L, | 65 | 67 | 68 | 70 | 73 | 73 | 74 | 75 |
M | 0.8 | 0.75 | 0.7 | 0.8 | 1 | 1.4 | 1.8 | 2.5 |
B, 2 |
8 | 7.5 | 7 | |||||
10Lg(S(X/Si) + 4/B) |
-2.3 | -2 | -1.8 | -2.3 | -3.1 | -4.3 | -5.1 | -6.1 |
L, | 63 | 65 | 66 | 68 | 70 | 69 | 69 | 69 |
L, |
83 | 74 | 68 | 63 | 60 | 57 | 55 | 54 |
, , 15. .
S.=dA/a
dA , ;
A .
8 a=0.7. :
S=S+S+2*S.+2*S.-2*S-S= 50+50+80+40-4-2=214 2.
dA a=0.7 S=2142, dA=1302. S=dA/a=130/0.7=1632.
, S=1642, .
.
, , , , .
.
, .
.
1. . - .:,1990
2. . .. - .:,1990
3. . - .: , 1994
4. . , . - .:, 1987
5. . .. - .:, 1988
6. . , .., . - - .: , 1990
7. . - .:, 1990
8. . , - .:, 1979
unit CompileUnit;
interface
uses Windows,Classes, SysUtils, ProgFormUnit, ProgramClasses, SyncObjs,
Forms, dbTables, ProjectOptionsFormUnit;
{DEFINE PRED_COMPILER_DEBUG}
const
StandardLexemsCount=16;
type
TSubStackNodeType=(ssntPredicate, ssntStdPredicate,
ssntArithmetic, ssntExtData);
TProgramSubStackNode=class(TObject)
ClauseIndex :integer; // ,
//
CreatedVariables :TStrings; //
FreeBefore :TStrings; //,
TempVariables :TPrologVariables;
//Arithmetic :Boolean; //True-
iType :TSubStackNodeType; //
Term :TPrologTerm; // ,
//
Belong :TObject; // TProgramStackNode,
//
ExtDataQuery :TQuery;
TheEndWasReached :Boolean;
//VarPacket :TPrologVariables; // ,
//
procedure ClearCreatedVariables;
procedure StepBack;
constructor Create;
destructor Destroy; override;
end;
TTraceMode=(tmNoTrace, tmTrace, tmStep);
//tmNoTrace -
//tmTrace -
//tmStep - ,
TProgramStackNode=class(TObject)
//
PredicateName :string; //
Predicate :TProgramPredicate;
InputParameters :TPrologVariables;
Variables :TPrologVariables; //
SubStack :array of TProgramSubStackNode;//integer; //, ,
//
CreatedVariables :array of array of string; //,
// i-
TermNumb :integer; // ,
ClauseNumb :integer; //
ClausesCount :integer;
TraceMode :TTraceMode;
OnBreakPoint :Boolean; //True-
constructor Create;
destructor Destroy; override;
end;
TPrologProgram=class(TObject)
Domains :array of TProgramDomain;
ExtData :array of TProgramExtData;
Predicates :array of TProgramPredicate;
Stack :array of TProgramStackNode;
BreakPoints :array of Integer;
StartPredicate :string;
OnTheRun :Boolean; //True-
Files :array of TPrologFile;
function CompileProgram:Boolean;
procedure RecieveStructurData;
procedure CutLexemsToPredicates(Lexems:TLexemsArray);
function CheckingBeforeCompile:Boolean;
procedure RunProgram(TraceMode:TTraceMode);
procedure EraseProgramStack;
function AddNodeToStack:TProgramStackNode;
function FindPredicate(PredicateName:string):TProgramPredicate;
function ExecutePredicate(var StackNode:TProgramStackNode):Boolean;
procedure DeleteLastNodeFromStack;
function DebugProcess(StackNode:TProgramStackNode):Boolean;
function PreDebugProcess(StackNode:TProgramStackNode):Boolean;
procedure CreateBreakPointsArray;
function CheckPredicateClausesCount(
Term:TPrologTerm;
SubStackNode:TProgramSubStackNode):Boolean;
constructor Create;
destructor Destroy; override;
function TranslateLexems (ProgPart:TStrings; //var Lexems:TStringList;
var LexemsRecs:TLexemsArray;
Comments:Boolean=False):TPoint;
function AnalizeLexem(st:string):TLexemRecord;
procedure AddLexem(var LexemsRecs:TLexemsArray;
st:string; x,y,APos:integer);
procedure CheckBreakPoints(StackNode:TProgramStackNode);
end;
var
PrologProgram :TPrologProgram;
function TranslateSintax (var Predicate:TProgramPredicate):TPoint;
function AnalizeListElements(LRecs:TLexemsArray;
var DstVar:TPrologVariable):Boolean;
function AnalizeStructElements(LRecs:TLexemsArray;
var DstVar:TPrologVariable):Boolean;
function AnalizeArguments(Predicate:TProgramPredicate;
Lexems:TLexemsArray; var VArr:TVariablesArray;
CheckFlag:Boolean=True):boolean;
function CheckConstantType(
Param:TPrologVariable; Domain:string):boolean;
function CheckPredicateParameters(SubTerm
:TSubTermPredicate):Boolean;
function GetHelpContext (Lexem: TLexemRecord):LongInt;
function TestReservedFunction(st:String):Boolean;
function TestReservedPredicate(st:String):Boolean;
.
unit ProgramClasses;
interface
uses Classes, SysUtils, ProgFormUnit, dbtables, db, ProjectOptionsFormUnit;
type
TLexemErrors=(leString,leComment, leOk);
//leString
//leComment
//
TLexemType=(ltPredicate, ltDomain, ltExtData,
ltVariable, ltFunction, ltUnknown,
ltPlus,ltMinus,ltMultiply,ltDivide,
ltLeftBracket,ltRightBracket,
ltLeftSquareBracket,ltRightSquareBracket,
ltListDivider,ltComma,ltPoint,
ltPointAndComma,ltEqual,ltIf,ltExclamation,
ltString,ltReal,ltInteger,ltTrue,ltFalse,
ltAnonimous, ltGT, ltLT, ltGE, ltLE,
ltReservedPredicate, ltNil, ltAnd, ltOr, ltNotEqual,
ltComment);
TLexemRecord=record
iType :TLexemType;
// LPredicate LDomain st
st :string;
x,y :integer; //
AbsPos :integer; //
NoInverse :Boolean; // ltPredicate -
//
end;
TLexemsArray=array of TLexemRecord;
TPrologVariablesTypes=(vtString,vtInteger,vtBoolean,
vtReal,vtList,vtStruct,vtUnknown,vtAnonimous);
TPrologVariable=class(TObject)
iType :TPrologVariablesTypes; //
Name :string; //
Data :Pointer; //
procedure CreateVariable(DomainType:string; vName:string);
procedure DestroyVariable;
constructor Create;
destructor Destroy; override;
procedure ClearVariable;
function CreateCopy:TPrologVariable; //
//
procedure AssignVariable (v:TPrologVariable); //
//.
end;
TVariablesArray=array of TPrologVariable;
TPrologListType=(pltStdList,pltHeadTail);
//pltStdList - Elements
//pltHeadTail - (
// elements
TPrologVariableList=class(TObject)
ListName :string; //
ElemName :string; //
ListType :TPrologListType; // .
Elements :TVariablesArray; // Data
DividerPos :integer; // ListType=pltHeadTail
//,
procedure ConvertList;
constructor Create;
destructor Destroy; override;
end;
TPrologVariableStruct=class(TObject)
StructName :string; //
ElemTypes :array of string; //
Elements :array of TPrologVariable; // Data
constructor Create;
destructor Destroy; override;
end;
TPrologVariables=class(TObject)
VarArr :array of TPrologVariable;
constructor Create;
destructor Destroy; override;
function Count:integer;
function High:integer;
procedure AddVariable(v:TPrologVariable);
procedure DeleteVariable(n:integer); overload;
procedure DeleteVariable(vName:string); overload;
procedure DeleteLastVariable;
function AddNewVariable:TPrologVariable;
function VariableByName(vName:string):TPrologVariable;
function GetVariable(ind:integer):TPrologVariable;
procedure SetVariable(ind:integer; v:TPrologVariable);
procedure ClearAndDestroyVariables;
property Variables[ind:integer]:TPrologVariable read GetVariable
write SetVariable; default;
end;
TSubTermPredicate=class(TObject)
Name :string;
StandardPredicate :Boolean; //True -
Params :TVariablesArray;
NoInverse :Boolean; //
constructor Create;
destructor Destroy; override;
end;
TSubTermExtData=class(TObject)
Name :string;
Params :TVariablesArray;
NoInverse :Boolean; //
constructor Create;
destructor Destroy; override;
end;
TExpressionOperation=
(eoPlus, eoMinus, eoMultiply, eoDivide, eoEqual,
eoGT, eoLT, eoGE, eoLE, eoVariable, eoFunction,
eoAnd, eoOR, eoNotEqual);
TSubTermExpression=class(TObject)
Operation :TExpressionOperation;
VarName :String; //
FuncName :string; //
StringStr :string; //
NumberInt :integer; //
NumberReal :Extended; //
BooleanVal :Boolean; //
Operand :TPrologVariable;
LeftHand :TSubTermExpression; //
//TSubTermExpression, TPrologVariable
RightHand :TSubTermExpression;
FuncParams :array of TSubTermExpression;
constructor Create;
destructor Destroy; override;
end;
TPrologTermType=(pttExpression,pttPredicate,pttExtData,pttCutting);
TPrologTerm=class(TObject)
TermType :TPrologTermType; //
Data :pointer; //
x,y :integer;
constructor Create;
destructor Destroy; override;
end;
TTermsArray=array of TPrologTerm;
TProgramDomain=class(TObject)
//
iType :TDomainTypes;
Name :string;
Params :TStrings;
ListParam :string;
constructor Create;
destructor Destroy; override;
end;
TProgramExtData=class(TObject)
Name :string;
Fields :TStrings;
FieldsTypes :TStrings;
FieldsLengths :TStrings;
FileName :string;
Table :TTable;
DataSource :TDataSource;
constructor Create;
destructor Destroy; override;
function Open:Boolean;
procedure Close;
end;
TPredicateClause=class(TObject)
Params :TVariablesArray;
Terms :TTermsArray;
x,y, Endx, EndY :integer;
constructor Create;
destructor Destroy; override;
end;
TProgramPredicate=class(TObject)
Name :string;
Params :TStrings;
Text :TStrings;
Lexems :TLexemsArray;
Clauses :array of TPredicateClause;
constructor Create;
destructor Destroy; override;
end;
TFileOpenMode=(fomRead,fomWrite,fomNotOpened);
TPrologFile=class(TObject)
Name :string;
HandlerNumb :integer;
OpenMode :TFileOpenMode;
FileVar :TextFile;
constructor Create;
destructor Destroy; override;
procedure OpenRead(FileName:string);
procedure OpenWrite(FileName:string);
procedure Close;
function EndOfFile:Boolean;
procedure ReadFile(var st:string);
procedure WriteFile(st:string);
end;
TVariableSize=record
Name :string;
iType :TPrologVariablesTypes;
size :integer;
end;
const
SimplePrologTypesCount=4;
SimplePrologTypes:set of TPrologVariablesTypes=
[vtString, vtInteger, vtBoolean, vtReal];
PrologVariablesSizes:array [0..5] of TVariableSize=
((Name:'STRING'; iType:vtString; Size:SizeOf(string)),
(Name:'INTEGER'; iType:vtInteger; Size:SizeOf(integer)),
(Name:'BOOLEAN'; iType:vtBoolean; Size:SizeOf(Boolean)),
(Name:'REAL'; iType:vtReal; Size:SizeOf(Extended)),
(Name:'LIST'; iType:vtList; Size:SizeOf(TPrologVariableList)),
(Name:'STRUCT'; iType:vtStruct; Size:SizeOf(TPrologVariableStruct)));
.
unit PrologRunTime;
interface
Uses SysUtils,CompileUnit, ProgramClasses, CommonFunctions;
type
TErrorCode=(ecType, ecNo, ecOverflow, ecDivideZero, ecExpressionValue,
ecArgsCount, ecArgType, ecTan, ecRealAsInteger, ecTypeInExtData,
ecListTail,ecPredicateParams,ecExtDataAbsent, ecExtDataDelete,
ecRangeError,ecConvertError,ecFileOpenError,ecFileCloseError,
ecFileAccessError,
ecCloseProgram,
ecStopPrologProgram);
//ecType -
//ecNo -
//ecOverflow -
//ecDivideZero -
//ecExpressionValue -
//ecArgsCount -
//ecArgType -
//ecTan -
//ecRealAsInteger -
// , ,
//
//ecTypeInExtData -
//ecListTail -
//ecCloseProgram -
//ecStopPrologProgram -
//ecPredicateParams -
TRunTimeError=class(TObject)
Code :TErrorCode;
PredicateName :string;
x,y :integer;
constructor Create;
procedure SetError(err:TErrorCode);
procedure ShowOnScreen;
end;
TOperatorFunction=function (
Oper1:TPrologVariable; Oper2:TPrologVariable):TPrologVariable;
TStdFunction=function (Args:TPrologVariables):TPrologVariable;
TStdPredicate=function (VarPacket:TPrologVariables; BackTracking:Boolean):Boolean;
function VariableToStr(v:TPrologVariable;
PrintName:Boolean=True; PrintCommas:Boolean=True;
SquareBrackets:boolean=True):string;
function EqualOperator (Dst:TPrologVariable;
Src:TPrologVariable):Boolean;
function OperatorEQ (
Oper1:TPrologVariable; Oper2:TPrologVariable;
Variables:TPrologVariables):TPrologVariable;
function OperatorPlus (
Oper1:TPrologVariable; Oper2:TPrologVariable):TPrologVariable;
function OperatorMinus (
Oper1:TPrologVariable; Oper2:TPrologVariable):TPrologVariable;
function OperatorMultiply (
Oper1:TPrologVariable; Oper2:TPrologVariable):TPrologVariable;
function OperatorDivide (
Oper1:TPrologVariable; Oper2:TPrologVariable):TPrologVariable;
function OperatorGT (
Oper1:TPrologVariable; Oper2:TPrologVariable):TPrologVariable;
function OperatorLT (
Oper1:TPrologVariable; Oper2:TPrologVariable):TPrologVariable;
function OperatorGE (
Oper1:TPrologVariable; Oper2:TPrologVariable):TPrologVariable;
function OperatorLE (
Oper1:TPrologVariable; Oper2:TPrologVariable):TPrologVariable;
function OperatorNotEQ (
Oper1:TPrologVariable; Oper2:TPrologVariable):TPrologVariable;
function OperatorAND (
Oper1:TPrologVariable; Oper2:TPrologVariable):TPrologVariable;
function OperatorOR (
Oper1:TPrologVariable; Oper2:TPrologVariable):TPrologVariable;
function StdFunctionNot(Args:TPrologVariables):TPrologVariable;
function StdFunctionSin(Args:TPrologVariables):TPrologVariable;
function StdFunctionCos(Args:TPrologVariables):TPrologVariable;
function StdFunctionTan(Args:TPrologVariables):TPrologVariable;
function StdFunctionInt(Args:TPrologVariables):TPrologVariable;
function StdFunctionFrac(Args:TPrologVariables):TPrologVariable;
function StdFunctionSubStr(Args:TPrologVariables):TPrologVariable;
function StdFunctionFindStr(Args:TPrologVariables):TPrologVariable;
function StdFunctionChr(Args:TPrologVariables):TPrologVariable;
function StdFunctionAsc(Args:TPrologVariables):TPrologVariable;
function StdFunctionExp(Args:TPrologVariables):TPrologVariable;
function StdFunctionLn(Args:TPrologVariables):TPrologVariable;
function StdFunctionNumbToStr(Args:TPrologVariables):TPrologVariable;
function StdFunctionStrToNumb(Args:TPrologVariables):TPrologVariable;
function StdFunctionAbs(Args:TPrologVariables):TPrologVariable;
function StdPWrite(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPWriteLn(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPnl(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPIsInteger(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPIsReal(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPIsNumeric(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPIsString(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPIsBoolean(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPIsList(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPIsStruct(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPIsFree(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPReadInt(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPReadString(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPReadReal(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPDBAppendZ(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPDBAppendA(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPDBDelete(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPDBClear(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPFileOpenRead(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPFileOpenWrite(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPFileClose(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPFileRead(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPFileWrite(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPEOF(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPStringToList(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
function StdPFail(VarPacket:TPrologVariables;
BackTracking:Boolean):Boolean;
var
RunTimeError :TRuntimeError;
.
DOMAINS
ListElement:Complex {}
Integer {}
Real {}
String {}
StringList {}
ParamsList:List of ListElement { }
StringList:List of String { }
ALIAS
DBDEMOS
DATABASES
Configs:'Configs.DB' {}
Task:String[33] {}
Frequency:Integer[4] {}
Processor:String[17] {}
Memory:Integer[4] {}
VideoMemory:Integer[4] {}
HDD:Integer[4] {}
MonitorSize:Integer[4] {}
Addition1Name:String[17] {}
Addition1Value:String[9] {}
Addition2Name:String[17] {}
Addition2Value:String[9] {}
Addition3Name:String[17] {}
Addition3Value:String[9] {}
Addition4Name:String[17] {}
Addition4Value:String[9] {}
DeviceClass:'DeviceClass.db' {}
TypeName:String[17] {}
SubType:String[33] {}
SubTypeIndex:Real{}
PREDICATES
_ReadParameters { ReadParameters}
String { }
StringList { }
StringList { }
AddElementToStringList { }
String {}
StringList { }
StringList { }
AddNewAddition { }
StringList { . -}
StringList { . -}
String { . -}
String { . -}
StringList {. . -}
StringList {. . -}
ChooseConfig { }
StringList { }
ParamsList { }
ParamsList { }
GetListElement { }
ParamsList {, }
Integer { }
Integer { }
ListElement { }
Max { }
ListElement { 1}
ListElement { 2}
ListElement { }
PrintAdditions { }
StringList { }
StringList { }
ReadParameters { }
StringList { }
StringList { }
run { }
SelectProcessor { }
String { 1}
Integer { 1}
String { 2}
Integer { 2}
String { }
Integer { }
GOAL
run
CLAUSES
ReadParameters(InList, OutList) if
ReadString(St),nl,
_ReadParameters(St, InList, OutList).
_ReadParameters("", InList, InList).
_ReadParameters(St, InList, OutList) if
AddElementToStringList(St, InList, InList2),
ReadParameters(InList2, OutList).
AddElementToStringList(A,T,[A|T]).
GetListElement([H|_],N,N,H).
GetListElement([_|T],N,N1,K) if
N2=N1+1,
GetListElement(T,N,N2,K).
Max (Value1, Value2, Value1) if Value1>=Value2.
Max (Value1, Value2, Value2) if Value1<Value2.
SelectProcessor(OldProc,OldFreq,Proc1,Freq1,Proc1,OldFreq) if
DeviceClass("Processor",OldProc,OldProcNumb),
DeviceClass("Processor",Proc1,Proc1Numb),
OldProcNumb=Proc1Numb,
OldFreq>=Freq1.
SelectProcessor(OldProc,OldFreq1,Proc1,Freq1,Proc1,Freq1) if
DeviceClass("Processor",OldProc,OldProcNumb),
DeviceClass("Processor",Proc1,Proc1Numb),
OldProcNumb=Proc1Numb,
OldFreq<Freq1.
SelectProcessor(OldProc,OldFreq,Proc1,Freq1,OldProc,OldFreq) if
DeviceClass("Processor",OldProc,OldProcNumb),
DeviceClass("Processor",Proc1,Proc1Numb),
OldProcNumb>Proc1Numb.
SelectProcessor(OldProc,OldFreq,Proc1,Freq1,Proc1,Freq1) if
DeviceClass("Processor",OldProc,OldProcNumb),
DeviceClass("Processor",Proc1,Proc1Numb),
OldProcNumb<Proc1Numb.
{CreateParamsList(Freq,Proc,Mem,VMem,HDD,Monitor,Names,Vals,
[Freq,Proc,Mem,VMem,HDD,Monitor,Names,Vals]).}
AddNewAddition(N,V,"","",N,V).
AddNewAddition([],[],An,Av,[An],[Av]).
AddNewAddition([Hn|Tn],[Hv|Tv],Hn,Av,[Hn|Tn],[Hv|Tv]) if
DeviceClass(Hn,Hv,OldNumb),
DeviceClass(Hn,Av,NewNumb),
OldNumb>=NewNumb.
AddNewAddition([Hn|Tn],[Hv|Tv],Hn,Av,[Hn|Tn],[Av|Tv]) if
DeviceClass(Hn,Hv,OldNumb),
DeviceClass(Hn,Av,NewNumb),
OldNumb<NewNumb.
AddNewAddition([Hn|Tn],[Hv|Tv],An,Av,[Hn|NewN],[Hv|NewV]) if
AddNewAddition(Tn,Tv,An,Av,NewN,NewV).
ChooseConfig([],InParams,InParams).
ChooseConfig([H|T], InParams, OutParams) if
Configs(H,Freq1,Proc1,Mem1,VMem1,HDD1,Monitor1,an1,av1,an2,av2,an3,av3,an4,av4),
GetListElement(InParams,6,0,OldAddsNames),
GetListElement(InParams,7,0,OldAddsVals),
AddNewAddition(OldAddsNames,OldAddsVals,an1,av1,AddsNames1,AddsVals1),
AddNewAddition(AddsNames1,AddsVals1,an2,av2,AddsNames2,AddsVals2),
AddNewAddition(AddsNames2,AddsVals2,an3,av3,AddsNames3,AddsVals3),
AddNewAddition(AddsNames3,AddsVals3,an4,av4,AddsNames4,AddsVals4),
GetListElement(InParams,5,0,OldMonitor),
Max(Monitor1,OldMonitor,NewMonitor),
GetListElement(InParams,4,0,OldHDD),
{Max(HDD1,OldHDD,NewHDD),}
NewHDD=OldHDD+HDD1,
GetListElement(InParams,3,0,OldVMem),
Max(VMem1,OldVMem,NewVMem),
GetListElement(InParams,2,0,OldMem),
Max(Mem1,OldMem,NewMem),
GetListElement(InParams,1,0,OldProc),
GetListElement(InParams,0,0,OldFreq),
SelectProcessor(OldProc,OldFreq,Proc1,Freq1,NewProc,NewFreq),
{CreateParamsList(NewFreq,NewProc,NewMem,NewVMem,NewHDD,NewMonitor,AddsNames4,AddsVals4,InParams1),
ChooseConfig(T,InParams1,OutParams)}
ChooseConfig(T,[NewFreq,NewProc,NewMem,NewVMem,NewHDD,NewMonitor,AddsNames4,AddsVals4],OutParams).
PrintAdditions([],[]).
PrintAdditions([Hn|Tn],[Hv|Tv]) if
Write(Hn), Write(" "), WriteLn(Hv),
PrintAdditions(Tn,Tv).
run if
{ReadParameters([],A),
WriteLn(A),}
ChooseConfig(["Internet"," ","Delphi 3"],[0,"86",0,0,0,0,[],[]],B),
{WriteLn(B),}
GetListElement(B,0,0,Freq),
GetListElement(B,1,0,Proc),
WriteLn(": ",Proc," ",Freq," MHz"),
GetListElement(B,2,0,Mem),
WriteLn(": ",Mem," "),
GetListElement(B,3,0,VMem),
WriteLn(" : ",VMem," "),
GetListElement(B,4,0,HDD),
WriteLn(": ",HDD," "),
GetListElement(B,5,0,Monitor),
WriteLn(": ",Monitor,""""),
GetListElement(B,6,0,Names),
GetListElement(B,7,0,Vals),
PrintAdditions(Names,Vals).
.
Copyright (c) 2024 Stud-Baza.ru , , , .