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,1068 @@
|
|
1
|
+
/*******************************************************/
|
2
|
+
/* "C" Language Integrated Production System */
|
3
|
+
/* */
|
4
|
+
/* CLIPS Version 6.41 11/12/22 */
|
5
|
+
/* */
|
6
|
+
/* PROCEDURAL FUNCTIONS PARSER MODULE */
|
7
|
+
/*******************************************************/
|
8
|
+
|
9
|
+
/*************************************************************/
|
10
|
+
/* Purpose: */
|
11
|
+
/* */
|
12
|
+
/* Principal Programmer(s): */
|
13
|
+
/* Gary D. Riley */
|
14
|
+
/* Brian L. Dantes */
|
15
|
+
/* */
|
16
|
+
/* Contributing Programmer(s): */
|
17
|
+
/* */
|
18
|
+
/* Revision History: */
|
19
|
+
/* */
|
20
|
+
/* 6.23: Changed name of variable exp to theExp */
|
21
|
+
/* because of Unix compiler warnings of shadowed */
|
22
|
+
/* definitions. */
|
23
|
+
/* */
|
24
|
+
/* 6.24: Renamed BOOLEAN macro type to intBool. */
|
25
|
+
/* */
|
26
|
+
/* 6.30: Local variables set with the bind function */
|
27
|
+
/* persist until a reset/clear command is issued. */
|
28
|
+
/* */
|
29
|
+
/* Support for long long integers. */
|
30
|
+
/* */
|
31
|
+
/* Added const qualifiers to remove C++ */
|
32
|
+
/* deprecation warnings. */
|
33
|
+
/* */
|
34
|
+
/* Fixed linkage issue when BLOAD_ONLY compiler */
|
35
|
+
/* flag is set to 1. */
|
36
|
+
/* */
|
37
|
+
/* 6.31: Fixed 'while' function bug with optional use */
|
38
|
+
/* of 'do' keyword. */
|
39
|
+
/* */
|
40
|
+
/* 6.40: Pragma once and other inclusion changes. */
|
41
|
+
/* */
|
42
|
+
/* Added support for booleans with <stdbool.h>. */
|
43
|
+
/* */
|
44
|
+
/* Removed use of void pointers for specific */
|
45
|
+
/* data structures. */
|
46
|
+
/* */
|
47
|
+
/* UDF redesign. */
|
48
|
+
/* */
|
49
|
+
/* Eval support for run time and bload only. */
|
50
|
+
/* */
|
51
|
+
/* 6.41: Fixed invalid constraint conflict error */
|
52
|
+
/* with bind function with multiple arguments. */
|
53
|
+
/* */
|
54
|
+
/*************************************************************/
|
55
|
+
|
56
|
+
#include <stdio.h>
|
57
|
+
|
58
|
+
#include "setup.h"
|
59
|
+
|
60
|
+
#include "argacces.h"
|
61
|
+
#include "constrnt.h"
|
62
|
+
#include "cstrnchk.h"
|
63
|
+
#include "cstrnops.h"
|
64
|
+
#include "cstrnutl.h"
|
65
|
+
#include "envrnmnt.h"
|
66
|
+
#include "exprnpsr.h"
|
67
|
+
#include "memalloc.h"
|
68
|
+
#include "modulutl.h"
|
69
|
+
#include "multifld.h"
|
70
|
+
#include "pprint.h"
|
71
|
+
#include "prntutil.h"
|
72
|
+
#include "router.h"
|
73
|
+
#include "scanner.h"
|
74
|
+
#include "utility.h"
|
75
|
+
|
76
|
+
#include "prcdrpsr.h"
|
77
|
+
|
78
|
+
#if DEFGLOBAL_CONSTRUCT
|
79
|
+
#include "globldef.h"
|
80
|
+
#include "globlpsr.h"
|
81
|
+
#endif
|
82
|
+
|
83
|
+
#define PRCDRPSR_DATA 12
|
84
|
+
|
85
|
+
struct procedureParserData
|
86
|
+
{
|
87
|
+
struct BindInfo *ListOfParsedBindNames;
|
88
|
+
};
|
89
|
+
|
90
|
+
#define ProcedureParserData(theEnv) ((struct procedureParserData *) GetEnvironmentData(theEnv,PRCDRPSR_DATA))
|
91
|
+
|
92
|
+
/***************************************/
|
93
|
+
/* LOCAL INTERNAL FUNCTION DEFINITIONS */
|
94
|
+
/***************************************/
|
95
|
+
|
96
|
+
static void DeallocateProceduralFunctionData(Environment *);
|
97
|
+
static struct expr *WhileParse(Environment *,struct expr *,const char *);
|
98
|
+
static struct expr *LoopForCountParse(Environment *,struct expr *,const char *);
|
99
|
+
static void ReplaceLoopCountVars(Environment *,CLIPSLexeme *,Expression *,int);
|
100
|
+
static struct expr *IfParse(Environment *,struct expr *,const char *);
|
101
|
+
static struct expr *PrognParse(Environment *,struct expr *,const char *);
|
102
|
+
static struct expr *BindParse(Environment *,struct expr *,const char *);
|
103
|
+
static int AddBindName(Environment *,CLIPSLexeme *,CONSTRAINT_RECORD *);
|
104
|
+
static struct expr *ReturnParse(Environment *,struct expr *,const char *);
|
105
|
+
static struct expr *BreakParse(Environment *,struct expr *,const char *);
|
106
|
+
static struct expr *SwitchParse(Environment *,struct expr *,const char *);
|
107
|
+
|
108
|
+
/*****************************/
|
109
|
+
/* ProceduralFunctionParsers */
|
110
|
+
/*****************************/
|
111
|
+
void ProceduralFunctionParsers(
|
112
|
+
Environment *theEnv)
|
113
|
+
{
|
114
|
+
AllocateEnvironmentData(theEnv,PRCDRPSR_DATA,sizeof(struct procedureParserData),DeallocateProceduralFunctionData);
|
115
|
+
|
116
|
+
AddFunctionParser(theEnv,"bind",BindParse);
|
117
|
+
AddFunctionParser(theEnv,"progn",PrognParse);
|
118
|
+
AddFunctionParser(theEnv,"if",IfParse);
|
119
|
+
AddFunctionParser(theEnv,"while",WhileParse);
|
120
|
+
AddFunctionParser(theEnv,"loop-for-count",LoopForCountParse);
|
121
|
+
AddFunctionParser(theEnv,"return",ReturnParse);
|
122
|
+
AddFunctionParser(theEnv,"break",BreakParse);
|
123
|
+
AddFunctionParser(theEnv,"switch",SwitchParse);
|
124
|
+
}
|
125
|
+
|
126
|
+
/*************************************************************/
|
127
|
+
/* DeallocateProceduralFunctionData: Deallocates environment */
|
128
|
+
/* data for procedural functions. */
|
129
|
+
/*************************************************************/
|
130
|
+
static void DeallocateProceduralFunctionData(
|
131
|
+
Environment *theEnv)
|
132
|
+
{
|
133
|
+
struct BindInfo *temp_bind;
|
134
|
+
|
135
|
+
while (ProcedureParserData(theEnv)->ListOfParsedBindNames != NULL)
|
136
|
+
{
|
137
|
+
temp_bind = ProcedureParserData(theEnv)->ListOfParsedBindNames->next;
|
138
|
+
rtn_struct(theEnv,BindInfo,ProcedureParserData(theEnv)->ListOfParsedBindNames);
|
139
|
+
ProcedureParserData(theEnv)->ListOfParsedBindNames = temp_bind;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
/***********************/
|
144
|
+
/* GetParsedBindNames: */
|
145
|
+
/***********************/
|
146
|
+
struct BindInfo *GetParsedBindNames(
|
147
|
+
Environment *theEnv)
|
148
|
+
{
|
149
|
+
return(ProcedureParserData(theEnv)->ListOfParsedBindNames);
|
150
|
+
}
|
151
|
+
|
152
|
+
/***********************/
|
153
|
+
/* SetParsedBindNames: */
|
154
|
+
/***********************/
|
155
|
+
void SetParsedBindNames(
|
156
|
+
Environment *theEnv,
|
157
|
+
struct BindInfo *newValue)
|
158
|
+
{
|
159
|
+
ProcedureParserData(theEnv)->ListOfParsedBindNames = newValue;
|
160
|
+
}
|
161
|
+
|
162
|
+
/*************************/
|
163
|
+
/* ClearParsedBindNames: */
|
164
|
+
/*************************/
|
165
|
+
void ClearParsedBindNames(
|
166
|
+
Environment *theEnv)
|
167
|
+
{
|
168
|
+
struct BindInfo *temp_bind;
|
169
|
+
|
170
|
+
while (ProcedureParserData(theEnv)->ListOfParsedBindNames != NULL)
|
171
|
+
{
|
172
|
+
temp_bind = ProcedureParserData(theEnv)->ListOfParsedBindNames->next;
|
173
|
+
RemoveConstraint(theEnv,ProcedureParserData(theEnv)->ListOfParsedBindNames->constraints);
|
174
|
+
rtn_struct(theEnv,BindInfo,ProcedureParserData(theEnv)->ListOfParsedBindNames);
|
175
|
+
ProcedureParserData(theEnv)->ListOfParsedBindNames = temp_bind;
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
/*************************/
|
180
|
+
/* ParsedBindNamesEmpty: */
|
181
|
+
/*************************/
|
182
|
+
bool ParsedBindNamesEmpty(
|
183
|
+
Environment *theEnv)
|
184
|
+
{
|
185
|
+
if (ProcedureParserData(theEnv)->ListOfParsedBindNames != NULL) return false;
|
186
|
+
|
187
|
+
return true;
|
188
|
+
}
|
189
|
+
|
190
|
+
/*********************************************************/
|
191
|
+
/* WhileParse: purpose is to parse the while statement. */
|
192
|
+
/* The parse of the statement is the return value. */
|
193
|
+
/* Syntax: (while <expression> do <action>+) */
|
194
|
+
/*********************************************************/
|
195
|
+
static struct expr *WhileParse(
|
196
|
+
Environment *theEnv,
|
197
|
+
struct expr *parse,
|
198
|
+
const char *infile)
|
199
|
+
{
|
200
|
+
struct token theToken;
|
201
|
+
bool read_first_token;
|
202
|
+
|
203
|
+
/*===============================*/
|
204
|
+
/* Process the while expression. */
|
205
|
+
/*===============================*/
|
206
|
+
|
207
|
+
SavePPBuffer(theEnv," ");
|
208
|
+
|
209
|
+
parse->argList = ParseAtomOrExpression(theEnv,infile,NULL);
|
210
|
+
if (parse->argList == NULL)
|
211
|
+
{
|
212
|
+
ReturnExpression(theEnv,parse);
|
213
|
+
return NULL;
|
214
|
+
}
|
215
|
+
|
216
|
+
/*====================================*/
|
217
|
+
/* Process the do keyword if present. */
|
218
|
+
/*====================================*/
|
219
|
+
|
220
|
+
GetToken(theEnv,infile,&theToken);
|
221
|
+
if ((theToken.tknType == SYMBOL_TOKEN) && (strcmp(theToken.lexemeValue->contents,"do") == 0))
|
222
|
+
{
|
223
|
+
read_first_token = true;
|
224
|
+
PPBackup(theEnv);
|
225
|
+
SavePPBuffer(theEnv," ");
|
226
|
+
SavePPBuffer(theEnv,theToken.printForm);
|
227
|
+
IncrementIndentDepth(theEnv,3);
|
228
|
+
PPCRAndIndent(theEnv);
|
229
|
+
}
|
230
|
+
else
|
231
|
+
{
|
232
|
+
read_first_token = false;
|
233
|
+
PPBackup(theEnv);
|
234
|
+
IncrementIndentDepth(theEnv,3);
|
235
|
+
PPCRAndIndent(theEnv);
|
236
|
+
SavePPBuffer(theEnv,theToken.printForm);
|
237
|
+
}
|
238
|
+
|
239
|
+
/*============================*/
|
240
|
+
/* Process the while actions. */
|
241
|
+
/*============================*/
|
242
|
+
|
243
|
+
if (ExpressionData(theEnv)->svContexts->rtn == true)
|
244
|
+
{ ExpressionData(theEnv)->ReturnContext = true; }
|
245
|
+
ExpressionData(theEnv)->BreakContext = true;
|
246
|
+
|
247
|
+
parse->argList->nextArg = GroupActions(theEnv,infile,&theToken,read_first_token,NULL,false);
|
248
|
+
|
249
|
+
if (parse->argList->nextArg == NULL)
|
250
|
+
{
|
251
|
+
ReturnExpression(theEnv,parse);
|
252
|
+
return NULL;
|
253
|
+
}
|
254
|
+
|
255
|
+
PPBackup(theEnv);
|
256
|
+
PPBackup(theEnv);
|
257
|
+
SavePPBuffer(theEnv,theToken.printForm);
|
258
|
+
|
259
|
+
/*=======================================================*/
|
260
|
+
/* Check for the closing right parenthesis of the while. */
|
261
|
+
/*=======================================================*/
|
262
|
+
|
263
|
+
if (theToken.tknType != RIGHT_PARENTHESIS_TOKEN)
|
264
|
+
{
|
265
|
+
SyntaxErrorMessage(theEnv,"while function");
|
266
|
+
ReturnExpression(theEnv,parse);
|
267
|
+
return NULL;
|
268
|
+
}
|
269
|
+
|
270
|
+
DecrementIndentDepth(theEnv,3);
|
271
|
+
|
272
|
+
return parse;
|
273
|
+
}
|
274
|
+
|
275
|
+
/******************************************************************************************/
|
276
|
+
/* LoopForCountParse: purpose is to parse the loop-for-count statement. */
|
277
|
+
/* The parse of the statement is the return value. */
|
278
|
+
/* Syntax: (loop-for-count <range> [do] <action>+) */
|
279
|
+
/* <range> ::= (<sf-var> [<start-integer-expression>] <end-integer-expression>) */
|
280
|
+
/******************************************************************************************/
|
281
|
+
static struct expr *LoopForCountParse(
|
282
|
+
Environment *theEnv,
|
283
|
+
struct expr *parse,
|
284
|
+
const char *infile)
|
285
|
+
{
|
286
|
+
struct token theToken;
|
287
|
+
CLIPSLexeme *loopVar = NULL;
|
288
|
+
Expression *tmpexp;
|
289
|
+
bool read_first_paren;
|
290
|
+
struct BindInfo *oldBindList,*newBindList,*prev;
|
291
|
+
|
292
|
+
/*======================================*/
|
293
|
+
/* Process the loop counter expression. */
|
294
|
+
/*======================================*/
|
295
|
+
|
296
|
+
SavePPBuffer(theEnv," ");
|
297
|
+
GetToken(theEnv,infile,&theToken);
|
298
|
+
|
299
|
+
/* ==========================================
|
300
|
+
Simple form: loop-for-count <end> [do] ...
|
301
|
+
========================================== */
|
302
|
+
if (theToken.tknType != LEFT_PARENTHESIS_TOKEN)
|
303
|
+
{
|
304
|
+
parse->argList = GenConstant(theEnv,INTEGER_TYPE,CreateInteger(theEnv,1LL));
|
305
|
+
parse->argList->nextArg = ParseAtomOrExpression(theEnv,infile,&theToken);
|
306
|
+
if (parse->argList->nextArg == NULL)
|
307
|
+
{
|
308
|
+
ReturnExpression(theEnv,parse);
|
309
|
+
return NULL;
|
310
|
+
}
|
311
|
+
}
|
312
|
+
else
|
313
|
+
{
|
314
|
+
GetToken(theEnv,infile,&theToken);
|
315
|
+
if (theToken.tknType != SF_VARIABLE_TOKEN)
|
316
|
+
{
|
317
|
+
if (theToken.tknType != SYMBOL_TOKEN)
|
318
|
+
goto LoopForCountParseError;
|
319
|
+
parse->argList = GenConstant(theEnv,INTEGER_TYPE,CreateInteger(theEnv,1LL));
|
320
|
+
parse->argList->nextArg = Function2Parse(theEnv,infile,theToken.lexemeValue->contents);
|
321
|
+
if (parse->argList->nextArg == NULL)
|
322
|
+
{
|
323
|
+
ReturnExpression(theEnv,parse);
|
324
|
+
return NULL;
|
325
|
+
}
|
326
|
+
}
|
327
|
+
|
328
|
+
/* =============================================================
|
329
|
+
Complex form: loop-for-count (<var> [<start>] <end>) [do] ...
|
330
|
+
============================================================= */
|
331
|
+
else
|
332
|
+
{
|
333
|
+
loopVar = theToken.lexemeValue;
|
334
|
+
SavePPBuffer(theEnv," ");
|
335
|
+
parse->argList = ParseAtomOrExpression(theEnv,infile,NULL);
|
336
|
+
if (parse->argList == NULL)
|
337
|
+
{
|
338
|
+
ReturnExpression(theEnv,parse);
|
339
|
+
return NULL;
|
340
|
+
}
|
341
|
+
|
342
|
+
if (CheckArgumentAgainstRestriction(theEnv,parse->argList,INTEGER_BIT))
|
343
|
+
goto LoopForCountParseError;
|
344
|
+
|
345
|
+
SavePPBuffer(theEnv," ");
|
346
|
+
GetToken(theEnv,infile,&theToken);
|
347
|
+
if (theToken.tknType == RIGHT_PARENTHESIS_TOKEN)
|
348
|
+
{
|
349
|
+
PPBackup(theEnv);
|
350
|
+
PPBackup(theEnv);
|
351
|
+
SavePPBuffer(theEnv,theToken.printForm);
|
352
|
+
tmpexp = GenConstant(theEnv,INTEGER_TYPE,CreateInteger(theEnv,1LL));
|
353
|
+
tmpexp->nextArg = parse->argList;
|
354
|
+
parse->argList = tmpexp;
|
355
|
+
}
|
356
|
+
else
|
357
|
+
{
|
358
|
+
parse->argList->nextArg = ParseAtomOrExpression(theEnv,infile,&theToken);
|
359
|
+
if (parse->argList->nextArg == NULL)
|
360
|
+
{
|
361
|
+
ReturnExpression(theEnv,parse);
|
362
|
+
return NULL;
|
363
|
+
}
|
364
|
+
GetToken(theEnv,infile,&theToken);
|
365
|
+
if (theToken.tknType != RIGHT_PARENTHESIS_TOKEN)
|
366
|
+
goto LoopForCountParseError;
|
367
|
+
}
|
368
|
+
SavePPBuffer(theEnv," ");
|
369
|
+
}
|
370
|
+
}
|
371
|
+
|
372
|
+
if (CheckArgumentAgainstRestriction(theEnv,parse->argList->nextArg,INTEGER_BIT))
|
373
|
+
goto LoopForCountParseError;
|
374
|
+
|
375
|
+
/*====================================*/
|
376
|
+
/* Process the do keyword if present. */
|
377
|
+
/*====================================*/
|
378
|
+
|
379
|
+
GetToken(theEnv,infile,&theToken);
|
380
|
+
if ((theToken.tknType == SYMBOL_TOKEN) && (strcmp(theToken.lexemeValue->contents,"do") == 0))
|
381
|
+
{
|
382
|
+
read_first_paren = true;
|
383
|
+
PPBackup(theEnv);
|
384
|
+
SavePPBuffer(theEnv," ");
|
385
|
+
SavePPBuffer(theEnv,theToken.printForm);
|
386
|
+
IncrementIndentDepth(theEnv,3);
|
387
|
+
PPCRAndIndent(theEnv);
|
388
|
+
}
|
389
|
+
else if (theToken.tknType == LEFT_PARENTHESIS_TOKEN)
|
390
|
+
{
|
391
|
+
read_first_paren = false;
|
392
|
+
PPBackup(theEnv);
|
393
|
+
IncrementIndentDepth(theEnv,3);
|
394
|
+
PPCRAndIndent(theEnv);
|
395
|
+
SavePPBuffer(theEnv,theToken.printForm);
|
396
|
+
}
|
397
|
+
else
|
398
|
+
goto LoopForCountParseError;
|
399
|
+
|
400
|
+
/*=====================================*/
|
401
|
+
/* Process the loop-for-count actions. */
|
402
|
+
/*=====================================*/
|
403
|
+
if (ExpressionData(theEnv)->svContexts->rtn == true)
|
404
|
+
ExpressionData(theEnv)->ReturnContext = true;
|
405
|
+
ExpressionData(theEnv)->BreakContext = true;
|
406
|
+
oldBindList = GetParsedBindNames(theEnv);
|
407
|
+
SetParsedBindNames(theEnv,NULL);
|
408
|
+
parse->argList->nextArg->nextArg =
|
409
|
+
GroupActions(theEnv,infile,&theToken,read_first_paren,NULL,false);
|
410
|
+
|
411
|
+
if (parse->argList->nextArg->nextArg == NULL)
|
412
|
+
{
|
413
|
+
SetParsedBindNames(theEnv,oldBindList);
|
414
|
+
ReturnExpression(theEnv,parse);
|
415
|
+
return NULL;
|
416
|
+
}
|
417
|
+
newBindList = GetParsedBindNames(theEnv);
|
418
|
+
prev = NULL;
|
419
|
+
while (newBindList != NULL)
|
420
|
+
{
|
421
|
+
if ((loopVar == NULL) ? false :
|
422
|
+
(strcmp(newBindList->name->contents,loopVar->contents) == 0))
|
423
|
+
{
|
424
|
+
ClearParsedBindNames(theEnv);
|
425
|
+
SetParsedBindNames(theEnv,oldBindList);
|
426
|
+
PrintErrorID(theEnv,"PRCDRPSR",1,true);
|
427
|
+
WriteString(theEnv,STDERR,"Cannot rebind loop variable in function loop-for-count.\n");
|
428
|
+
ReturnExpression(theEnv,parse);
|
429
|
+
return NULL;
|
430
|
+
}
|
431
|
+
prev = newBindList;
|
432
|
+
newBindList = newBindList->next;
|
433
|
+
}
|
434
|
+
if (prev == NULL)
|
435
|
+
SetParsedBindNames(theEnv,oldBindList);
|
436
|
+
else
|
437
|
+
prev->next = oldBindList;
|
438
|
+
if (loopVar != NULL)
|
439
|
+
ReplaceLoopCountVars(theEnv,loopVar,parse->argList->nextArg->nextArg,0);
|
440
|
+
PPBackup(theEnv);
|
441
|
+
PPBackup(theEnv);
|
442
|
+
SavePPBuffer(theEnv,theToken.printForm);
|
443
|
+
|
444
|
+
/*================================================================*/
|
445
|
+
/* Check for the closing right parenthesis of the loop-for-count. */
|
446
|
+
/*================================================================*/
|
447
|
+
|
448
|
+
if (theToken.tknType != RIGHT_PARENTHESIS_TOKEN)
|
449
|
+
{
|
450
|
+
SyntaxErrorMessage(theEnv,"loop-for-count function");
|
451
|
+
ReturnExpression(theEnv,parse);
|
452
|
+
return NULL;
|
453
|
+
}
|
454
|
+
|
455
|
+
DecrementIndentDepth(theEnv,3);
|
456
|
+
|
457
|
+
return(parse);
|
458
|
+
|
459
|
+
LoopForCountParseError:
|
460
|
+
SyntaxErrorMessage(theEnv,"loop-for-count function");
|
461
|
+
ReturnExpression(theEnv,parse);
|
462
|
+
return NULL;
|
463
|
+
}
|
464
|
+
|
465
|
+
/*************************/
|
466
|
+
/* ReplaceLoopCountVars: */
|
467
|
+
/*************************/
|
468
|
+
static void ReplaceLoopCountVars(
|
469
|
+
Environment *theEnv,
|
470
|
+
CLIPSLexeme *loopVar,
|
471
|
+
Expression *theExp,
|
472
|
+
int depth)
|
473
|
+
{
|
474
|
+
while (theExp != NULL)
|
475
|
+
{
|
476
|
+
if ((theExp->type != SF_VARIABLE) ? false :
|
477
|
+
(strcmp(theExp->lexemeValue->contents,loopVar->contents) == 0))
|
478
|
+
{
|
479
|
+
theExp->type = FCALL;
|
480
|
+
theExp->value = FindFunction(theEnv,"(get-loop-count)");
|
481
|
+
theExp->argList = GenConstant(theEnv,INTEGER_TYPE,CreateInteger(theEnv,depth));
|
482
|
+
}
|
483
|
+
else if (theExp->argList != NULL)
|
484
|
+
{
|
485
|
+
if ((theExp->type != FCALL) ? false :
|
486
|
+
(theExp->value == (void *) FindFunction(theEnv,"loop-for-count")))
|
487
|
+
ReplaceLoopCountVars(theEnv,loopVar,theExp->argList,depth+1);
|
488
|
+
else
|
489
|
+
ReplaceLoopCountVars(theEnv,loopVar,theExp->argList,depth);
|
490
|
+
}
|
491
|
+
theExp = theExp->nextArg;
|
492
|
+
}
|
493
|
+
}
|
494
|
+
|
495
|
+
/*********************************************************/
|
496
|
+
/* IfParse: purpose is to parse the if statement. The */
|
497
|
+
/* parse of the statement is the return value. */
|
498
|
+
/* Syntax: (if <expression> then <action>+ */
|
499
|
+
/* [ else <action>+ ] ) */
|
500
|
+
/*********************************************************/
|
501
|
+
static struct expr *IfParse(
|
502
|
+
Environment *theEnv,
|
503
|
+
struct expr *top,
|
504
|
+
const char *infile)
|
505
|
+
{
|
506
|
+
struct token theToken;
|
507
|
+
|
508
|
+
/*============================*/
|
509
|
+
/* Process the if expression. */
|
510
|
+
/*============================*/
|
511
|
+
|
512
|
+
SavePPBuffer(theEnv," ");
|
513
|
+
|
514
|
+
top->argList = ParseAtomOrExpression(theEnv,infile,NULL);
|
515
|
+
|
516
|
+
if (top->argList == NULL)
|
517
|
+
{
|
518
|
+
ReturnExpression(theEnv,top);
|
519
|
+
return NULL;
|
520
|
+
}
|
521
|
+
|
522
|
+
/*========================================*/
|
523
|
+
/* Keyword 'then' must follow expression. */
|
524
|
+
/*========================================*/
|
525
|
+
|
526
|
+
IncrementIndentDepth(theEnv,3);
|
527
|
+
PPCRAndIndent(theEnv);
|
528
|
+
|
529
|
+
GetToken(theEnv,infile,&theToken);
|
530
|
+
if ((theToken.tknType != SYMBOL_TOKEN) || (strcmp(theToken.lexemeValue->contents,"then") != 0))
|
531
|
+
{
|
532
|
+
SyntaxErrorMessage(theEnv,"if function");
|
533
|
+
ReturnExpression(theEnv,top);
|
534
|
+
return NULL;
|
535
|
+
}
|
536
|
+
|
537
|
+
/*==============================*/
|
538
|
+
/* Process the if then actions. */
|
539
|
+
/*==============================*/
|
540
|
+
|
541
|
+
PPCRAndIndent(theEnv);
|
542
|
+
if (ExpressionData(theEnv)->svContexts->rtn == true)
|
543
|
+
ExpressionData(theEnv)->ReturnContext = true;
|
544
|
+
if (ExpressionData(theEnv)->svContexts->brk == true)
|
545
|
+
ExpressionData(theEnv)->BreakContext = true;
|
546
|
+
top->argList->nextArg = GroupActions(theEnv,infile,&theToken,true,"else",false);
|
547
|
+
|
548
|
+
if (top->argList->nextArg == NULL)
|
549
|
+
{
|
550
|
+
ReturnExpression(theEnv,top);
|
551
|
+
return NULL;
|
552
|
+
}
|
553
|
+
|
554
|
+
top->argList->nextArg = RemoveUnneededProgn(theEnv,top->argList->nextArg);
|
555
|
+
|
556
|
+
/*===========================================*/
|
557
|
+
/* A ')' signals an if then without an else. */
|
558
|
+
/*===========================================*/
|
559
|
+
|
560
|
+
if (theToken.tknType == RIGHT_PARENTHESIS_TOKEN)
|
561
|
+
{
|
562
|
+
DecrementIndentDepth(theEnv,3);
|
563
|
+
PPBackup(theEnv);
|
564
|
+
PPBackup(theEnv);
|
565
|
+
SavePPBuffer(theEnv,theToken.printForm);
|
566
|
+
return(top);
|
567
|
+
}
|
568
|
+
|
569
|
+
/*=============================================*/
|
570
|
+
/* Keyword 'else' must follow if then actions. */
|
571
|
+
/*=============================================*/
|
572
|
+
|
573
|
+
if ((theToken.tknType != SYMBOL_TOKEN) || (strcmp(theToken.lexemeValue->contents,"else") != 0))
|
574
|
+
{
|
575
|
+
SyntaxErrorMessage(theEnv,"if function");
|
576
|
+
ReturnExpression(theEnv,top);
|
577
|
+
return NULL;
|
578
|
+
}
|
579
|
+
|
580
|
+
/*==============================*/
|
581
|
+
/* Process the if else actions. */
|
582
|
+
/*==============================*/
|
583
|
+
|
584
|
+
PPCRAndIndent(theEnv);
|
585
|
+
top->argList->nextArg->nextArg = GroupActions(theEnv,infile,&theToken,true,NULL,false);
|
586
|
+
|
587
|
+
if (top->argList->nextArg->nextArg == NULL)
|
588
|
+
{
|
589
|
+
ReturnExpression(theEnv,top);
|
590
|
+
return NULL;
|
591
|
+
}
|
592
|
+
|
593
|
+
top->argList->nextArg->nextArg = RemoveUnneededProgn(theEnv,top->argList->nextArg->nextArg);
|
594
|
+
|
595
|
+
/*======================================================*/
|
596
|
+
/* Check for the closing right parenthesis of the if. */
|
597
|
+
/*======================================================*/
|
598
|
+
|
599
|
+
if (theToken.tknType != RIGHT_PARENTHESIS_TOKEN)
|
600
|
+
{
|
601
|
+
SyntaxErrorMessage(theEnv,"if function");
|
602
|
+
ReturnExpression(theEnv,top);
|
603
|
+
return NULL;
|
604
|
+
}
|
605
|
+
|
606
|
+
/*===========================================*/
|
607
|
+
/* A ')' signals an if then without an else. */
|
608
|
+
/*===========================================*/
|
609
|
+
|
610
|
+
PPBackup(theEnv);
|
611
|
+
PPBackup(theEnv);
|
612
|
+
SavePPBuffer(theEnv,")");
|
613
|
+
DecrementIndentDepth(theEnv,3);
|
614
|
+
return(top);
|
615
|
+
}
|
616
|
+
|
617
|
+
/********************************************************/
|
618
|
+
/* PrognParse: purpose is to parse the progn statement. */
|
619
|
+
/* The parse of the statement is the return value. */
|
620
|
+
/* Syntax: (progn <expression>*) */
|
621
|
+
/********************************************************/
|
622
|
+
static struct expr *PrognParse(
|
623
|
+
Environment *theEnv,
|
624
|
+
struct expr *top,
|
625
|
+
const char *infile)
|
626
|
+
{
|
627
|
+
struct token tkn;
|
628
|
+
struct expr *tmp;
|
629
|
+
|
630
|
+
ReturnExpression(theEnv,top);
|
631
|
+
ExpressionData(theEnv)->BreakContext = ExpressionData(theEnv)->svContexts->brk;
|
632
|
+
ExpressionData(theEnv)->ReturnContext = ExpressionData(theEnv)->svContexts->rtn;
|
633
|
+
IncrementIndentDepth(theEnv,3);
|
634
|
+
PPCRAndIndent(theEnv);
|
635
|
+
tmp = GroupActions(theEnv,infile,&tkn,true,NULL,false);
|
636
|
+
DecrementIndentDepth(theEnv,3);
|
637
|
+
PPBackup(theEnv);
|
638
|
+
PPBackup(theEnv);
|
639
|
+
SavePPBuffer(theEnv,tkn.printForm);
|
640
|
+
return(tmp);
|
641
|
+
}
|
642
|
+
|
643
|
+
/***********************************************************/
|
644
|
+
/* BindParse: purpose is to parse the bind statement. The */
|
645
|
+
/* parse of the statement is the return value. */
|
646
|
+
/* Syntax: (bind ?var <expression>) */
|
647
|
+
/***********************************************************/
|
648
|
+
static struct expr *BindParse(
|
649
|
+
Environment *theEnv,
|
650
|
+
struct expr *top,
|
651
|
+
const char *infile)
|
652
|
+
{
|
653
|
+
struct token theToken;
|
654
|
+
CLIPSLexeme *variableName;
|
655
|
+
struct expr *texp;
|
656
|
+
CONSTRAINT_RECORD *theConstraint = NULL;
|
657
|
+
#if DEFGLOBAL_CONSTRUCT
|
658
|
+
Defglobal *theGlobal = NULL;
|
659
|
+
unsigned int count;
|
660
|
+
#endif
|
661
|
+
|
662
|
+
SavePPBuffer(theEnv," ");
|
663
|
+
|
664
|
+
/*=============================================*/
|
665
|
+
/* Next token must be the name of the variable */
|
666
|
+
/* to be bound. */
|
667
|
+
/*=============================================*/
|
668
|
+
|
669
|
+
GetToken(theEnv,infile,&theToken);
|
670
|
+
if ((theToken.tknType != SF_VARIABLE_TOKEN) &&
|
671
|
+
(theToken.tknType != GBL_VARIABLE_TOKEN))
|
672
|
+
{
|
673
|
+
if ((theToken.tknType != MF_VARIABLE_TOKEN) || ExpressionData(theEnv)->SequenceOpMode)
|
674
|
+
{
|
675
|
+
SyntaxErrorMessage(theEnv,"bind function");
|
676
|
+
ReturnExpression(theEnv,top);
|
677
|
+
return NULL;
|
678
|
+
}
|
679
|
+
}
|
680
|
+
|
681
|
+
/*==============================*/
|
682
|
+
/* Process the bind expression. */
|
683
|
+
/*==============================*/
|
684
|
+
|
685
|
+
top->argList = GenConstant(theEnv,SYMBOL_TYPE,theToken.value);
|
686
|
+
variableName = theToken.lexemeValue;
|
687
|
+
|
688
|
+
#if DEFGLOBAL_CONSTRUCT
|
689
|
+
if ((theToken.tknType == GBL_VARIABLE_TOKEN) ?
|
690
|
+
((theGlobal = (Defglobal *)
|
691
|
+
FindImportedConstruct(theEnv,"defglobal",NULL,variableName->contents,
|
692
|
+
&count,true,NULL)) != NULL) :
|
693
|
+
false)
|
694
|
+
{
|
695
|
+
top->argList->type = DEFGLOBAL_PTR;
|
696
|
+
top->argList->value = theGlobal;
|
697
|
+
}
|
698
|
+
else if (theToken.tknType == GBL_VARIABLE_TOKEN)
|
699
|
+
{
|
700
|
+
GlobalReferenceErrorMessage(theEnv,variableName->contents);
|
701
|
+
ReturnExpression(theEnv,top);
|
702
|
+
return NULL;
|
703
|
+
}
|
704
|
+
#endif
|
705
|
+
|
706
|
+
texp = get_struct(theEnv,expr);
|
707
|
+
texp->argList = texp->nextArg = NULL;
|
708
|
+
if (CollectArguments(theEnv,texp,infile) == NULL)
|
709
|
+
{
|
710
|
+
ReturnExpression(theEnv,top);
|
711
|
+
return NULL;
|
712
|
+
}
|
713
|
+
|
714
|
+
top->argList->nextArg = texp->argList;
|
715
|
+
rtn_struct(theEnv,expr,texp);
|
716
|
+
|
717
|
+
#if DEFGLOBAL_CONSTRUCT
|
718
|
+
if (top->argList->type == DEFGLOBAL_PTR) return(top);
|
719
|
+
#endif
|
720
|
+
|
721
|
+
if (top->argList->nextArg != NULL)
|
722
|
+
{
|
723
|
+
if (top->argList->nextArg->nextArg != NULL)
|
724
|
+
{
|
725
|
+
theConstraint = GetConstraintRecord(theEnv);
|
726
|
+
theConstraint->multifieldsAllowed = true;
|
727
|
+
}
|
728
|
+
else
|
729
|
+
{ theConstraint = ExpressionToConstraintRecord(theEnv,top->argList->nextArg); }
|
730
|
+
}
|
731
|
+
|
732
|
+
AddBindName(theEnv,variableName,theConstraint);
|
733
|
+
|
734
|
+
return(top);
|
735
|
+
}
|
736
|
+
|
737
|
+
/********************************************/
|
738
|
+
/* ReturnParse: Parses the return function. */
|
739
|
+
/********************************************/
|
740
|
+
static struct expr *ReturnParse(
|
741
|
+
Environment *theEnv,
|
742
|
+
struct expr *top,
|
743
|
+
const char *infile)
|
744
|
+
{
|
745
|
+
bool error_flag = false;
|
746
|
+
struct token theToken;
|
747
|
+
|
748
|
+
if (ExpressionData(theEnv)->svContexts->rtn == true)
|
749
|
+
ExpressionData(theEnv)->ReturnContext = true;
|
750
|
+
if (ExpressionData(theEnv)->ReturnContext == false)
|
751
|
+
{
|
752
|
+
PrintErrorID(theEnv,"PRCDRPSR",2,true);
|
753
|
+
WriteString(theEnv,STDERR,"The return function is not valid in this context.\n");
|
754
|
+
ReturnExpression(theEnv,top);
|
755
|
+
return NULL;
|
756
|
+
}
|
757
|
+
ExpressionData(theEnv)->ReturnContext = false;
|
758
|
+
|
759
|
+
SavePPBuffer(theEnv," ");
|
760
|
+
|
761
|
+
top->argList = ArgumentParse(theEnv,infile,&error_flag);
|
762
|
+
if (error_flag)
|
763
|
+
{
|
764
|
+
ReturnExpression(theEnv,top);
|
765
|
+
return NULL;
|
766
|
+
}
|
767
|
+
else if (top->argList == NULL)
|
768
|
+
{
|
769
|
+
PPBackup(theEnv);
|
770
|
+
PPBackup(theEnv);
|
771
|
+
SavePPBuffer(theEnv,")");
|
772
|
+
}
|
773
|
+
else
|
774
|
+
{
|
775
|
+
SavePPBuffer(theEnv," ");
|
776
|
+
GetToken(theEnv,infile,&theToken);
|
777
|
+
if (theToken.tknType != RIGHT_PARENTHESIS_TOKEN)
|
778
|
+
{
|
779
|
+
SyntaxErrorMessage(theEnv,"return function");
|
780
|
+
ReturnExpression(theEnv,top);
|
781
|
+
return NULL;
|
782
|
+
}
|
783
|
+
PPBackup(theEnv);
|
784
|
+
PPBackup(theEnv);
|
785
|
+
SavePPBuffer(theEnv,")");
|
786
|
+
}
|
787
|
+
return(top);
|
788
|
+
}
|
789
|
+
|
790
|
+
/***************/
|
791
|
+
/* BreakParse: */
|
792
|
+
/***************/
|
793
|
+
static struct expr *BreakParse(
|
794
|
+
Environment *theEnv,
|
795
|
+
struct expr *top,
|
796
|
+
const char *infile)
|
797
|
+
{
|
798
|
+
struct token theToken;
|
799
|
+
|
800
|
+
if (ExpressionData(theEnv)->svContexts->brk == false)
|
801
|
+
{
|
802
|
+
PrintErrorID(theEnv,"PRCDRPSR",2,true);
|
803
|
+
WriteString(theEnv,STDERR,"The break function not valid in this context.\n");
|
804
|
+
ReturnExpression(theEnv,top);
|
805
|
+
return NULL;
|
806
|
+
}
|
807
|
+
|
808
|
+
SavePPBuffer(theEnv," ");
|
809
|
+
GetToken(theEnv,infile,&theToken);
|
810
|
+
if (theToken.tknType != RIGHT_PARENTHESIS_TOKEN)
|
811
|
+
{
|
812
|
+
SyntaxErrorMessage(theEnv,"break function");
|
813
|
+
ReturnExpression(theEnv,top);
|
814
|
+
return NULL;
|
815
|
+
}
|
816
|
+
PPBackup(theEnv);
|
817
|
+
PPBackup(theEnv);
|
818
|
+
SavePPBuffer(theEnv,")");
|
819
|
+
return(top);
|
820
|
+
}
|
821
|
+
|
822
|
+
/****************/
|
823
|
+
/* SwitchParse: */
|
824
|
+
/****************/
|
825
|
+
static struct expr *SwitchParse(
|
826
|
+
Environment *theEnv,
|
827
|
+
struct expr *top,
|
828
|
+
const char *infile)
|
829
|
+
{
|
830
|
+
struct token theToken;
|
831
|
+
Expression *theExp,*chk;
|
832
|
+
int default_count = 0;
|
833
|
+
|
834
|
+
/*============================*/
|
835
|
+
/* Process the switch value */
|
836
|
+
/*============================*/
|
837
|
+
IncrementIndentDepth(theEnv,3);
|
838
|
+
SavePPBuffer(theEnv," ");
|
839
|
+
top->argList = theExp = ParseAtomOrExpression(theEnv,infile,NULL);
|
840
|
+
if (theExp == NULL)
|
841
|
+
goto SwitchParseError;
|
842
|
+
|
843
|
+
/*========================*/
|
844
|
+
/* Parse case statements. */
|
845
|
+
/*========================*/
|
846
|
+
GetToken(theEnv,infile,&theToken);
|
847
|
+
while (theToken.tknType != RIGHT_PARENTHESIS_TOKEN)
|
848
|
+
{
|
849
|
+
PPBackup(theEnv);
|
850
|
+
PPCRAndIndent(theEnv);
|
851
|
+
SavePPBuffer(theEnv,theToken.printForm);
|
852
|
+
if (theToken.tknType != LEFT_PARENTHESIS_TOKEN)
|
853
|
+
goto SwitchParseErrorAndMessage;
|
854
|
+
GetToken(theEnv,infile,&theToken);
|
855
|
+
SavePPBuffer(theEnv," ");
|
856
|
+
if ((theToken.tknType == SYMBOL_TOKEN) &&
|
857
|
+
(strcmp(theToken.lexemeValue->contents,"case") == 0))
|
858
|
+
{
|
859
|
+
if (default_count != 0)
|
860
|
+
goto SwitchParseErrorAndMessage;
|
861
|
+
theExp->nextArg = ParseAtomOrExpression(theEnv,infile,NULL);
|
862
|
+
SavePPBuffer(theEnv," ");
|
863
|
+
if (theExp->nextArg == NULL)
|
864
|
+
goto SwitchParseError;
|
865
|
+
for (chk = top->argList->nextArg ; chk != theExp->nextArg ; chk = chk->nextArg)
|
866
|
+
{
|
867
|
+
if ((chk->type == theExp->nextArg->type) &&
|
868
|
+
(chk->value == theExp->nextArg->value) &&
|
869
|
+
IdenticalExpression(chk->argList,theExp->nextArg->argList))
|
870
|
+
{
|
871
|
+
PrintErrorID(theEnv,"PRCDRPSR",3,true);
|
872
|
+
WriteString(theEnv,STDERR,"Duplicate case found in switch function.\n");
|
873
|
+
goto SwitchParseError;
|
874
|
+
}
|
875
|
+
}
|
876
|
+
GetToken(theEnv,infile,&theToken);
|
877
|
+
if ((theToken.tknType != SYMBOL_TOKEN) ? true :
|
878
|
+
(strcmp(theToken.lexemeValue->contents,"then") != 0))
|
879
|
+
goto SwitchParseErrorAndMessage;
|
880
|
+
}
|
881
|
+
else if ((theToken.tknType == SYMBOL_TOKEN) &&
|
882
|
+
(strcmp(theToken.lexemeValue->contents,"default") == 0))
|
883
|
+
{
|
884
|
+
if (default_count)
|
885
|
+
goto SwitchParseErrorAndMessage;
|
886
|
+
theExp->nextArg = GenConstant(theEnv,VOID_TYPE,NULL);
|
887
|
+
default_count = 1;
|
888
|
+
}
|
889
|
+
else
|
890
|
+
goto SwitchParseErrorAndMessage;
|
891
|
+
theExp = theExp->nextArg;
|
892
|
+
if (ExpressionData(theEnv)->svContexts->rtn == true)
|
893
|
+
ExpressionData(theEnv)->ReturnContext = true;
|
894
|
+
if (ExpressionData(theEnv)->svContexts->brk == true)
|
895
|
+
ExpressionData(theEnv)->BreakContext = true;
|
896
|
+
IncrementIndentDepth(theEnv,3);
|
897
|
+
PPCRAndIndent(theEnv);
|
898
|
+
theExp->nextArg = GroupActions(theEnv,infile,&theToken,true,NULL,false);
|
899
|
+
DecrementIndentDepth(theEnv,3);
|
900
|
+
ExpressionData(theEnv)->ReturnContext = false;
|
901
|
+
ExpressionData(theEnv)->BreakContext = false;
|
902
|
+
if (theExp->nextArg == NULL)
|
903
|
+
goto SwitchParseError;
|
904
|
+
theExp = theExp->nextArg;
|
905
|
+
PPBackup(theEnv);
|
906
|
+
PPBackup(theEnv);
|
907
|
+
SavePPBuffer(theEnv,theToken.printForm);
|
908
|
+
GetToken(theEnv,infile,&theToken);
|
909
|
+
}
|
910
|
+
DecrementIndentDepth(theEnv,3);
|
911
|
+
return(top);
|
912
|
+
|
913
|
+
SwitchParseErrorAndMessage:
|
914
|
+
SyntaxErrorMessage(theEnv,"switch function");
|
915
|
+
SwitchParseError:
|
916
|
+
ReturnExpression(theEnv,top);
|
917
|
+
DecrementIndentDepth(theEnv,3);
|
918
|
+
return NULL;
|
919
|
+
}
|
920
|
+
|
921
|
+
/**************************/
|
922
|
+
/* SearchParsedBindNames: */
|
923
|
+
/**************************/
|
924
|
+
unsigned short SearchParsedBindNames(
|
925
|
+
Environment *theEnv,
|
926
|
+
CLIPSLexeme *name_sought)
|
927
|
+
{
|
928
|
+
struct BindInfo *var_ptr;
|
929
|
+
unsigned short theIndex = 1;
|
930
|
+
|
931
|
+
var_ptr = ProcedureParserData(theEnv)->ListOfParsedBindNames;
|
932
|
+
while (var_ptr != NULL)
|
933
|
+
{
|
934
|
+
if (var_ptr->name == name_sought)
|
935
|
+
{ return theIndex; }
|
936
|
+
var_ptr = var_ptr->next;
|
937
|
+
theIndex++;
|
938
|
+
}
|
939
|
+
|
940
|
+
return 0;
|
941
|
+
}
|
942
|
+
|
943
|
+
/************************/
|
944
|
+
/* FindBindConstraints: */
|
945
|
+
/************************/
|
946
|
+
struct constraintRecord *FindBindConstraints(
|
947
|
+
Environment *theEnv,
|
948
|
+
CLIPSLexeme *nameSought)
|
949
|
+
{
|
950
|
+
struct BindInfo *theVariable;
|
951
|
+
|
952
|
+
theVariable = ProcedureParserData(theEnv)->ListOfParsedBindNames;
|
953
|
+
while (theVariable != NULL)
|
954
|
+
{
|
955
|
+
if (theVariable->name == nameSought)
|
956
|
+
{ return(theVariable->constraints); }
|
957
|
+
theVariable = theVariable->next;
|
958
|
+
}
|
959
|
+
|
960
|
+
return NULL;
|
961
|
+
}
|
962
|
+
|
963
|
+
/********************************************************/
|
964
|
+
/* CountParsedBindNames: Counts the number of variables */
|
965
|
+
/* names that have been bound using the bind function */
|
966
|
+
/* in the current context (e.g. the RHS of a rule). */
|
967
|
+
/********************************************************/
|
968
|
+
unsigned short CountParsedBindNames(
|
969
|
+
Environment *theEnv)
|
970
|
+
{
|
971
|
+
struct BindInfo *theVariable;
|
972
|
+
unsigned short theIndex = 0;
|
973
|
+
|
974
|
+
theVariable = ProcedureParserData(theEnv)->ListOfParsedBindNames;
|
975
|
+
while (theVariable != NULL)
|
976
|
+
{
|
977
|
+
theVariable = theVariable->next;
|
978
|
+
theIndex++;
|
979
|
+
}
|
980
|
+
|
981
|
+
return theIndex;
|
982
|
+
}
|
983
|
+
|
984
|
+
/****************************************************************/
|
985
|
+
/* AddBindName: Adds a variable name used as the first argument */
|
986
|
+
/* of the bind function to the list of variable names parsed */
|
987
|
+
/* within the current semantic context (e.g. RHS of a rule). */
|
988
|
+
/****************************************************************/
|
989
|
+
static int AddBindName(
|
990
|
+
Environment *theEnv,
|
991
|
+
CLIPSLexeme *variableName,
|
992
|
+
CONSTRAINT_RECORD *theConstraint)
|
993
|
+
{
|
994
|
+
CONSTRAINT_RECORD *tmpConstraint;
|
995
|
+
struct BindInfo *currentBind, *lastBind;
|
996
|
+
int theIndex = 1;
|
997
|
+
|
998
|
+
/*=========================================================*/
|
999
|
+
/* Look for the variable name in the list of bind variable */
|
1000
|
+
/* names already parsed. If it is found, then return the */
|
1001
|
+
/* index to the variable and union the new constraint */
|
1002
|
+
/* information with the old constraint information. */
|
1003
|
+
/*=========================================================*/
|
1004
|
+
|
1005
|
+
lastBind = NULL;
|
1006
|
+
currentBind = ProcedureParserData(theEnv)->ListOfParsedBindNames;
|
1007
|
+
while (currentBind != NULL)
|
1008
|
+
{
|
1009
|
+
if (currentBind->name == variableName)
|
1010
|
+
{
|
1011
|
+
if (theConstraint != NULL)
|
1012
|
+
{
|
1013
|
+
tmpConstraint = currentBind->constraints;
|
1014
|
+
currentBind->constraints = UnionConstraints(theEnv,theConstraint,currentBind->constraints);
|
1015
|
+
RemoveConstraint(theEnv,tmpConstraint);
|
1016
|
+
RemoveConstraint(theEnv,theConstraint);
|
1017
|
+
}
|
1018
|
+
|
1019
|
+
return(theIndex);
|
1020
|
+
}
|
1021
|
+
lastBind = currentBind;
|
1022
|
+
currentBind = currentBind->next;
|
1023
|
+
theIndex++;
|
1024
|
+
}
|
1025
|
+
|
1026
|
+
/*===============================================================*/
|
1027
|
+
/* If the variable name wasn't found, then add it to the list of */
|
1028
|
+
/* variable names and store the constraint information with it. */
|
1029
|
+
/*===============================================================*/
|
1030
|
+
|
1031
|
+
currentBind = get_struct(theEnv,BindInfo);
|
1032
|
+
currentBind->name = variableName;
|
1033
|
+
currentBind->constraints = theConstraint;
|
1034
|
+
currentBind->next = NULL;
|
1035
|
+
|
1036
|
+
if (lastBind == NULL) ProcedureParserData(theEnv)->ListOfParsedBindNames = currentBind;
|
1037
|
+
else lastBind->next = currentBind;
|
1038
|
+
|
1039
|
+
return(theIndex);
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
/*************************/
|
1043
|
+
/* RemoveParsedBindName: */
|
1044
|
+
/*************************/
|
1045
|
+
void RemoveParsedBindName(
|
1046
|
+
Environment *theEnv,
|
1047
|
+
CLIPSLexeme *bname)
|
1048
|
+
{
|
1049
|
+
struct BindInfo *prv,*tmp;
|
1050
|
+
|
1051
|
+
prv = NULL;
|
1052
|
+
tmp = ProcedureParserData(theEnv)->ListOfParsedBindNames;
|
1053
|
+
while ((tmp != NULL) ? (tmp->name != bname) : false)
|
1054
|
+
{
|
1055
|
+
prv = tmp;
|
1056
|
+
tmp = tmp->next;
|
1057
|
+
}
|
1058
|
+
if (tmp != NULL)
|
1059
|
+
{
|
1060
|
+
if (prv == NULL)
|
1061
|
+
ProcedureParserData(theEnv)->ListOfParsedBindNames = tmp->next;
|
1062
|
+
else
|
1063
|
+
prv->next = tmp->next;
|
1064
|
+
|
1065
|
+
RemoveConstraint(theEnv,tmp->constraints);
|
1066
|
+
rtn_struct(theEnv,BindInfo,tmp);
|
1067
|
+
}
|
1068
|
+
}
|