clipsruby 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/clipsruby/agenda.c +1373 -0
- data/ext/clipsruby/agenda.h +169 -0
- data/ext/clipsruby/analysis.c +1142 -0
- data/ext/clipsruby/analysis.h +61 -0
- data/ext/clipsruby/argacces.c +526 -0
- data/ext/clipsruby/argacces.h +77 -0
- data/ext/clipsruby/bload.c +884 -0
- data/ext/clipsruby/bload.h +94 -0
- data/ext/clipsruby/bmathfun.c +557 -0
- data/ext/clipsruby/bmathfun.h +66 -0
- data/ext/clipsruby/bsave.c +634 -0
- data/ext/clipsruby/bsave.h +130 -0
- data/ext/clipsruby/classcom.c +976 -0
- data/ext/clipsruby/classcom.h +115 -0
- data/ext/clipsruby/classexm.c +1376 -0
- data/ext/clipsruby/classexm.h +97 -0
- data/ext/clipsruby/classfun.c +1392 -0
- data/ext/clipsruby/classfun.h +164 -0
- data/ext/clipsruby/classinf.c +1245 -0
- data/ext/clipsruby/classinf.h +94 -0
- data/ext/clipsruby/classini.c +843 -0
- data/ext/clipsruby/classini.h +75 -0
- data/ext/clipsruby/classpsr.c +957 -0
- data/ext/clipsruby/classpsr.h +73 -0
- data/ext/clipsruby/clips.h +133 -0
- data/ext/clipsruby/clipsruby.c +619 -0
- data/ext/clipsruby/clsltpsr.c +931 -0
- data/ext/clipsruby/clsltpsr.h +72 -0
- data/ext/clipsruby/commline.c +1217 -0
- data/ext/clipsruby/commline.h +131 -0
- data/ext/clipsruby/conscomp.c +1593 -0
- data/ext/clipsruby/conscomp.h +150 -0
- data/ext/clipsruby/constant.h +264 -0
- data/ext/clipsruby/constrct.c +1090 -0
- data/ext/clipsruby/constrct.h +216 -0
- data/ext/clipsruby/constrnt.c +554 -0
- data/ext/clipsruby/constrnt.h +132 -0
- data/ext/clipsruby/crstrtgy.c +1088 -0
- data/ext/clipsruby/crstrtgy.h +85 -0
- data/ext/clipsruby/cstrcbin.c +185 -0
- data/ext/clipsruby/cstrcbin.h +61 -0
- data/ext/clipsruby/cstrccmp.h +43 -0
- data/ext/clipsruby/cstrccom.c +1791 -0
- data/ext/clipsruby/cstrccom.h +115 -0
- data/ext/clipsruby/cstrcpsr.c +835 -0
- data/ext/clipsruby/cstrcpsr.h +97 -0
- data/ext/clipsruby/cstrnbin.c +282 -0
- data/ext/clipsruby/cstrnbin.h +55 -0
- data/ext/clipsruby/cstrnchk.c +826 -0
- data/ext/clipsruby/cstrnchk.h +91 -0
- data/ext/clipsruby/cstrncmp.c +238 -0
- data/ext/clipsruby/cstrncmp.h +57 -0
- data/ext/clipsruby/cstrnops.c +1176 -0
- data/ext/clipsruby/cstrnops.h +47 -0
- data/ext/clipsruby/cstrnpsr.c +1394 -0
- data/ext/clipsruby/cstrnpsr.h +88 -0
- data/ext/clipsruby/cstrnutl.c +564 -0
- data/ext/clipsruby/cstrnutl.h +54 -0
- data/ext/clipsruby/default.c +454 -0
- data/ext/clipsruby/default.h +57 -0
- data/ext/clipsruby/defins.c +971 -0
- data/ext/clipsruby/defins.h +127 -0
- data/ext/clipsruby/developr.c +677 -0
- data/ext/clipsruby/developr.h +69 -0
- data/ext/clipsruby/dffctbin.c +477 -0
- data/ext/clipsruby/dffctbin.h +76 -0
- data/ext/clipsruby/dffctbsc.c +308 -0
- data/ext/clipsruby/dffctbsc.h +72 -0
- data/ext/clipsruby/dffctcmp.c +297 -0
- data/ext/clipsruby/dffctcmp.h +44 -0
- data/ext/clipsruby/dffctdef.c +364 -0
- data/ext/clipsruby/dffctdef.h +104 -0
- data/ext/clipsruby/dffctpsr.c +179 -0
- data/ext/clipsruby/dffctpsr.h +49 -0
- data/ext/clipsruby/dffnxbin.c +520 -0
- data/ext/clipsruby/dffnxbin.h +67 -0
- data/ext/clipsruby/dffnxcmp.c +378 -0
- data/ext/clipsruby/dffnxcmp.h +54 -0
- data/ext/clipsruby/dffnxexe.c +241 -0
- data/ext/clipsruby/dffnxexe.h +58 -0
- data/ext/clipsruby/dffnxfun.c +1192 -0
- data/ext/clipsruby/dffnxfun.h +155 -0
- data/ext/clipsruby/dffnxpsr.c +514 -0
- data/ext/clipsruby/dffnxpsr.h +57 -0
- data/ext/clipsruby/dfinsbin.c +509 -0
- data/ext/clipsruby/dfinsbin.h +66 -0
- data/ext/clipsruby/dfinscmp.c +345 -0
- data/ext/clipsruby/dfinscmp.h +48 -0
- data/ext/clipsruby/drive.c +1191 -0
- data/ext/clipsruby/drive.h +65 -0
- data/ext/clipsruby/emathfun.c +1213 -0
- data/ext/clipsruby/emathfun.h +99 -0
- data/ext/clipsruby/engine.c +1568 -0
- data/ext/clipsruby/engine.h +203 -0
- data/ext/clipsruby/entities.h +276 -0
- data/ext/clipsruby/envrnbld.c +514 -0
- data/ext/clipsruby/envrnbld.h +40 -0
- data/ext/clipsruby/envrnmnt.c +257 -0
- data/ext/clipsruby/envrnmnt.h +112 -0
- data/ext/clipsruby/evaluatn.c +1736 -0
- data/ext/clipsruby/evaluatn.h +211 -0
- data/ext/clipsruby/expressn.c +494 -0
- data/ext/clipsruby/expressn.h +154 -0
- data/ext/clipsruby/exprnbin.c +538 -0
- data/ext/clipsruby/exprnbin.h +60 -0
- data/ext/clipsruby/exprnops.c +564 -0
- data/ext/clipsruby/exprnops.h +67 -0
- data/ext/clipsruby/exprnpsr.c +1112 -0
- data/ext/clipsruby/exprnpsr.h +98 -0
- data/ext/clipsruby/extconf.rb +2 -0
- data/ext/clipsruby/extnfunc.c +1015 -0
- data/ext/clipsruby/extnfunc.h +157 -0
- data/ext/clipsruby/factbin.c +447 -0
- data/ext/clipsruby/factbin.h +56 -0
- data/ext/clipsruby/factbld.c +1035 -0
- data/ext/clipsruby/factbld.h +63 -0
- data/ext/clipsruby/factcmp.c +386 -0
- data/ext/clipsruby/factcmp.h +46 -0
- data/ext/clipsruby/factcom.c +759 -0
- data/ext/clipsruby/factcom.h +80 -0
- data/ext/clipsruby/factfile.c +1761 -0
- data/ext/clipsruby/factfile.h +54 -0
- data/ext/clipsruby/factfun.c +682 -0
- data/ext/clipsruby/factfun.h +77 -0
- data/ext/clipsruby/factgen.c +1305 -0
- data/ext/clipsruby/factgen.h +229 -0
- data/ext/clipsruby/facthsh.c +438 -0
- data/ext/clipsruby/facthsh.h +81 -0
- data/ext/clipsruby/factlhs.c +250 -0
- data/ext/clipsruby/factlhs.h +54 -0
- data/ext/clipsruby/factmch.c +905 -0
- data/ext/clipsruby/factmch.h +68 -0
- data/ext/clipsruby/factmngr.c +3373 -0
- data/ext/clipsruby/factmngr.h +325 -0
- data/ext/clipsruby/factprt.c +498 -0
- data/ext/clipsruby/factprt.h +60 -0
- data/ext/clipsruby/factqpsr.c +796 -0
- data/ext/clipsruby/factqpsr.h +61 -0
- data/ext/clipsruby/factqury.c +1267 -0
- data/ext/clipsruby/factqury.h +112 -0
- data/ext/clipsruby/factrete.c +978 -0
- data/ext/clipsruby/factrete.h +70 -0
- data/ext/clipsruby/factrhs.c +667 -0
- data/ext/clipsruby/factrhs.h +55 -0
- data/ext/clipsruby/filecom.c +353 -0
- data/ext/clipsruby/filecom.h +137 -0
- data/ext/clipsruby/filertr.c +481 -0
- data/ext/clipsruby/filertr.h +94 -0
- data/ext/clipsruby/fileutil.c +1020 -0
- data/ext/clipsruby/fileutil.h +50 -0
- data/ext/clipsruby/generate.c +1079 -0
- data/ext/clipsruby/generate.h +57 -0
- data/ext/clipsruby/genrcbin.c +902 -0
- data/ext/clipsruby/genrcbin.h +69 -0
- data/ext/clipsruby/genrccmp.c +640 -0
- data/ext/clipsruby/genrccmp.h +59 -0
- data/ext/clipsruby/genrccom.c +2017 -0
- data/ext/clipsruby/genrccom.h +119 -0
- data/ext/clipsruby/genrcexe.c +737 -0
- data/ext/clipsruby/genrcexe.h +73 -0
- data/ext/clipsruby/genrcfun.c +890 -0
- data/ext/clipsruby/genrcfun.h +185 -0
- data/ext/clipsruby/genrcpsr.c +1618 -0
- data/ext/clipsruby/genrcpsr.h +80 -0
- data/ext/clipsruby/globlbin.c +458 -0
- data/ext/clipsruby/globlbin.h +71 -0
- data/ext/clipsruby/globlbsc.c +361 -0
- data/ext/clipsruby/globlbsc.h +83 -0
- data/ext/clipsruby/globlcmp.c +330 -0
- data/ext/clipsruby/globlcmp.h +52 -0
- data/ext/clipsruby/globlcom.c +289 -0
- data/ext/clipsruby/globlcom.h +63 -0
- data/ext/clipsruby/globldef.c +1087 -0
- data/ext/clipsruby/globldef.h +151 -0
- data/ext/clipsruby/globlpsr.c +530 -0
- data/ext/clipsruby/globlpsr.h +59 -0
- data/ext/clipsruby/immthpsr.c +431 -0
- data/ext/clipsruby/immthpsr.h +55 -0
- data/ext/clipsruby/incrrset.c +530 -0
- data/ext/clipsruby/incrrset.h +73 -0
- data/ext/clipsruby/inherpsr.c +850 -0
- data/ext/clipsruby/inherpsr.h +52 -0
- data/ext/clipsruby/inscom.c +2076 -0
- data/ext/clipsruby/inscom.h +182 -0
- data/ext/clipsruby/insfile.c +1764 -0
- data/ext/clipsruby/insfile.h +96 -0
- data/ext/clipsruby/insfun.c +1451 -0
- data/ext/clipsruby/insfun.h +134 -0
- data/ext/clipsruby/insmngr.c +2550 -0
- data/ext/clipsruby/insmngr.h +125 -0
- data/ext/clipsruby/insmoddp.c +1041 -0
- data/ext/clipsruby/insmoddp.h +91 -0
- data/ext/clipsruby/insmult.c +804 -0
- data/ext/clipsruby/insmult.h +62 -0
- data/ext/clipsruby/inspsr.c +602 -0
- data/ext/clipsruby/inspsr.h +60 -0
- data/ext/clipsruby/insquery.c +1278 -0
- data/ext/clipsruby/insquery.h +115 -0
- data/ext/clipsruby/insqypsr.c +729 -0
- data/ext/clipsruby/insqypsr.h +63 -0
- data/ext/clipsruby/iofun.c +2045 -0
- data/ext/clipsruby/iofun.h +116 -0
- data/ext/clipsruby/lgcldpnd.c +644 -0
- data/ext/clipsruby/lgcldpnd.h +75 -0
- data/ext/clipsruby/main.c +112 -0
- data/ext/clipsruby/match.h +142 -0
- data/ext/clipsruby/memalloc.c +481 -0
- data/ext/clipsruby/memalloc.h +197 -0
- data/ext/clipsruby/miscfun.c +1801 -0
- data/ext/clipsruby/miscfun.h +132 -0
- data/ext/clipsruby/modulbin.c +607 -0
- data/ext/clipsruby/modulbin.h +84 -0
- data/ext/clipsruby/modulbsc.c +347 -0
- data/ext/clipsruby/modulbsc.h +67 -0
- data/ext/clipsruby/modulcmp.c +499 -0
- data/ext/clipsruby/modulcmp.h +54 -0
- data/ext/clipsruby/moduldef.c +817 -0
- data/ext/clipsruby/moduldef.h +271 -0
- data/ext/clipsruby/modulpsr.c +1150 -0
- data/ext/clipsruby/modulpsr.h +69 -0
- data/ext/clipsruby/modulutl.c +1036 -0
- data/ext/clipsruby/modulutl.h +84 -0
- data/ext/clipsruby/msgcom.c +1221 -0
- data/ext/clipsruby/msgcom.h +125 -0
- data/ext/clipsruby/msgfun.c +1076 -0
- data/ext/clipsruby/msgfun.h +118 -0
- data/ext/clipsruby/msgpass.c +1441 -0
- data/ext/clipsruby/msgpass.h +103 -0
- data/ext/clipsruby/msgpsr.c +698 -0
- data/ext/clipsruby/msgpsr.h +73 -0
- data/ext/clipsruby/multifld.c +1404 -0
- data/ext/clipsruby/multifld.h +130 -0
- data/ext/clipsruby/multifun.c +2182 -0
- data/ext/clipsruby/multifun.h +102 -0
- data/ext/clipsruby/network.h +142 -0
- data/ext/clipsruby/objbin.c +1522 -0
- data/ext/clipsruby/objbin.h +79 -0
- data/ext/clipsruby/objcmp.c +1507 -0
- data/ext/clipsruby/objcmp.h +71 -0
- data/ext/clipsruby/object.h +260 -0
- data/ext/clipsruby/objrtbin.c +701 -0
- data/ext/clipsruby/objrtbin.h +79 -0
- data/ext/clipsruby/objrtbld.c +2393 -0
- data/ext/clipsruby/objrtbld.h +66 -0
- data/ext/clipsruby/objrtcmp.c +734 -0
- data/ext/clipsruby/objrtcmp.h +66 -0
- data/ext/clipsruby/objrtfnx.c +1330 -0
- data/ext/clipsruby/objrtfnx.h +222 -0
- data/ext/clipsruby/objrtgen.c +736 -0
- data/ext/clipsruby/objrtgen.h +63 -0
- data/ext/clipsruby/objrtmch.c +1524 -0
- data/ext/clipsruby/objrtmch.h +160 -0
- data/ext/clipsruby/parsefun.c +415 -0
- data/ext/clipsruby/parsefun.h +67 -0
- data/ext/clipsruby/pattern.c +1265 -0
- data/ext/clipsruby/pattern.h +163 -0
- data/ext/clipsruby/pprint.c +328 -0
- data/ext/clipsruby/pprint.h +79 -0
- data/ext/clipsruby/prccode.c +1478 -0
- data/ext/clipsruby/prccode.h +145 -0
- data/ext/clipsruby/prcdrfun.c +640 -0
- data/ext/clipsruby/prcdrfun.h +95 -0
- data/ext/clipsruby/prcdrpsr.c +1068 -0
- data/ext/clipsruby/prcdrpsr.h +79 -0
- data/ext/clipsruby/prdctfun.c +869 -0
- data/ext/clipsruby/prdctfun.h +77 -0
- data/ext/clipsruby/prntutil.c +878 -0
- data/ext/clipsruby/prntutil.h +125 -0
- data/ext/clipsruby/proflfun.c +827 -0
- data/ext/clipsruby/proflfun.h +118 -0
- data/ext/clipsruby/reorder.c +2082 -0
- data/ext/clipsruby/reorder.h +172 -0
- data/ext/clipsruby/reteutil.c +1732 -0
- data/ext/clipsruby/reteutil.h +111 -0
- data/ext/clipsruby/retract.c +710 -0
- data/ext/clipsruby/retract.h +74 -0
- data/ext/clipsruby/router.c +737 -0
- data/ext/clipsruby/router.h +147 -0
- data/ext/clipsruby/rulebin.c +1136 -0
- data/ext/clipsruby/rulebin.h +153 -0
- data/ext/clipsruby/rulebld.c +1328 -0
- data/ext/clipsruby/rulebld.h +62 -0
- data/ext/clipsruby/rulebsc.c +517 -0
- data/ext/clipsruby/rulebsc.h +91 -0
- data/ext/clipsruby/rulecmp.c +733 -0
- data/ext/clipsruby/rulecmp.h +63 -0
- data/ext/clipsruby/rulecom.c +1583 -0
- data/ext/clipsruby/rulecom.h +116 -0
- data/ext/clipsruby/rulecstr.c +892 -0
- data/ext/clipsruby/rulecstr.h +53 -0
- data/ext/clipsruby/ruledef.c +559 -0
- data/ext/clipsruby/ruledef.h +179 -0
- data/ext/clipsruby/ruledlt.c +599 -0
- data/ext/clipsruby/ruledlt.h +58 -0
- data/ext/clipsruby/rulelhs.c +1216 -0
- data/ext/clipsruby/rulelhs.h +52 -0
- data/ext/clipsruby/rulepsr.c +1073 -0
- data/ext/clipsruby/rulepsr.h +61 -0
- data/ext/clipsruby/scanner.c +856 -0
- data/ext/clipsruby/scanner.h +112 -0
- data/ext/clipsruby/setup.h +488 -0
- data/ext/clipsruby/sortfun.c +433 -0
- data/ext/clipsruby/sortfun.h +55 -0
- data/ext/clipsruby/strngfun.c +1173 -0
- data/ext/clipsruby/strngfun.h +96 -0
- data/ext/clipsruby/strngrtr.c +523 -0
- data/ext/clipsruby/strngrtr.h +97 -0
- data/ext/clipsruby/symblbin.c +648 -0
- data/ext/clipsruby/symblbin.h +64 -0
- data/ext/clipsruby/symblcmp.c +893 -0
- data/ext/clipsruby/symblcmp.h +61 -0
- data/ext/clipsruby/symbol.c +1961 -0
- data/ext/clipsruby/symbol.h +243 -0
- data/ext/clipsruby/sysdep.c +894 -0
- data/ext/clipsruby/sysdep.h +164 -0
- data/ext/clipsruby/textpro.c +1388 -0
- data/ext/clipsruby/textpro.h +77 -0
- data/ext/clipsruby/tmpltbin.c +609 -0
- data/ext/clipsruby/tmpltbin.h +108 -0
- data/ext/clipsruby/tmpltbsc.c +327 -0
- data/ext/clipsruby/tmpltbsc.h +87 -0
- data/ext/clipsruby/tmpltcmp.c +450 -0
- data/ext/clipsruby/tmpltcmp.h +57 -0
- data/ext/clipsruby/tmpltdef.c +584 -0
- data/ext/clipsruby/tmpltdef.h +155 -0
- data/ext/clipsruby/tmpltfun.c +2477 -0
- data/ext/clipsruby/tmpltfun.h +122 -0
- data/ext/clipsruby/tmpltlhs.c +379 -0
- data/ext/clipsruby/tmpltlhs.h +50 -0
- data/ext/clipsruby/tmpltpsr.c +819 -0
- data/ext/clipsruby/tmpltpsr.h +59 -0
- data/ext/clipsruby/tmpltrhs.c +595 -0
- data/ext/clipsruby/tmpltrhs.h +55 -0
- data/ext/clipsruby/tmpltutl.c +637 -0
- data/ext/clipsruby/tmpltutl.h +82 -0
- data/ext/clipsruby/userdata.c +156 -0
- data/ext/clipsruby/userdata.h +72 -0
- data/ext/clipsruby/userfunctions.c +70 -0
- data/ext/clipsruby/usrsetup.h +7 -0
- data/ext/clipsruby/utility.c +1594 -0
- data/ext/clipsruby/utility.h +250 -0
- data/ext/clipsruby/watch.c +865 -0
- data/ext/clipsruby/watch.h +124 -0
- data/lib/clipsruby.rb +1 -0
- metadata +388 -0
@@ -0,0 +1,796 @@
|
|
1
|
+
/*******************************************************/
|
2
|
+
/* "C" Language Integrated Production System */
|
3
|
+
/* */
|
4
|
+
/* CLIPS Version 6.40 09/22/17 */
|
5
|
+
/* */
|
6
|
+
/* FACT-SET QUERIES PARSER MODULE */
|
7
|
+
/*******************************************************/
|
8
|
+
|
9
|
+
/*************************************************************/
|
10
|
+
/* Purpose: Fact_set Queries Parsing Routines */
|
11
|
+
/* */
|
12
|
+
/* Principal Programmer(s): */
|
13
|
+
/* Brian L. Dantes */
|
14
|
+
/* */
|
15
|
+
/* Contributing Programmer(s): */
|
16
|
+
/* Gary D. Riley */
|
17
|
+
/* */
|
18
|
+
/* Revision History: */
|
19
|
+
/* */
|
20
|
+
/* 6.23: Added fact-set queries. */
|
21
|
+
/* */
|
22
|
+
/* Changed name of variable exp to theExp */
|
23
|
+
/* because of Unix compiler warnings of shadowed */
|
24
|
+
/* definitions. */
|
25
|
+
/* */
|
26
|
+
/* 6.24: Renamed BOOLEAN macro type to intBool. */
|
27
|
+
/* */
|
28
|
+
/* 6.30: Fixed memory leaks when error occurred. */
|
29
|
+
/* */
|
30
|
+
/* Changed integer type/precision. */
|
31
|
+
/* */
|
32
|
+
/* Added const qualifiers to remove C++ */
|
33
|
+
/* deprecation warnings. */
|
34
|
+
/* */
|
35
|
+
/* Added code to keep track of pointers to */
|
36
|
+
/* constructs that are contained externally to */
|
37
|
+
/* to constructs, DanglingConstructs. */
|
38
|
+
/* */
|
39
|
+
/* 6.31: Error check for non-symbolic slot names. */
|
40
|
+
/* */
|
41
|
+
/* 6.40: Pragma once and other inclusion changes. */
|
42
|
+
/* */
|
43
|
+
/* Added support for booleans with <stdbool.h>. */
|
44
|
+
/* */
|
45
|
+
/* Removed use of void pointers for specific */
|
46
|
+
/* data structures. */
|
47
|
+
/* */
|
48
|
+
/* Eval support for run time and bload only. */
|
49
|
+
/* */
|
50
|
+
/*************************************************************/
|
51
|
+
|
52
|
+
/* =========================================
|
53
|
+
*****************************************
|
54
|
+
EXTERNAL DEFINITIONS
|
55
|
+
=========================================
|
56
|
+
***************************************** */
|
57
|
+
#include "setup.h"
|
58
|
+
|
59
|
+
#if FACT_SET_QUERIES
|
60
|
+
|
61
|
+
#include <string.h>
|
62
|
+
|
63
|
+
#include "envrnmnt.h"
|
64
|
+
#include "exprnpsr.h"
|
65
|
+
#include "extnfunc.h"
|
66
|
+
#include "factqury.h"
|
67
|
+
#include "modulutl.h"
|
68
|
+
#include "prcdrpsr.h"
|
69
|
+
#include "pprint.h"
|
70
|
+
#include "prntutil.h"
|
71
|
+
#include "router.h"
|
72
|
+
#include "scanner.h"
|
73
|
+
#include "strngrtr.h"
|
74
|
+
|
75
|
+
#include "factqpsr.h"
|
76
|
+
|
77
|
+
/* =========================================
|
78
|
+
*****************************************
|
79
|
+
CONSTANTS
|
80
|
+
=========================================
|
81
|
+
***************************************** */
|
82
|
+
#define FACT_SLOT_REF ':'
|
83
|
+
|
84
|
+
/* =========================================
|
85
|
+
*****************************************
|
86
|
+
INTERNALLY VISIBLE FUNCTION HEADERS
|
87
|
+
=========================================
|
88
|
+
***************************************** */
|
89
|
+
|
90
|
+
/***************************************/
|
91
|
+
/* LOCAL INTERNAL FUNCTION DEFINITIONS */
|
92
|
+
/***************************************/
|
93
|
+
|
94
|
+
static Expression *ParseQueryRestrictions(Environment *,Expression *,const char *,struct token *);
|
95
|
+
static bool ReplaceTemplateNameWithReference(Environment *,Expression *);
|
96
|
+
static bool ParseQueryTestExpression(Environment *,Expression *,const char *);
|
97
|
+
static bool ParseQueryActionExpression(Environment *,Expression *,const char *,Expression *,struct token *);
|
98
|
+
static bool ReplaceFactVariables(Environment *,Expression *,Expression *,bool,int);
|
99
|
+
static bool ReplaceSlotReference(Environment *,Expression *,Expression *,
|
100
|
+
struct functionDefinition *,int);
|
101
|
+
static bool IsQueryFunction(Expression *);
|
102
|
+
|
103
|
+
/* =========================================
|
104
|
+
*****************************************
|
105
|
+
EXTERNALLY VISIBLE FUNCTIONS
|
106
|
+
=========================================
|
107
|
+
***************************************** */
|
108
|
+
|
109
|
+
/***********************************************************************
|
110
|
+
NAME : FactParseQueryNoAction
|
111
|
+
DESCRIPTION : Parses the following functions :
|
112
|
+
(any-factp)
|
113
|
+
(find-first-fact)
|
114
|
+
(find-all-facts)
|
115
|
+
INPUTS : 1) The address of the top node of the query function
|
116
|
+
2) The logical name of the input
|
117
|
+
RETURNS : The completed expression chain, or NULL on errors
|
118
|
+
SIDE EFFECTS : The expression chain is extended, or the "top" node
|
119
|
+
is deleted on errors
|
120
|
+
NOTES : H/L Syntax :
|
121
|
+
|
122
|
+
(<function> <query-block>)
|
123
|
+
|
124
|
+
<query-block> :== (<fact-var>+) <query-expression>
|
125
|
+
<fact-var> :== (<var-name> <template-name>+)
|
126
|
+
|
127
|
+
Parses into following form :
|
128
|
+
|
129
|
+
<query-function>
|
130
|
+
|
|
131
|
+
V
|
132
|
+
<query-expression> ->
|
133
|
+
|
134
|
+
<template-1a> -> <template-1b> -> (QDS) ->
|
135
|
+
|
136
|
+
<template-2a> -> <template-2b> -> (QDS) -> ...
|
137
|
+
***********************************************************************/
|
138
|
+
Expression *FactParseQueryNoAction(
|
139
|
+
Environment *theEnv,
|
140
|
+
Expression *top,
|
141
|
+
const char *readSource)
|
142
|
+
{
|
143
|
+
Expression *factQuerySetVars;
|
144
|
+
struct token queryInputToken;
|
145
|
+
|
146
|
+
factQuerySetVars = ParseQueryRestrictions(theEnv,top,readSource,&queryInputToken);
|
147
|
+
if (factQuerySetVars == NULL)
|
148
|
+
{ return NULL; }
|
149
|
+
|
150
|
+
IncrementIndentDepth(theEnv,3);
|
151
|
+
PPCRAndIndent(theEnv);
|
152
|
+
|
153
|
+
if (ParseQueryTestExpression(theEnv,top,readSource) == false)
|
154
|
+
{
|
155
|
+
DecrementIndentDepth(theEnv,3);
|
156
|
+
ReturnExpression(theEnv,factQuerySetVars);
|
157
|
+
return NULL;
|
158
|
+
}
|
159
|
+
|
160
|
+
DecrementIndentDepth(theEnv,3);
|
161
|
+
|
162
|
+
GetToken(theEnv,readSource,&queryInputToken);
|
163
|
+
if (queryInputToken.tknType != RIGHT_PARENTHESIS_TOKEN)
|
164
|
+
{
|
165
|
+
SyntaxErrorMessage(theEnv,"fact-set query function");
|
166
|
+
ReturnExpression(theEnv,top);
|
167
|
+
ReturnExpression(theEnv,factQuerySetVars);
|
168
|
+
return NULL;
|
169
|
+
}
|
170
|
+
|
171
|
+
if (ReplaceFactVariables(theEnv,factQuerySetVars,top->argList,true,0))
|
172
|
+
{
|
173
|
+
ReturnExpression(theEnv,top);
|
174
|
+
ReturnExpression(theEnv,factQuerySetVars);
|
175
|
+
return NULL;
|
176
|
+
}
|
177
|
+
|
178
|
+
ReturnExpression(theEnv,factQuerySetVars);
|
179
|
+
|
180
|
+
return top;
|
181
|
+
}
|
182
|
+
|
183
|
+
/***********************************************************************
|
184
|
+
NAME : FactParseQueryAction
|
185
|
+
DESCRIPTION : Parses the following functions :
|
186
|
+
(do-for-fact)
|
187
|
+
(do-for-all-facts)
|
188
|
+
(delayed-do-for-all-facts)
|
189
|
+
INPUTS : 1) The address of the top node of the query function
|
190
|
+
2) The logical name of the input
|
191
|
+
RETURNS : The completed expression chain, or NULL on errors
|
192
|
+
SIDE EFFECTS : The expression chain is extended, or the "top" node
|
193
|
+
is deleted on errors
|
194
|
+
NOTES : H/L Syntax :
|
195
|
+
|
196
|
+
(<function> <query-block> <query-action>)
|
197
|
+
|
198
|
+
<query-block> :== (<fact-var>+) <query-expression>
|
199
|
+
<fact-var> :== (<var-name> <template-name>+)
|
200
|
+
|
201
|
+
Parses into following form :
|
202
|
+
|
203
|
+
<query-function>
|
204
|
+
|
|
205
|
+
V
|
206
|
+
<query-expression> -> <query-action> ->
|
207
|
+
|
208
|
+
<template-1a> -> <template-1b> -> (QDS) ->
|
209
|
+
|
210
|
+
<template-2a> -> <template-2b> -> (QDS) -> ...
|
211
|
+
***********************************************************************/
|
212
|
+
Expression *FactParseQueryAction(
|
213
|
+
Environment *theEnv,
|
214
|
+
Expression *top,
|
215
|
+
const char *readSource)
|
216
|
+
{
|
217
|
+
Expression *factQuerySetVars;
|
218
|
+
struct token queryInputToken;
|
219
|
+
|
220
|
+
factQuerySetVars = ParseQueryRestrictions(theEnv,top,readSource,&queryInputToken);
|
221
|
+
if (factQuerySetVars == NULL)
|
222
|
+
{ return NULL; }
|
223
|
+
|
224
|
+
IncrementIndentDepth(theEnv,3);
|
225
|
+
PPCRAndIndent(theEnv);
|
226
|
+
|
227
|
+
if (ParseQueryTestExpression(theEnv,top,readSource) == false)
|
228
|
+
{
|
229
|
+
DecrementIndentDepth(theEnv,3);
|
230
|
+
ReturnExpression(theEnv,factQuerySetVars);
|
231
|
+
return NULL;
|
232
|
+
}
|
233
|
+
|
234
|
+
PPCRAndIndent(theEnv);
|
235
|
+
|
236
|
+
if (ParseQueryActionExpression(theEnv,top,readSource,factQuerySetVars,&queryInputToken) == false)
|
237
|
+
{
|
238
|
+
DecrementIndentDepth(theEnv,3);
|
239
|
+
ReturnExpression(theEnv,factQuerySetVars);
|
240
|
+
return NULL;
|
241
|
+
}
|
242
|
+
|
243
|
+
DecrementIndentDepth(theEnv,3);
|
244
|
+
|
245
|
+
if (queryInputToken.tknType != RIGHT_PARENTHESIS_TOKEN)
|
246
|
+
{
|
247
|
+
SyntaxErrorMessage(theEnv,"fact-set query function");
|
248
|
+
ReturnExpression(theEnv,top);
|
249
|
+
ReturnExpression(theEnv,factQuerySetVars);
|
250
|
+
return NULL;
|
251
|
+
}
|
252
|
+
|
253
|
+
if (ReplaceFactVariables(theEnv,factQuerySetVars,top->argList,true,0))
|
254
|
+
{
|
255
|
+
ReturnExpression(theEnv,top);
|
256
|
+
ReturnExpression(theEnv,factQuerySetVars);
|
257
|
+
return NULL;
|
258
|
+
}
|
259
|
+
|
260
|
+
if (ReplaceFactVariables(theEnv,factQuerySetVars,top->argList->nextArg,false,0))
|
261
|
+
{
|
262
|
+
ReturnExpression(theEnv,top);
|
263
|
+
ReturnExpression(theEnv,factQuerySetVars);
|
264
|
+
return NULL;
|
265
|
+
}
|
266
|
+
|
267
|
+
ReturnExpression(theEnv,factQuerySetVars);
|
268
|
+
|
269
|
+
return top;
|
270
|
+
}
|
271
|
+
|
272
|
+
/* =========================================
|
273
|
+
*****************************************
|
274
|
+
INTERNALLY VISIBLE FUNCTIONS
|
275
|
+
=========================================
|
276
|
+
***************************************** */
|
277
|
+
|
278
|
+
/***************************************************************
|
279
|
+
NAME : ParseQueryRestrictions
|
280
|
+
DESCRIPTION : Parses the template restrictions for a query
|
281
|
+
INPUTS : 1) The top node of the query expression
|
282
|
+
2) The logical name of the input
|
283
|
+
3) Caller's token buffer
|
284
|
+
RETURNS : The fact-variable expressions
|
285
|
+
SIDE EFFECTS : Entire query expression deleted on errors
|
286
|
+
Nodes allocated for restrictions and fact
|
287
|
+
variable expressions
|
288
|
+
Template restrictions attached to query-expression
|
289
|
+
as arguments
|
290
|
+
NOTES : Expects top != NULL
|
291
|
+
***************************************************************/
|
292
|
+
static Expression *ParseQueryRestrictions(
|
293
|
+
Environment *theEnv,
|
294
|
+
Expression *top,
|
295
|
+
const char *readSource,
|
296
|
+
struct token *queryInputToken)
|
297
|
+
{
|
298
|
+
Expression *factQuerySetVars = NULL,*lastFactQuerySetVars = NULL,
|
299
|
+
*templateExp = NULL,*lastTemplateExp,
|
300
|
+
*tmp,*lastOne = NULL;
|
301
|
+
bool error = false;
|
302
|
+
|
303
|
+
SavePPBuffer(theEnv," ");
|
304
|
+
|
305
|
+
GetToken(theEnv,readSource,queryInputToken);
|
306
|
+
if (queryInputToken->tknType != LEFT_PARENTHESIS_TOKEN)
|
307
|
+
{ goto ParseQueryRestrictionsError1; }
|
308
|
+
|
309
|
+
GetToken(theEnv,readSource,queryInputToken);
|
310
|
+
if (queryInputToken->tknType != LEFT_PARENTHESIS_TOKEN)
|
311
|
+
{ goto ParseQueryRestrictionsError1; }
|
312
|
+
|
313
|
+
while (queryInputToken->tknType == LEFT_PARENTHESIS_TOKEN)
|
314
|
+
{
|
315
|
+
GetToken(theEnv,readSource,queryInputToken);
|
316
|
+
if (queryInputToken->tknType != SF_VARIABLE_TOKEN)
|
317
|
+
{ goto ParseQueryRestrictionsError1; }
|
318
|
+
|
319
|
+
tmp = factQuerySetVars;
|
320
|
+
while (tmp != NULL)
|
321
|
+
{
|
322
|
+
if (tmp->value == queryInputToken->value)
|
323
|
+
{
|
324
|
+
PrintErrorID(theEnv,"FACTQPSR",1,false);
|
325
|
+
WriteString(theEnv,STDERR,"Duplicate fact member variable name in function ");
|
326
|
+
WriteString(theEnv,STDERR,ExpressionFunctionCallName(top)->contents);
|
327
|
+
WriteString(theEnv,STDERR,".\n");
|
328
|
+
goto ParseQueryRestrictionsError2;
|
329
|
+
}
|
330
|
+
|
331
|
+
tmp = tmp->nextArg;
|
332
|
+
}
|
333
|
+
|
334
|
+
tmp = GenConstant(theEnv,SF_VARIABLE,queryInputToken->value);
|
335
|
+
if (factQuerySetVars == NULL)
|
336
|
+
{ factQuerySetVars = tmp; }
|
337
|
+
else
|
338
|
+
{ lastFactQuerySetVars->nextArg = tmp; }
|
339
|
+
|
340
|
+
lastFactQuerySetVars = tmp;
|
341
|
+
SavePPBuffer(theEnv," ");
|
342
|
+
|
343
|
+
templateExp = ArgumentParse(theEnv,readSource,&error);
|
344
|
+
|
345
|
+
if (error)
|
346
|
+
{ goto ParseQueryRestrictionsError2; }
|
347
|
+
|
348
|
+
if (templateExp == NULL)
|
349
|
+
{ goto ParseQueryRestrictionsError1; }
|
350
|
+
|
351
|
+
if (ReplaceTemplateNameWithReference(theEnv,templateExp) == false)
|
352
|
+
{ goto ParseQueryRestrictionsError2; }
|
353
|
+
|
354
|
+
lastTemplateExp = templateExp;
|
355
|
+
SavePPBuffer(theEnv," ");
|
356
|
+
|
357
|
+
while ((tmp = ArgumentParse(theEnv,readSource,&error)) != NULL)
|
358
|
+
{
|
359
|
+
if (ReplaceTemplateNameWithReference(theEnv,tmp) == false)
|
360
|
+
goto ParseQueryRestrictionsError2;
|
361
|
+
lastTemplateExp->nextArg = tmp;
|
362
|
+
lastTemplateExp = tmp;
|
363
|
+
SavePPBuffer(theEnv," ");
|
364
|
+
}
|
365
|
+
|
366
|
+
if (error)
|
367
|
+
{ goto ParseQueryRestrictionsError2; }
|
368
|
+
|
369
|
+
PPBackup(theEnv);
|
370
|
+
PPBackup(theEnv);
|
371
|
+
SavePPBuffer(theEnv,")");
|
372
|
+
|
373
|
+
tmp = GenConstant(theEnv,SYMBOL_TYPE,FactQueryData(theEnv)->QUERY_DELIMITER_SYMBOL);
|
374
|
+
|
375
|
+
lastTemplateExp->nextArg = tmp;
|
376
|
+
lastTemplateExp = tmp;
|
377
|
+
|
378
|
+
if (top->argList == NULL)
|
379
|
+
{ top->argList = templateExp; }
|
380
|
+
else
|
381
|
+
{ lastOne->nextArg = templateExp; }
|
382
|
+
|
383
|
+
lastOne = lastTemplateExp;
|
384
|
+
templateExp = NULL;
|
385
|
+
SavePPBuffer(theEnv," ");
|
386
|
+
GetToken(theEnv,readSource,queryInputToken);
|
387
|
+
}
|
388
|
+
|
389
|
+
if (queryInputToken->tknType != RIGHT_PARENTHESIS_TOKEN)
|
390
|
+
{ goto ParseQueryRestrictionsError1; }
|
391
|
+
|
392
|
+
PPBackup(theEnv);
|
393
|
+
PPBackup(theEnv);
|
394
|
+
SavePPBuffer(theEnv,")");
|
395
|
+
return(factQuerySetVars);
|
396
|
+
|
397
|
+
ParseQueryRestrictionsError1:
|
398
|
+
SyntaxErrorMessage(theEnv,"fact-set query function");
|
399
|
+
|
400
|
+
ParseQueryRestrictionsError2:
|
401
|
+
ReturnExpression(theEnv,templateExp);
|
402
|
+
ReturnExpression(theEnv,top);
|
403
|
+
ReturnExpression(theEnv,factQuerySetVars);
|
404
|
+
return NULL;
|
405
|
+
}
|
406
|
+
|
407
|
+
/***************************************************
|
408
|
+
NAME : ReplaceTemplateNameWithReference
|
409
|
+
DESCRIPTION : In parsing an fact-set query,
|
410
|
+
this function replaces a constant
|
411
|
+
template name with an actual pointer
|
412
|
+
to the template
|
413
|
+
INPUTS : The expression
|
414
|
+
RETURNS : True if all OK, otherwise false
|
415
|
+
if template cannot be found
|
416
|
+
SIDE EFFECTS : The expression type and value are
|
417
|
+
modified if template is found
|
418
|
+
NOTES : Searches current and imported
|
419
|
+
modules for reference
|
420
|
+
***************************************************/
|
421
|
+
static bool ReplaceTemplateNameWithReference(
|
422
|
+
Environment *theEnv,
|
423
|
+
Expression *theExp)
|
424
|
+
{
|
425
|
+
const char *theTemplateName;
|
426
|
+
void *theDeftemplate;
|
427
|
+
unsigned int count;
|
428
|
+
|
429
|
+
if (theExp->type == SYMBOL_TYPE)
|
430
|
+
{
|
431
|
+
theTemplateName = theExp->lexemeValue->contents;
|
432
|
+
|
433
|
+
theDeftemplate = (Deftemplate *)
|
434
|
+
FindImportedConstruct(theEnv,"deftemplate",NULL,theTemplateName,
|
435
|
+
&count,true,NULL);
|
436
|
+
|
437
|
+
if (theDeftemplate == NULL)
|
438
|
+
{
|
439
|
+
CantFindItemErrorMessage(theEnv,"deftemplate",theTemplateName,true);
|
440
|
+
return false;
|
441
|
+
}
|
442
|
+
|
443
|
+
if (count > 1)
|
444
|
+
{
|
445
|
+
AmbiguousReferenceErrorMessage(theEnv,"deftemplate",theTemplateName);
|
446
|
+
return false;
|
447
|
+
}
|
448
|
+
|
449
|
+
theExp->type = DEFTEMPLATE_PTR;
|
450
|
+
theExp->value = theDeftemplate;
|
451
|
+
|
452
|
+
#if (! RUN_TIME) && (! BLOAD_ONLY)
|
453
|
+
if (! ConstructData(theEnv)->ParsingConstruct)
|
454
|
+
{ ConstructData(theEnv)->DanglingConstructs++; }
|
455
|
+
#endif
|
456
|
+
}
|
457
|
+
|
458
|
+
return true;
|
459
|
+
}
|
460
|
+
|
461
|
+
/*************************************************************
|
462
|
+
NAME : ParseQueryTestExpression
|
463
|
+
DESCRIPTION : Parses the test-expression for a query
|
464
|
+
INPUTS : 1) The top node of the query expression
|
465
|
+
2) The logical name of the input
|
466
|
+
RETURNS : True if all OK, false otherwise
|
467
|
+
SIDE EFFECTS : Entire query-expression deleted on errors
|
468
|
+
Nodes allocated for new expression
|
469
|
+
Test shoved in front of class-restrictions on
|
470
|
+
query argument list
|
471
|
+
NOTES : Expects top != NULL
|
472
|
+
*************************************************************/
|
473
|
+
static bool ParseQueryTestExpression(
|
474
|
+
Environment *theEnv,
|
475
|
+
Expression *top,
|
476
|
+
const char *readSource)
|
477
|
+
{
|
478
|
+
Expression *qtest;
|
479
|
+
bool error;
|
480
|
+
struct BindInfo *oldBindList;
|
481
|
+
|
482
|
+
error = false;
|
483
|
+
oldBindList = GetParsedBindNames(theEnv);
|
484
|
+
SetParsedBindNames(theEnv,NULL);
|
485
|
+
|
486
|
+
qtest = ArgumentParse(theEnv,readSource,&error);
|
487
|
+
|
488
|
+
if (error == true)
|
489
|
+
{
|
490
|
+
ClearParsedBindNames(theEnv);
|
491
|
+
SetParsedBindNames(theEnv,oldBindList);
|
492
|
+
ReturnExpression(theEnv,top);
|
493
|
+
return false;
|
494
|
+
}
|
495
|
+
|
496
|
+
if (qtest == NULL)
|
497
|
+
{
|
498
|
+
ClearParsedBindNames(theEnv);
|
499
|
+
SetParsedBindNames(theEnv,oldBindList);
|
500
|
+
SyntaxErrorMessage(theEnv,"fact-set query function");
|
501
|
+
ReturnExpression(theEnv,top);
|
502
|
+
return false;
|
503
|
+
}
|
504
|
+
|
505
|
+
qtest->nextArg = top->argList;
|
506
|
+
top->argList = qtest;
|
507
|
+
|
508
|
+
if (ParsedBindNamesEmpty(theEnv) == false)
|
509
|
+
{
|
510
|
+
ClearParsedBindNames(theEnv);
|
511
|
+
SetParsedBindNames(theEnv,oldBindList);
|
512
|
+
PrintErrorID(theEnv,"FACTQPSR",2,false);
|
513
|
+
WriteString(theEnv,STDERR,"Binds are not allowed in fact-set query in function ");
|
514
|
+
WriteString(theEnv,STDERR,ExpressionFunctionCallName(top)->contents);
|
515
|
+
WriteString(theEnv,STDERR,".\n");
|
516
|
+
ReturnExpression(theEnv,top);
|
517
|
+
return false;
|
518
|
+
}
|
519
|
+
|
520
|
+
SetParsedBindNames(theEnv,oldBindList);
|
521
|
+
|
522
|
+
return true;
|
523
|
+
}
|
524
|
+
|
525
|
+
/*************************************************************
|
526
|
+
NAME : ParseQueryActionExpression
|
527
|
+
DESCRIPTION : Parses the action-expression for a query
|
528
|
+
INPUTS : 1) The top node of the query expression
|
529
|
+
2) The logical name of the input
|
530
|
+
3) List of query parameters
|
531
|
+
RETURNS : True if all OK, false otherwise
|
532
|
+
SIDE EFFECTS : Entire query-expression deleted on errors
|
533
|
+
Nodes allocated for new expression
|
534
|
+
Action shoved in front of template-restrictions
|
535
|
+
and in back of test-expression on query
|
536
|
+
argument list
|
537
|
+
NOTES : Expects top != NULL && top->argList != NULL
|
538
|
+
*************************************************************/
|
539
|
+
static bool ParseQueryActionExpression(
|
540
|
+
Environment *theEnv,
|
541
|
+
Expression *top,
|
542
|
+
const char *readSource,
|
543
|
+
Expression *factQuerySetVars,
|
544
|
+
struct token *queryInputToken)
|
545
|
+
{
|
546
|
+
Expression *qaction,*tmpFactSetVars;
|
547
|
+
struct BindInfo *oldBindList,*newBindList,*prev;
|
548
|
+
|
549
|
+
oldBindList = GetParsedBindNames(theEnv);
|
550
|
+
SetParsedBindNames(theEnv,NULL);
|
551
|
+
|
552
|
+
ExpressionData(theEnv)->BreakContext = true;
|
553
|
+
ExpressionData(theEnv)->ReturnContext = ExpressionData(theEnv)->svContexts->rtn;
|
554
|
+
|
555
|
+
qaction = GroupActions(theEnv,readSource,queryInputToken,true,NULL,false);
|
556
|
+
|
557
|
+
PPBackup(theEnv);
|
558
|
+
PPBackup(theEnv);
|
559
|
+
SavePPBuffer(theEnv,queryInputToken->printForm);
|
560
|
+
|
561
|
+
ExpressionData(theEnv)->BreakContext = false;
|
562
|
+
|
563
|
+
if (qaction == NULL)
|
564
|
+
{
|
565
|
+
ClearParsedBindNames(theEnv);
|
566
|
+
SetParsedBindNames(theEnv,oldBindList);
|
567
|
+
SyntaxErrorMessage(theEnv,"fact-set query function");
|
568
|
+
ReturnExpression(theEnv,top);
|
569
|
+
return false;
|
570
|
+
}
|
571
|
+
|
572
|
+
qaction->nextArg = top->argList->nextArg;
|
573
|
+
top->argList->nextArg = qaction;
|
574
|
+
|
575
|
+
newBindList = GetParsedBindNames(theEnv);
|
576
|
+
prev = NULL;
|
577
|
+
while (newBindList != NULL)
|
578
|
+
{
|
579
|
+
tmpFactSetVars = factQuerySetVars;
|
580
|
+
while (tmpFactSetVars != NULL)
|
581
|
+
{
|
582
|
+
if (tmpFactSetVars->value == (void *) newBindList->name)
|
583
|
+
{
|
584
|
+
ClearParsedBindNames(theEnv);
|
585
|
+
SetParsedBindNames(theEnv,oldBindList);
|
586
|
+
PrintErrorID(theEnv,"FACTQPSR",3,false);
|
587
|
+
WriteString(theEnv,STDERR,"Cannot rebind fact-set member variable ");
|
588
|
+
WriteString(theEnv,STDERR,tmpFactSetVars->lexemeValue->contents);
|
589
|
+
WriteString(theEnv,STDERR," in function ");
|
590
|
+
WriteString(theEnv,STDERR,ExpressionFunctionCallName(top)->contents);
|
591
|
+
WriteString(theEnv,STDERR,".\n");
|
592
|
+
ReturnExpression(theEnv,top);
|
593
|
+
return false;
|
594
|
+
}
|
595
|
+
tmpFactSetVars = tmpFactSetVars->nextArg;
|
596
|
+
}
|
597
|
+
prev = newBindList;
|
598
|
+
newBindList = newBindList->next;
|
599
|
+
}
|
600
|
+
|
601
|
+
if (prev == NULL)
|
602
|
+
{ SetParsedBindNames(theEnv,oldBindList); }
|
603
|
+
else
|
604
|
+
{ prev->next = oldBindList; }
|
605
|
+
|
606
|
+
return true;
|
607
|
+
}
|
608
|
+
|
609
|
+
/***********************************************************************************
|
610
|
+
NAME : ReplaceFactVariables
|
611
|
+
DESCRIPTION : Replaces all references to fact-variables within an
|
612
|
+
fact query-function with function calls to query-fact
|
613
|
+
(which references the fact array at run-time)
|
614
|
+
INPUTS : 1) The fact-variable list
|
615
|
+
2) A boolean expression containing variable references
|
616
|
+
3) A flag indicating whether to allow slot references of the type
|
617
|
+
<fact-query-variable>:<slot-name> for direct slot access
|
618
|
+
or not
|
619
|
+
4) Nesting depth of query functions
|
620
|
+
RETURNS : Nothing useful
|
621
|
+
SIDE EFFECTS : If a SF_VARIABLE node is found and is on the list of fact
|
622
|
+
variables, it is replaced with a query-fact function call.
|
623
|
+
NOTES : Other SF_VARIABLE(S) are left alone for replacement by other
|
624
|
+
parsers. This implies that a user may use defgeneric,
|
625
|
+
defrule, and defmessage-handler variables within a query-function
|
626
|
+
where they do not conflict with fact-variable names.
|
627
|
+
***********************************************************************************/
|
628
|
+
static bool ReplaceFactVariables(
|
629
|
+
Environment *theEnv,
|
630
|
+
Expression *vlist,
|
631
|
+
Expression *bexp,
|
632
|
+
bool sdirect,
|
633
|
+
int ndepth)
|
634
|
+
{
|
635
|
+
Expression *eptr;
|
636
|
+
struct functionDefinition *rindx_func, *rslot_func;
|
637
|
+
int posn;
|
638
|
+
|
639
|
+
rindx_func = FindFunction(theEnv,"(query-fact)");
|
640
|
+
rslot_func = FindFunction(theEnv,"(query-fact-slot)");
|
641
|
+
while (bexp != NULL)
|
642
|
+
{
|
643
|
+
if (bexp->type == SF_VARIABLE)
|
644
|
+
{
|
645
|
+
eptr = vlist;
|
646
|
+
posn = 0;
|
647
|
+
while ((eptr != NULL) ? (eptr->value != bexp->value) : false)
|
648
|
+
{
|
649
|
+
eptr = eptr->nextArg;
|
650
|
+
posn++;
|
651
|
+
}
|
652
|
+
if (eptr != NULL)
|
653
|
+
{
|
654
|
+
bexp->type = FCALL;
|
655
|
+
bexp->value = rindx_func;
|
656
|
+
eptr = GenConstant(theEnv,INTEGER_TYPE,CreateInteger(theEnv,ndepth));
|
657
|
+
eptr->nextArg = GenConstant(theEnv,INTEGER_TYPE,CreateInteger(theEnv,posn));
|
658
|
+
bexp->argList = eptr;
|
659
|
+
}
|
660
|
+
else if (sdirect == true)
|
661
|
+
{
|
662
|
+
if (ReplaceSlotReference(theEnv,vlist,bexp,rslot_func,ndepth))
|
663
|
+
{ return true; }
|
664
|
+
}
|
665
|
+
}
|
666
|
+
if (bexp->argList != NULL)
|
667
|
+
{
|
668
|
+
if (IsQueryFunction(bexp))
|
669
|
+
{
|
670
|
+
if (ReplaceFactVariables(theEnv,vlist,bexp->argList,sdirect,ndepth+1))
|
671
|
+
{ return true; }
|
672
|
+
}
|
673
|
+
else
|
674
|
+
{
|
675
|
+
if (ReplaceFactVariables(theEnv,vlist,bexp->argList,sdirect,ndepth))
|
676
|
+
{ return true; }
|
677
|
+
}
|
678
|
+
}
|
679
|
+
bexp = bexp->nextArg;
|
680
|
+
}
|
681
|
+
|
682
|
+
return false;
|
683
|
+
}
|
684
|
+
|
685
|
+
/*************************************************************************
|
686
|
+
NAME : ReplaceSlotReference
|
687
|
+
DESCRIPTION : Replaces fact-set query function variable
|
688
|
+
references of the form: <fact-variable>:<slot-name>
|
689
|
+
with function calls to get these fact-slots at run
|
690
|
+
time
|
691
|
+
INPUTS : 1) The fact-set variable list
|
692
|
+
2) The expression containing the variable
|
693
|
+
3) The address of the fact slot access function
|
694
|
+
4) Nesting depth of query functions
|
695
|
+
RETURNS : Nothing useful
|
696
|
+
SIDE EFFECTS : If the variable is a slot reference, then it is replaced
|
697
|
+
with the appropriate function-call.
|
698
|
+
NOTES : None
|
699
|
+
*************************************************************************/
|
700
|
+
static bool ReplaceSlotReference(
|
701
|
+
Environment *theEnv,
|
702
|
+
Expression *vlist,
|
703
|
+
Expression *theExp,
|
704
|
+
struct functionDefinition *func,
|
705
|
+
int ndepth)
|
706
|
+
{
|
707
|
+
size_t len;
|
708
|
+
int posn;
|
709
|
+
bool oldpp;
|
710
|
+
size_t i;
|
711
|
+
const char *str;
|
712
|
+
Expression *eptr;
|
713
|
+
struct token itkn;
|
714
|
+
|
715
|
+
str = theExp->lexemeValue->contents;
|
716
|
+
len = strlen(str);
|
717
|
+
if (len < 3)
|
718
|
+
{ return false; }
|
719
|
+
|
720
|
+
for (i = len-2 ; i >= 1 ; i--)
|
721
|
+
{
|
722
|
+
if ((str[i] == FACT_SLOT_REF) ? (i >= 1) : false)
|
723
|
+
{
|
724
|
+
eptr = vlist;
|
725
|
+
posn = 0;
|
726
|
+
while (eptr && ((i != strlen(eptr->lexemeValue->contents)) ||
|
727
|
+
strncmp(eptr->lexemeValue->contents,str,
|
728
|
+
(STD_SIZE) i)))
|
729
|
+
{
|
730
|
+
eptr = eptr->nextArg;
|
731
|
+
posn++;
|
732
|
+
}
|
733
|
+
if (eptr != NULL)
|
734
|
+
{
|
735
|
+
OpenStringSource(theEnv,"query-var",str+i+1,0);
|
736
|
+
oldpp = GetPPBufferStatus(theEnv);
|
737
|
+
SetPPBufferStatus(theEnv,false);
|
738
|
+
GetToken(theEnv,"query-var",&itkn);
|
739
|
+
SetPPBufferStatus(theEnv,oldpp);
|
740
|
+
CloseStringSource(theEnv,"query-var");
|
741
|
+
|
742
|
+
if (itkn.tknType != SYMBOL_TOKEN)
|
743
|
+
{
|
744
|
+
InvalidVarSlotErrorMessage(theEnv,str);
|
745
|
+
SetEvaluationError(theEnv,true);
|
746
|
+
return true;
|
747
|
+
}
|
748
|
+
|
749
|
+
theExp->type = FCALL;
|
750
|
+
theExp->value = func;
|
751
|
+
theExp->argList = GenConstant(theEnv,INTEGER_TYPE,CreateInteger(theEnv,ndepth));
|
752
|
+
theExp->argList->nextArg = GenConstant(theEnv,INTEGER_TYPE,CreateInteger(theEnv,posn));
|
753
|
+
theExp->argList->nextArg->nextArg = GenConstant(theEnv,TokenTypeToType(itkn.tknType),itkn.value);
|
754
|
+
theExp->argList->nextArg->nextArg->nextArg = GenConstant(theEnv,SYMBOL_TYPE,CreateSymbol(theEnv,str));
|
755
|
+
return false;
|
756
|
+
}
|
757
|
+
}
|
758
|
+
}
|
759
|
+
|
760
|
+
return false;
|
761
|
+
}
|
762
|
+
|
763
|
+
/********************************************************************
|
764
|
+
NAME : IsQueryFunction
|
765
|
+
DESCRIPTION : Determines if an expression is a query function call
|
766
|
+
INPUTS : The expression
|
767
|
+
RETURNS : True if query function call, false otherwise
|
768
|
+
SIDE EFFECTS : None
|
769
|
+
NOTES : None
|
770
|
+
********************************************************************/
|
771
|
+
static bool IsQueryFunction(
|
772
|
+
Expression *theExp)
|
773
|
+
{
|
774
|
+
int (*fptr)(void);
|
775
|
+
|
776
|
+
if (theExp->type != FCALL)
|
777
|
+
return false;
|
778
|
+
fptr = (int (*)(void)) ExpressionFunctionPointer(theExp);
|
779
|
+
|
780
|
+
if (fptr == (int (*)(void)) AnyFacts)
|
781
|
+
return true;
|
782
|
+
if (fptr == (int (*)(void)) QueryFindFact)
|
783
|
+
return true;
|
784
|
+
if (fptr == (int (*)(void)) QueryFindAllFacts)
|
785
|
+
return true;
|
786
|
+
if (fptr == (int (*)(void)) QueryDoForFact)
|
787
|
+
return true;
|
788
|
+
if (fptr == (int (*)(void)) QueryDoForAllFacts)
|
789
|
+
return true;
|
790
|
+
if (fptr == (int (*)(void)) DelayedQueryDoForAllFacts)
|
791
|
+
return true;
|
792
|
+
|
793
|
+
return false;
|
794
|
+
}
|
795
|
+
|
796
|
+
#endif
|