diff options
Diffstat (limited to '')
16 files changed, 0 insertions, 15874 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Atom.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Atom.cs deleted file mode 100644 index 27ab04e..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Atom.cs +++ /dev/null | |||
@@ -1,218 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections.Generic; | ||
33 | using System.Text; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
36 | { | ||
37 | public class Atom : IUnifiable | ||
38 | { | ||
39 | private static Dictionary<string, Atom> _atomStore = new Dictionary<string, Atom>(); | ||
40 | public readonly string _name; | ||
41 | public readonly Atom _module; | ||
42 | |||
43 | /// <summary> | ||
44 | /// You should not call this constructor, but use Atom.a instead. | ||
45 | /// </summary> | ||
46 | /// <param name="name"></param> | ||
47 | /// <param name="module"></param> | ||
48 | private Atom(string name, Atom module) | ||
49 | { | ||
50 | _name = name; | ||
51 | _module = module; | ||
52 | } | ||
53 | |||
54 | /// <summary> | ||
55 | /// Return the unique Atom object for name where module is null. You should use this to create | ||
56 | /// an Atom instead of calling the Atom constructor. | ||
57 | /// </summary> | ||
58 | /// <param name="name"></param> | ||
59 | /// <returns></returns> | ||
60 | public static Atom a(string name) | ||
61 | { | ||
62 | Atom atom; | ||
63 | if (!_atomStore.TryGetValue(name, out atom)) | ||
64 | { | ||
65 | atom = new Atom(name, null); | ||
66 | _atomStore[name] = atom; | ||
67 | } | ||
68 | return atom; | ||
69 | } | ||
70 | |||
71 | /// <summary> | ||
72 | /// Return an Atom object with the name and module. If module is null or Atom.NIL, | ||
73 | /// this behaves like Atom.a(name) and returns the unique object where the module is null. | ||
74 | /// If module is not null or Atom.NIL, this may or may not be the same object as another Atom | ||
75 | /// with the same name and module. | ||
76 | /// </summary> | ||
77 | /// <param name="name"></param> | ||
78 | /// <param name="module"></param> | ||
79 | /// <returns></returns> | ||
80 | public static Atom a(string name, Atom module) | ||
81 | { | ||
82 | if (module == null || module == Atom.NIL) | ||
83 | return a(name); | ||
84 | return new Atom(name, module); | ||
85 | } | ||
86 | |||
87 | /// <summary> | ||
88 | /// If Obj is an Atom unify its _module with Module. If the Atom's _module is null, use Atom.NIL. | ||
89 | /// </summary> | ||
90 | /// <param name="Atom"></param> | ||
91 | /// <param name="Module"></param> | ||
92 | /// <returns></returns> | ||
93 | public static IEnumerable<bool> module(object Obj, object Module) | ||
94 | { | ||
95 | Obj = YP.getValue(Obj); | ||
96 | if (Obj is Atom) | ||
97 | { | ||
98 | if (((Atom)Obj)._module == null) | ||
99 | return YP.unify(Module, Atom.NIL); | ||
100 | else | ||
101 | return YP.unify(Module, ((Atom)Obj)._module); | ||
102 | } | ||
103 | return YP.fail(); | ||
104 | } | ||
105 | |||
106 | public static readonly Atom NIL = Atom.a("[]"); | ||
107 | public static readonly Atom DOT = Atom.a("."); | ||
108 | public static readonly Atom F = Atom.a("f"); | ||
109 | public static readonly Atom SLASH = Atom.a("/"); | ||
110 | public static readonly Atom HAT = Atom.a("^"); | ||
111 | public static readonly Atom RULE = Atom.a(":-"); | ||
112 | |||
113 | public IEnumerable<bool> unify(object arg) | ||
114 | { | ||
115 | arg = YP.getValue(arg); | ||
116 | if (arg is Atom) | ||
117 | return Equals(arg) ? YP.succeed() : YP.fail(); | ||
118 | else if (arg is Variable) | ||
119 | return ((Variable)arg).unify(this); | ||
120 | else | ||
121 | return YP.fail(); | ||
122 | } | ||
123 | |||
124 | public void addUniqueVariables(List<Variable> variableSet) | ||
125 | { | ||
126 | // Atom does not contain variables. | ||
127 | } | ||
128 | |||
129 | public object makeCopy(Variable.CopyStore copyStore) | ||
130 | { | ||
131 | // Atom does not contain variables that need to be copied. | ||
132 | return this; | ||
133 | } | ||
134 | |||
135 | public bool termEqual(object term) | ||
136 | { | ||
137 | return Equals(YP.getValue(term)); | ||
138 | } | ||
139 | |||
140 | public bool ground() | ||
141 | { | ||
142 | // Atom is always ground. | ||
143 | return true; | ||
144 | } | ||
145 | |||
146 | public override bool Equals(object obj) | ||
147 | { | ||
148 | if (obj is Atom) | ||
149 | { | ||
150 | if (_module == null && ((Atom)obj)._module == null) | ||
151 | // When _declaringClass is null, we always use an identical object from _atomStore. | ||
152 | return this == obj; | ||
153 | // Otherwise, ignore _declaringClass and do a normal string compare on the _name. | ||
154 | return _name == ((Atom)obj)._name; | ||
155 | } | ||
156 | return false; | ||
157 | } | ||
158 | |||
159 | public override string ToString() | ||
160 | { | ||
161 | return _name; | ||
162 | } | ||
163 | |||
164 | public override int GetHashCode() | ||
165 | { | ||
166 | // Debug: need to check _declaringClass. | ||
167 | return _name.GetHashCode(); | ||
168 | } | ||
169 | |||
170 | public string toQuotedString() | ||
171 | { | ||
172 | if (_name.Length == 0) | ||
173 | return "''"; | ||
174 | else if (this == Atom.NIL) | ||
175 | return "[]"; | ||
176 | |||
177 | StringBuilder result = new StringBuilder(_name.Length); | ||
178 | bool useQuotes = false; | ||
179 | foreach (char c in _name) | ||
180 | { | ||
181 | int cInt = (int)c; | ||
182 | if (c == '\'') | ||
183 | { | ||
184 | result.Append("''"); | ||
185 | useQuotes = true; | ||
186 | } | ||
187 | else if (c == '_' || cInt >= (int)'a' && cInt <= (int)'z' || | ||
188 | cInt >= (int)'A' && cInt <= (int)'Z' || cInt >= (int)'0' && cInt <= (int)'9') | ||
189 | result.Append(c); | ||
190 | else | ||
191 | { | ||
192 | // Debug: Need to handle non-printable chars. | ||
193 | result.Append(c); | ||
194 | useQuotes = true; | ||
195 | } | ||
196 | } | ||
197 | |||
198 | if (!useQuotes && (int)_name[0] >= (int)'a' && (int)_name[0] <= (int)'z') | ||
199 | return result.ToString(); | ||
200 | else | ||
201 | { | ||
202 | // Surround in single quotes. | ||
203 | result.Append('\''); | ||
204 | return "'" + result; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | /// <summary> | ||
209 | /// Return true if _name is lexicographically less than atom._name. | ||
210 | /// </summary> | ||
211 | /// <param name="atom"></param> | ||
212 | /// <returns></returns> | ||
213 | public bool lessThan(Atom atom) | ||
214 | { | ||
215 | return _name.CompareTo(atom._name) < 0; | ||
216 | } | ||
217 | } | ||
218 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/BagofAnswers.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/BagofAnswers.cs deleted file mode 100644 index bbf1a5b..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/BagofAnswers.cs +++ /dev/null | |||
@@ -1,239 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections; | ||
33 | using System.Collections.Generic; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// A BagofAnswers holds answers for bagof and setof. | ||
39 | /// </summary> | ||
40 | public class BagofAnswers | ||
41 | { | ||
42 | private object _template; | ||
43 | private Variable[] _freeVariables; | ||
44 | private Dictionary<object[], List<object>> _bagForFreeVariables; | ||
45 | private List<object> _findallBagArray; | ||
46 | private static TermArrayEqualityComparer _termArrayEqualityComparer = | ||
47 | new TermArrayEqualityComparer(); | ||
48 | |||
49 | /// <summary> | ||
50 | /// To get the free variables, split off any existential qualifiers from Goal such as the X in | ||
51 | /// "X ^ f(Y)", get the set of unbound variables in Goal that are not qualifiers, then remove | ||
52 | /// the unbound variables that are qualifiers as well as the unbound variables in Template. | ||
53 | /// </summary> | ||
54 | /// <param name="Template"></param> | ||
55 | /// <param name="Goal"></param> | ||
56 | public BagofAnswers(object Template, object Goal) | ||
57 | { | ||
58 | _template = Template; | ||
59 | |||
60 | // First get the set of variables that are not free variables. | ||
61 | List<Variable> variableSet = new List<Variable>(); | ||
62 | YP.addUniqueVariables(Template, variableSet); | ||
63 | object UnqualifiedGoal = YP.getValue(Goal); | ||
64 | while (UnqualifiedGoal is Functor2 && ((Functor2)UnqualifiedGoal)._name == Atom.HAT) | ||
65 | { | ||
66 | YP.addUniqueVariables(((Functor2)UnqualifiedGoal)._arg1, variableSet); | ||
67 | UnqualifiedGoal = YP.getValue(((Functor2)UnqualifiedGoal)._arg2); | ||
68 | } | ||
69 | |||
70 | // Remember how many non-free variables there are so we can find the unique free variables | ||
71 | // that are added. | ||
72 | int nNonFreeVariables = variableSet.Count; | ||
73 | YP.addUniqueVariables(UnqualifiedGoal, variableSet); | ||
74 | int nFreeVariables = variableSet.Count - nNonFreeVariables; | ||
75 | if (nFreeVariables == 0) | ||
76 | { | ||
77 | // There were no free variables added, so we won't waste time with _bagForFreeVariables. | ||
78 | _freeVariables = null; | ||
79 | _findallBagArray = new List<object>(); | ||
80 | } | ||
81 | else | ||
82 | { | ||
83 | // Copy the free variables. | ||
84 | _freeVariables = new Variable[nFreeVariables]; | ||
85 | for (int i = 0; i < nFreeVariables; ++i) | ||
86 | _freeVariables[i] = variableSet[i + nNonFreeVariables]; | ||
87 | |||
88 | _bagForFreeVariables = new Dictionary<object[], List<object>>(_termArrayEqualityComparer); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | public void add() | ||
93 | { | ||
94 | if (_freeVariables == null) | ||
95 | // The goal has bound the values in _template but we don't bother with _freeVariables. | ||
96 | _findallBagArray.Add(YP.makeCopy(_template, new Variable.CopyStore())); | ||
97 | else | ||
98 | { | ||
99 | // The goal has bound the values in _template and _freeVariables. | ||
100 | // Find the entry for this set of _freeVariables values. | ||
101 | object[] freeVariableValues = new object[_freeVariables.Length]; | ||
102 | for (int i = 0; i < _freeVariables.Length; ++i) | ||
103 | freeVariableValues[i] = YP.getValue(_freeVariables[i]); | ||
104 | List<object> bagArray; | ||
105 | if (!_bagForFreeVariables.TryGetValue(freeVariableValues, out bagArray)) | ||
106 | { | ||
107 | bagArray = new List<object>(); | ||
108 | _bagForFreeVariables[freeVariableValues] = bagArray; | ||
109 | } | ||
110 | |||
111 | // Now copy the template and add to the bag for the freeVariables values. | ||
112 | bagArray.Add(YP.makeCopy(_template, new Variable.CopyStore())); | ||
113 | } | ||
114 | } | ||
115 | |||
116 | // disable warning on l1, don't see how we can | ||
117 | // code this differently | ||
118 | #pragma warning disable 0168, 0219 | ||
119 | |||
120 | /// <summary> | ||
121 | /// For each result, unify the _freeVariables and unify bagArrayVariable with the associated bag. | ||
122 | /// </summary> | ||
123 | /// <param name="bagArrayVariable">this is unified with the List<object> of matches for template that | ||
124 | /// corresponds to the bindings for freeVariables. Be very careful: this does not unify with a Prolog | ||
125 | /// list.</param> | ||
126 | /// <returns></returns> | ||
127 | public IEnumerable<bool> resultArray(Variable bagArrayVariable) | ||
128 | { | ||
129 | if (_freeVariables == null) | ||
130 | { | ||
131 | // No unbound free variables, so we only filled one bag. If empty, bagof fails. | ||
132 | if (_findallBagArray.Count > 0) | ||
133 | { | ||
134 | foreach (bool l1 in bagArrayVariable.unify(_findallBagArray)) | ||
135 | yield return false; | ||
136 | } | ||
137 | } | ||
138 | else | ||
139 | { | ||
140 | foreach (KeyValuePair<object[], List<object>> valuesAndBag in _bagForFreeVariables) | ||
141 | { | ||
142 | foreach (bool l1 in YP.unifyArrays(_freeVariables, valuesAndBag.Key)) | ||
143 | { | ||
144 | foreach (bool l2 in bagArrayVariable.unify(valuesAndBag.Value)) | ||
145 | yield return false; | ||
146 | } | ||
147 | // Debug: Should we free memory of the answers already returned? | ||
148 | } | ||
149 | } | ||
150 | } | ||
151 | |||
152 | /// <summary> | ||
153 | /// For each result, unify the _freeVariables and unify Bag with the associated bag. | ||
154 | /// </summary> | ||
155 | /// <param name="Bag"></param> | ||
156 | /// <returns></returns> | ||
157 | public IEnumerable<bool> result(object Bag) | ||
158 | { | ||
159 | Variable bagArrayVariable = new Variable(); | ||
160 | foreach (bool l1 in resultArray(bagArrayVariable)) | ||
161 | { | ||
162 | foreach (bool l2 in YP.unify(Bag, ListPair.make((List<object>)bagArrayVariable.getValue()))) | ||
163 | yield return false; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | /// <summary> | ||
168 | /// For each result, unify the _freeVariables and unify Bag with the associated bag which is sorted | ||
169 | /// with duplicates removed, as in setof. | ||
170 | /// </summary> | ||
171 | /// <param name="Bag"></param> | ||
172 | /// <returns></returns> | ||
173 | public IEnumerable<bool> resultSet(object Bag) | ||
174 | { | ||
175 | Variable bagArrayVariable = new Variable(); | ||
176 | foreach (bool l1 in resultArray(bagArrayVariable)) | ||
177 | { | ||
178 | List<object> bagArray = (List<object>)bagArrayVariable.getValue(); | ||
179 | YP.sortArray(bagArray); | ||
180 | foreach (bool l2 in YP.unify(Bag, ListPair.makeWithoutRepeatedTerms(bagArray))) | ||
181 | yield return false; | ||
182 | } | ||
183 | } | ||
184 | |||
185 | public static IEnumerable<bool> bagofArray | ||
186 | (object Template, object Goal, IEnumerable<bool> goalIterator, Variable bagArrayVariable) | ||
187 | { | ||
188 | BagofAnswers bagOfAnswers = new BagofAnswers(Template, Goal); | ||
189 | foreach (bool l1 in goalIterator) | ||
190 | bagOfAnswers.add(); | ||
191 | return bagOfAnswers.resultArray(bagArrayVariable); | ||
192 | } | ||
193 | |||
194 | public static IEnumerable<bool> bagof | ||
195 | (object Template, object Goal, IEnumerable<bool> goalIterator, object Bag) | ||
196 | { | ||
197 | BagofAnswers bagOfAnswers = new BagofAnswers(Template, Goal); | ||
198 | foreach (bool l1 in goalIterator) | ||
199 | bagOfAnswers.add(); | ||
200 | return bagOfAnswers.result(Bag); | ||
201 | } | ||
202 | |||
203 | public static IEnumerable<bool> setof | ||
204 | (object Template, object Goal, IEnumerable<bool> goalIterator, object Bag) | ||
205 | { | ||
206 | BagofAnswers bagOfAnswers = new BagofAnswers(Template, Goal); | ||
207 | foreach (bool l1 in goalIterator) | ||
208 | bagOfAnswers.add(); | ||
209 | return bagOfAnswers.resultSet(Bag); | ||
210 | } | ||
211 | #pragma warning restore 0168, 0219 | ||
212 | |||
213 | /// <summary> | ||
214 | /// A TermArrayEqualityComparer implements IEqualityComparer to compare two object arrays using YP.termEqual. | ||
215 | /// </summary> | ||
216 | private class TermArrayEqualityComparer : IEqualityComparer<object[]> | ||
217 | { | ||
218 | public bool Equals(object[] array1, object[] array2) | ||
219 | { | ||
220 | if (array1.Length != array2.Length) | ||
221 | return false; | ||
222 | for (int i = 0; i < array1.Length; ++i) | ||
223 | { | ||
224 | if (!YP.termEqual(array1[i], array2[i])) | ||
225 | return false; | ||
226 | } | ||
227 | return true; | ||
228 | } | ||
229 | |||
230 | public int GetHashCode(object[] array) | ||
231 | { | ||
232 | int hashCode = 0; | ||
233 | for (int i = 0; i < array.Length; ++i) | ||
234 | hashCode ^= array[i].GetHashCode(); | ||
235 | return hashCode; | ||
236 | } | ||
237 | } | ||
238 | } | ||
239 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/FindallAnswers.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/FindallAnswers.cs deleted file mode 100644 index fb9569e..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/FindallAnswers.cs +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections; | ||
33 | using System.Collections.Generic; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// A FindallAnswers holds answers for findall. | ||
39 | /// </summary> | ||
40 | public class FindallAnswers | ||
41 | { | ||
42 | private object _template; | ||
43 | private List<object> _bagArray; | ||
44 | |||
45 | public FindallAnswers(object Template) | ||
46 | { | ||
47 | _template = Template; | ||
48 | _bagArray = new List<object>(); | ||
49 | } | ||
50 | |||
51 | public void add() | ||
52 | { | ||
53 | _bagArray.Add(YP.makeCopy(_template, new Variable.CopyStore())); | ||
54 | } | ||
55 | |||
56 | public List<object> resultArray() | ||
57 | { | ||
58 | return _bagArray; | ||
59 | } | ||
60 | |||
61 | /// <summary> | ||
62 | /// Unify Bag with the result. This frees the internal answers, so you can only call this once. | ||
63 | /// </summary> | ||
64 | /// <param name="Bag"></param> | ||
65 | /// <returns></returns> | ||
66 | public IEnumerable<bool> result(object Bag) | ||
67 | { | ||
68 | object result = ListPair.make(_bagArray); | ||
69 | // Try to free the memory. | ||
70 | _bagArray = null; | ||
71 | return YP.unify(Bag, result); | ||
72 | } | ||
73 | |||
74 | // disable warning on l1, don't see how we can | ||
75 | // code this differently | ||
76 | #pragma warning disable 0168, 0219 | ||
77 | |||
78 | /// <summary> | ||
79 | /// This is a simplified findall when the goal is a single call. | ||
80 | /// </summary> | ||
81 | /// <param name="Template"></param> | ||
82 | /// <param name="goal"></param> | ||
83 | /// <param name="Bag"></param> | ||
84 | /// <returns></returns> | ||
85 | public static IEnumerable<bool> findall(object Template, IEnumerable<bool> goal, object Bag) | ||
86 | { | ||
87 | FindallAnswers findallAnswers = new FindallAnswers(Template); | ||
88 | foreach (bool l1 in goal) | ||
89 | findallAnswers.add(); | ||
90 | return findallAnswers.result(Bag); | ||
91 | } | ||
92 | |||
93 | /// <summary> | ||
94 | /// Like findall, except return an array of the results. | ||
95 | /// </summary> | ||
96 | /// <param name="template"></param> | ||
97 | /// <param name="goal"></param> | ||
98 | /// <returns></returns> | ||
99 | public static List<object> findallArray(object Template, IEnumerable<bool> goal) | ||
100 | { | ||
101 | FindallAnswers findallAnswers = new FindallAnswers(Template); | ||
102 | foreach (bool l1 in goal) | ||
103 | findallAnswers.add(); | ||
104 | return findallAnswers.resultArray(); | ||
105 | } | ||
106 | #pragma warning restore 0168, 0219 | ||
107 | } | ||
108 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor.cs deleted file mode 100644 index 4d65f5b..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor.cs +++ /dev/null | |||
@@ -1,196 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections.Generic; | ||
33 | |||
34 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
35 | { | ||
36 | public class Functor : IUnifiable | ||
37 | { | ||
38 | public readonly Atom _name; | ||
39 | public readonly object[] _args; | ||
40 | |||
41 | public Functor(Atom name, object[] args) | ||
42 | { | ||
43 | if (args.Length <= 3) | ||
44 | { | ||
45 | if (args.Length == 0) | ||
46 | throw new Exception("For arity 0 functor, just use name as an Atom"); | ||
47 | else if (args.Length == 1) | ||
48 | throw new Exception("For arity 1 functor, use Functor1"); | ||
49 | else if (args.Length == 2) | ||
50 | throw new Exception("For arity 2 functor, use Functor2"); | ||
51 | else if (args.Length == 3) | ||
52 | throw new Exception("For arity 3 functor, use Functor3"); | ||
53 | else | ||
54 | // (This shouldn't happen, but include it for completeness. | ||
55 | throw new Exception("Cannot create a Functor of arity " + args.Length); | ||
56 | } | ||
57 | |||
58 | _name = name; | ||
59 | _args = args; | ||
60 | } | ||
61 | |||
62 | public Functor(string name, object[] args) | ||
63 | : this(Atom.a(name), args) | ||
64 | { | ||
65 | } | ||
66 | |||
67 | /// <summary> | ||
68 | /// Return an Atom, Functor1, Functor2, Functor3 or Functor depending on the | ||
69 | /// length of args. | ||
70 | /// Note that this is different than the Functor constructor which requires | ||
71 | /// the length of args to be greater than 3. | ||
72 | /// </summary> | ||
73 | /// <param name="name"></param> | ||
74 | /// <param name="args"></param> | ||
75 | /// <returns></returns> | ||
76 | public static object make(Atom name, object[] args) | ||
77 | { | ||
78 | if (args.Length <= 0) | ||
79 | return name; | ||
80 | else if (args.Length == 1) | ||
81 | return new Functor1(name, args[0]); | ||
82 | else if (args.Length == 2) | ||
83 | return new Functor2(name, args[0], args[1]); | ||
84 | else if (args.Length == 3) | ||
85 | return new Functor3(name, args[0], args[1], args[2]); | ||
86 | else | ||
87 | return new Functor(name, args); | ||
88 | } | ||
89 | |||
90 | /// <summary> | ||
91 | /// Call the main make, first converting name to an Atom. | ||
92 | /// </summary> | ||
93 | /// <param name="name"></param> | ||
94 | /// <param name="args"></param> | ||
95 | /// <returns></returns> | ||
96 | public static object make(string name, object[] args) | ||
97 | { | ||
98 | return make(Atom.a(name), args); | ||
99 | } | ||
100 | |||
101 | /// <summary> | ||
102 | /// If arg is another Functor, then succeed (yield once) if this and arg have the | ||
103 | /// same name and all functor args unify, otherwise fail (don't yield). | ||
104 | /// If arg is a Variable, then call its unify to unify with this. | ||
105 | /// Otherwise fail (don't yield). | ||
106 | /// </summary> | ||
107 | /// <param name="arg"></param> | ||
108 | /// <returns></returns> | ||
109 | public IEnumerable<bool> unify(object arg) | ||
110 | { | ||
111 | arg = YP.getValue(arg); | ||
112 | if (arg is Functor) | ||
113 | { | ||
114 | Functor argFunctor = (Functor)arg; | ||
115 | if (_name.Equals(argFunctor._name)) | ||
116 | return YP.unifyArrays(_args, argFunctor._args); | ||
117 | else | ||
118 | return YP.fail(); | ||
119 | } | ||
120 | else if (arg is Variable) | ||
121 | return ((Variable)arg).unify(this); | ||
122 | else | ||
123 | return YP.fail(); | ||
124 | } | ||
125 | |||
126 | public override string ToString() | ||
127 | { | ||
128 | string result = _name + "(" + YP.getValue(_args[0]); | ||
129 | for (int i = 1; i < _args.Length; ++i) | ||
130 | result += ", " + YP.getValue(_args[i]); | ||
131 | result += ")"; | ||
132 | return result; | ||
133 | } | ||
134 | |||
135 | public bool termEqual(object term) | ||
136 | { | ||
137 | term = YP.getValue(term); | ||
138 | if (term is Functor) | ||
139 | { | ||
140 | Functor termFunctor = (Functor)term; | ||
141 | if (_name.Equals(termFunctor._name) && _args.Length == termFunctor._args.Length) | ||
142 | { | ||
143 | for (int i = 0; i < _args.Length; ++i) | ||
144 | { | ||
145 | if (!YP.termEqual(_args[i], termFunctor._args[i])) | ||
146 | return false; | ||
147 | } | ||
148 | return true; | ||
149 | } | ||
150 | } | ||
151 | return false; | ||
152 | } | ||
153 | |||
154 | public bool lessThan(Functor functor) | ||
155 | { | ||
156 | // Do the equal check first since it is faster. | ||
157 | if (!_name.Equals(functor._name)) | ||
158 | return _name.lessThan(functor._name); | ||
159 | |||
160 | if (_args.Length != functor._args.Length) | ||
161 | return _args.Length < functor._args.Length; | ||
162 | |||
163 | for (int i = 0; i < _args.Length; ++i) | ||
164 | { | ||
165 | if (!YP.termEqual(_args[i], functor._args[i])) | ||
166 | return YP.termLessThan(_args[i], functor._args[i]); | ||
167 | } | ||
168 | |||
169 | return false; | ||
170 | } | ||
171 | |||
172 | public bool ground() | ||
173 | { | ||
174 | for (int i = 0; i < _args.Length; ++i) | ||
175 | { | ||
176 | if (!YP.ground(_args[i])) | ||
177 | return false; | ||
178 | } | ||
179 | return true; | ||
180 | } | ||
181 | |||
182 | public void addUniqueVariables(List<Variable> variableSet) | ||
183 | { | ||
184 | for (int i = 0; i < _args.Length; ++i) | ||
185 | YP.addUniqueVariables(_args[i], variableSet); | ||
186 | } | ||
187 | |||
188 | public object makeCopy(Variable.CopyStore copyStore) | ||
189 | { | ||
190 | object[] argsCopy = new object[_args.Length]; | ||
191 | for (int i = 0; i < _args.Length; ++i) | ||
192 | argsCopy[i] = YP.makeCopy(_args[i], copyStore); | ||
193 | return new Functor(_name, argsCopy); | ||
194 | } | ||
195 | } | ||
196 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor1.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor1.cs deleted file mode 100644 index 80d98b1..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor1.cs +++ /dev/null | |||
@@ -1,124 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections.Generic; | ||
33 | |||
34 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
35 | { | ||
36 | public class Functor1 : IUnifiable | ||
37 | { | ||
38 | public readonly Atom _name; | ||
39 | public readonly object _arg1; | ||
40 | |||
41 | public Functor1(Atom name, object arg1) | ||
42 | { | ||
43 | _name = name; | ||
44 | _arg1 = arg1; | ||
45 | } | ||
46 | |||
47 | public Functor1(string name, object arg1) | ||
48 | : this(Atom.a(name), arg1) | ||
49 | { | ||
50 | } | ||
51 | |||
52 | // disable warning on l1, don't see how we can | ||
53 | // code this differently | ||
54 | #pragma warning disable 0168, 0219 | ||
55 | /// <summary> | ||
56 | /// If arg is another Functor1, then succeed (yield once) if this and arg have the | ||
57 | /// same name and the functor args unify, otherwise fail (don't yield). | ||
58 | /// If arg is a Variable, then call its unify to unify with this. | ||
59 | /// Otherwise fail (don't yield). | ||
60 | /// </summary> | ||
61 | /// <param name="arg"></param> | ||
62 | /// <returns></returns> | ||
63 | public IEnumerable<bool> unify(object arg) | ||
64 | { | ||
65 | arg = YP.getValue(arg); | ||
66 | if (arg is Functor1) | ||
67 | { | ||
68 | Functor1 argFunctor = (Functor1)arg; | ||
69 | if (_name.Equals(argFunctor._name)) | ||
70 | { | ||
71 | foreach (bool l1 in YP.unify(_arg1, argFunctor._arg1)) | ||
72 | yield return false; | ||
73 | } | ||
74 | } | ||
75 | else if (arg is Variable) | ||
76 | { | ||
77 | foreach (bool l1 in ((Variable)arg).unify(this)) | ||
78 | yield return false; | ||
79 | } | ||
80 | } | ||
81 | #pragma warning restore 0168, 0219 | ||
82 | |||
83 | |||
84 | public override string ToString() | ||
85 | { | ||
86 | return _name + "(" + YP.getValue(_arg1) + ")"; | ||
87 | } | ||
88 | |||
89 | public bool termEqual(object term) | ||
90 | { | ||
91 | term = YP.getValue(term); | ||
92 | if (term is Functor1) | ||
93 | { | ||
94 | Functor1 termFunctor = (Functor1)term; | ||
95 | return _name.Equals(termFunctor._name) && YP.termEqual(_arg1, termFunctor._arg1); | ||
96 | } | ||
97 | return false; | ||
98 | } | ||
99 | |||
100 | public bool lessThan(Functor1 functor) | ||
101 | { | ||
102 | // Do the equal check first since it is faster. | ||
103 | if (!_name.Equals(functor._name)) | ||
104 | return _name.lessThan(functor._name); | ||
105 | |||
106 | return YP.termLessThan(_arg1, functor._arg1); | ||
107 | } | ||
108 | |||
109 | public bool ground() | ||
110 | { | ||
111 | return YP.ground(_arg1); | ||
112 | } | ||
113 | |||
114 | public void addUniqueVariables(List<Variable> variableSet) | ||
115 | { | ||
116 | YP.addUniqueVariables(_arg1, variableSet); | ||
117 | } | ||
118 | |||
119 | public object makeCopy(Variable.CopyStore copyStore) | ||
120 | { | ||
121 | return new Functor1(_name, YP.makeCopy(_arg1, copyStore)); | ||
122 | } | ||
123 | } | ||
124 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor2.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor2.cs deleted file mode 100644 index 4c501d6..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor2.cs +++ /dev/null | |||
@@ -1,163 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections.Generic; | ||
33 | |||
34 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
35 | { | ||
36 | public class Functor2 : IUnifiable | ||
37 | { | ||
38 | public readonly Atom _name; | ||
39 | public readonly object _arg1; | ||
40 | public readonly object _arg2; | ||
41 | |||
42 | public Functor2(Atom name, object arg1, object arg2) | ||
43 | { | ||
44 | _name = name; | ||
45 | _arg1 = arg1; | ||
46 | _arg2 = arg2; | ||
47 | } | ||
48 | |||
49 | public Functor2(string name, object arg1, object arg2) | ||
50 | : this(Atom.a(name), arg1, arg2) | ||
51 | { | ||
52 | } | ||
53 | |||
54 | // disable warning on l1, don't see how we can | ||
55 | // code this differently | ||
56 | #pragma warning disable 0168, 0219 | ||
57 | /// If arg is another Functor2, then succeed (yield once) if this and arg have the | ||
58 | /// same name and all functor args unify, otherwise fail (don't yield). | ||
59 | /// If arg is a Variable, then call its unify to unify with this. | ||
60 | /// Otherwise fail (don't yield). | ||
61 | public IEnumerable<bool> unify(object arg) | ||
62 | { | ||
63 | arg = YP.getValue(arg); | ||
64 | if (arg is Functor2) | ||
65 | { | ||
66 | Functor2 argFunctor = (Functor2)arg; | ||
67 | if (_name.Equals(argFunctor._name)) | ||
68 | { | ||
69 | foreach (bool l1 in YP.unify(_arg1, argFunctor._arg1)) | ||
70 | { | ||
71 | foreach (bool l2 in YP.unify(_arg2, argFunctor._arg2)) | ||
72 | yield return false; | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | else if (arg is Variable) | ||
77 | { | ||
78 | foreach (bool l1 in ((Variable)arg).unify(this)) | ||
79 | yield return false; | ||
80 | } | ||
81 | } | ||
82 | #pragma warning restore 0168, 0219 | ||
83 | |||
84 | |||
85 | public override string ToString() | ||
86 | { | ||
87 | if (_name == Atom.DOT) | ||
88 | return listPairToString(this); | ||
89 | else | ||
90 | return _name + "(" + YP.getValue(_arg1) + ", " + YP.getValue(_arg2) + ")"; | ||
91 | } | ||
92 | |||
93 | public bool termEqual(object term) | ||
94 | { | ||
95 | term = YP.getValue(term); | ||
96 | if (term is Functor2) | ||
97 | { | ||
98 | Functor2 termFunctor = (Functor2)term; | ||
99 | return _name.Equals(termFunctor._name) && YP.termEqual(_arg1, termFunctor._arg1) | ||
100 | && YP.termEqual(_arg2, termFunctor._arg2); | ||
101 | } | ||
102 | return false; | ||
103 | } | ||
104 | |||
105 | public bool lessThan(Functor2 functor) | ||
106 | { | ||
107 | // Do the equal check first since it is faster. | ||
108 | if (!_name.Equals(functor._name)) | ||
109 | return _name.lessThan(functor._name); | ||
110 | |||
111 | if (!YP.termEqual(_arg1, functor._arg1)) | ||
112 | return YP.termLessThan(_arg1, functor._arg1); | ||
113 | |||
114 | return YP.termLessThan(_arg2, functor._arg2); | ||
115 | } | ||
116 | |||
117 | public bool ground() | ||
118 | { | ||
119 | return YP.ground(_arg1) && YP.ground(_arg2); | ||
120 | } | ||
121 | |||
122 | public void addUniqueVariables(List<Variable> variableSet) | ||
123 | { | ||
124 | YP.addUniqueVariables(_arg1, variableSet); | ||
125 | YP.addUniqueVariables(_arg2, variableSet); | ||
126 | } | ||
127 | |||
128 | public object makeCopy(Variable.CopyStore copyStore) | ||
129 | { | ||
130 | return new Functor2(_name, YP.makeCopy(_arg1, copyStore), | ||
131 | YP.makeCopy(_arg2, copyStore)); | ||
132 | } | ||
133 | |||
134 | private static string listPairToString(Functor2 listPair) | ||
135 | { | ||
136 | string result = "["; | ||
137 | while (true) | ||
138 | { | ||
139 | object head = YP.getValue(listPair._arg1); | ||
140 | object tail = YP.getValue(listPair._arg2); | ||
141 | if (tail == (object)Atom.NIL) | ||
142 | { | ||
143 | result += head; | ||
144 | break; | ||
145 | } | ||
146 | else if (tail is Functor2 && ((Functor2)tail)._name == Atom.DOT) | ||
147 | { | ||
148 | result += head + ", "; | ||
149 | listPair = (Functor2)tail; | ||
150 | // Loop again. | ||
151 | } | ||
152 | else | ||
153 | { | ||
154 | // The list is not terminated with NIL. | ||
155 | result += head + "|" + tail; | ||
156 | break; | ||
157 | } | ||
158 | } | ||
159 | result += "]"; | ||
160 | return result; | ||
161 | } | ||
162 | } | ||
163 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor3.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor3.cs deleted file mode 100644 index 94e39c4..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor3.cs +++ /dev/null | |||
@@ -1,141 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections.Generic; | ||
33 | |||
34 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
35 | { | ||
36 | public class Functor3 : IUnifiable | ||
37 | { | ||
38 | public readonly Atom _name; | ||
39 | public readonly object _arg1; | ||
40 | public readonly object _arg2; | ||
41 | public readonly object _arg3; | ||
42 | |||
43 | public Functor3(Atom name, object arg1, object arg2, object arg3) | ||
44 | { | ||
45 | _name = name; | ||
46 | _arg1 = arg1; | ||
47 | _arg2 = arg2; | ||
48 | _arg3 = arg3; | ||
49 | } | ||
50 | |||
51 | public Functor3(string name, object arg1, object arg2, object arg3) | ||
52 | : this(Atom.a(name), arg1, arg2, arg3) | ||
53 | { | ||
54 | } | ||
55 | |||
56 | // disable warning on l1, don't see how we can | ||
57 | // code this differently | ||
58 | #pragma warning disable 0168, 0219 | ||
59 | /// If arg is another Functor3, then succeed (yield once) if this and arg have the | ||
60 | /// same name and all functor args unify, otherwise fail (don't yield). | ||
61 | /// If arg is a Variable, then call its unify to unify with this. | ||
62 | /// Otherwise fail (don't yield). | ||
63 | public IEnumerable<bool> unify(object arg) | ||
64 | { | ||
65 | arg = YP.getValue(arg); | ||
66 | if (arg is Functor3) | ||
67 | { | ||
68 | Functor3 argFunctor = (Functor3)arg; | ||
69 | if (_name.Equals(argFunctor._name)) | ||
70 | { | ||
71 | foreach (bool l1 in YP.unify(_arg1, argFunctor._arg1)) | ||
72 | { | ||
73 | foreach (bool l2 in YP.unify(_arg2, argFunctor._arg2)) | ||
74 | { | ||
75 | foreach (bool l3 in YP.unify(_arg3, argFunctor._arg3)) | ||
76 | yield return false; | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | } | ||
81 | else if (arg is Variable) | ||
82 | { | ||
83 | foreach (bool l1 in ((Variable)arg).unify(this)) | ||
84 | yield return false; | ||
85 | } | ||
86 | } | ||
87 | #pragma warning restore 0168, 0219 | ||
88 | |||
89 | public override string ToString() | ||
90 | { | ||
91 | return _name + "(" + YP.getValue(_arg1) + ", " + YP.getValue(_arg2) + ", " + | ||
92 | YP.getValue(_arg3) + ")"; | ||
93 | } | ||
94 | |||
95 | public bool termEqual(object term) | ||
96 | { | ||
97 | term = YP.getValue(term); | ||
98 | if (term is Functor3) | ||
99 | { | ||
100 | Functor3 termFunctor = (Functor3)term; | ||
101 | return _name.Equals(termFunctor._name) && YP.termEqual(_arg1, termFunctor._arg1) | ||
102 | && YP.termEqual(_arg2, termFunctor._arg2) | ||
103 | && YP.termEqual(_arg3, termFunctor._arg3); | ||
104 | } | ||
105 | return false; | ||
106 | } | ||
107 | |||
108 | public bool lessThan(Functor3 functor) | ||
109 | { | ||
110 | // Do the equal check first since it is faster. | ||
111 | if (!_name.Equals(functor._name)) | ||
112 | return _name.lessThan(functor._name); | ||
113 | |||
114 | if (!YP.termEqual(_arg1, functor._arg1)) | ||
115 | return YP.termLessThan(_arg1, functor._arg1); | ||
116 | |||
117 | if (!YP.termEqual(_arg2, functor._arg2)) | ||
118 | return YP.termLessThan(_arg2, functor._arg2); | ||
119 | |||
120 | return YP.termLessThan(_arg3, functor._arg3); | ||
121 | } | ||
122 | |||
123 | public bool ground() | ||
124 | { | ||
125 | return YP.ground(_arg1) && YP.ground(_arg2) && YP.ground(_arg3); | ||
126 | } | ||
127 | |||
128 | public void addUniqueVariables(List<Variable> variableSet) | ||
129 | { | ||
130 | YP.addUniqueVariables(_arg1, variableSet); | ||
131 | YP.addUniqueVariables(_arg2, variableSet); | ||
132 | YP.addUniqueVariables(_arg3, variableSet); | ||
133 | } | ||
134 | |||
135 | public object makeCopy(Variable.CopyStore copyStore) | ||
136 | { | ||
137 | return new Functor3(_name, YP.makeCopy(_arg1, copyStore), | ||
138 | YP.makeCopy(_arg2, copyStore), YP.makeCopy(_arg3, copyStore)); | ||
139 | } | ||
140 | } | ||
141 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/IndexedAnswers.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/IndexedAnswers.cs deleted file mode 100644 index 09a9a08..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/IndexedAnswers.cs +++ /dev/null | |||
@@ -1,385 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections; | ||
33 | using System.Collections.Generic; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// An IndexedAnswers holds answers to a query based on the values of index arguments. | ||
39 | /// </summary> | ||
40 | public class IndexedAnswers : YP.IClause | ||
41 | { | ||
42 | private int _arity; | ||
43 | // addAnswer adds the answer here and indexes it later. | ||
44 | private List<object[]> _allAnswers = new List<object[]>(); | ||
45 | // The key has the arity of answers with non-null values for each indexed arg. The value | ||
46 | // is a list of the matching answers. The signature is implicit in the pattern on non-null index args. | ||
47 | private Dictionary<HashedList, List<object[]>> _indexedAnswers = | ||
48 | new Dictionary<HashedList, List<object[]>>(); | ||
49 | // Keeps track of whether we have started adding entries to _indexedAnswers for the signature. | ||
50 | private Dictionary<int, object> _gotAnswersForSignature = new Dictionary<int, object>(); | ||
51 | private const int MAX_INDEX_ARGS = 31; | ||
52 | |||
53 | public IndexedAnswers(int arity) | ||
54 | { | ||
55 | _arity = arity; | ||
56 | } | ||
57 | |||
58 | /// <summary> | ||
59 | /// Append the answer to the list and update the indexes, if any. | ||
60 | /// Elements of answer must be ground, since arguments with unbound variables make this | ||
61 | /// into a dynamic rule which we don't index. | ||
62 | /// </summary> | ||
63 | /// <param name="answer"></param> | ||
64 | public void addAnswer(object[] answer) | ||
65 | { | ||
66 | addOrPrependAnswer(answer, false); | ||
67 | } | ||
68 | |||
69 | /// <summary> | ||
70 | /// Prepend the answer to the list and clear the indexes so that they must be re-computed | ||
71 | /// on the next call to match. (Only addAnswer will maintain the indexes while adding answers.) | ||
72 | /// Elements of answer must be ground, since arguments with unbound variables make this | ||
73 | /// into a dynamic rule which we don't index. | ||
74 | /// </summary> | ||
75 | /// <param name="answer"></param> | ||
76 | public void prependAnswer(object[] answer) | ||
77 | { | ||
78 | addOrPrependAnswer(answer, true); | ||
79 | } | ||
80 | |||
81 | /// <summary> | ||
82 | /// Do the work of addAnswer or prependAnswer. | ||
83 | /// </summary> | ||
84 | /// <param name="answer"></param> | ||
85 | private void addOrPrependAnswer(object[] answer, bool prepend) | ||
86 | { | ||
87 | if (answer.Length != _arity) | ||
88 | return; | ||
89 | |||
90 | // Store a copy of the answer array. | ||
91 | object[] answerCopy = new object[answer.Length]; | ||
92 | Variable.CopyStore copyStore = new Variable.CopyStore(); | ||
93 | for (int i = 0; i < answer.Length; ++i) | ||
94 | answerCopy[i] = YP.makeCopy(answer[i], copyStore); | ||
95 | if (copyStore.getNUniqueVariables() > 0) | ||
96 | throw new InvalidOperationException | ||
97 | ("Elements of answer must be ground, but found " + copyStore.getNUniqueVariables() + | ||
98 | " unbound variables"); | ||
99 | |||
100 | if (prepend) | ||
101 | { | ||
102 | _allAnswers.Insert(0, answerCopy); | ||
103 | clearIndexes(); | ||
104 | } | ||
105 | else | ||
106 | { | ||
107 | _allAnswers.Add(answerCopy); | ||
108 | // If match has already indexed answers for a signature, we need to add | ||
109 | // this to the existing indexed answers. | ||
110 | foreach (int signature in _gotAnswersForSignature.Keys) | ||
111 | indexAnswerForSignature(answerCopy, signature); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | private void indexAnswerForSignature(object[] answer, int signature) | ||
116 | { | ||
117 | // First find out which of the answer values can be used as an index. | ||
118 | object[] indexValues = new object[answer.Length]; | ||
119 | for (int i = 0; i < answer.Length; ++i) | ||
120 | { | ||
121 | // We limit the number of indexed args in a 32-bit signature. | ||
122 | if (i >= MAX_INDEX_ARGS) | ||
123 | indexValues[i] = null; | ||
124 | else | ||
125 | indexValues[i] = getIndexValue(YP.getValue(answer[i])); | ||
126 | } | ||
127 | |||
128 | // We need an entry in indexArgs from indexValues for each 1 bit in signature. | ||
129 | HashedList indexArgs = new HashedList(indexValues.Length); | ||
130 | for (int i = 0; i < indexValues.Length; ++i) | ||
131 | { | ||
132 | if ((signature & (1 << i)) == 0) | ||
133 | indexArgs.Add(null); | ||
134 | else | ||
135 | { | ||
136 | if (indexValues[i] == null) | ||
137 | // The signature wants an index value here, but we don't have one so | ||
138 | // we can't add it as an answer for this signature. | ||
139 | return; | ||
140 | else | ||
141 | indexArgs.Add(indexValues[i]); | ||
142 | } | ||
143 | } | ||
144 | |||
145 | // Add the answer to the answers list for indexArgs, creating the entry if needed. | ||
146 | List<object[]> answers; | ||
147 | if (!_indexedAnswers.TryGetValue(indexArgs, out answers)) | ||
148 | { | ||
149 | answers = new List<object[]>(); | ||
150 | _indexedAnswers[indexArgs] = answers; | ||
151 | } | ||
152 | answers.Add(answer); | ||
153 | } | ||
154 | |||
155 | public IEnumerable<bool> match(object[] arguments) | ||
156 | { | ||
157 | if (arguments.Length != _arity) | ||
158 | yield break; | ||
159 | |||
160 | // Set up indexArgs, up to arg position MAX_INDEX_ARGS. The signature has a 1 bit for | ||
161 | // each non-null index arg. | ||
162 | HashedList indexArgs = new HashedList(arguments.Length); | ||
163 | bool gotAllIndexArgs = true; | ||
164 | int signature = 0; | ||
165 | for (int i = 0; i < arguments.Length; ++i) | ||
166 | { | ||
167 | object indexValue = null; | ||
168 | if (i < MAX_INDEX_ARGS) | ||
169 | { | ||
170 | // We limit the number of args in a 32-bit signature. | ||
171 | indexValue = getIndexValue(YP.getValue(arguments[i])); | ||
172 | if (indexValue != null) | ||
173 | signature += (1 << i); | ||
174 | } | ||
175 | if (indexValue == null) | ||
176 | gotAllIndexArgs = false; | ||
177 | indexArgs.Add(indexValue); | ||
178 | } | ||
179 | |||
180 | List<object[]> answers; | ||
181 | if (signature == 0) | ||
182 | // No index args, so we have to match from _allAnswers. | ||
183 | answers = _allAnswers; | ||
184 | else | ||
185 | { | ||
186 | if (!_gotAnswersForSignature.ContainsKey(signature)) | ||
187 | { | ||
188 | // We need to create the entry in _indexedAnswers. | ||
189 | foreach (object[] answer in _allAnswers) | ||
190 | indexAnswerForSignature(answer, signature); | ||
191 | // Mark that we did this signature. | ||
192 | _gotAnswersForSignature[signature] = null; | ||
193 | } | ||
194 | if (!_indexedAnswers.TryGetValue(indexArgs, out answers)) | ||
195 | yield break; | ||
196 | } | ||
197 | |||
198 | if (gotAllIndexArgs) | ||
199 | { | ||
200 | // All the arguments were already bound, so we don't need to do bindings. | ||
201 | yield return false; | ||
202 | yield break; | ||
203 | } | ||
204 | |||
205 | // Find matches in answers. | ||
206 | IEnumerator<bool>[] iterators = new IEnumerator<bool>[arguments.Length]; | ||
207 | // Debug: If the caller asserts another answer into this same predicate during yield, the iterator | ||
208 | // over clauses will be corrupted. Should we take the time to copy answers? | ||
209 | foreach (object[] answer in answers) | ||
210 | { | ||
211 | bool gotMatch = true; | ||
212 | int nIterators = 0; | ||
213 | // Try to bind all the arguments. | ||
214 | for (int i = 0; i < arguments.Length; ++i) | ||
215 | { | ||
216 | if (indexArgs[i] != null) | ||
217 | // We already matched this argument by looking up _indexedAnswers. | ||
218 | continue; | ||
219 | |||
220 | IEnumerator<bool> iterator = YP.unify(arguments[i], answer[i]).GetEnumerator(); | ||
221 | iterators[nIterators++] = iterator; | ||
222 | // MoveNext() is true if YP.unify succeeds. | ||
223 | if (!iterator.MoveNext()) | ||
224 | { | ||
225 | gotMatch = false; | ||
226 | break; | ||
227 | } | ||
228 | } | ||
229 | int z = 0; | ||
230 | try | ||
231 | { | ||
232 | if (gotMatch) | ||
233 | yield return false; | ||
234 | } | ||
235 | finally | ||
236 | { | ||
237 | // Manually finalize all the iterators. | ||
238 | for (z = 0; z < nIterators; ++z) | ||
239 | iterators[z].Dispose(); | ||
240 | } | ||
241 | } | ||
242 | } | ||
243 | |||
244 | public IEnumerable<bool> clause(object Head, object Body) | ||
245 | { | ||
246 | Head = YP.getValue(Head); | ||
247 | if (Head is Variable) | ||
248 | throw new PrologException("instantiation_error", "Head is an unbound variable"); | ||
249 | object[] arguments = YP.getFunctorArgs(Head); | ||
250 | |||
251 | // We always match Head from _allAnswers, and the Body is Atom.a("true"). | ||
252 | #pragma warning disable 0168, 0219 | ||
253 | foreach (bool l1 in YP.unify(Body, Atom.a("true"))) | ||
254 | { | ||
255 | // The caller can assert another answer into this same predicate during yield, so we have to | ||
256 | // make a copy of the answers. | ||
257 | foreach (object[] answer in _allAnswers.ToArray()) | ||
258 | { | ||
259 | foreach (bool l2 in YP.unifyArrays(arguments, answer)) | ||
260 | yield return false; | ||
261 | } | ||
262 | } | ||
263 | #pragma warning restore 0168, 0219 | ||
264 | } | ||
265 | |||
266 | public IEnumerable<bool> retract(object Head, object Body) | ||
267 | { | ||
268 | Head = YP.getValue(Head); | ||
269 | if (Head is Variable) | ||
270 | throw new PrologException("instantiation_error", "Head is an unbound variable"); | ||
271 | object[] arguments = YP.getFunctorArgs(Head); | ||
272 | |||
273 | // We always match Head from _allAnswers, and the Body is Atom.a("true"). | ||
274 | #pragma warning disable 0168, 0219 | ||
275 | foreach (bool l1 in YP.unify(Body, Atom.a("true"))) | ||
276 | { | ||
277 | // The caller can assert another answer into this same predicate during yield, so we have to | ||
278 | // make a copy of the answers. | ||
279 | foreach (object[] answer in _allAnswers.ToArray()) | ||
280 | { | ||
281 | foreach (bool l2 in YP.unifyArrays(arguments, answer)) | ||
282 | { | ||
283 | _allAnswers.Remove(answer); | ||
284 | clearIndexes(); | ||
285 | yield return false; | ||
286 | } | ||
287 | } | ||
288 | } | ||
289 | #pragma warning restore 0168, 0219 | ||
290 | } | ||
291 | |||
292 | /// <summary> | ||
293 | /// After retracting or prepending an answer in _allAnswers, the indexes are invalid, so clear them. | ||
294 | /// </summary> | ||
295 | private void clearIndexes() | ||
296 | { | ||
297 | _indexedAnswers.Clear(); | ||
298 | _gotAnswersForSignature.Clear(); | ||
299 | } | ||
300 | |||
301 | /// <summary> | ||
302 | /// A HashedList extends an ArrayList with methods to get a hash and to check equality | ||
303 | /// based on the elements of the list. | ||
304 | /// </summary> | ||
305 | public class HashedList : ArrayList | ||
306 | { | ||
307 | private bool _gotHashCode = false; | ||
308 | private int _hashCode; | ||
309 | |||
310 | public HashedList() | ||
311 | : base() | ||
312 | { | ||
313 | } | ||
314 | |||
315 | public HashedList(int capacity) | ||
316 | : base(capacity) | ||
317 | { | ||
318 | } | ||
319 | |||
320 | public HashedList(ICollection c) | ||
321 | : base(c) | ||
322 | { | ||
323 | } | ||
324 | |||
325 | // Debug: Should override all the other methods that change this. | ||
326 | public override int Add(object value) | ||
327 | { | ||
328 | _gotHashCode = false; | ||
329 | return base.Add(value); | ||
330 | } | ||
331 | |||
332 | public override int GetHashCode() | ||
333 | { | ||
334 | if (!_gotHashCode) | ||
335 | { | ||
336 | int hashCode = 1; | ||
337 | foreach (object obj in this) | ||
338 | hashCode = 31 * hashCode + (obj == null ? 0 : obj.GetHashCode()); | ||
339 | _hashCode = hashCode; | ||
340 | _gotHashCode = true; | ||
341 | } | ||
342 | return _hashCode; | ||
343 | } | ||
344 | |||
345 | public override bool Equals(object obj) | ||
346 | { | ||
347 | if (!(obj is ArrayList)) | ||
348 | return false; | ||
349 | |||
350 | ArrayList objList = (ArrayList)obj; | ||
351 | if (objList.Count != Count) | ||
352 | return false; | ||
353 | |||
354 | for (int i = 0; i < Count; ++i) | ||
355 | { | ||
356 | object value = objList[i]; | ||
357 | if (value == null) | ||
358 | { | ||
359 | if (this[i] != null) | ||
360 | return false; | ||
361 | } | ||
362 | else | ||
363 | { | ||
364 | if (!value.Equals(this[i])) | ||
365 | return false; | ||
366 | } | ||
367 | } | ||
368 | return true; | ||
369 | } | ||
370 | } | ||
371 | |||
372 | /// <summary> | ||
373 | /// If we keep an index on value, return the value, or null if we don't index it. | ||
374 | /// </summary> | ||
375 | /// <param name="value">the term to examine. Assume you already called YP.getValue(value)</param> | ||
376 | /// <returns></returns> | ||
377 | public static object getIndexValue(object value) | ||
378 | { | ||
379 | if (value is Atom || value is string || value is Int32 || value is DateTime) | ||
380 | return value; | ||
381 | else | ||
382 | return null; | ||
383 | } | ||
384 | } | ||
385 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/ListPair.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/ListPair.cs deleted file mode 100644 index daac0ba..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/ListPair.cs +++ /dev/null | |||
@@ -1,166 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections.Generic; | ||
33 | |||
34 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
35 | { | ||
36 | public class ListPair : Functor2 | ||
37 | { | ||
38 | public ListPair(object head, object tail) : base(Atom.DOT, head, tail) | ||
39 | { | ||
40 | } | ||
41 | |||
42 | public static object make(List<object> list) | ||
43 | { | ||
44 | if (list.Count <= 0) | ||
45 | return Atom.NIL; | ||
46 | |||
47 | object result = Atom.NIL; | ||
48 | // Start from the end. | ||
49 | for (int i = list.Count - 1; i >= 0; --i) | ||
50 | result = new ListPair(list[i], result); | ||
51 | return result; | ||
52 | } | ||
53 | |||
54 | public static object make(object[] array) | ||
55 | { | ||
56 | if (array.Length <= 0) | ||
57 | return Atom.NIL; | ||
58 | |||
59 | object result = Atom.NIL; | ||
60 | // Start from the end. | ||
61 | for (int i = array.Length - 1; i >= 0; --i) | ||
62 | result = new ListPair(array[i], result); | ||
63 | return result; | ||
64 | } | ||
65 | |||
66 | /// <summary> | ||
67 | /// Return a ListPair version of array, where repeated elements | ||
68 | /// (according to YP.termEqual) are removed. | ||
69 | /// </summary> | ||
70 | /// <param name="array"></param> | ||
71 | /// <returns></returns> | ||
72 | public static object makeWithoutRepeatedTerms(object[] array) | ||
73 | { | ||
74 | if (array.Length <= 0) | ||
75 | return Atom.NIL; | ||
76 | |||
77 | // Start from the end. | ||
78 | object previousTerm = array[array.Length - 1]; | ||
79 | object result = new ListPair(previousTerm, Atom.NIL); | ||
80 | for (int i = array.Length - 2; i >= 0; --i) | ||
81 | { | ||
82 | object term = array[i]; | ||
83 | if (YP.termEqual(term, previousTerm)) | ||
84 | continue; | ||
85 | result = new ListPair(term, result); | ||
86 | previousTerm = term; | ||
87 | } | ||
88 | return result; | ||
89 | } | ||
90 | |||
91 | /// <summary> | ||
92 | /// Return a ListPair version of array, where repeated elements | ||
93 | /// (according to YP.termEqual) are removed. | ||
94 | /// </summary> | ||
95 | /// <param name="array"></param> | ||
96 | /// <returns></returns> | ||
97 | public static object makeWithoutRepeatedTerms(List<object> array) | ||
98 | { | ||
99 | if (array.Count <= 0) | ||
100 | return Atom.NIL; | ||
101 | |||
102 | // Start from the end. | ||
103 | object previousTerm = array[array.Count - 1]; | ||
104 | object result = new ListPair(previousTerm, Atom.NIL); | ||
105 | for (int i = array.Count - 2; i >= 0; --i) | ||
106 | { | ||
107 | object term = array[i]; | ||
108 | if (YP.termEqual(term, previousTerm)) | ||
109 | continue; | ||
110 | result = new ListPair(term, result); | ||
111 | previousTerm = term; | ||
112 | } | ||
113 | return result; | ||
114 | } | ||
115 | |||
116 | public static object make(object element1) | ||
117 | { | ||
118 | return new ListPair(element1, Atom.NIL); | ||
119 | } | ||
120 | |||
121 | public static object make(object element1, object element2) | ||
122 | { | ||
123 | return new ListPair(element1, new ListPair(element2, Atom.NIL)); | ||
124 | } | ||
125 | |||
126 | public static object make(object element1, object element2, object element3) | ||
127 | { | ||
128 | return new ListPair(element1, | ||
129 | new ListPair(element2, new ListPair(element3, Atom.NIL))); | ||
130 | } | ||
131 | |||
132 | /// <summary> | ||
133 | /// Return an array of the elements in list or null if it is not | ||
134 | /// a proper list. If list is Atom.NIL, return an array of zero elements. | ||
135 | /// If the list or one of the tails of the list is Variable, raise an instantiation_error. | ||
136 | /// This does not call YP.getValue on each element. | ||
137 | /// </summary> | ||
138 | /// <param name="list"></param> | ||
139 | /// <returns></returns> | ||
140 | public static object[] toArray(object list) | ||
141 | { | ||
142 | list = YP.getValue(list); | ||
143 | if (list.Equals(Atom.NIL)) | ||
144 | return new object[0]; | ||
145 | |||
146 | List<object> result = new List<object>(); | ||
147 | object element = list; | ||
148 | while (true) { | ||
149 | if (element == Atom.NIL) | ||
150 | break; | ||
151 | if (element is Variable) | ||
152 | throw new PrologException(Atom.a("instantiation_error"), | ||
153 | "List tail is an unbound variable"); | ||
154 | if (!(element is Functor2 && ((Functor2)element)._name == Atom.DOT)) | ||
155 | // Not a proper list. | ||
156 | return null; | ||
157 | result.Add(((Functor2)element)._arg1); | ||
158 | element = YP.getValue(((Functor2)element)._arg2); | ||
159 | } | ||
160 | |||
161 | if (result.Count <= 0) | ||
162 | return null; | ||
163 | return result.ToArray(); | ||
164 | } | ||
165 | } | ||
166 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Parser.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Parser.cs deleted file mode 100644 index 34010e7..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Parser.cs +++ /dev/null | |||
@@ -1,4575 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections.Generic; | ||
33 | |||
34 | // disable warning on l1, don't see how we can | ||
35 | // code this differently | ||
36 | #pragma warning disable 0168, 0219, 0162 | ||
37 | |||
38 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
39 | { | ||
40 | public class Parser | ||
41 | { | ||
42 | public static IEnumerable<bool> read_term2(object Term, object Options) | ||
43 | { | ||
44 | Variable Answer = new Variable(); | ||
45 | Variable Variables = new Variable(); | ||
46 | foreach (bool l1 in read_termOptions(Options, Variables)) | ||
47 | { | ||
48 | foreach (bool l2 in portable_read3(Answer, Variables, new Variable())) | ||
49 | { | ||
50 | foreach (bool l3 in remove_pos(Answer, Term)) | ||
51 | yield return false; | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | |||
56 | public static IEnumerable<bool> read_term3(object Input, object Term, object Options) | ||
57 | { | ||
58 | Variable SaveInput = new Variable(); | ||
59 | Variable Answer = new Variable(); | ||
60 | Variable Variables = new Variable(); | ||
61 | foreach (bool l1 in read_termOptions(Options, Variables)) | ||
62 | { | ||
63 | foreach (bool l2 in YP.current_input(SaveInput)) | ||
64 | { | ||
65 | try | ||
66 | { | ||
67 | YP.see(Input); | ||
68 | foreach (bool l3 in portable_read3(Answer, Variables, new Variable())) | ||
69 | { | ||
70 | foreach (bool l4 in remove_pos(Answer, Term)) | ||
71 | yield return false; | ||
72 | } | ||
73 | } | ||
74 | finally | ||
75 | { | ||
76 | YP.see(SaveInput); | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | } | ||
81 | |||
82 | /// <summary> | ||
83 | /// For read_term, check if Options has variable_names(Variables). | ||
84 | /// Otherwise, ignore Options. | ||
85 | /// </summary> | ||
86 | /// <param name="Options"></param> | ||
87 | /// <param name="Variables"></param> | ||
88 | /// <returns></returns> | ||
89 | private static IEnumerable<bool> read_termOptions(object Options, object Variables) | ||
90 | { | ||
91 | Options = YP.getValue(Options); | ||
92 | if (Options is Variable) | ||
93 | throw new PrologException(Atom.a("instantiation_error"), "Options is an unbound variable"); | ||
94 | // First try to match Options = [variable_names(Variables)] | ||
95 | foreach (bool l1 in YP.unify(Options, ListPair.make(new Functor1("variable_names", Variables)))) | ||
96 | { | ||
97 | yield return false; | ||
98 | yield break; | ||
99 | } | ||
100 | // Default: Ignore Options. | ||
101 | yield return false; | ||
102 | } | ||
103 | |||
104 | public static IEnumerable<bool> read1(object Term) | ||
105 | { | ||
106 | return read_term2(Term, Atom.NIL); | ||
107 | } | ||
108 | |||
109 | public static IEnumerable<bool> read2(object Input, object Term) | ||
110 | { | ||
111 | return read_term3(Input, Term, Atom.NIL); | ||
112 | } | ||
113 | |||
114 | public static IEnumerable<bool> formatError(object Output, object Format, object Arguments) | ||
115 | { | ||
116 | // Debug: Simple implementation for now. | ||
117 | YP.write(Format); | ||
118 | YP.write(Arguments); | ||
119 | YP.nl(); | ||
120 | yield return false; | ||
121 | } | ||
122 | |||
123 | |||
124 | // Debug: Hand-modify this central predicate to do tail recursion. | ||
125 | public static IEnumerable<bool> read_tokens(object arg1, object arg2, object arg3) | ||
126 | { | ||
127 | bool repeat = true; | ||
128 | while (repeat) | ||
129 | { | ||
130 | repeat = false; | ||
131 | { | ||
132 | object C1 = arg1; | ||
133 | object Dict = arg2; | ||
134 | object Tokens = arg3; | ||
135 | Variable C2 = new Variable(); | ||
136 | if (YP.lessThanOrEqual(C1, new ListPair(32, Atom.NIL))) | ||
137 | { | ||
138 | if (YP.greaterThanOrEqual(C1, 0)) | ||
139 | { | ||
140 | foreach (bool l4 in YP.get_code(C2)) | ||
141 | { | ||
142 | #if false | ||
143 | foreach (bool l5 in read_tokens(C2, Dict, Tokens)) | ||
144 | { | ||
145 | yield return false; | ||
146 | } | ||
147 | #endif | ||
148 | arg1 = YP.getValue(C2); | ||
149 | arg2 = YP.getValue(Dict); | ||
150 | arg3 = YP.getValue(Tokens); | ||
151 | repeat = true; | ||
152 | } | ||
153 | } | ||
154 | goto cutIf1; | ||
155 | } | ||
156 | if (YP.greaterThanOrEqual(C1, new ListPair(97, Atom.NIL))) | ||
157 | { | ||
158 | if (YP.lessThanOrEqual(C1, new ListPair(122, Atom.NIL))) | ||
159 | { | ||
160 | foreach (bool l4 in read_identifier(C1, Dict, Tokens)) | ||
161 | { | ||
162 | yield return false; | ||
163 | } | ||
164 | goto cutIf2; | ||
165 | } | ||
166 | } | ||
167 | if (YP.greaterThanOrEqual(C1, new ListPair(65, Atom.NIL))) | ||
168 | { | ||
169 | if (YP.lessThanOrEqual(C1, new ListPair(90, Atom.NIL))) | ||
170 | { | ||
171 | foreach (bool l4 in read_variable(C1, Dict, Tokens)) | ||
172 | { | ||
173 | yield return false; | ||
174 | } | ||
175 | goto cutIf3; | ||
176 | } | ||
177 | } | ||
178 | if (YP.greaterThanOrEqual(C1, new ListPair(48, Atom.NIL))) | ||
179 | { | ||
180 | if (YP.lessThanOrEqual(C1, new ListPair(57, Atom.NIL))) | ||
181 | { | ||
182 | foreach (bool l4 in read_number(C1, Dict, Tokens)) | ||
183 | { | ||
184 | yield return false; | ||
185 | } | ||
186 | goto cutIf4; | ||
187 | } | ||
188 | } | ||
189 | if (YP.lessThan(C1, 127)) | ||
190 | { | ||
191 | foreach (bool l3 in read_special(C1, Dict, Tokens)) | ||
192 | { | ||
193 | yield return false; | ||
194 | } | ||
195 | goto cutIf5; | ||
196 | } | ||
197 | if (YP.lessThanOrEqual(C1, 160)) | ||
198 | { | ||
199 | foreach (bool l3 in YP.get_code(C2)) | ||
200 | { | ||
201 | #if false | ||
202 | foreach (bool l4 in read_tokens(C2, Dict, Tokens)) | ||
203 | { | ||
204 | yield return false; | ||
205 | } | ||
206 | #endif | ||
207 | arg1 = YP.getValue(C2); | ||
208 | arg2 = YP.getValue(Dict); | ||
209 | arg3 = YP.getValue(Tokens); | ||
210 | repeat = true; | ||
211 | } | ||
212 | goto cutIf6; | ||
213 | } | ||
214 | if (YP.greaterThanOrEqual(C1, 223)) | ||
215 | { | ||
216 | if (YP.notEqual(C1, 247)) | ||
217 | { | ||
218 | foreach (bool l4 in read_identifier(C1, Dict, Tokens)) | ||
219 | { | ||
220 | yield return false; | ||
221 | } | ||
222 | goto cutIf7; | ||
223 | } | ||
224 | } | ||
225 | if (YP.greaterThanOrEqual(C1, 192)) | ||
226 | { | ||
227 | if (YP.notEqual(C1, 215)) | ||
228 | { | ||
229 | foreach (bool l4 in read_variable(C1, Dict, Tokens)) | ||
230 | { | ||
231 | yield return false; | ||
232 | } | ||
233 | goto cutIf8; | ||
234 | } | ||
235 | } | ||
236 | if (YP.notEqual(C1, 170)) | ||
237 | { | ||
238 | if (YP.notEqual(C1, 186)) | ||
239 | { | ||
240 | foreach (bool l4 in read_symbol(C1, Dict, Tokens)) | ||
241 | { | ||
242 | yield return false; | ||
243 | } | ||
244 | goto cutIf9; | ||
245 | } | ||
246 | } | ||
247 | foreach (bool l2 in read_identifier(C1, Dict, Tokens)) | ||
248 | { | ||
249 | yield return false; | ||
250 | } | ||
251 | cutIf9: | ||
252 | cutIf8: | ||
253 | cutIf7: | ||
254 | cutIf6: | ||
255 | cutIf5: | ||
256 | cutIf4: | ||
257 | cutIf3: | ||
258 | cutIf2: | ||
259 | cutIf1: | ||
260 | { } | ||
261 | } | ||
262 | } | ||
263 | } | ||
264 | |||
265 | // Compiler output follows. | ||
266 | |||
267 | class YPInnerClass { } | ||
268 | // static Type getDeclaringClass() { return typeof(YPInnerClass).DeclaringType; } | ||
269 | |||
270 | public static IEnumerable<bool> parseInput(object TermList) | ||
271 | { | ||
272 | { | ||
273 | Variable TermAndVariables = new Variable(); | ||
274 | FindallAnswers findallAnswers1 = new FindallAnswers(TermAndVariables); | ||
275 | foreach (bool l2 in parseInputHelper(TermAndVariables)) | ||
276 | { | ||
277 | findallAnswers1.add(); | ||
278 | } | ||
279 | foreach (bool l2 in findallAnswers1.result(TermList)) | ||
280 | { | ||
281 | yield return false; | ||
282 | } | ||
283 | } | ||
284 | } | ||
285 | |||
286 | public static IEnumerable<bool> parseInputHelper(object arg1) | ||
287 | { | ||
288 | { | ||
289 | Variable Term = new Variable(); | ||
290 | Variable Variables = new Variable(); | ||
291 | Variable Answer = new Variable(); | ||
292 | Variable x4 = new Variable(); | ||
293 | foreach (bool l2 in YP.unify(arg1, new Functor2("f", Term, Variables))) | ||
294 | { | ||
295 | foreach (bool l3 in YP.repeat()) | ||
296 | { | ||
297 | foreach (bool l4 in portable_read3(Answer, Variables, x4)) | ||
298 | { | ||
299 | foreach (bool l5 in remove_pos(Answer, Term)) | ||
300 | { | ||
301 | if (YP.termEqual(Term, Atom.a("end_of_file"))) | ||
302 | { | ||
303 | yield break; | ||
304 | goto cutIf1; | ||
305 | } | ||
306 | yield return false; | ||
307 | cutIf1: | ||
308 | { } | ||
309 | } | ||
310 | } | ||
311 | } | ||
312 | } | ||
313 | } | ||
314 | } | ||
315 | |||
316 | public static IEnumerable<bool> clear_errors() | ||
317 | { | ||
318 | { | ||
319 | yield return false; | ||
320 | } | ||
321 | } | ||
322 | |||
323 | public static IEnumerable<bool> remove_pos(object arg1, object arg2) | ||
324 | { | ||
325 | { | ||
326 | Variable X = new Variable(); | ||
327 | foreach (bool l2 in YP.unify(arg1, X)) | ||
328 | { | ||
329 | foreach (bool l3 in YP.unify(arg2, X)) | ||
330 | { | ||
331 | if (YP.var(X)) | ||
332 | { | ||
333 | yield return true; | ||
334 | yield break; | ||
335 | } | ||
336 | } | ||
337 | } | ||
338 | } | ||
339 | { | ||
340 | object X = arg2; | ||
341 | Variable _Pos = new Variable(); | ||
342 | Variable _Name = new Variable(); | ||
343 | foreach (bool l2 in YP.unify(arg1, new Functor3("$VAR", _Pos, _Name, X))) | ||
344 | { | ||
345 | if (YP.var(X)) | ||
346 | { | ||
347 | yield return true; | ||
348 | yield break; | ||
349 | } | ||
350 | } | ||
351 | } | ||
352 | { | ||
353 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
354 | { | ||
355 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
356 | { | ||
357 | yield return true; | ||
358 | yield break; | ||
359 | } | ||
360 | } | ||
361 | } | ||
362 | { | ||
363 | Variable H = new Variable(); | ||
364 | Variable T = new Variable(); | ||
365 | Variable NH = new Variable(); | ||
366 | Variable NT = new Variable(); | ||
367 | foreach (bool l2 in YP.unify(arg1, new ListPair(H, T))) | ||
368 | { | ||
369 | foreach (bool l3 in YP.unify(arg2, new ListPair(NH, NT))) | ||
370 | { | ||
371 | foreach (bool l4 in remove_pos(H, NH)) | ||
372 | { | ||
373 | foreach (bool l5 in remove_pos(T, NT)) | ||
374 | { | ||
375 | yield return false; | ||
376 | } | ||
377 | } | ||
378 | yield break; | ||
379 | } | ||
380 | } | ||
381 | } | ||
382 | { | ||
383 | Variable A = new Variable(); | ||
384 | Variable B = new Variable(); | ||
385 | Variable NA = new Variable(); | ||
386 | Variable NB = new Variable(); | ||
387 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", A, B))) | ||
388 | { | ||
389 | foreach (bool l3 in YP.unify(arg2, new Functor2(",", NA, NB))) | ||
390 | { | ||
391 | foreach (bool l4 in remove_pos(A, NA)) | ||
392 | { | ||
393 | foreach (bool l5 in remove_pos(B, NB)) | ||
394 | { | ||
395 | yield return false; | ||
396 | } | ||
397 | } | ||
398 | yield break; | ||
399 | } | ||
400 | } | ||
401 | } | ||
402 | { | ||
403 | Variable Atom_1 = new Variable(); | ||
404 | Variable _F = new Variable(); | ||
405 | foreach (bool l2 in YP.unify(arg1, Atom_1)) | ||
406 | { | ||
407 | foreach (bool l3 in YP.unify(arg2, Atom_1)) | ||
408 | { | ||
409 | foreach (bool l4 in YP.functor(Atom_1, _F, 0)) | ||
410 | { | ||
411 | yield return false; | ||
412 | } | ||
413 | } | ||
414 | } | ||
415 | } | ||
416 | { | ||
417 | object Term = arg1; | ||
418 | object NewTerm = arg2; | ||
419 | Variable Func = new Variable(); | ||
420 | Variable _Pos = new Variable(); | ||
421 | Variable Args = new Variable(); | ||
422 | Variable NArgs = new Variable(); | ||
423 | if (YP.nonvar(Term)) | ||
424 | { | ||
425 | foreach (bool l3 in YP.univ(Term, new ListPair(Func, new ListPair(_Pos, Args)))) | ||
426 | { | ||
427 | foreach (bool l4 in remove_pos(Args, NArgs)) | ||
428 | { | ||
429 | foreach (bool l5 in YP.univ(NewTerm, new ListPair(Func, NArgs))) | ||
430 | { | ||
431 | yield return false; | ||
432 | } | ||
433 | } | ||
434 | } | ||
435 | } | ||
436 | } | ||
437 | } | ||
438 | |||
439 | public static IEnumerable<bool> portable_read_position(object Term, object PosTerm, object Syntax) | ||
440 | { | ||
441 | { | ||
442 | foreach (bool l2 in portable_read(PosTerm, Syntax)) | ||
443 | { | ||
444 | foreach (bool l3 in remove_pos(PosTerm, Term)) | ||
445 | { | ||
446 | yield return false; | ||
447 | } | ||
448 | } | ||
449 | } | ||
450 | } | ||
451 | |||
452 | public static IEnumerable<bool> portable_read(object Answer, object Syntax) | ||
453 | { | ||
454 | { | ||
455 | Variable Tokens = new Variable(); | ||
456 | Variable ParseTokens = new Variable(); | ||
457 | foreach (bool l2 in read_tokens1(Tokens)) | ||
458 | { | ||
459 | foreach (bool l3 in remove_comments(Tokens, ParseTokens, Syntax)) | ||
460 | { | ||
461 | foreach (bool l4 in parse2(ParseTokens, Answer)) | ||
462 | { | ||
463 | yield return false; | ||
464 | } | ||
465 | } | ||
466 | } | ||
467 | } | ||
468 | } | ||
469 | |||
470 | public static IEnumerable<bool> portable_read3(object Answer, object Variables, object Syntax) | ||
471 | { | ||
472 | { | ||
473 | Variable Tokens = new Variable(); | ||
474 | Variable ParseTokens = new Variable(); | ||
475 | foreach (bool l2 in read_tokens2(Tokens, Variables)) | ||
476 | { | ||
477 | foreach (bool l3 in remove_comments(Tokens, ParseTokens, Syntax)) | ||
478 | { | ||
479 | foreach (bool l4 in parse2(ParseTokens, Answer)) | ||
480 | { | ||
481 | yield return false; | ||
482 | } | ||
483 | } | ||
484 | } | ||
485 | } | ||
486 | } | ||
487 | |||
488 | public static IEnumerable<bool> remove_comments(object arg1, object arg2, object arg3) | ||
489 | { | ||
490 | { | ||
491 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
492 | { | ||
493 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
494 | { | ||
495 | foreach (bool l4 in YP.unify(arg3, Atom.NIL)) | ||
496 | { | ||
497 | yield return false; | ||
498 | } | ||
499 | } | ||
500 | } | ||
501 | } | ||
502 | { | ||
503 | object Ys = arg2; | ||
504 | Variable S = new Variable(); | ||
505 | Variable E = new Variable(); | ||
506 | Variable Xs = new Variable(); | ||
507 | Variable Zs = new Variable(); | ||
508 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("comment", S, E), Xs))) | ||
509 | { | ||
510 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("comment", S, E), Zs))) | ||
511 | { | ||
512 | foreach (bool l4 in remove_comments(Xs, Ys, Zs)) | ||
513 | { | ||
514 | yield return false; | ||
515 | } | ||
516 | yield break; | ||
517 | } | ||
518 | } | ||
519 | } | ||
520 | { | ||
521 | Variable Pos = new Variable(); | ||
522 | Variable Xs = new Variable(); | ||
523 | Variable Ys = new Variable(); | ||
524 | Variable Pos2 = new Variable(); | ||
525 | Variable Zs = new Variable(); | ||
526 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("/", Atom.a("["), Pos), Xs))) | ||
527 | { | ||
528 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a("["), Ys))) | ||
529 | { | ||
530 | foreach (bool l4 in YP.unify(arg3, new ListPair(new Functor2("list", Pos, Pos2), Zs))) | ||
531 | { | ||
532 | foreach (bool l5 in YP.unify(Pos2, YP.add(Pos, 1))) | ||
533 | { | ||
534 | foreach (bool l6 in remove_comments(Xs, Ys, Zs)) | ||
535 | { | ||
536 | yield return false; | ||
537 | } | ||
538 | } | ||
539 | yield break; | ||
540 | } | ||
541 | } | ||
542 | } | ||
543 | } | ||
544 | { | ||
545 | Variable Pos = new Variable(); | ||
546 | Variable Xs = new Variable(); | ||
547 | Variable Ys = new Variable(); | ||
548 | Variable Pos2 = new Variable(); | ||
549 | Variable Zs = new Variable(); | ||
550 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("/", Atom.a("]"), Pos), Xs))) | ||
551 | { | ||
552 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a("]"), Ys))) | ||
553 | { | ||
554 | foreach (bool l4 in YP.unify(arg3, new ListPair(new Functor2("list", Pos, Pos2), Zs))) | ||
555 | { | ||
556 | foreach (bool l5 in YP.unify(Pos2, YP.add(Pos, 1))) | ||
557 | { | ||
558 | foreach (bool l6 in remove_comments(Xs, Ys, Zs)) | ||
559 | { | ||
560 | yield return false; | ||
561 | } | ||
562 | } | ||
563 | yield break; | ||
564 | } | ||
565 | } | ||
566 | } | ||
567 | } | ||
568 | { | ||
569 | object Zs = arg3; | ||
570 | Variable Token = new Variable(); | ||
571 | Variable Xs = new Variable(); | ||
572 | Variable Ys = new Variable(); | ||
573 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, Xs))) | ||
574 | { | ||
575 | foreach (bool l3 in YP.unify(arg2, new ListPair(Token, Ys))) | ||
576 | { | ||
577 | foreach (bool l4 in remove_comments(Xs, Ys, Zs)) | ||
578 | { | ||
579 | yield return false; | ||
580 | } | ||
581 | } | ||
582 | } | ||
583 | } | ||
584 | } | ||
585 | |||
586 | public static IEnumerable<bool> expect(object Token, object arg2, object arg3) | ||
587 | { | ||
588 | { | ||
589 | object Rest = arg3; | ||
590 | foreach (bool l2 in YP.unify(arg2, new ListPair(Token, Rest))) | ||
591 | { | ||
592 | yield return true; | ||
593 | yield break; | ||
594 | } | ||
595 | } | ||
596 | { | ||
597 | object S0 = arg2; | ||
598 | object x3 = arg3; | ||
599 | foreach (bool l2 in syntax_error(ListPair.make(new object[] { Token, Atom.a("or"), Atom.a("operator"), Atom.a("expected") }), S0)) | ||
600 | { | ||
601 | yield return false; | ||
602 | } | ||
603 | } | ||
604 | } | ||
605 | |||
606 | public static IEnumerable<bool> parse2(object Tokens, object Answer) | ||
607 | { | ||
608 | { | ||
609 | Variable Term = new Variable(); | ||
610 | Variable LeftOver = new Variable(); | ||
611 | foreach (bool l2 in clear_errors()) | ||
612 | { | ||
613 | foreach (bool l3 in parse(Tokens, 1200, Term, LeftOver)) | ||
614 | { | ||
615 | foreach (bool l4 in all_read(LeftOver)) | ||
616 | { | ||
617 | foreach (bool l5 in YP.unify(Answer, Term)) | ||
618 | { | ||
619 | yield return false; | ||
620 | } | ||
621 | yield break; | ||
622 | } | ||
623 | } | ||
624 | foreach (bool l3 in syntax_error(Tokens)) | ||
625 | { | ||
626 | yield return false; | ||
627 | } | ||
628 | } | ||
629 | } | ||
630 | } | ||
631 | |||
632 | public static IEnumerable<bool> all_read(object arg1) | ||
633 | { | ||
634 | { | ||
635 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
636 | { | ||
637 | yield return false; | ||
638 | } | ||
639 | } | ||
640 | { | ||
641 | Variable Token = new Variable(); | ||
642 | Variable S = new Variable(); | ||
643 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, S))) | ||
644 | { | ||
645 | foreach (bool l3 in syntax_error(ListPair.make(new object[] { Atom.a("operator"), Atom.a("expected"), Atom.a("after"), Atom.a("expression") }), new ListPair(Token, S))) | ||
646 | { | ||
647 | yield return false; | ||
648 | } | ||
649 | } | ||
650 | } | ||
651 | } | ||
652 | |||
653 | public static IEnumerable<bool> parse(object arg1, object arg2, object arg3, object arg4) | ||
654 | { | ||
655 | { | ||
656 | object x1 = arg2; | ||
657 | object x2 = arg3; | ||
658 | object x3 = arg4; | ||
659 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
660 | { | ||
661 | foreach (bool l3 in syntax_error(new ListPair(Atom.a("expression"), new ListPair(Atom.a("expected"), Atom.NIL)), Atom.NIL)) | ||
662 | { | ||
663 | yield return false; | ||
664 | } | ||
665 | } | ||
666 | } | ||
667 | { | ||
668 | object Precedence = arg2; | ||
669 | object Term = arg3; | ||
670 | object LeftOver = arg4; | ||
671 | Variable Token = new Variable(); | ||
672 | Variable RestTokens = new Variable(); | ||
673 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, RestTokens))) | ||
674 | { | ||
675 | foreach (bool l3 in parse5(Token, RestTokens, Precedence, Term, LeftOver)) | ||
676 | { | ||
677 | yield return false; | ||
678 | } | ||
679 | } | ||
680 | } | ||
681 | } | ||
682 | |||
683 | public static IEnumerable<bool> parse5(object arg1, object arg2, object arg3, object arg4, object arg5) | ||
684 | { | ||
685 | { | ||
686 | object S0 = arg2; | ||
687 | object x2 = arg3; | ||
688 | object x3 = arg4; | ||
689 | object x4 = arg5; | ||
690 | foreach (bool l2 in YP.unify(arg1, Atom.a("}"))) | ||
691 | { | ||
692 | foreach (bool l3 in cannot_start(Atom.a("}"), S0)) | ||
693 | { | ||
694 | yield return false; | ||
695 | } | ||
696 | } | ||
697 | } | ||
698 | { | ||
699 | object S0 = arg2; | ||
700 | object x2 = arg3; | ||
701 | object x3 = arg4; | ||
702 | object x4 = arg5; | ||
703 | foreach (bool l2 in YP.unify(arg1, Atom.a("]"))) | ||
704 | { | ||
705 | foreach (bool l3 in cannot_start(Atom.a("]"), S0)) | ||
706 | { | ||
707 | yield return false; | ||
708 | } | ||
709 | } | ||
710 | } | ||
711 | { | ||
712 | object S0 = arg2; | ||
713 | object x2 = arg3; | ||
714 | object x3 = arg4; | ||
715 | object x4 = arg5; | ||
716 | foreach (bool l2 in YP.unify(arg1, Atom.a(")"))) | ||
717 | { | ||
718 | foreach (bool l3 in cannot_start(Atom.a(")"), S0)) | ||
719 | { | ||
720 | yield return false; | ||
721 | } | ||
722 | } | ||
723 | } | ||
724 | { | ||
725 | object S0 = arg2; | ||
726 | object x2 = arg3; | ||
727 | object x3 = arg4; | ||
728 | object x4 = arg5; | ||
729 | foreach (bool l2 in YP.unify(arg1, Atom.a(","))) | ||
730 | { | ||
731 | foreach (bool l3 in cannot_start(Atom.a(","), S0)) | ||
732 | { | ||
733 | yield return false; | ||
734 | } | ||
735 | } | ||
736 | } | ||
737 | { | ||
738 | object S0 = arg2; | ||
739 | object x2 = arg3; | ||
740 | object x3 = arg4; | ||
741 | object x4 = arg5; | ||
742 | foreach (bool l2 in YP.unify(arg1, Atom.a("|"))) | ||
743 | { | ||
744 | foreach (bool l3 in cannot_start(Atom.a("|"), S0)) | ||
745 | { | ||
746 | yield return false; | ||
747 | } | ||
748 | } | ||
749 | } | ||
750 | { | ||
751 | object S0 = arg2; | ||
752 | object Precedence = arg3; | ||
753 | object Answer = arg4; | ||
754 | object S = arg5; | ||
755 | Variable Codes = new Variable(); | ||
756 | Variable Term = new Variable(); | ||
757 | Variable A = new Variable(); | ||
758 | foreach (bool l2 in YP.unify(arg1, new Functor1("string", Codes))) | ||
759 | { | ||
760 | foreach (bool l3 in YP.current_prolog_flag(Atom.a("double_quotes"), Atom.a("atom"))) | ||
761 | { | ||
762 | foreach (bool l4 in YP.atom_codes(Term, Codes)) | ||
763 | { | ||
764 | foreach (bool l5 in exprtl0(S0, Term, Precedence, Answer, S)) | ||
765 | { | ||
766 | yield return false; | ||
767 | } | ||
768 | } | ||
769 | goto cutIf1; | ||
770 | } | ||
771 | foreach (bool l3 in YP.current_prolog_flag(Atom.a("double_quotes"), Atom.a("chars"))) | ||
772 | { | ||
773 | foreach (bool l4 in YP.atom_codes(A, Codes)) | ||
774 | { | ||
775 | foreach (bool l5 in YP.atom_chars(A, Term)) | ||
776 | { | ||
777 | foreach (bool l6 in exprtl0(S0, Term, Precedence, Answer, S)) | ||
778 | { | ||
779 | yield return false; | ||
780 | } | ||
781 | } | ||
782 | } | ||
783 | goto cutIf2; | ||
784 | } | ||
785 | foreach (bool l3 in YP.unify(Term, Codes)) | ||
786 | { | ||
787 | foreach (bool l4 in exprtl0(S0, Term, Precedence, Answer, S)) | ||
788 | { | ||
789 | yield return false; | ||
790 | } | ||
791 | } | ||
792 | cutIf2: | ||
793 | cutIf1: | ||
794 | { } | ||
795 | } | ||
796 | } | ||
797 | { | ||
798 | object S0 = arg2; | ||
799 | object Precedence = arg3; | ||
800 | object Answer = arg4; | ||
801 | object S = arg5; | ||
802 | Variable Number = new Variable(); | ||
803 | foreach (bool l2 in YP.unify(arg1, new Functor1("number", Number))) | ||
804 | { | ||
805 | foreach (bool l3 in exprtl0(S0, Number, Precedence, Answer, S)) | ||
806 | { | ||
807 | yield return false; | ||
808 | } | ||
809 | } | ||
810 | } | ||
811 | { | ||
812 | object Precedence = arg3; | ||
813 | object Answer = arg4; | ||
814 | object S = arg5; | ||
815 | Variable S1 = new Variable(); | ||
816 | foreach (bool l2 in YP.unify(arg1, Atom.a("["))) | ||
817 | { | ||
818 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a("]"), S1))) | ||
819 | { | ||
820 | foreach (bool l4 in read_atom(new Functor2("/", Atom.NIL, 0), S1, Precedence, Answer, S)) | ||
821 | { | ||
822 | yield return false; | ||
823 | } | ||
824 | yield break; | ||
825 | } | ||
826 | } | ||
827 | } | ||
828 | { | ||
829 | object S1 = arg2; | ||
830 | object Precedence = arg3; | ||
831 | object Answer = arg4; | ||
832 | object S = arg5; | ||
833 | Variable Arg1 = new Variable(); | ||
834 | Variable S2 = new Variable(); | ||
835 | Variable RestArgs = new Variable(); | ||
836 | Variable S3 = new Variable(); | ||
837 | foreach (bool l2 in YP.unify(arg1, Atom.a("["))) | ||
838 | { | ||
839 | foreach (bool l3 in parse(S1, 999, Arg1, S2)) | ||
840 | { | ||
841 | foreach (bool l4 in read_list(S2, RestArgs, S3)) | ||
842 | { | ||
843 | foreach (bool l5 in exprtl0(S3, new ListPair(Arg1, RestArgs), Precedence, Answer, S)) | ||
844 | { | ||
845 | yield return false; | ||
846 | } | ||
847 | yield break; | ||
848 | } | ||
849 | } | ||
850 | } | ||
851 | } | ||
852 | { | ||
853 | object S1 = arg2; | ||
854 | object Precedence = arg3; | ||
855 | object Answer = arg4; | ||
856 | object S = arg5; | ||
857 | Variable Term = new Variable(); | ||
858 | Variable S2 = new Variable(); | ||
859 | Variable S3 = new Variable(); | ||
860 | foreach (bool l2 in YP.unify(arg1, Atom.a("("))) | ||
861 | { | ||
862 | foreach (bool l3 in parse(S1, 1200, Term, S2)) | ||
863 | { | ||
864 | foreach (bool l4 in expect(Atom.a(")"), S2, S3)) | ||
865 | { | ||
866 | foreach (bool l5 in exprtl0(S3, Term, Precedence, Answer, S)) | ||
867 | { | ||
868 | yield return false; | ||
869 | } | ||
870 | yield break; | ||
871 | } | ||
872 | } | ||
873 | } | ||
874 | } | ||
875 | { | ||
876 | object S1 = arg2; | ||
877 | object Precedence = arg3; | ||
878 | object Answer = arg4; | ||
879 | object S = arg5; | ||
880 | Variable Term = new Variable(); | ||
881 | Variable S2 = new Variable(); | ||
882 | Variable S3 = new Variable(); | ||
883 | foreach (bool l2 in YP.unify(arg1, Atom.a(" ("))) | ||
884 | { | ||
885 | foreach (bool l3 in parse(S1, 1200, Term, S2)) | ||
886 | { | ||
887 | foreach (bool l4 in expect(Atom.a(")"), S2, S3)) | ||
888 | { | ||
889 | foreach (bool l5 in exprtl0(S3, Term, Precedence, Answer, S)) | ||
890 | { | ||
891 | yield return false; | ||
892 | } | ||
893 | yield break; | ||
894 | } | ||
895 | } | ||
896 | } | ||
897 | } | ||
898 | { | ||
899 | object Precedence = arg3; | ||
900 | object Answer = arg4; | ||
901 | object S = arg5; | ||
902 | Variable _Pos = new Variable(); | ||
903 | Variable S1 = new Variable(); | ||
904 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", Atom.a("{"), _Pos))) | ||
905 | { | ||
906 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a("}"), S1))) | ||
907 | { | ||
908 | foreach (bool l4 in read_atom(Atom.a("{}"), S1, Precedence, Answer, S)) | ||
909 | { | ||
910 | yield return false; | ||
911 | } | ||
912 | yield break; | ||
913 | } | ||
914 | } | ||
915 | } | ||
916 | { | ||
917 | object S1 = arg2; | ||
918 | object Precedence = arg3; | ||
919 | object Answer = arg4; | ||
920 | object S = arg5; | ||
921 | Variable Pos = new Variable(); | ||
922 | Variable Term = new Variable(); | ||
923 | Variable S2 = new Variable(); | ||
924 | Variable S3 = new Variable(); | ||
925 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", Atom.a("{"), Pos))) | ||
926 | { | ||
927 | foreach (bool l3 in parse(S1, 1200, Term, S2)) | ||
928 | { | ||
929 | foreach (bool l4 in expect(Atom.a("}"), S2, S3)) | ||
930 | { | ||
931 | foreach (bool l5 in exprtl0(S3, new Functor2("{}", Pos, Term), Precedence, Answer, S)) | ||
932 | { | ||
933 | yield return false; | ||
934 | } | ||
935 | yield break; | ||
936 | } | ||
937 | } | ||
938 | } | ||
939 | } | ||
940 | { | ||
941 | object Precedence = arg3; | ||
942 | object Answer = arg4; | ||
943 | object S = arg5; | ||
944 | Variable Variable_1 = new Variable(); | ||
945 | Variable Name = new Variable(); | ||
946 | Variable Pos = new Variable(); | ||
947 | Variable S1 = new Variable(); | ||
948 | Variable Arg1 = new Variable(); | ||
949 | Variable S2 = new Variable(); | ||
950 | Variable RestArgs = new Variable(); | ||
951 | Variable S3 = new Variable(); | ||
952 | Variable Term = new Variable(); | ||
953 | foreach (bool l2 in YP.unify(arg1, new Functor3("var", Variable_1, Name, Pos))) | ||
954 | { | ||
955 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a("("), S1))) | ||
956 | { | ||
957 | foreach (bool l4 in parse(S1, 999, Arg1, S2)) | ||
958 | { | ||
959 | foreach (bool l5 in read_args(S2, RestArgs, S3)) | ||
960 | { | ||
961 | foreach (bool l6 in YP.univ(Term, new ListPair(Atom.a("call"), new ListPair(new Functor3("$VAR", Pos, Name, Variable_1), new ListPair(Arg1, RestArgs))))) | ||
962 | { | ||
963 | foreach (bool l7 in exprtl0(S3, Term, Precedence, Answer, S)) | ||
964 | { | ||
965 | yield return false; | ||
966 | } | ||
967 | } | ||
968 | yield break; | ||
969 | } | ||
970 | } | ||
971 | yield break; | ||
972 | } | ||
973 | } | ||
974 | } | ||
975 | { | ||
976 | object S0 = arg2; | ||
977 | object Precedence = arg3; | ||
978 | object Answer = arg4; | ||
979 | object S = arg5; | ||
980 | Variable Variable_1 = new Variable(); | ||
981 | Variable Name = new Variable(); | ||
982 | Variable Pos = new Variable(); | ||
983 | foreach (bool l2 in YP.unify(arg1, new Functor3("var", Variable_1, Name, Pos))) | ||
984 | { | ||
985 | foreach (bool l3 in exprtl0(S0, new Functor3("$VAR", Pos, Name, Variable_1), Precedence, Answer, S)) | ||
986 | { | ||
987 | yield return false; | ||
988 | } | ||
989 | } | ||
990 | } | ||
991 | { | ||
992 | object S0 = arg2; | ||
993 | object Precedence = arg3; | ||
994 | object Answer = arg4; | ||
995 | object S = arg5; | ||
996 | Variable Atom_1 = new Variable(); | ||
997 | Variable P = new Variable(); | ||
998 | foreach (bool l2 in YP.unify(arg1, new Functor2("atom", Atom_1, P))) | ||
999 | { | ||
1000 | foreach (bool l3 in read_atom(new Functor2("/", Atom_1, P), S0, Precedence, Answer, S)) | ||
1001 | { | ||
1002 | yield return false; | ||
1003 | } | ||
1004 | } | ||
1005 | } | ||
1006 | } | ||
1007 | |||
1008 | public static IEnumerable<bool> read_atom(object arg1, object arg2, object Precedence, object Answer, object S) | ||
1009 | { | ||
1010 | { | ||
1011 | Variable _Pos = new Variable(); | ||
1012 | Variable Number = new Variable(); | ||
1013 | Variable S1 = new Variable(); | ||
1014 | Variable Negative = new Variable(); | ||
1015 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", Atom.a("-"), _Pos))) | ||
1016 | { | ||
1017 | foreach (bool l3 in YP.unify(arg2, new ListPair(new Functor1("number", Number), S1))) | ||
1018 | { | ||
1019 | foreach (bool l4 in YP.unify(Negative, YP.negate(Number))) | ||
1020 | { | ||
1021 | foreach (bool l5 in exprtl0(S1, Negative, Precedence, Answer, S)) | ||
1022 | { | ||
1023 | yield return false; | ||
1024 | } | ||
1025 | } | ||
1026 | yield break; | ||
1027 | } | ||
1028 | } | ||
1029 | } | ||
1030 | { | ||
1031 | Variable Functor_1 = new Variable(); | ||
1032 | Variable Pos = new Variable(); | ||
1033 | Variable S1 = new Variable(); | ||
1034 | Variable Arg1 = new Variable(); | ||
1035 | Variable S2 = new Variable(); | ||
1036 | Variable RestArgs = new Variable(); | ||
1037 | Variable S3 = new Variable(); | ||
1038 | Variable Term = new Variable(); | ||
1039 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", Functor_1, Pos))) | ||
1040 | { | ||
1041 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a("("), S1))) | ||
1042 | { | ||
1043 | foreach (bool l4 in parse(S1, 999, Arg1, S2)) | ||
1044 | { | ||
1045 | foreach (bool l5 in read_args(S2, RestArgs, S3)) | ||
1046 | { | ||
1047 | foreach (bool l6 in YP.univ(Term, new ListPair(Functor_1, new ListPair(Pos, new ListPair(Arg1, RestArgs))))) | ||
1048 | { | ||
1049 | foreach (bool l7 in exprtl0(S3, Term, Precedence, Answer, S)) | ||
1050 | { | ||
1051 | yield return false; | ||
1052 | } | ||
1053 | } | ||
1054 | yield break; | ||
1055 | } | ||
1056 | } | ||
1057 | yield break; | ||
1058 | } | ||
1059 | } | ||
1060 | } | ||
1061 | { | ||
1062 | object S0 = arg2; | ||
1063 | Variable Op = new Variable(); | ||
1064 | Variable Pos = new Variable(); | ||
1065 | Variable Oprec = new Variable(); | ||
1066 | Variable Aprec = new Variable(); | ||
1067 | Variable Flag = new Variable(); | ||
1068 | Variable Term = new Variable(); | ||
1069 | Variable Arg = new Variable(); | ||
1070 | Variable S1 = new Variable(); | ||
1071 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", Op, Pos))) | ||
1072 | { | ||
1073 | foreach (bool l3 in prefixop(Op, Oprec, Aprec)) | ||
1074 | { | ||
1075 | foreach (bool l4 in possible_right_operand(S0, Flag)) | ||
1076 | { | ||
1077 | if (YP.lessThan(Flag, 0)) | ||
1078 | { | ||
1079 | foreach (bool l6 in YP.univ(Term, new ListPair(Op, new ListPair(Pos, Atom.NIL)))) | ||
1080 | { | ||
1081 | foreach (bool l7 in exprtl0(S0, Term, Precedence, Answer, S)) | ||
1082 | { | ||
1083 | yield return false; | ||
1084 | } | ||
1085 | } | ||
1086 | goto cutIf1; | ||
1087 | } | ||
1088 | if (YP.greaterThan(Oprec, Precedence)) | ||
1089 | { | ||
1090 | foreach (bool l6 in syntax_error(ListPair.make(new object[] { Atom.a("prefix"), Atom.a("operator"), Op, Atom.a("in"), Atom.a("context"), Atom.a("with"), Atom.a("precedence"), Precedence }), S0)) | ||
1091 | { | ||
1092 | yield return false; | ||
1093 | } | ||
1094 | goto cutIf2; | ||
1095 | } | ||
1096 | if (YP.greaterThan(Flag, 0)) | ||
1097 | { | ||
1098 | foreach (bool l6 in parse(S0, Aprec, Arg, S1)) | ||
1099 | { | ||
1100 | foreach (bool l7 in YP.univ(Term, ListPair.make(new object[] { Op, Pos, Arg }))) | ||
1101 | { | ||
1102 | foreach (bool l8 in exprtl(S1, Oprec, Term, Precedence, Answer, S)) | ||
1103 | { | ||
1104 | yield return false; | ||
1105 | } | ||
1106 | } | ||
1107 | yield break; | ||
1108 | } | ||
1109 | goto cutIf3; | ||
1110 | } | ||
1111 | foreach (bool l5 in peepop(S0, S1)) | ||
1112 | { | ||
1113 | foreach (bool l6 in prefix_is_atom(S1, Oprec)) | ||
1114 | { | ||
1115 | foreach (bool l7 in exprtl(S1, Oprec, new Functor2("/", Op, Pos), Precedence, Answer, S)) | ||
1116 | { | ||
1117 | yield return false; | ||
1118 | } | ||
1119 | } | ||
1120 | } | ||
1121 | foreach (bool l5 in parse(S0, Aprec, Arg, S1)) | ||
1122 | { | ||
1123 | foreach (bool l6 in YP.univ(Term, ListPair.make(new object[] { Op, Pos, Arg }))) | ||
1124 | { | ||
1125 | foreach (bool l7 in exprtl(S1, Oprec, Term, Precedence, Answer, S)) | ||
1126 | { | ||
1127 | yield return false; | ||
1128 | } | ||
1129 | } | ||
1130 | yield break; | ||
1131 | } | ||
1132 | cutIf3: | ||
1133 | cutIf2: | ||
1134 | cutIf1: | ||
1135 | { } | ||
1136 | } | ||
1137 | yield break; | ||
1138 | } | ||
1139 | } | ||
1140 | } | ||
1141 | { | ||
1142 | object S0 = arg2; | ||
1143 | Variable Atom_1 = new Variable(); | ||
1144 | Variable Pos = new Variable(); | ||
1145 | Variable Term = new Variable(); | ||
1146 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", Atom_1, Pos))) | ||
1147 | { | ||
1148 | foreach (bool l3 in YP.univ(Term, new ListPair(Atom_1, new ListPair(Pos, Atom.NIL)))) | ||
1149 | { | ||
1150 | foreach (bool l4 in exprtl0(S0, Term, Precedence, Answer, S)) | ||
1151 | { | ||
1152 | yield return false; | ||
1153 | } | ||
1154 | } | ||
1155 | } | ||
1156 | } | ||
1157 | } | ||
1158 | |||
1159 | public static IEnumerable<bool> cannot_start(object Token, object S0) | ||
1160 | { | ||
1161 | { | ||
1162 | foreach (bool l2 in syntax_error(ListPair.make(new object[] { Token, Atom.a("cannot"), Atom.a("start"), Atom.a("an"), Atom.a("expression") }), S0)) | ||
1163 | { | ||
1164 | yield return false; | ||
1165 | } | ||
1166 | } | ||
1167 | } | ||
1168 | |||
1169 | public static IEnumerable<bool> read_args(object arg1, object arg2, object arg3) | ||
1170 | { | ||
1171 | { | ||
1172 | object S = arg3; | ||
1173 | Variable S1 = new Variable(); | ||
1174 | Variable Term = new Variable(); | ||
1175 | Variable Rest = new Variable(); | ||
1176 | Variable S2 = new Variable(); | ||
1177 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(","), S1))) | ||
1178 | { | ||
1179 | foreach (bool l3 in YP.unify(arg2, new ListPair(Term, Rest))) | ||
1180 | { | ||
1181 | foreach (bool l4 in parse(S1, 999, Term, S2)) | ||
1182 | { | ||
1183 | foreach (bool l5 in read_args(S2, Rest, S)) | ||
1184 | { | ||
1185 | yield return false; | ||
1186 | } | ||
1187 | yield break; | ||
1188 | } | ||
1189 | yield break; | ||
1190 | } | ||
1191 | } | ||
1192 | } | ||
1193 | { | ||
1194 | object S = arg3; | ||
1195 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(")"), S))) | ||
1196 | { | ||
1197 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
1198 | { | ||
1199 | yield return true; | ||
1200 | yield break; | ||
1201 | } | ||
1202 | } | ||
1203 | } | ||
1204 | { | ||
1205 | object S = arg1; | ||
1206 | object x2 = arg2; | ||
1207 | object x3 = arg3; | ||
1208 | foreach (bool l2 in syntax_error(ListPair.make(new object[] { Atom.a(", or )"), Atom.a("expected"), Atom.a("in"), Atom.a("arguments") }), S)) | ||
1209 | { | ||
1210 | yield return false; | ||
1211 | } | ||
1212 | } | ||
1213 | } | ||
1214 | |||
1215 | public static IEnumerable<bool> read_list(object arg1, object arg2, object arg3) | ||
1216 | { | ||
1217 | { | ||
1218 | object x1 = arg2; | ||
1219 | object x2 = arg3; | ||
1220 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1221 | { | ||
1222 | foreach (bool l3 in syntax_error(ListPair.make(new object[] { Atom.a(", | or ]"), Atom.a("expected"), Atom.a("in"), Atom.a("list") }), Atom.NIL)) | ||
1223 | { | ||
1224 | yield return false; | ||
1225 | } | ||
1226 | } | ||
1227 | } | ||
1228 | { | ||
1229 | object Rest = arg2; | ||
1230 | object S = arg3; | ||
1231 | Variable Token = new Variable(); | ||
1232 | Variable S1 = new Variable(); | ||
1233 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, S1))) | ||
1234 | { | ||
1235 | foreach (bool l3 in read_list4(Token, S1, Rest, S)) | ||
1236 | { | ||
1237 | yield return false; | ||
1238 | } | ||
1239 | } | ||
1240 | } | ||
1241 | } | ||
1242 | |||
1243 | public static IEnumerable<bool> read_list4(object arg1, object arg2, object arg3, object arg4) | ||
1244 | { | ||
1245 | { | ||
1246 | object S1 = arg2; | ||
1247 | object S = arg4; | ||
1248 | Variable Term = new Variable(); | ||
1249 | Variable Rest = new Variable(); | ||
1250 | Variable S2 = new Variable(); | ||
1251 | foreach (bool l2 in YP.unify(arg1, Atom.a(","))) | ||
1252 | { | ||
1253 | foreach (bool l3 in YP.unify(arg3, new ListPair(Term, Rest))) | ||
1254 | { | ||
1255 | foreach (bool l4 in parse(S1, 999, Term, S2)) | ||
1256 | { | ||
1257 | foreach (bool l5 in read_list(S2, Rest, S)) | ||
1258 | { | ||
1259 | yield return false; | ||
1260 | } | ||
1261 | yield break; | ||
1262 | } | ||
1263 | yield break; | ||
1264 | } | ||
1265 | } | ||
1266 | } | ||
1267 | { | ||
1268 | object S1 = arg2; | ||
1269 | object Rest = arg3; | ||
1270 | object S = arg4; | ||
1271 | Variable S2 = new Variable(); | ||
1272 | foreach (bool l2 in YP.unify(arg1, Atom.a("|"))) | ||
1273 | { | ||
1274 | foreach (bool l3 in parse(S1, 999, Rest, S2)) | ||
1275 | { | ||
1276 | foreach (bool l4 in expect(Atom.a("]"), S2, S)) | ||
1277 | { | ||
1278 | yield return false; | ||
1279 | } | ||
1280 | yield break; | ||
1281 | } | ||
1282 | yield break; | ||
1283 | } | ||
1284 | } | ||
1285 | { | ||
1286 | Variable S1 = new Variable(); | ||
1287 | foreach (bool l2 in YP.unify(arg1, Atom.a("]"))) | ||
1288 | { | ||
1289 | foreach (bool l3 in YP.unify(arg2, S1)) | ||
1290 | { | ||
1291 | foreach (bool l4 in YP.unify(arg3, Atom.NIL)) | ||
1292 | { | ||
1293 | foreach (bool l5 in YP.unify(arg4, S1)) | ||
1294 | { | ||
1295 | yield return true; | ||
1296 | yield break; | ||
1297 | } | ||
1298 | } | ||
1299 | } | ||
1300 | } | ||
1301 | } | ||
1302 | { | ||
1303 | object Token = arg1; | ||
1304 | object S1 = arg2; | ||
1305 | object x3 = arg3; | ||
1306 | object x4 = arg4; | ||
1307 | foreach (bool l2 in syntax_error(ListPair.make(new object[] { Atom.a(", | or ]"), Atom.a("expected"), Atom.a("in"), Atom.a("list") }), new ListPair(Token, S1))) | ||
1308 | { | ||
1309 | yield return false; | ||
1310 | } | ||
1311 | } | ||
1312 | } | ||
1313 | |||
1314 | public static IEnumerable<bool> possible_right_operand(object arg1, object arg2) | ||
1315 | { | ||
1316 | { | ||
1317 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1318 | { | ||
1319 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1320 | { | ||
1321 | yield return false; | ||
1322 | } | ||
1323 | } | ||
1324 | } | ||
1325 | { | ||
1326 | object Flag = arg2; | ||
1327 | Variable H = new Variable(); | ||
1328 | Variable T = new Variable(); | ||
1329 | foreach (bool l2 in YP.unify(arg1, new ListPair(H, T))) | ||
1330 | { | ||
1331 | foreach (bool l3 in possible_right_operand3(H, Flag, T)) | ||
1332 | { | ||
1333 | yield return false; | ||
1334 | } | ||
1335 | } | ||
1336 | } | ||
1337 | } | ||
1338 | |||
1339 | public static IEnumerable<bool> possible_right_operand3(object arg1, object arg2, object arg3) | ||
1340 | { | ||
1341 | { | ||
1342 | object x4 = arg3; | ||
1343 | Variable x1 = new Variable(); | ||
1344 | Variable x2 = new Variable(); | ||
1345 | Variable x3 = new Variable(); | ||
1346 | foreach (bool l2 in YP.unify(arg1, new Functor3("var", x1, x2, x3))) | ||
1347 | { | ||
1348 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1349 | { | ||
1350 | yield return false; | ||
1351 | } | ||
1352 | } | ||
1353 | } | ||
1354 | { | ||
1355 | object x2 = arg3; | ||
1356 | Variable x1 = new Variable(); | ||
1357 | foreach (bool l2 in YP.unify(arg1, new Functor1("number", x1))) | ||
1358 | { | ||
1359 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1360 | { | ||
1361 | yield return false; | ||
1362 | } | ||
1363 | } | ||
1364 | } | ||
1365 | { | ||
1366 | object x2 = arg3; | ||
1367 | Variable x1 = new Variable(); | ||
1368 | foreach (bool l2 in YP.unify(arg1, new Functor1("string", x1))) | ||
1369 | { | ||
1370 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1371 | { | ||
1372 | yield return false; | ||
1373 | } | ||
1374 | } | ||
1375 | } | ||
1376 | { | ||
1377 | object x1 = arg3; | ||
1378 | foreach (bool l2 in YP.unify(arg1, Atom.a(" ("))) | ||
1379 | { | ||
1380 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1381 | { | ||
1382 | yield return false; | ||
1383 | } | ||
1384 | } | ||
1385 | } | ||
1386 | { | ||
1387 | object x1 = arg3; | ||
1388 | foreach (bool l2 in YP.unify(arg1, Atom.a("("))) | ||
1389 | { | ||
1390 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
1391 | { | ||
1392 | yield return false; | ||
1393 | } | ||
1394 | } | ||
1395 | } | ||
1396 | { | ||
1397 | object x1 = arg3; | ||
1398 | foreach (bool l2 in YP.unify(arg1, Atom.a(")"))) | ||
1399 | { | ||
1400 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1401 | { | ||
1402 | yield return false; | ||
1403 | } | ||
1404 | } | ||
1405 | } | ||
1406 | { | ||
1407 | Variable x1 = new Variable(); | ||
1408 | foreach (bool l2 in YP.unify(arg1, Atom.a("["))) | ||
1409 | { | ||
1410 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
1411 | { | ||
1412 | foreach (bool l4 in YP.unify(arg3, new ListPair(Atom.a("]"), x1))) | ||
1413 | { | ||
1414 | yield return true; | ||
1415 | yield break; | ||
1416 | } | ||
1417 | } | ||
1418 | } | ||
1419 | } | ||
1420 | { | ||
1421 | object x1 = arg3; | ||
1422 | foreach (bool l2 in YP.unify(arg1, Atom.a("["))) | ||
1423 | { | ||
1424 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1425 | { | ||
1426 | yield return false; | ||
1427 | } | ||
1428 | } | ||
1429 | } | ||
1430 | { | ||
1431 | object x1 = arg3; | ||
1432 | foreach (bool l2 in YP.unify(arg1, Atom.a("]"))) | ||
1433 | { | ||
1434 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1435 | { | ||
1436 | yield return false; | ||
1437 | } | ||
1438 | } | ||
1439 | } | ||
1440 | { | ||
1441 | Variable x1 = new Variable(); | ||
1442 | foreach (bool l2 in YP.unify(arg1, Atom.a("{"))) | ||
1443 | { | ||
1444 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
1445 | { | ||
1446 | foreach (bool l4 in YP.unify(arg3, new ListPair(Atom.a("}"), x1))) | ||
1447 | { | ||
1448 | yield return true; | ||
1449 | yield break; | ||
1450 | } | ||
1451 | } | ||
1452 | } | ||
1453 | } | ||
1454 | { | ||
1455 | object x1 = arg3; | ||
1456 | foreach (bool l2 in YP.unify(arg1, Atom.a("{"))) | ||
1457 | { | ||
1458 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1459 | { | ||
1460 | yield return false; | ||
1461 | } | ||
1462 | } | ||
1463 | } | ||
1464 | { | ||
1465 | object x1 = arg3; | ||
1466 | foreach (bool l2 in YP.unify(arg1, Atom.a("}"))) | ||
1467 | { | ||
1468 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1469 | { | ||
1470 | yield return false; | ||
1471 | } | ||
1472 | } | ||
1473 | } | ||
1474 | { | ||
1475 | object x1 = arg3; | ||
1476 | foreach (bool l2 in YP.unify(arg1, Atom.a(","))) | ||
1477 | { | ||
1478 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1479 | { | ||
1480 | yield return false; | ||
1481 | } | ||
1482 | } | ||
1483 | } | ||
1484 | { | ||
1485 | object x1 = arg3; | ||
1486 | foreach (bool l2 in YP.unify(arg1, Atom.a("|"))) | ||
1487 | { | ||
1488 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1489 | { | ||
1490 | yield return false; | ||
1491 | } | ||
1492 | } | ||
1493 | } | ||
1494 | { | ||
1495 | object x3 = arg3; | ||
1496 | Variable x1 = new Variable(); | ||
1497 | Variable x2 = new Variable(); | ||
1498 | foreach (bool l2 in YP.unify(arg1, new Functor2("atom", x1, x2))) | ||
1499 | { | ||
1500 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
1501 | { | ||
1502 | yield return false; | ||
1503 | } | ||
1504 | } | ||
1505 | } | ||
1506 | } | ||
1507 | |||
1508 | public static IEnumerable<bool> peepop(object arg1, object arg2) | ||
1509 | { | ||
1510 | { | ||
1511 | Variable F = new Variable(); | ||
1512 | Variable Pos = new Variable(); | ||
1513 | Variable S1 = new Variable(); | ||
1514 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("atom", F, Pos), new ListPair(Atom.a("("), S1)))) | ||
1515 | { | ||
1516 | foreach (bool l3 in YP.unify(arg2, new ListPair(new Functor2("atom", F, Pos), new ListPair(Atom.a("("), S1)))) | ||
1517 | { | ||
1518 | yield return true; | ||
1519 | yield break; | ||
1520 | } | ||
1521 | } | ||
1522 | } | ||
1523 | { | ||
1524 | Variable F = new Variable(); | ||
1525 | Variable Pos = new Variable(); | ||
1526 | Variable S1 = new Variable(); | ||
1527 | Variable L = new Variable(); | ||
1528 | Variable P = new Variable(); | ||
1529 | Variable R = new Variable(); | ||
1530 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("atom", F, Pos), S1))) | ||
1531 | { | ||
1532 | foreach (bool l3 in YP.unify(arg2, new ListPair(new Functor(Atom.a("infixop", Atom.a("")), new object[] { new Functor2("/", F, Pos), L, P, R }), S1))) | ||
1533 | { | ||
1534 | foreach (bool l4 in infixop(F, L, P, R)) | ||
1535 | { | ||
1536 | yield return false; | ||
1537 | } | ||
1538 | } | ||
1539 | } | ||
1540 | } | ||
1541 | { | ||
1542 | Variable F = new Variable(); | ||
1543 | Variable Pos = new Variable(); | ||
1544 | Variable S1 = new Variable(); | ||
1545 | Variable L = new Variable(); | ||
1546 | Variable P = new Variable(); | ||
1547 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("atom", F, Pos), S1))) | ||
1548 | { | ||
1549 | foreach (bool l3 in YP.unify(arg2, new ListPair(new Functor3(Atom.a("postfixop", Atom.a("")), new Functor2("/", F, Pos), L, P), S1))) | ||
1550 | { | ||
1551 | foreach (bool l4 in postfixop(F, L, P)) | ||
1552 | { | ||
1553 | yield return false; | ||
1554 | } | ||
1555 | } | ||
1556 | } | ||
1557 | } | ||
1558 | { | ||
1559 | Variable S0 = new Variable(); | ||
1560 | foreach (bool l2 in YP.unify(arg1, S0)) | ||
1561 | { | ||
1562 | foreach (bool l3 in YP.unify(arg2, S0)) | ||
1563 | { | ||
1564 | yield return false; | ||
1565 | } | ||
1566 | } | ||
1567 | } | ||
1568 | } | ||
1569 | |||
1570 | public static IEnumerable<bool> prefix_is_atom(object arg1, object arg2) | ||
1571 | { | ||
1572 | { | ||
1573 | object Precedence = arg2; | ||
1574 | Variable Token = new Variable(); | ||
1575 | Variable x2 = new Variable(); | ||
1576 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, x2))) | ||
1577 | { | ||
1578 | foreach (bool l3 in prefix_is_atom(Token, Precedence)) | ||
1579 | { | ||
1580 | yield return false; | ||
1581 | } | ||
1582 | } | ||
1583 | } | ||
1584 | { | ||
1585 | object P = arg2; | ||
1586 | Variable x1 = new Variable(); | ||
1587 | Variable L = new Variable(); | ||
1588 | Variable x3 = new Variable(); | ||
1589 | Variable x4 = new Variable(); | ||
1590 | foreach (bool l2 in YP.unify(arg1, new Functor(Atom.a("infixop", Atom.a("")), new object[] { x1, L, x3, x4 }))) | ||
1591 | { | ||
1592 | if (YP.greaterThanOrEqual(L, P)) | ||
1593 | { | ||
1594 | yield return false; | ||
1595 | } | ||
1596 | } | ||
1597 | } | ||
1598 | { | ||
1599 | object P = arg2; | ||
1600 | Variable x1 = new Variable(); | ||
1601 | Variable L = new Variable(); | ||
1602 | Variable x3 = new Variable(); | ||
1603 | foreach (bool l2 in YP.unify(arg1, new Functor3(Atom.a("postfixop", Atom.a("")), x1, L, x3))) | ||
1604 | { | ||
1605 | if (YP.greaterThanOrEqual(L, P)) | ||
1606 | { | ||
1607 | yield return false; | ||
1608 | } | ||
1609 | } | ||
1610 | } | ||
1611 | { | ||
1612 | object x1 = arg2; | ||
1613 | foreach (bool l2 in YP.unify(arg1, Atom.a(")"))) | ||
1614 | { | ||
1615 | yield return false; | ||
1616 | } | ||
1617 | } | ||
1618 | { | ||
1619 | object x1 = arg2; | ||
1620 | foreach (bool l2 in YP.unify(arg1, Atom.a("]"))) | ||
1621 | { | ||
1622 | yield return false; | ||
1623 | } | ||
1624 | } | ||
1625 | { | ||
1626 | object x1 = arg2; | ||
1627 | foreach (bool l2 in YP.unify(arg1, Atom.a("}"))) | ||
1628 | { | ||
1629 | yield return false; | ||
1630 | } | ||
1631 | } | ||
1632 | { | ||
1633 | object P = arg2; | ||
1634 | foreach (bool l2 in YP.unify(arg1, Atom.a("|"))) | ||
1635 | { | ||
1636 | if (YP.greaterThanOrEqual(1100, P)) | ||
1637 | { | ||
1638 | yield return false; | ||
1639 | } | ||
1640 | } | ||
1641 | } | ||
1642 | { | ||
1643 | object P = arg2; | ||
1644 | foreach (bool l2 in YP.unify(arg1, Atom.a(","))) | ||
1645 | { | ||
1646 | if (YP.greaterThanOrEqual(1000, P)) | ||
1647 | { | ||
1648 | yield return false; | ||
1649 | } | ||
1650 | } | ||
1651 | } | ||
1652 | { | ||
1653 | object x1 = arg2; | ||
1654 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1655 | { | ||
1656 | yield return false; | ||
1657 | } | ||
1658 | } | ||
1659 | } | ||
1660 | |||
1661 | public static IEnumerable<bool> exprtl0(object arg1, object arg2, object arg3, object arg4, object arg5) | ||
1662 | { | ||
1663 | { | ||
1664 | object x2 = arg3; | ||
1665 | Variable Term = new Variable(); | ||
1666 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1667 | { | ||
1668 | foreach (bool l3 in YP.unify(arg2, Term)) | ||
1669 | { | ||
1670 | foreach (bool l4 in YP.unify(arg4, Term)) | ||
1671 | { | ||
1672 | foreach (bool l5 in YP.unify(arg5, Atom.NIL)) | ||
1673 | { | ||
1674 | yield return false; | ||
1675 | } | ||
1676 | } | ||
1677 | } | ||
1678 | } | ||
1679 | } | ||
1680 | { | ||
1681 | object Term = arg2; | ||
1682 | object Precedence = arg3; | ||
1683 | object Answer = arg4; | ||
1684 | object S = arg5; | ||
1685 | Variable Token = new Variable(); | ||
1686 | Variable S1 = new Variable(); | ||
1687 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, S1))) | ||
1688 | { | ||
1689 | foreach (bool l3 in exprtl0_6(Token, Term, Precedence, Answer, S, S1)) | ||
1690 | { | ||
1691 | yield return false; | ||
1692 | } | ||
1693 | } | ||
1694 | } | ||
1695 | } | ||
1696 | |||
1697 | public static IEnumerable<bool> exprtl0_6(object arg1, object arg2, object arg3, object arg4, object arg5, object arg6) | ||
1698 | { | ||
1699 | { | ||
1700 | object x2 = arg3; | ||
1701 | object S1 = arg6; | ||
1702 | Variable Term = new Variable(); | ||
1703 | foreach (bool l2 in YP.unify(arg1, Atom.a("}"))) | ||
1704 | { | ||
1705 | foreach (bool l3 in YP.unify(arg2, Term)) | ||
1706 | { | ||
1707 | foreach (bool l4 in YP.unify(arg4, Term)) | ||
1708 | { | ||
1709 | foreach (bool l5 in YP.unify(arg5, new ListPair(Atom.a("}"), S1))) | ||
1710 | { | ||
1711 | yield return false; | ||
1712 | } | ||
1713 | } | ||
1714 | } | ||
1715 | } | ||
1716 | } | ||
1717 | { | ||
1718 | object x2 = arg3; | ||
1719 | object S1 = arg6; | ||
1720 | Variable Term = new Variable(); | ||
1721 | foreach (bool l2 in YP.unify(arg1, Atom.a("]"))) | ||
1722 | { | ||
1723 | foreach (bool l3 in YP.unify(arg2, Term)) | ||
1724 | { | ||
1725 | foreach (bool l4 in YP.unify(arg4, Term)) | ||
1726 | { | ||
1727 | foreach (bool l5 in YP.unify(arg5, new ListPair(Atom.a("]"), S1))) | ||
1728 | { | ||
1729 | yield return false; | ||
1730 | } | ||
1731 | } | ||
1732 | } | ||
1733 | } | ||
1734 | } | ||
1735 | { | ||
1736 | object x2 = arg3; | ||
1737 | object S1 = arg6; | ||
1738 | Variable Term = new Variable(); | ||
1739 | foreach (bool l2 in YP.unify(arg1, Atom.a(")"))) | ||
1740 | { | ||
1741 | foreach (bool l3 in YP.unify(arg2, Term)) | ||
1742 | { | ||
1743 | foreach (bool l4 in YP.unify(arg4, Term)) | ||
1744 | { | ||
1745 | foreach (bool l5 in YP.unify(arg5, new ListPair(Atom.a(")"), S1))) | ||
1746 | { | ||
1747 | yield return false; | ||
1748 | } | ||
1749 | } | ||
1750 | } | ||
1751 | } | ||
1752 | } | ||
1753 | { | ||
1754 | object Term = arg2; | ||
1755 | object Precedence = arg3; | ||
1756 | object Answer = arg4; | ||
1757 | object S = arg5; | ||
1758 | object S1 = arg6; | ||
1759 | Variable Next = new Variable(); | ||
1760 | Variable S2 = new Variable(); | ||
1761 | foreach (bool l2 in YP.unify(arg1, Atom.a(","))) | ||
1762 | { | ||
1763 | if (YP.greaterThanOrEqual(Precedence, 1000)) | ||
1764 | { | ||
1765 | foreach (bool l4 in parse(S1, 1000, Next, S2)) | ||
1766 | { | ||
1767 | foreach (bool l5 in exprtl(S2, 1000, new Functor2(",", Term, Next), Precedence, Answer, S)) | ||
1768 | { | ||
1769 | yield return false; | ||
1770 | } | ||
1771 | yield break; | ||
1772 | } | ||
1773 | goto cutIf1; | ||
1774 | } | ||
1775 | foreach (bool l3 in YP.unify(Answer, Term)) | ||
1776 | { | ||
1777 | foreach (bool l4 in YP.unify(S, new ListPair(Atom.a(","), S1))) | ||
1778 | { | ||
1779 | yield return false; | ||
1780 | } | ||
1781 | } | ||
1782 | cutIf1: | ||
1783 | { } | ||
1784 | } | ||
1785 | } | ||
1786 | { | ||
1787 | object Term = arg2; | ||
1788 | object Precedence = arg3; | ||
1789 | object Answer = arg4; | ||
1790 | object S = arg5; | ||
1791 | object S1 = arg6; | ||
1792 | Variable Next = new Variable(); | ||
1793 | Variable S2 = new Variable(); | ||
1794 | foreach (bool l2 in YP.unify(arg1, Atom.a("|"))) | ||
1795 | { | ||
1796 | if (YP.greaterThanOrEqual(Precedence, 1100)) | ||
1797 | { | ||
1798 | foreach (bool l4 in parse(S1, 1100, Next, S2)) | ||
1799 | { | ||
1800 | foreach (bool l5 in exprtl(S2, 1100, new Functor2(";", Term, Next), Precedence, Answer, S)) | ||
1801 | { | ||
1802 | yield return false; | ||
1803 | } | ||
1804 | yield break; | ||
1805 | } | ||
1806 | goto cutIf2; | ||
1807 | } | ||
1808 | foreach (bool l3 in YP.unify(Answer, Term)) | ||
1809 | { | ||
1810 | foreach (bool l4 in YP.unify(S, new ListPair(Atom.a("|"), S1))) | ||
1811 | { | ||
1812 | yield return false; | ||
1813 | } | ||
1814 | } | ||
1815 | cutIf2: | ||
1816 | { } | ||
1817 | } | ||
1818 | } | ||
1819 | { | ||
1820 | object x2 = arg2; | ||
1821 | object x3 = arg3; | ||
1822 | object x4 = arg4; | ||
1823 | object x5 = arg5; | ||
1824 | object S1 = arg6; | ||
1825 | Variable S = new Variable(); | ||
1826 | foreach (bool l2 in YP.unify(arg1, new Functor1("string", S))) | ||
1827 | { | ||
1828 | foreach (bool l3 in cannot_follow(Atom.a("chars"), new Functor1("string", S), S1)) | ||
1829 | { | ||
1830 | yield return false; | ||
1831 | } | ||
1832 | } | ||
1833 | } | ||
1834 | { | ||
1835 | object x2 = arg2; | ||
1836 | object x3 = arg3; | ||
1837 | object x4 = arg4; | ||
1838 | object x5 = arg5; | ||
1839 | object S1 = arg6; | ||
1840 | Variable N = new Variable(); | ||
1841 | foreach (bool l2 in YP.unify(arg1, new Functor1("number", N))) | ||
1842 | { | ||
1843 | foreach (bool l3 in cannot_follow(Atom.a("number"), new Functor1("number", N), S1)) | ||
1844 | { | ||
1845 | yield return false; | ||
1846 | } | ||
1847 | } | ||
1848 | } | ||
1849 | { | ||
1850 | object Term = arg2; | ||
1851 | object Precedence = arg3; | ||
1852 | object Answer = arg4; | ||
1853 | object S = arg5; | ||
1854 | Variable S1 = new Variable(); | ||
1855 | foreach (bool l2 in YP.unify(arg1, Atom.a("{"))) | ||
1856 | { | ||
1857 | foreach (bool l3 in YP.unify(arg6, new ListPair(Atom.a("}"), S1))) | ||
1858 | { | ||
1859 | foreach (bool l4 in exprtl0_atom(Atom.a("{}"), Term, Precedence, Answer, S, S1)) | ||
1860 | { | ||
1861 | yield return false; | ||
1862 | } | ||
1863 | yield break; | ||
1864 | } | ||
1865 | } | ||
1866 | } | ||
1867 | { | ||
1868 | object x1 = arg2; | ||
1869 | object x2 = arg3; | ||
1870 | object x3 = arg4; | ||
1871 | object x4 = arg5; | ||
1872 | object S1 = arg6; | ||
1873 | foreach (bool l2 in YP.unify(arg1, Atom.a("{"))) | ||
1874 | { | ||
1875 | foreach (bool l3 in cannot_follow(Atom.a("brace"), Atom.a("{"), S1)) | ||
1876 | { | ||
1877 | yield return false; | ||
1878 | } | ||
1879 | } | ||
1880 | } | ||
1881 | { | ||
1882 | object Term = arg2; | ||
1883 | object Precedence = arg3; | ||
1884 | object Answer = arg4; | ||
1885 | object S = arg5; | ||
1886 | Variable S1 = new Variable(); | ||
1887 | foreach (bool l2 in YP.unify(arg1, Atom.a("["))) | ||
1888 | { | ||
1889 | foreach (bool l3 in YP.unify(arg6, new ListPair(Atom.a("]"), S1))) | ||
1890 | { | ||
1891 | foreach (bool l4 in exprtl0_atom(Atom.NIL, Term, Precedence, Answer, S, S1)) | ||
1892 | { | ||
1893 | yield return false; | ||
1894 | } | ||
1895 | yield break; | ||
1896 | } | ||
1897 | } | ||
1898 | } | ||
1899 | { | ||
1900 | object x1 = arg2; | ||
1901 | object x2 = arg3; | ||
1902 | object x3 = arg4; | ||
1903 | object x4 = arg5; | ||
1904 | object S1 = arg6; | ||
1905 | foreach (bool l2 in YP.unify(arg1, Atom.a("["))) | ||
1906 | { | ||
1907 | foreach (bool l3 in cannot_follow(Atom.a("bracket"), Atom.a("["), S1)) | ||
1908 | { | ||
1909 | yield return false; | ||
1910 | } | ||
1911 | } | ||
1912 | } | ||
1913 | { | ||
1914 | object x1 = arg2; | ||
1915 | object x2 = arg3; | ||
1916 | object x3 = arg4; | ||
1917 | object x4 = arg5; | ||
1918 | object S1 = arg6; | ||
1919 | foreach (bool l2 in YP.unify(arg1, Atom.a("("))) | ||
1920 | { | ||
1921 | foreach (bool l3 in cannot_follow(Atom.a("parenthesis"), Atom.a("("), S1)) | ||
1922 | { | ||
1923 | yield return false; | ||
1924 | } | ||
1925 | } | ||
1926 | } | ||
1927 | { | ||
1928 | object x1 = arg2; | ||
1929 | object x2 = arg3; | ||
1930 | object x3 = arg4; | ||
1931 | object x4 = arg5; | ||
1932 | object S1 = arg6; | ||
1933 | foreach (bool l2 in YP.unify(arg1, Atom.a(" ("))) | ||
1934 | { | ||
1935 | foreach (bool l3 in cannot_follow(Atom.a("parenthesis"), Atom.a("("), S1)) | ||
1936 | { | ||
1937 | yield return false; | ||
1938 | } | ||
1939 | } | ||
1940 | } | ||
1941 | { | ||
1942 | object x4 = arg2; | ||
1943 | object x5 = arg3; | ||
1944 | object x6 = arg4; | ||
1945 | object x7 = arg5; | ||
1946 | object S1 = arg6; | ||
1947 | Variable A = new Variable(); | ||
1948 | Variable B = new Variable(); | ||
1949 | Variable P = new Variable(); | ||
1950 | foreach (bool l2 in YP.unify(arg1, new Functor3("var", A, B, P))) | ||
1951 | { | ||
1952 | foreach (bool l3 in cannot_follow(Atom.a("variable"), new Functor3("var", A, B, P), S1)) | ||
1953 | { | ||
1954 | yield return false; | ||
1955 | } | ||
1956 | } | ||
1957 | } | ||
1958 | { | ||
1959 | object Term = arg2; | ||
1960 | object Precedence = arg3; | ||
1961 | object Answer = arg4; | ||
1962 | object S = arg5; | ||
1963 | object S1 = arg6; | ||
1964 | Variable F = new Variable(); | ||
1965 | Variable P = new Variable(); | ||
1966 | foreach (bool l2 in YP.unify(arg1, new Functor2("atom", F, P))) | ||
1967 | { | ||
1968 | foreach (bool l3 in exprtl0_atom(new Functor2("/", F, P), Term, Precedence, Answer, S, S1)) | ||
1969 | { | ||
1970 | yield return false; | ||
1971 | } | ||
1972 | } | ||
1973 | } | ||
1974 | } | ||
1975 | |||
1976 | public static IEnumerable<bool> exprtl0_atom(object arg1, object arg2, object arg3, object arg4, object arg5, object S1) | ||
1977 | { | ||
1978 | { | ||
1979 | object Term = arg2; | ||
1980 | object Precedence = arg3; | ||
1981 | object Answer = arg4; | ||
1982 | object S = arg5; | ||
1983 | Variable F = new Variable(); | ||
1984 | Variable Pos = new Variable(); | ||
1985 | Variable L1 = new Variable(); | ||
1986 | Variable O1 = new Variable(); | ||
1987 | Variable R1 = new Variable(); | ||
1988 | Variable L2 = new Variable(); | ||
1989 | Variable O2 = new Variable(); | ||
1990 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", F, Pos))) | ||
1991 | { | ||
1992 | foreach (bool l3 in ambigop(F, Precedence, L1, O1, R1, L2, O2)) | ||
1993 | { | ||
1994 | foreach (bool l4 in prefix_is_atom(S1, Precedence)) | ||
1995 | { | ||
1996 | foreach (bool l5 in exprtl(new ListPair(new Functor3(Atom.a("postfixop", Atom.a("")), new Functor2("/", F, Pos), L2, O2), S1), 0, Term, Precedence, Answer, S)) | ||
1997 | { | ||
1998 | yield return false; | ||
1999 | } | ||
2000 | yield break; | ||
2001 | } | ||
2002 | foreach (bool l4 in exprtl(new ListPair(new Functor(Atom.a("infixop", Atom.a("")), new object[] { new Functor2("/", F, Pos), L1, O1, R1 }), S1), 0, Term, Precedence, Answer, S)) | ||
2003 | { | ||
2004 | yield return false; | ||
2005 | } | ||
2006 | foreach (bool l4 in exprtl(new ListPair(new Functor3(Atom.a("postfixop", Atom.a("")), new Functor2("/", F, Pos), L2, O2), S1), 0, Term, Precedence, Answer, S)) | ||
2007 | { | ||
2008 | yield return false; | ||
2009 | } | ||
2010 | yield break; | ||
2011 | } | ||
2012 | } | ||
2013 | } | ||
2014 | { | ||
2015 | object Term = arg2; | ||
2016 | object Precedence = arg3; | ||
2017 | object Answer = arg4; | ||
2018 | object S = arg5; | ||
2019 | Variable F = new Variable(); | ||
2020 | Variable Pos = new Variable(); | ||
2021 | Variable L1 = new Variable(); | ||
2022 | Variable O1 = new Variable(); | ||
2023 | Variable R1 = new Variable(); | ||
2024 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", F, Pos))) | ||
2025 | { | ||
2026 | foreach (bool l3 in infixop(F, L1, O1, R1)) | ||
2027 | { | ||
2028 | foreach (bool l4 in exprtl(new ListPair(new Functor(Atom.a("infixop", Atom.a("")), new object[] { new Functor2("/", F, Pos), L1, O1, R1 }), S1), 0, Term, Precedence, Answer, S)) | ||
2029 | { | ||
2030 | yield return false; | ||
2031 | } | ||
2032 | yield break; | ||
2033 | } | ||
2034 | } | ||
2035 | } | ||
2036 | { | ||
2037 | object Term = arg2; | ||
2038 | object Precedence = arg3; | ||
2039 | object Answer = arg4; | ||
2040 | object S = arg5; | ||
2041 | Variable F = new Variable(); | ||
2042 | Variable Pos = new Variable(); | ||
2043 | Variable L2 = new Variable(); | ||
2044 | Variable O2 = new Variable(); | ||
2045 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", F, Pos))) | ||
2046 | { | ||
2047 | foreach (bool l3 in postfixop(F, L2, O2)) | ||
2048 | { | ||
2049 | foreach (bool l4 in exprtl(new ListPair(new Functor3(Atom.a("postfixop", Atom.a("")), new Functor2("/", F, Pos), L2, O2), S1), 0, Term, Precedence, Answer, S)) | ||
2050 | { | ||
2051 | yield return false; | ||
2052 | } | ||
2053 | yield break; | ||
2054 | } | ||
2055 | } | ||
2056 | } | ||
2057 | { | ||
2058 | object X = arg1; | ||
2059 | object x2 = arg2; | ||
2060 | object x3 = arg3; | ||
2061 | object x4 = arg4; | ||
2062 | object x5 = arg5; | ||
2063 | Variable x7 = new Variable(); | ||
2064 | foreach (bool l2 in syntax_error(ListPair.make(new object[] { new Functor2("-", Atom.a("non"), Atom.a("operator")), X, Atom.a("follows"), Atom.a("expression") }), new ListPair(new Functor2("atom", X, x7), S1))) | ||
2065 | { | ||
2066 | yield return false; | ||
2067 | } | ||
2068 | yield break; | ||
2069 | } | ||
2070 | } | ||
2071 | |||
2072 | public static IEnumerable<bool> cannot_follow(object Type, object Token, object Tokens) | ||
2073 | { | ||
2074 | { | ||
2075 | foreach (bool l2 in syntax_error(ListPair.make(new object[] { Type, Atom.a("follows"), Atom.a("expression") }), new ListPair(Token, Tokens))) | ||
2076 | { | ||
2077 | yield return false; | ||
2078 | } | ||
2079 | } | ||
2080 | } | ||
2081 | |||
2082 | public static IEnumerable<bool> exprtl(object arg1, object arg2, object arg3, object arg4, object arg5, object arg6) | ||
2083 | { | ||
2084 | { | ||
2085 | object x1 = arg2; | ||
2086 | object x3 = arg4; | ||
2087 | Variable Term = new Variable(); | ||
2088 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
2089 | { | ||
2090 | foreach (bool l3 in YP.unify(arg3, Term)) | ||
2091 | { | ||
2092 | foreach (bool l4 in YP.unify(arg5, Term)) | ||
2093 | { | ||
2094 | foreach (bool l5 in YP.unify(arg6, Atom.NIL)) | ||
2095 | { | ||
2096 | yield return false; | ||
2097 | } | ||
2098 | } | ||
2099 | } | ||
2100 | } | ||
2101 | } | ||
2102 | { | ||
2103 | object C = arg2; | ||
2104 | object Term = arg3; | ||
2105 | object Precedence = arg4; | ||
2106 | object Answer = arg5; | ||
2107 | object S = arg6; | ||
2108 | Variable Token = new Variable(); | ||
2109 | Variable Tokens = new Variable(); | ||
2110 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, Tokens))) | ||
2111 | { | ||
2112 | foreach (bool l3 in exprtl_7(Token, C, Term, Precedence, Answer, S, Tokens)) | ||
2113 | { | ||
2114 | yield return false; | ||
2115 | } | ||
2116 | } | ||
2117 | } | ||
2118 | } | ||
2119 | |||
2120 | public static IEnumerable<bool> exprtl_7(object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7) | ||
2121 | { | ||
2122 | { | ||
2123 | object C = arg2; | ||
2124 | object Term = arg3; | ||
2125 | object Precedence = arg4; | ||
2126 | object Answer = arg5; | ||
2127 | object S = arg6; | ||
2128 | object S1 = arg7; | ||
2129 | Variable F = new Variable(); | ||
2130 | Variable Pos = new Variable(); | ||
2131 | Variable L = new Variable(); | ||
2132 | Variable O = new Variable(); | ||
2133 | Variable R = new Variable(); | ||
2134 | Variable Other = new Variable(); | ||
2135 | Variable S2 = new Variable(); | ||
2136 | Variable Expr = new Variable(); | ||
2137 | foreach (bool l2 in YP.unify(arg1, new Functor(Atom.a("infixop", Atom.a("")), new object[] { new Functor2("/", F, Pos), L, O, R }))) | ||
2138 | { | ||
2139 | if (YP.greaterThanOrEqual(Precedence, O)) | ||
2140 | { | ||
2141 | if (YP.lessThanOrEqual(C, L)) | ||
2142 | { | ||
2143 | foreach (bool l5 in parse(S1, R, Other, S2)) | ||
2144 | { | ||
2145 | foreach (bool l6 in YP.univ(Expr, ListPair.make(new object[] { F, Pos, Term, Other }))) | ||
2146 | { | ||
2147 | foreach (bool l7 in exprtl(S2, O, Expr, Precedence, Answer, S)) | ||
2148 | { | ||
2149 | yield return false; | ||
2150 | } | ||
2151 | } | ||
2152 | } | ||
2153 | yield break; | ||
2154 | } | ||
2155 | } | ||
2156 | } | ||
2157 | } | ||
2158 | { | ||
2159 | object C = arg2; | ||
2160 | object Term = arg3; | ||
2161 | object Precedence = arg4; | ||
2162 | object Answer = arg5; | ||
2163 | object S = arg6; | ||
2164 | object S1 = arg7; | ||
2165 | Variable F = new Variable(); | ||
2166 | Variable Pos = new Variable(); | ||
2167 | Variable L = new Variable(); | ||
2168 | Variable O = new Variable(); | ||
2169 | Variable Expr = new Variable(); | ||
2170 | Variable S2 = new Variable(); | ||
2171 | foreach (bool l2 in YP.unify(arg1, new Functor3(Atom.a("postfixop", Atom.a("")), new Functor2("/", F, Pos), L, O))) | ||
2172 | { | ||
2173 | if (YP.greaterThanOrEqual(Precedence, O)) | ||
2174 | { | ||
2175 | if (YP.lessThanOrEqual(C, L)) | ||
2176 | { | ||
2177 | foreach (bool l5 in YP.univ(Expr, ListPair.make(new object[] { F, Pos, Term }))) | ||
2178 | { | ||
2179 | foreach (bool l6 in peepop(S1, S2)) | ||
2180 | { | ||
2181 | foreach (bool l7 in exprtl(S2, O, Expr, Precedence, Answer, S)) | ||
2182 | { | ||
2183 | yield return false; | ||
2184 | } | ||
2185 | } | ||
2186 | } | ||
2187 | yield break; | ||
2188 | } | ||
2189 | } | ||
2190 | } | ||
2191 | } | ||
2192 | { | ||
2193 | object C = arg2; | ||
2194 | object Term = arg3; | ||
2195 | object Precedence = arg4; | ||
2196 | object Answer = arg5; | ||
2197 | object S = arg6; | ||
2198 | object S1 = arg7; | ||
2199 | Variable Next = new Variable(); | ||
2200 | Variable S2 = new Variable(); | ||
2201 | foreach (bool l2 in YP.unify(arg1, Atom.a(","))) | ||
2202 | { | ||
2203 | if (YP.greaterThanOrEqual(Precedence, 1000)) | ||
2204 | { | ||
2205 | if (YP.lessThan(C, 1000)) | ||
2206 | { | ||
2207 | foreach (bool l5 in parse(S1, 1000, Next, S2)) | ||
2208 | { | ||
2209 | foreach (bool l6 in exprtl(S2, 1000, new Functor2(",", Term, Next), Precedence, Answer, S)) | ||
2210 | { | ||
2211 | yield return false; | ||
2212 | } | ||
2213 | } | ||
2214 | yield break; | ||
2215 | } | ||
2216 | } | ||
2217 | } | ||
2218 | } | ||
2219 | { | ||
2220 | object C = arg2; | ||
2221 | object Term = arg3; | ||
2222 | object Precedence = arg4; | ||
2223 | object Answer = arg5; | ||
2224 | object S = arg6; | ||
2225 | object S1 = arg7; | ||
2226 | Variable Next = new Variable(); | ||
2227 | Variable S2 = new Variable(); | ||
2228 | foreach (bool l2 in YP.unify(arg1, Atom.a("|"))) | ||
2229 | { | ||
2230 | if (YP.greaterThanOrEqual(Precedence, 1100)) | ||
2231 | { | ||
2232 | if (YP.lessThan(C, 1100)) | ||
2233 | { | ||
2234 | foreach (bool l5 in parse(S1, 1100, Next, S2)) | ||
2235 | { | ||
2236 | foreach (bool l6 in exprtl(S2, 1100, new Functor2(";", Term, Next), Precedence, Answer, S)) | ||
2237 | { | ||
2238 | yield return false; | ||
2239 | } | ||
2240 | } | ||
2241 | yield break; | ||
2242 | } | ||
2243 | } | ||
2244 | } | ||
2245 | } | ||
2246 | { | ||
2247 | object Token = arg1; | ||
2248 | object x2 = arg2; | ||
2249 | object x4 = arg4; | ||
2250 | object Tokens = arg7; | ||
2251 | Variable Term = new Variable(); | ||
2252 | foreach (bool l2 in YP.unify(arg3, Term)) | ||
2253 | { | ||
2254 | foreach (bool l3 in YP.unify(arg5, Term)) | ||
2255 | { | ||
2256 | foreach (bool l4 in YP.unify(arg6, new ListPair(Token, Tokens))) | ||
2257 | { | ||
2258 | yield return false; | ||
2259 | } | ||
2260 | } | ||
2261 | } | ||
2262 | } | ||
2263 | } | ||
2264 | |||
2265 | public static IEnumerable<bool> syntax_error(object _Message, object _List) | ||
2266 | { | ||
2267 | { | ||
2268 | yield break; | ||
2269 | } | ||
2270 | foreach (bool l1 in YP.fail()) | ||
2271 | { | ||
2272 | yield return false; | ||
2273 | } | ||
2274 | } | ||
2275 | |||
2276 | public static IEnumerable<bool> syntax_error(object _List) | ||
2277 | { | ||
2278 | { | ||
2279 | yield break; | ||
2280 | } | ||
2281 | foreach (bool l1 in YP.fail()) | ||
2282 | { | ||
2283 | yield return false; | ||
2284 | } | ||
2285 | } | ||
2286 | |||
2287 | public static IEnumerable<bool> prefixop(object F, object O, object Q) | ||
2288 | { | ||
2289 | { | ||
2290 | foreach (bool l2 in YP.current_op(O, Atom.a("fx"), F)) | ||
2291 | { | ||
2292 | foreach (bool l3 in YP.unify(Q, YP.subtract(O, 1))) | ||
2293 | { | ||
2294 | yield return false; | ||
2295 | } | ||
2296 | goto cutIf1; | ||
2297 | } | ||
2298 | foreach (bool l2 in YP.current_op(O, Atom.a("fy"), F)) | ||
2299 | { | ||
2300 | foreach (bool l3 in YP.unify(Q, O)) | ||
2301 | { | ||
2302 | yield return false; | ||
2303 | } | ||
2304 | goto cutIf2; | ||
2305 | } | ||
2306 | cutIf2: | ||
2307 | cutIf1: | ||
2308 | { } | ||
2309 | } | ||
2310 | } | ||
2311 | |||
2312 | public static IEnumerable<bool> postfixop(object F, object P, object O) | ||
2313 | { | ||
2314 | { | ||
2315 | foreach (bool l2 in YP.current_op(O, Atom.a("xf"), F)) | ||
2316 | { | ||
2317 | foreach (bool l3 in YP.unify(P, YP.subtract(O, 1))) | ||
2318 | { | ||
2319 | yield return false; | ||
2320 | } | ||
2321 | goto cutIf1; | ||
2322 | } | ||
2323 | foreach (bool l2 in YP.current_op(O, Atom.a("yf"), F)) | ||
2324 | { | ||
2325 | foreach (bool l3 in YP.unify(P, O)) | ||
2326 | { | ||
2327 | yield return false; | ||
2328 | } | ||
2329 | goto cutIf2; | ||
2330 | } | ||
2331 | cutIf2: | ||
2332 | cutIf1: | ||
2333 | { } | ||
2334 | } | ||
2335 | } | ||
2336 | |||
2337 | public static IEnumerable<bool> infixop(object F, object P, object O, object Q) | ||
2338 | { | ||
2339 | { | ||
2340 | foreach (bool l2 in YP.current_op(O, Atom.a("xfy"), F)) | ||
2341 | { | ||
2342 | foreach (bool l3 in YP.unify(P, YP.subtract(O, 1))) | ||
2343 | { | ||
2344 | foreach (bool l4 in YP.unify(Q, O)) | ||
2345 | { | ||
2346 | yield return false; | ||
2347 | } | ||
2348 | } | ||
2349 | goto cutIf1; | ||
2350 | } | ||
2351 | foreach (bool l2 in YP.current_op(O, Atom.a("xfx"), F)) | ||
2352 | { | ||
2353 | foreach (bool l3 in YP.unify(P, YP.subtract(O, 1))) | ||
2354 | { | ||
2355 | foreach (bool l4 in YP.unify(Q, P)) | ||
2356 | { | ||
2357 | yield return false; | ||
2358 | } | ||
2359 | } | ||
2360 | goto cutIf2; | ||
2361 | } | ||
2362 | foreach (bool l2 in YP.current_op(O, Atom.a("yfx"), F)) | ||
2363 | { | ||
2364 | foreach (bool l3 in YP.unify(Q, YP.subtract(O, 1))) | ||
2365 | { | ||
2366 | foreach (bool l4 in YP.unify(P, O)) | ||
2367 | { | ||
2368 | yield return false; | ||
2369 | } | ||
2370 | } | ||
2371 | goto cutIf3; | ||
2372 | } | ||
2373 | cutIf3: | ||
2374 | cutIf2: | ||
2375 | cutIf1: | ||
2376 | { } | ||
2377 | } | ||
2378 | } | ||
2379 | |||
2380 | public static IEnumerable<bool> ambigop(object F, object Precedence, object L1, object O1, object R1, object L2, object O2) | ||
2381 | { | ||
2382 | { | ||
2383 | foreach (bool l2 in postfixop(F, L2, O2)) | ||
2384 | { | ||
2385 | if (YP.lessThanOrEqual(O2, Precedence)) | ||
2386 | { | ||
2387 | foreach (bool l4 in infixop(F, L1, O1, R1)) | ||
2388 | { | ||
2389 | if (YP.lessThanOrEqual(O1, Precedence)) | ||
2390 | { | ||
2391 | yield return false; | ||
2392 | } | ||
2393 | } | ||
2394 | } | ||
2395 | } | ||
2396 | } | ||
2397 | } | ||
2398 | |||
2399 | public static IEnumerable<bool> read_tokens1(object arg1) | ||
2400 | { | ||
2401 | { | ||
2402 | object TokenList = arg1; | ||
2403 | Variable C1 = new Variable(); | ||
2404 | Variable _X = new Variable(); | ||
2405 | Variable ListOfTokens = new Variable(); | ||
2406 | foreach (bool l2 in YP.get_code(C1)) | ||
2407 | { | ||
2408 | foreach (bool l3 in read_tokens(C1, _X, ListOfTokens)) | ||
2409 | { | ||
2410 | foreach (bool l4 in YP.unify(TokenList, ListOfTokens)) | ||
2411 | { | ||
2412 | yield return false; | ||
2413 | } | ||
2414 | yield break; | ||
2415 | } | ||
2416 | } | ||
2417 | } | ||
2418 | { | ||
2419 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("atom", Atom.a("end_of_file"), 0), Atom.NIL))) | ||
2420 | { | ||
2421 | yield return false; | ||
2422 | } | ||
2423 | } | ||
2424 | } | ||
2425 | |||
2426 | public static IEnumerable<bool> read_tokens2(object arg1, object arg2) | ||
2427 | { | ||
2428 | { | ||
2429 | object TokenList = arg1; | ||
2430 | object Dictionary = arg2; | ||
2431 | Variable C1 = new Variable(); | ||
2432 | Variable Dict = new Variable(); | ||
2433 | Variable ListOfTokens = new Variable(); | ||
2434 | foreach (bool l2 in YP.get_code(C1)) | ||
2435 | { | ||
2436 | foreach (bool l3 in read_tokens(C1, Dict, ListOfTokens)) | ||
2437 | { | ||
2438 | foreach (bool l4 in terminate_list(Dict)) | ||
2439 | { | ||
2440 | foreach (bool l5 in YP.unify(Dictionary, Dict)) | ||
2441 | { | ||
2442 | foreach (bool l6 in YP.unify(TokenList, ListOfTokens)) | ||
2443 | { | ||
2444 | yield return false; | ||
2445 | } | ||
2446 | } | ||
2447 | yield break; | ||
2448 | } | ||
2449 | } | ||
2450 | } | ||
2451 | } | ||
2452 | { | ||
2453 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("atom", Atom.a("end_of_file"), 0), Atom.NIL))) | ||
2454 | { | ||
2455 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
2456 | { | ||
2457 | yield return false; | ||
2458 | } | ||
2459 | } | ||
2460 | } | ||
2461 | } | ||
2462 | |||
2463 | public static IEnumerable<bool> terminate_list(object arg1) | ||
2464 | { | ||
2465 | { | ||
2466 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
2467 | { | ||
2468 | yield return false; | ||
2469 | } | ||
2470 | } | ||
2471 | { | ||
2472 | Variable x1 = new Variable(); | ||
2473 | Variable Tail = new Variable(); | ||
2474 | foreach (bool l2 in YP.unify(arg1, new ListPair(x1, Tail))) | ||
2475 | { | ||
2476 | foreach (bool l3 in terminate_list(Tail)) | ||
2477 | { | ||
2478 | yield return false; | ||
2479 | } | ||
2480 | } | ||
2481 | } | ||
2482 | } | ||
2483 | |||
2484 | public static IEnumerable<bool> read_special(object arg1, object Dict, object arg3) | ||
2485 | { | ||
2486 | { | ||
2487 | object Tokens = arg3; | ||
2488 | foreach (bool l2 in YP.unify(arg1, 95)) | ||
2489 | { | ||
2490 | foreach (bool l3 in read_variable(95, Dict, Tokens)) | ||
2491 | { | ||
2492 | yield return false; | ||
2493 | } | ||
2494 | } | ||
2495 | } | ||
2496 | { | ||
2497 | object Tokens = arg3; | ||
2498 | foreach (bool l2 in YP.unify(arg1, 247)) | ||
2499 | { | ||
2500 | foreach (bool l3 in read_symbol(247, Dict, Tokens)) | ||
2501 | { | ||
2502 | yield return false; | ||
2503 | } | ||
2504 | } | ||
2505 | } | ||
2506 | { | ||
2507 | object Tokens = arg3; | ||
2508 | foreach (bool l2 in YP.unify(arg1, 215)) | ||
2509 | { | ||
2510 | foreach (bool l3 in read_symbol(215, Dict, Tokens)) | ||
2511 | { | ||
2512 | yield return false; | ||
2513 | } | ||
2514 | } | ||
2515 | } | ||
2516 | { | ||
2517 | Variable StartPos = new Variable(); | ||
2518 | Variable EndPos = new Variable(); | ||
2519 | Variable Tokens = new Variable(); | ||
2520 | Variable Ch = new Variable(); | ||
2521 | Variable NextCh = new Variable(); | ||
2522 | foreach (bool l2 in YP.unify(arg1, 37)) | ||
2523 | { | ||
2524 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("comment", StartPos, EndPos), Tokens))) | ||
2525 | { | ||
2526 | foreach (bool l4 in get_current_position(StartPos)) | ||
2527 | { | ||
2528 | foreach (bool l5 in YP.repeat()) | ||
2529 | { | ||
2530 | foreach (bool l6 in YP.get_code(Ch)) | ||
2531 | { | ||
2532 | if (YP.lessThan(Ch, new ListPair(32, Atom.NIL))) | ||
2533 | { | ||
2534 | if (YP.notEqual(Ch, 9)) | ||
2535 | { | ||
2536 | if (YP.termNotEqual(Ch, -1)) | ||
2537 | { | ||
2538 | foreach (bool l10 in get_current_position(EndPos)) | ||
2539 | { | ||
2540 | foreach (bool l11 in YP.get_code(NextCh)) | ||
2541 | { | ||
2542 | foreach (bool l12 in read_tokens(NextCh, Dict, Tokens)) | ||
2543 | { | ||
2544 | yield return false; | ||
2545 | } | ||
2546 | } | ||
2547 | } | ||
2548 | } | ||
2549 | yield break; | ||
2550 | } | ||
2551 | } | ||
2552 | } | ||
2553 | } | ||
2554 | } | ||
2555 | } | ||
2556 | } | ||
2557 | } | ||
2558 | { | ||
2559 | object T = arg3; | ||
2560 | Variable C2 = new Variable(); | ||
2561 | Variable StartPos = new Variable(); | ||
2562 | Variable EndPos = new Variable(); | ||
2563 | Variable Tokens = new Variable(); | ||
2564 | Variable StartPos1 = new Variable(); | ||
2565 | Variable NextCh = new Variable(); | ||
2566 | Variable Chars = new Variable(); | ||
2567 | foreach (bool l2 in YP.unify(arg1, 47)) | ||
2568 | { | ||
2569 | foreach (bool l3 in YP.get_code(C2)) | ||
2570 | { | ||
2571 | if (YP.equal(C2, new ListPair(42, Atom.NIL))) | ||
2572 | { | ||
2573 | foreach (bool l5 in YP.unify(T, new ListPair(new Functor2("comment", StartPos, EndPos), Tokens))) | ||
2574 | { | ||
2575 | foreach (bool l6 in get_current_position(StartPos1)) | ||
2576 | { | ||
2577 | foreach (bool l7 in YP.unify(StartPos, YP.subtract(StartPos1, 1))) | ||
2578 | { | ||
2579 | foreach (bool l8 in read_solidus(32, NextCh)) | ||
2580 | { | ||
2581 | foreach (bool l9 in get_current_position(EndPos)) | ||
2582 | { | ||
2583 | foreach (bool l10 in read_tokens(NextCh, Dict, Tokens)) | ||
2584 | { | ||
2585 | yield return false; | ||
2586 | } | ||
2587 | } | ||
2588 | } | ||
2589 | } | ||
2590 | } | ||
2591 | } | ||
2592 | goto cutIf1; | ||
2593 | } | ||
2594 | foreach (bool l4 in YP.unify(T, Tokens)) | ||
2595 | { | ||
2596 | foreach (bool l5 in rest_symbol(C2, Chars, NextCh)) | ||
2597 | { | ||
2598 | foreach (bool l6 in read_after_atom4(NextCh, Dict, Tokens, new ListPair(47, Chars))) | ||
2599 | { | ||
2600 | yield return false; | ||
2601 | } | ||
2602 | } | ||
2603 | } | ||
2604 | cutIf1: | ||
2605 | { } | ||
2606 | } | ||
2607 | } | ||
2608 | } | ||
2609 | { | ||
2610 | Variable Pos = new Variable(); | ||
2611 | Variable Tokens = new Variable(); | ||
2612 | Variable NextCh = new Variable(); | ||
2613 | foreach (bool l2 in YP.unify(arg1, 33)) | ||
2614 | { | ||
2615 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("atom", Atom.a("!"), Pos), Tokens))) | ||
2616 | { | ||
2617 | foreach (bool l4 in get_current_position(Pos)) | ||
2618 | { | ||
2619 | foreach (bool l5 in YP.get_code(NextCh)) | ||
2620 | { | ||
2621 | foreach (bool l6 in read_after_atom(NextCh, Dict, Tokens)) | ||
2622 | { | ||
2623 | yield return false; | ||
2624 | } | ||
2625 | } | ||
2626 | } | ||
2627 | } | ||
2628 | } | ||
2629 | } | ||
2630 | { | ||
2631 | Variable Tokens = new Variable(); | ||
2632 | Variable NextCh = new Variable(); | ||
2633 | foreach (bool l2 in YP.unify(arg1, 40)) | ||
2634 | { | ||
2635 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(" ("), Tokens))) | ||
2636 | { | ||
2637 | foreach (bool l4 in YP.get_code(NextCh)) | ||
2638 | { | ||
2639 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
2640 | { | ||
2641 | yield return false; | ||
2642 | } | ||
2643 | } | ||
2644 | } | ||
2645 | } | ||
2646 | } | ||
2647 | { | ||
2648 | Variable Tokens = new Variable(); | ||
2649 | Variable NextCh = new Variable(); | ||
2650 | foreach (bool l2 in YP.unify(arg1, 41)) | ||
2651 | { | ||
2652 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(")"), Tokens))) | ||
2653 | { | ||
2654 | foreach (bool l4 in YP.get_code(NextCh)) | ||
2655 | { | ||
2656 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
2657 | { | ||
2658 | yield return false; | ||
2659 | } | ||
2660 | } | ||
2661 | } | ||
2662 | } | ||
2663 | } | ||
2664 | { | ||
2665 | Variable Tokens = new Variable(); | ||
2666 | Variable NextCh = new Variable(); | ||
2667 | foreach (bool l2 in YP.unify(arg1, 44)) | ||
2668 | { | ||
2669 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(","), Tokens))) | ||
2670 | { | ||
2671 | foreach (bool l4 in YP.get_code(NextCh)) | ||
2672 | { | ||
2673 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
2674 | { | ||
2675 | yield return false; | ||
2676 | } | ||
2677 | } | ||
2678 | } | ||
2679 | } | ||
2680 | } | ||
2681 | { | ||
2682 | Variable Pos = new Variable(); | ||
2683 | Variable Tokens = new Variable(); | ||
2684 | Variable NextCh = new Variable(); | ||
2685 | foreach (bool l2 in YP.unify(arg1, 59)) | ||
2686 | { | ||
2687 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("atom", Atom.a(";"), Pos), Tokens))) | ||
2688 | { | ||
2689 | foreach (bool l4 in get_current_position(Pos)) | ||
2690 | { | ||
2691 | foreach (bool l5 in YP.get_code(NextCh)) | ||
2692 | { | ||
2693 | foreach (bool l6 in read_after_atom(NextCh, Dict, Tokens)) | ||
2694 | { | ||
2695 | yield return false; | ||
2696 | } | ||
2697 | } | ||
2698 | } | ||
2699 | } | ||
2700 | } | ||
2701 | } | ||
2702 | { | ||
2703 | Variable Pos = new Variable(); | ||
2704 | Variable Tokens = new Variable(); | ||
2705 | Variable NextCh = new Variable(); | ||
2706 | foreach (bool l2 in YP.unify(arg1, 91)) | ||
2707 | { | ||
2708 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("/", Atom.a("["), Pos), Tokens))) | ||
2709 | { | ||
2710 | foreach (bool l4 in get_current_position(Pos)) | ||
2711 | { | ||
2712 | foreach (bool l5 in YP.get_code(NextCh)) | ||
2713 | { | ||
2714 | foreach (bool l6 in read_tokens(NextCh, Dict, Tokens)) | ||
2715 | { | ||
2716 | yield return false; | ||
2717 | } | ||
2718 | } | ||
2719 | } | ||
2720 | } | ||
2721 | } | ||
2722 | } | ||
2723 | { | ||
2724 | Variable Pos = new Variable(); | ||
2725 | Variable Tokens = new Variable(); | ||
2726 | Variable NextCh = new Variable(); | ||
2727 | foreach (bool l2 in YP.unify(arg1, 93)) | ||
2728 | { | ||
2729 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("/", Atom.a("]"), Pos), Tokens))) | ||
2730 | { | ||
2731 | foreach (bool l4 in get_current_position(Pos)) | ||
2732 | { | ||
2733 | foreach (bool l5 in YP.get_code(NextCh)) | ||
2734 | { | ||
2735 | foreach (bool l6 in read_after_atom(NextCh, Dict, Tokens)) | ||
2736 | { | ||
2737 | yield return false; | ||
2738 | } | ||
2739 | } | ||
2740 | } | ||
2741 | } | ||
2742 | } | ||
2743 | } | ||
2744 | { | ||
2745 | Variable Pos = new Variable(); | ||
2746 | Variable Tokens = new Variable(); | ||
2747 | Variable NextCh = new Variable(); | ||
2748 | foreach (bool l2 in YP.unify(arg1, 123)) | ||
2749 | { | ||
2750 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("/", Atom.a("{"), Pos), Tokens))) | ||
2751 | { | ||
2752 | foreach (bool l4 in get_current_position(Pos)) | ||
2753 | { | ||
2754 | foreach (bool l5 in YP.get_code(NextCh)) | ||
2755 | { | ||
2756 | foreach (bool l6 in read_tokens(NextCh, Dict, Tokens)) | ||
2757 | { | ||
2758 | yield return false; | ||
2759 | } | ||
2760 | } | ||
2761 | } | ||
2762 | } | ||
2763 | } | ||
2764 | } | ||
2765 | { | ||
2766 | Variable Tokens = new Variable(); | ||
2767 | Variable NextCh = new Variable(); | ||
2768 | foreach (bool l2 in YP.unify(arg1, 124)) | ||
2769 | { | ||
2770 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("|"), Tokens))) | ||
2771 | { | ||
2772 | foreach (bool l4 in YP.get_code(NextCh)) | ||
2773 | { | ||
2774 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
2775 | { | ||
2776 | yield return false; | ||
2777 | } | ||
2778 | } | ||
2779 | } | ||
2780 | } | ||
2781 | } | ||
2782 | { | ||
2783 | Variable Tokens = new Variable(); | ||
2784 | Variable NextCh = new Variable(); | ||
2785 | foreach (bool l2 in YP.unify(arg1, 125)) | ||
2786 | { | ||
2787 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("}"), Tokens))) | ||
2788 | { | ||
2789 | foreach (bool l4 in YP.get_code(NextCh)) | ||
2790 | { | ||
2791 | foreach (bool l5 in read_after_atom(NextCh, Dict, Tokens)) | ||
2792 | { | ||
2793 | yield return false; | ||
2794 | } | ||
2795 | } | ||
2796 | } | ||
2797 | } | ||
2798 | } | ||
2799 | { | ||
2800 | object Tokens = arg3; | ||
2801 | Variable NextCh = new Variable(); | ||
2802 | foreach (bool l2 in YP.unify(arg1, 46)) | ||
2803 | { | ||
2804 | foreach (bool l3 in YP.get_code(NextCh)) | ||
2805 | { | ||
2806 | foreach (bool l4 in read_fullstop(NextCh, Dict, Tokens)) | ||
2807 | { | ||
2808 | yield return false; | ||
2809 | } | ||
2810 | } | ||
2811 | } | ||
2812 | } | ||
2813 | { | ||
2814 | Variable Chars = new Variable(); | ||
2815 | Variable Tokens = new Variable(); | ||
2816 | Variable NextCh = new Variable(); | ||
2817 | foreach (bool l2 in YP.unify(arg1, 34)) | ||
2818 | { | ||
2819 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor1("string", Chars), Tokens))) | ||
2820 | { | ||
2821 | foreach (bool l4 in read_string(Chars, 34, NextCh)) | ||
2822 | { | ||
2823 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
2824 | { | ||
2825 | yield return false; | ||
2826 | } | ||
2827 | } | ||
2828 | } | ||
2829 | } | ||
2830 | } | ||
2831 | { | ||
2832 | object Tokens = arg3; | ||
2833 | Variable Chars = new Variable(); | ||
2834 | Variable NextCh = new Variable(); | ||
2835 | foreach (bool l2 in YP.unify(arg1, 39)) | ||
2836 | { | ||
2837 | foreach (bool l3 in read_string(Chars, 39, NextCh)) | ||
2838 | { | ||
2839 | foreach (bool l4 in read_after_atom4(NextCh, Dict, Tokens, Chars)) | ||
2840 | { | ||
2841 | yield return false; | ||
2842 | } | ||
2843 | } | ||
2844 | } | ||
2845 | } | ||
2846 | { | ||
2847 | object Tokens = arg3; | ||
2848 | foreach (bool l2 in YP.unify(arg1, 35)) | ||
2849 | { | ||
2850 | foreach (bool l3 in read_symbol(35, Dict, Tokens)) | ||
2851 | { | ||
2852 | yield return false; | ||
2853 | } | ||
2854 | } | ||
2855 | } | ||
2856 | { | ||
2857 | object Tokens = arg3; | ||
2858 | foreach (bool l2 in YP.unify(arg1, 36)) | ||
2859 | { | ||
2860 | foreach (bool l3 in read_symbol(36, Dict, Tokens)) | ||
2861 | { | ||
2862 | yield return false; | ||
2863 | } | ||
2864 | } | ||
2865 | } | ||
2866 | { | ||
2867 | object Tokens = arg3; | ||
2868 | foreach (bool l2 in YP.unify(arg1, 38)) | ||
2869 | { | ||
2870 | foreach (bool l3 in read_symbol(38, Dict, Tokens)) | ||
2871 | { | ||
2872 | yield return false; | ||
2873 | } | ||
2874 | } | ||
2875 | } | ||
2876 | { | ||
2877 | object Tokens = arg3; | ||
2878 | foreach (bool l2 in YP.unify(arg1, 42)) | ||
2879 | { | ||
2880 | foreach (bool l3 in read_symbol(42, Dict, Tokens)) | ||
2881 | { | ||
2882 | yield return false; | ||
2883 | } | ||
2884 | } | ||
2885 | } | ||
2886 | { | ||
2887 | object Tokens = arg3; | ||
2888 | foreach (bool l2 in YP.unify(arg1, 43)) | ||
2889 | { | ||
2890 | foreach (bool l3 in read_symbol(43, Dict, Tokens)) | ||
2891 | { | ||
2892 | yield return false; | ||
2893 | } | ||
2894 | } | ||
2895 | } | ||
2896 | { | ||
2897 | object Tokens = arg3; | ||
2898 | foreach (bool l2 in YP.unify(arg1, 45)) | ||
2899 | { | ||
2900 | foreach (bool l3 in read_symbol(45, Dict, Tokens)) | ||
2901 | { | ||
2902 | yield return false; | ||
2903 | } | ||
2904 | } | ||
2905 | } | ||
2906 | { | ||
2907 | object Tokens = arg3; | ||
2908 | foreach (bool l2 in YP.unify(arg1, 58)) | ||
2909 | { | ||
2910 | foreach (bool l3 in read_symbol(58, Dict, Tokens)) | ||
2911 | { | ||
2912 | yield return false; | ||
2913 | } | ||
2914 | } | ||
2915 | } | ||
2916 | { | ||
2917 | object Tokens = arg3; | ||
2918 | foreach (bool l2 in YP.unify(arg1, 60)) | ||
2919 | { | ||
2920 | foreach (bool l3 in read_symbol(60, Dict, Tokens)) | ||
2921 | { | ||
2922 | yield return false; | ||
2923 | } | ||
2924 | } | ||
2925 | } | ||
2926 | { | ||
2927 | object Tokens = arg3; | ||
2928 | foreach (bool l2 in YP.unify(arg1, 61)) | ||
2929 | { | ||
2930 | foreach (bool l3 in read_symbol(61, Dict, Tokens)) | ||
2931 | { | ||
2932 | yield return false; | ||
2933 | } | ||
2934 | } | ||
2935 | } | ||
2936 | { | ||
2937 | object Tokens = arg3; | ||
2938 | foreach (bool l2 in YP.unify(arg1, 62)) | ||
2939 | { | ||
2940 | foreach (bool l3 in read_symbol(62, Dict, Tokens)) | ||
2941 | { | ||
2942 | yield return false; | ||
2943 | } | ||
2944 | } | ||
2945 | } | ||
2946 | { | ||
2947 | object Tokens = arg3; | ||
2948 | foreach (bool l2 in YP.unify(arg1, 63)) | ||
2949 | { | ||
2950 | foreach (bool l3 in read_symbol(63, Dict, Tokens)) | ||
2951 | { | ||
2952 | yield return false; | ||
2953 | } | ||
2954 | } | ||
2955 | } | ||
2956 | { | ||
2957 | object Tokens = arg3; | ||
2958 | foreach (bool l2 in YP.unify(arg1, 64)) | ||
2959 | { | ||
2960 | foreach (bool l3 in read_symbol(64, Dict, Tokens)) | ||
2961 | { | ||
2962 | yield return false; | ||
2963 | } | ||
2964 | } | ||
2965 | } | ||
2966 | { | ||
2967 | object Tokens = arg3; | ||
2968 | foreach (bool l2 in YP.unify(arg1, 92)) | ||
2969 | { | ||
2970 | foreach (bool l3 in read_symbol(92, Dict, Tokens)) | ||
2971 | { | ||
2972 | yield return false; | ||
2973 | } | ||
2974 | } | ||
2975 | } | ||
2976 | { | ||
2977 | object Tokens = arg3; | ||
2978 | foreach (bool l2 in YP.unify(arg1, 94)) | ||
2979 | { | ||
2980 | foreach (bool l3 in read_symbol(94, Dict, Tokens)) | ||
2981 | { | ||
2982 | yield return false; | ||
2983 | } | ||
2984 | } | ||
2985 | } | ||
2986 | { | ||
2987 | object Tokens = arg3; | ||
2988 | foreach (bool l2 in YP.unify(arg1, 96)) | ||
2989 | { | ||
2990 | foreach (bool l3 in read_symbol(96, Dict, Tokens)) | ||
2991 | { | ||
2992 | yield return false; | ||
2993 | } | ||
2994 | } | ||
2995 | } | ||
2996 | { | ||
2997 | object Tokens = arg3; | ||
2998 | foreach (bool l2 in YP.unify(arg1, 126)) | ||
2999 | { | ||
3000 | foreach (bool l3 in read_symbol(126, Dict, Tokens)) | ||
3001 | { | ||
3002 | yield return false; | ||
3003 | } | ||
3004 | } | ||
3005 | } | ||
3006 | } | ||
3007 | |||
3008 | public static IEnumerable<bool> read_symbol(object C1, object Dict, object Tokens) | ||
3009 | { | ||
3010 | { | ||
3011 | Variable C2 = new Variable(); | ||
3012 | Variable Chars = new Variable(); | ||
3013 | Variable NextCh = new Variable(); | ||
3014 | foreach (bool l2 in YP.get_code(C2)) | ||
3015 | { | ||
3016 | foreach (bool l3 in rest_symbol(C2, Chars, NextCh)) | ||
3017 | { | ||
3018 | foreach (bool l4 in read_after_atom4(NextCh, Dict, Tokens, new ListPair(C1, Chars))) | ||
3019 | { | ||
3020 | yield return false; | ||
3021 | } | ||
3022 | } | ||
3023 | } | ||
3024 | } | ||
3025 | } | ||
3026 | |||
3027 | public static IEnumerable<bool> rest_symbol(object arg1, object arg2, object arg3) | ||
3028 | { | ||
3029 | { | ||
3030 | object C2 = arg1; | ||
3031 | object LastCh = arg3; | ||
3032 | Variable Chars = new Variable(); | ||
3033 | Variable NextCh = new Variable(); | ||
3034 | foreach (bool l2 in YP.unify(arg2, new ListPair(C2, Chars))) | ||
3035 | { | ||
3036 | if (YP.greaterThan(C2, 160)) | ||
3037 | { | ||
3038 | if (YP.lessThan(C2, 192)) | ||
3039 | { | ||
3040 | if (YP.notEqual(C2, 186)) | ||
3041 | { | ||
3042 | if (YP.notEqual(C2, 170)) | ||
3043 | { | ||
3044 | foreach (bool l7 in YP.get_code(NextCh)) | ||
3045 | { | ||
3046 | foreach (bool l8 in rest_symbol(NextCh, Chars, LastCh)) | ||
3047 | { | ||
3048 | yield return false; | ||
3049 | } | ||
3050 | } | ||
3051 | yield break; | ||
3052 | } | ||
3053 | } | ||
3054 | } | ||
3055 | goto cutIf1; | ||
3056 | } | ||
3057 | foreach (bool l3 in symbol_char(C2)) | ||
3058 | { | ||
3059 | foreach (bool l4 in YP.get_code(NextCh)) | ||
3060 | { | ||
3061 | foreach (bool l5 in rest_symbol(NextCh, Chars, LastCh)) | ||
3062 | { | ||
3063 | yield return false; | ||
3064 | } | ||
3065 | } | ||
3066 | yield break; | ||
3067 | } | ||
3068 | cutIf1: | ||
3069 | { } | ||
3070 | } | ||
3071 | } | ||
3072 | { | ||
3073 | Variable C2 = new Variable(); | ||
3074 | foreach (bool l2 in YP.unify(arg1, C2)) | ||
3075 | { | ||
3076 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
3077 | { | ||
3078 | foreach (bool l4 in YP.unify(arg3, C2)) | ||
3079 | { | ||
3080 | yield return false; | ||
3081 | } | ||
3082 | } | ||
3083 | } | ||
3084 | } | ||
3085 | } | ||
3086 | |||
3087 | public static IEnumerable<bool> symbol_char(object arg1) | ||
3088 | { | ||
3089 | { | ||
3090 | foreach (bool l2 in YP.unify(arg1, 35)) | ||
3091 | { | ||
3092 | yield return false; | ||
3093 | } | ||
3094 | } | ||
3095 | { | ||
3096 | foreach (bool l2 in YP.unify(arg1, 36)) | ||
3097 | { | ||
3098 | yield return false; | ||
3099 | } | ||
3100 | } | ||
3101 | { | ||
3102 | foreach (bool l2 in YP.unify(arg1, 38)) | ||
3103 | { | ||
3104 | yield return false; | ||
3105 | } | ||
3106 | } | ||
3107 | { | ||
3108 | foreach (bool l2 in YP.unify(arg1, 42)) | ||
3109 | { | ||
3110 | yield return false; | ||
3111 | } | ||
3112 | } | ||
3113 | { | ||
3114 | foreach (bool l2 in YP.unify(arg1, 43)) | ||
3115 | { | ||
3116 | yield return false; | ||
3117 | } | ||
3118 | } | ||
3119 | { | ||
3120 | foreach (bool l2 in YP.unify(arg1, 45)) | ||
3121 | { | ||
3122 | yield return false; | ||
3123 | } | ||
3124 | } | ||
3125 | { | ||
3126 | foreach (bool l2 in YP.unify(arg1, 46)) | ||
3127 | { | ||
3128 | yield return false; | ||
3129 | } | ||
3130 | } | ||
3131 | { | ||
3132 | foreach (bool l2 in YP.unify(arg1, 47)) | ||
3133 | { | ||
3134 | yield return false; | ||
3135 | } | ||
3136 | } | ||
3137 | { | ||
3138 | foreach (bool l2 in YP.unify(arg1, 58)) | ||
3139 | { | ||
3140 | yield return false; | ||
3141 | } | ||
3142 | } | ||
3143 | { | ||
3144 | foreach (bool l2 in YP.unify(arg1, 60)) | ||
3145 | { | ||
3146 | yield return false; | ||
3147 | } | ||
3148 | } | ||
3149 | { | ||
3150 | foreach (bool l2 in YP.unify(arg1, 61)) | ||
3151 | { | ||
3152 | yield return false; | ||
3153 | } | ||
3154 | } | ||
3155 | { | ||
3156 | foreach (bool l2 in YP.unify(arg1, 62)) | ||
3157 | { | ||
3158 | yield return false; | ||
3159 | } | ||
3160 | } | ||
3161 | { | ||
3162 | foreach (bool l2 in YP.unify(arg1, 63)) | ||
3163 | { | ||
3164 | yield return false; | ||
3165 | } | ||
3166 | } | ||
3167 | { | ||
3168 | foreach (bool l2 in YP.unify(arg1, 64)) | ||
3169 | { | ||
3170 | yield return false; | ||
3171 | } | ||
3172 | } | ||
3173 | { | ||
3174 | foreach (bool l2 in YP.unify(arg1, 92)) | ||
3175 | { | ||
3176 | yield return false; | ||
3177 | } | ||
3178 | } | ||
3179 | { | ||
3180 | foreach (bool l2 in YP.unify(arg1, 94)) | ||
3181 | { | ||
3182 | yield return false; | ||
3183 | } | ||
3184 | } | ||
3185 | { | ||
3186 | foreach (bool l2 in YP.unify(arg1, 96)) | ||
3187 | { | ||
3188 | yield return false; | ||
3189 | } | ||
3190 | } | ||
3191 | { | ||
3192 | foreach (bool l2 in YP.unify(arg1, 126)) | ||
3193 | { | ||
3194 | yield return false; | ||
3195 | } | ||
3196 | } | ||
3197 | } | ||
3198 | |||
3199 | public static IEnumerable<bool> get_current_position(object Pos) | ||
3200 | { | ||
3201 | { | ||
3202 | foreach (bool l2 in YP.unify(Pos, 0)) | ||
3203 | { | ||
3204 | yield return false; | ||
3205 | } | ||
3206 | } | ||
3207 | } | ||
3208 | |||
3209 | public static IEnumerable<bool> read_after_atom4(object Ch, object Dict, object arg3, object Chars) | ||
3210 | { | ||
3211 | { | ||
3212 | Variable Atom_1 = new Variable(); | ||
3213 | Variable Pos = new Variable(); | ||
3214 | Variable Tokens = new Variable(); | ||
3215 | foreach (bool l2 in YP.unify(arg3, new ListPair(new Functor2("atom", Atom_1, Pos), Tokens))) | ||
3216 | { | ||
3217 | foreach (bool l3 in YP.unify(Pos, 0)) | ||
3218 | { | ||
3219 | foreach (bool l4 in YP.atom_codes(Atom_1, Chars)) | ||
3220 | { | ||
3221 | foreach (bool l5 in read_after_atom(Ch, Dict, Tokens)) | ||
3222 | { | ||
3223 | yield return false; | ||
3224 | } | ||
3225 | } | ||
3226 | } | ||
3227 | } | ||
3228 | } | ||
3229 | } | ||
3230 | |||
3231 | public static IEnumerable<bool> read_after_atom(object arg1, object Dict, object arg3) | ||
3232 | { | ||
3233 | { | ||
3234 | Variable Tokens = new Variable(); | ||
3235 | Variable NextCh = new Variable(); | ||
3236 | foreach (bool l2 in YP.unify(arg1, 40)) | ||
3237 | { | ||
3238 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("("), Tokens))) | ||
3239 | { | ||
3240 | foreach (bool l4 in YP.get_code(NextCh)) | ||
3241 | { | ||
3242 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
3243 | { | ||
3244 | yield return false; | ||
3245 | } | ||
3246 | } | ||
3247 | yield break; | ||
3248 | } | ||
3249 | } | ||
3250 | } | ||
3251 | { | ||
3252 | object Ch = arg1; | ||
3253 | object Tokens = arg3; | ||
3254 | foreach (bool l2 in read_tokens(Ch, Dict, Tokens)) | ||
3255 | { | ||
3256 | yield return false; | ||
3257 | } | ||
3258 | } | ||
3259 | } | ||
3260 | |||
3261 | public static IEnumerable<bool> read_string(object Chars, object Quote, object NextCh) | ||
3262 | { | ||
3263 | { | ||
3264 | Variable Ch = new Variable(); | ||
3265 | Variable Char = new Variable(); | ||
3266 | Variable Next = new Variable(); | ||
3267 | foreach (bool l2 in YP.get_code(Ch)) | ||
3268 | { | ||
3269 | foreach (bool l3 in read_char(Ch, Quote, Char, Next)) | ||
3270 | { | ||
3271 | foreach (bool l4 in rest_string5(Char, Next, Chars, Quote, NextCh)) | ||
3272 | { | ||
3273 | yield return false; | ||
3274 | } | ||
3275 | } | ||
3276 | } | ||
3277 | } | ||
3278 | } | ||
3279 | |||
3280 | public static IEnumerable<bool> rest_string5(object arg1, object arg2, object arg3, object arg4, object arg5) | ||
3281 | { | ||
3282 | { | ||
3283 | object _X = arg4; | ||
3284 | Variable NextCh = new Variable(); | ||
3285 | foreach (bool l2 in YP.unify(arg1, -1)) | ||
3286 | { | ||
3287 | foreach (bool l3 in YP.unify(arg2, NextCh)) | ||
3288 | { | ||
3289 | foreach (bool l4 in YP.unify(arg3, Atom.NIL)) | ||
3290 | { | ||
3291 | foreach (bool l5 in YP.unify(arg5, NextCh)) | ||
3292 | { | ||
3293 | yield return true; | ||
3294 | yield break; | ||
3295 | } | ||
3296 | } | ||
3297 | } | ||
3298 | } | ||
3299 | } | ||
3300 | { | ||
3301 | object Char = arg1; | ||
3302 | object Next = arg2; | ||
3303 | object Quote = arg4; | ||
3304 | object NextCh = arg5; | ||
3305 | Variable Chars = new Variable(); | ||
3306 | Variable Char2 = new Variable(); | ||
3307 | Variable Next2 = new Variable(); | ||
3308 | foreach (bool l2 in YP.unify(arg3, new ListPair(Char, Chars))) | ||
3309 | { | ||
3310 | foreach (bool l3 in read_char(Next, Quote, Char2, Next2)) | ||
3311 | { | ||
3312 | foreach (bool l4 in rest_string5(Char2, Next2, Chars, Quote, NextCh)) | ||
3313 | { | ||
3314 | yield return false; | ||
3315 | } | ||
3316 | } | ||
3317 | } | ||
3318 | } | ||
3319 | } | ||
3320 | |||
3321 | public static IEnumerable<bool> escape_char(object arg1, object arg2) | ||
3322 | { | ||
3323 | { | ||
3324 | foreach (bool l2 in YP.unify(arg1, 110)) | ||
3325 | { | ||
3326 | foreach (bool l3 in YP.unify(arg2, 10)) | ||
3327 | { | ||
3328 | yield return false; | ||
3329 | } | ||
3330 | } | ||
3331 | } | ||
3332 | { | ||
3333 | foreach (bool l2 in YP.unify(arg1, 78)) | ||
3334 | { | ||
3335 | foreach (bool l3 in YP.unify(arg2, 10)) | ||
3336 | { | ||
3337 | yield return false; | ||
3338 | } | ||
3339 | } | ||
3340 | } | ||
3341 | { | ||
3342 | foreach (bool l2 in YP.unify(arg1, 116)) | ||
3343 | { | ||
3344 | foreach (bool l3 in YP.unify(arg2, 9)) | ||
3345 | { | ||
3346 | yield return false; | ||
3347 | } | ||
3348 | } | ||
3349 | } | ||
3350 | { | ||
3351 | foreach (bool l2 in YP.unify(arg1, 84)) | ||
3352 | { | ||
3353 | foreach (bool l3 in YP.unify(arg2, 9)) | ||
3354 | { | ||
3355 | yield return false; | ||
3356 | } | ||
3357 | } | ||
3358 | } | ||
3359 | { | ||
3360 | foreach (bool l2 in YP.unify(arg1, 114)) | ||
3361 | { | ||
3362 | foreach (bool l3 in YP.unify(arg2, 13)) | ||
3363 | { | ||
3364 | yield return false; | ||
3365 | } | ||
3366 | } | ||
3367 | } | ||
3368 | { | ||
3369 | foreach (bool l2 in YP.unify(arg1, 82)) | ||
3370 | { | ||
3371 | foreach (bool l3 in YP.unify(arg2, 13)) | ||
3372 | { | ||
3373 | yield return false; | ||
3374 | } | ||
3375 | } | ||
3376 | } | ||
3377 | { | ||
3378 | foreach (bool l2 in YP.unify(arg1, 118)) | ||
3379 | { | ||
3380 | foreach (bool l3 in YP.unify(arg2, 11)) | ||
3381 | { | ||
3382 | yield return false; | ||
3383 | } | ||
3384 | } | ||
3385 | } | ||
3386 | { | ||
3387 | foreach (bool l2 in YP.unify(arg1, 86)) | ||
3388 | { | ||
3389 | foreach (bool l3 in YP.unify(arg2, 11)) | ||
3390 | { | ||
3391 | yield return false; | ||
3392 | } | ||
3393 | } | ||
3394 | } | ||
3395 | { | ||
3396 | foreach (bool l2 in YP.unify(arg1, 98)) | ||
3397 | { | ||
3398 | foreach (bool l3 in YP.unify(arg2, 8)) | ||
3399 | { | ||
3400 | yield return false; | ||
3401 | } | ||
3402 | } | ||
3403 | } | ||
3404 | { | ||
3405 | foreach (bool l2 in YP.unify(arg1, 66)) | ||
3406 | { | ||
3407 | foreach (bool l3 in YP.unify(arg2, 8)) | ||
3408 | { | ||
3409 | yield return false; | ||
3410 | } | ||
3411 | } | ||
3412 | } | ||
3413 | { | ||
3414 | foreach (bool l2 in YP.unify(arg1, 102)) | ||
3415 | { | ||
3416 | foreach (bool l3 in YP.unify(arg2, 12)) | ||
3417 | { | ||
3418 | yield return false; | ||
3419 | } | ||
3420 | } | ||
3421 | } | ||
3422 | { | ||
3423 | foreach (bool l2 in YP.unify(arg1, 70)) | ||
3424 | { | ||
3425 | foreach (bool l3 in YP.unify(arg2, 12)) | ||
3426 | { | ||
3427 | yield return false; | ||
3428 | } | ||
3429 | } | ||
3430 | } | ||
3431 | { | ||
3432 | foreach (bool l2 in YP.unify(arg1, 101)) | ||
3433 | { | ||
3434 | foreach (bool l3 in YP.unify(arg2, 27)) | ||
3435 | { | ||
3436 | yield return false; | ||
3437 | } | ||
3438 | } | ||
3439 | } | ||
3440 | { | ||
3441 | foreach (bool l2 in YP.unify(arg1, 69)) | ||
3442 | { | ||
3443 | foreach (bool l3 in YP.unify(arg2, 27)) | ||
3444 | { | ||
3445 | yield return false; | ||
3446 | } | ||
3447 | } | ||
3448 | } | ||
3449 | { | ||
3450 | foreach (bool l2 in YP.unify(arg1, 100)) | ||
3451 | { | ||
3452 | foreach (bool l3 in YP.unify(arg2, 127)) | ||
3453 | { | ||
3454 | yield return false; | ||
3455 | } | ||
3456 | } | ||
3457 | } | ||
3458 | { | ||
3459 | foreach (bool l2 in YP.unify(arg1, 68)) | ||
3460 | { | ||
3461 | foreach (bool l3 in YP.unify(arg2, 127)) | ||
3462 | { | ||
3463 | yield return false; | ||
3464 | } | ||
3465 | } | ||
3466 | } | ||
3467 | { | ||
3468 | foreach (bool l2 in YP.unify(arg1, 115)) | ||
3469 | { | ||
3470 | foreach (bool l3 in YP.unify(arg2, 32)) | ||
3471 | { | ||
3472 | yield return false; | ||
3473 | } | ||
3474 | } | ||
3475 | } | ||
3476 | { | ||
3477 | foreach (bool l2 in YP.unify(arg1, 83)) | ||
3478 | { | ||
3479 | foreach (bool l3 in YP.unify(arg2, 32)) | ||
3480 | { | ||
3481 | yield return false; | ||
3482 | } | ||
3483 | } | ||
3484 | } | ||
3485 | { | ||
3486 | foreach (bool l2 in YP.unify(arg1, 122)) | ||
3487 | { | ||
3488 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
3489 | { | ||
3490 | yield return false; | ||
3491 | } | ||
3492 | } | ||
3493 | } | ||
3494 | { | ||
3495 | foreach (bool l2 in YP.unify(arg1, 90)) | ||
3496 | { | ||
3497 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
3498 | { | ||
3499 | yield return false; | ||
3500 | } | ||
3501 | } | ||
3502 | } | ||
3503 | } | ||
3504 | |||
3505 | public static IEnumerable<bool> read_variable(object C1, object Dict, object arg3) | ||
3506 | { | ||
3507 | { | ||
3508 | Variable Var = new Variable(); | ||
3509 | Variable Name = new Variable(); | ||
3510 | Variable StartPos = new Variable(); | ||
3511 | Variable Tokens = new Variable(); | ||
3512 | Variable Chars = new Variable(); | ||
3513 | Variable NextCh = new Variable(); | ||
3514 | foreach (bool l2 in YP.unify(arg3, new ListPair(new Functor3("var", Var, Name, StartPos), Tokens))) | ||
3515 | { | ||
3516 | foreach (bool l3 in get_current_position(StartPos)) | ||
3517 | { | ||
3518 | foreach (bool l4 in read_name(C1, Chars, NextCh)) | ||
3519 | { | ||
3520 | foreach (bool l5 in YP.atom_codes(Name, Chars)) | ||
3521 | { | ||
3522 | if (YP.termEqual(Name, Atom.a("_"))) | ||
3523 | { | ||
3524 | foreach (bool l7 in read_after_atom(NextCh, Dict, Tokens)) | ||
3525 | { | ||
3526 | yield return false; | ||
3527 | } | ||
3528 | goto cutIf1; | ||
3529 | } | ||
3530 | foreach (bool l6 in read_lookup(Dict, Name, Var)) | ||
3531 | { | ||
3532 | foreach (bool l7 in read_after_atom(NextCh, Dict, Tokens)) | ||
3533 | { | ||
3534 | yield return false; | ||
3535 | } | ||
3536 | } | ||
3537 | cutIf1: | ||
3538 | { } | ||
3539 | } | ||
3540 | } | ||
3541 | } | ||
3542 | } | ||
3543 | } | ||
3544 | } | ||
3545 | |||
3546 | public static IEnumerable<bool> read_lookup(object arg1, object Name, object Var) | ||
3547 | { | ||
3548 | { | ||
3549 | Variable N = new Variable(); | ||
3550 | Variable V = new Variable(); | ||
3551 | Variable L = new Variable(); | ||
3552 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("=", N, V), L))) | ||
3553 | { | ||
3554 | foreach (bool l3 in YP.unify(N, Name)) | ||
3555 | { | ||
3556 | foreach (bool l4 in YP.unify(V, Var)) | ||
3557 | { | ||
3558 | yield return false; | ||
3559 | } | ||
3560 | goto cutIf1; | ||
3561 | } | ||
3562 | foreach (bool l3 in read_lookup(L, Name, Var)) | ||
3563 | { | ||
3564 | yield return false; | ||
3565 | } | ||
3566 | cutIf1: | ||
3567 | { } | ||
3568 | } | ||
3569 | } | ||
3570 | } | ||
3571 | |||
3572 | public static IEnumerable<bool> read_solidus(object Ch, object LastCh) | ||
3573 | { | ||
3574 | { | ||
3575 | Variable NextCh = new Variable(); | ||
3576 | if (YP.equal(Ch, 42)) | ||
3577 | { | ||
3578 | foreach (bool l3 in YP.get_code(NextCh)) | ||
3579 | { | ||
3580 | if (YP.equal(NextCh, 47)) | ||
3581 | { | ||
3582 | foreach (bool l5 in YP.get_code(LastCh)) | ||
3583 | { | ||
3584 | yield return false; | ||
3585 | } | ||
3586 | goto cutIf2; | ||
3587 | } | ||
3588 | foreach (bool l4 in read_solidus(NextCh, LastCh)) | ||
3589 | { | ||
3590 | yield return false; | ||
3591 | } | ||
3592 | cutIf2: | ||
3593 | { } | ||
3594 | } | ||
3595 | goto cutIf1; | ||
3596 | } | ||
3597 | if (YP.notEqual(Ch, -1)) | ||
3598 | { | ||
3599 | foreach (bool l3 in YP.get_code(NextCh)) | ||
3600 | { | ||
3601 | foreach (bool l4 in read_solidus(NextCh, LastCh)) | ||
3602 | { | ||
3603 | yield return false; | ||
3604 | } | ||
3605 | } | ||
3606 | goto cutIf3; | ||
3607 | } | ||
3608 | foreach (bool l2 in YP.unify(LastCh, Ch)) | ||
3609 | { | ||
3610 | foreach (bool l3 in formatError(Atom.a("user_error"), Atom.a("~N** end of file in /*comment~n"), Atom.NIL)) | ||
3611 | { | ||
3612 | yield return false; | ||
3613 | } | ||
3614 | } | ||
3615 | cutIf3: | ||
3616 | cutIf1: | ||
3617 | { } | ||
3618 | } | ||
3619 | } | ||
3620 | |||
3621 | public static IEnumerable<bool> read_identifier(object C1, object Dict, object Tokens) | ||
3622 | { | ||
3623 | { | ||
3624 | Variable Chars = new Variable(); | ||
3625 | Variable NextCh = new Variable(); | ||
3626 | foreach (bool l2 in read_name(C1, Chars, NextCh)) | ||
3627 | { | ||
3628 | foreach (bool l3 in read_after_atom4(NextCh, Dict, Tokens, Chars)) | ||
3629 | { | ||
3630 | yield return false; | ||
3631 | } | ||
3632 | } | ||
3633 | } | ||
3634 | } | ||
3635 | |||
3636 | public static IEnumerable<bool> read_name(object C1, object arg2, object LastCh) | ||
3637 | { | ||
3638 | { | ||
3639 | Variable Chars = new Variable(); | ||
3640 | Variable C2 = new Variable(); | ||
3641 | foreach (bool l2 in YP.unify(arg2, new ListPair(C1, Chars))) | ||
3642 | { | ||
3643 | foreach (bool l3 in YP.get_code(C2)) | ||
3644 | { | ||
3645 | if (YP.greaterThanOrEqual(C2, new ListPair(97, Atom.NIL))) | ||
3646 | { | ||
3647 | if (YP.lessThanOrEqual(C2, new ListPair(122, Atom.NIL))) | ||
3648 | { | ||
3649 | foreach (bool l6 in read_name(C2, Chars, LastCh)) | ||
3650 | { | ||
3651 | yield return false; | ||
3652 | } | ||
3653 | goto cutIf2; | ||
3654 | } | ||
3655 | if (YP.lessThan(C2, 192)) | ||
3656 | { | ||
3657 | if (YP.notEqual(YP.bitwiseOr(C2, 16), 186)) | ||
3658 | { | ||
3659 | foreach (bool l7 in YP.unify(Chars, Atom.NIL)) | ||
3660 | { | ||
3661 | foreach (bool l8 in YP.unify(LastCh, C2)) | ||
3662 | { | ||
3663 | yield return false; | ||
3664 | } | ||
3665 | } | ||
3666 | goto cutIf3; | ||
3667 | } | ||
3668 | } | ||
3669 | if (YP.equal(YP.bitwiseOr(C2, 32), 247)) | ||
3670 | { | ||
3671 | foreach (bool l6 in YP.unify(Chars, Atom.NIL)) | ||
3672 | { | ||
3673 | foreach (bool l7 in YP.unify(LastCh, C2)) | ||
3674 | { | ||
3675 | yield return false; | ||
3676 | } | ||
3677 | } | ||
3678 | goto cutIf4; | ||
3679 | } | ||
3680 | foreach (bool l5 in read_name(C2, Chars, LastCh)) | ||
3681 | { | ||
3682 | yield return false; | ||
3683 | } | ||
3684 | cutIf4: | ||
3685 | cutIf3: | ||
3686 | cutIf2: | ||
3687 | goto cutIf1; | ||
3688 | } | ||
3689 | if (YP.greaterThanOrEqual(C2, new ListPair(65, Atom.NIL))) | ||
3690 | { | ||
3691 | if (YP.greaterThan(C2, new ListPair(90, Atom.NIL))) | ||
3692 | { | ||
3693 | if (YP.notEqual(C2, new ListPair(95, Atom.NIL))) | ||
3694 | { | ||
3695 | foreach (bool l7 in YP.unify(Chars, Atom.NIL)) | ||
3696 | { | ||
3697 | foreach (bool l8 in YP.unify(LastCh, C2)) | ||
3698 | { | ||
3699 | yield return false; | ||
3700 | } | ||
3701 | } | ||
3702 | goto cutIf6; | ||
3703 | } | ||
3704 | } | ||
3705 | foreach (bool l5 in read_name(C2, Chars, LastCh)) | ||
3706 | { | ||
3707 | yield return false; | ||
3708 | } | ||
3709 | cutIf6: | ||
3710 | goto cutIf5; | ||
3711 | } | ||
3712 | if (YP.greaterThanOrEqual(C2, new ListPair(48, Atom.NIL))) | ||
3713 | { | ||
3714 | if (YP.lessThanOrEqual(C2, new ListPair(57, Atom.NIL))) | ||
3715 | { | ||
3716 | foreach (bool l6 in read_name(C2, Chars, LastCh)) | ||
3717 | { | ||
3718 | yield return false; | ||
3719 | } | ||
3720 | goto cutIf7; | ||
3721 | } | ||
3722 | } | ||
3723 | foreach (bool l4 in YP.unify(Chars, Atom.NIL)) | ||
3724 | { | ||
3725 | foreach (bool l5 in YP.unify(LastCh, C2)) | ||
3726 | { | ||
3727 | yield return false; | ||
3728 | } | ||
3729 | } | ||
3730 | cutIf7: | ||
3731 | cutIf5: | ||
3732 | cutIf1: | ||
3733 | { } | ||
3734 | } | ||
3735 | } | ||
3736 | } | ||
3737 | } | ||
3738 | |||
3739 | public static IEnumerable<bool> read_fullstop(object Ch, object Dict, object Tokens) | ||
3740 | { | ||
3741 | { | ||
3742 | Variable Number = new Variable(); | ||
3743 | Variable Tokens1 = new Variable(); | ||
3744 | Variable Chars = new Variable(); | ||
3745 | Variable NextCh = new Variable(); | ||
3746 | if (YP.lessThanOrEqual(Ch, new ListPair(57, Atom.NIL))) | ||
3747 | { | ||
3748 | if (YP.greaterThanOrEqual(Ch, new ListPair(48, Atom.NIL))) | ||
3749 | { | ||
3750 | foreach (bool l4 in YP.unify(Tokens, new ListPair(new Functor1("number", Number), Tokens1))) | ||
3751 | { | ||
3752 | foreach (bool l5 in read_float(Number, Dict, Tokens1, new ListPair(48, Atom.NIL), Ch)) | ||
3753 | { | ||
3754 | yield return false; | ||
3755 | } | ||
3756 | } | ||
3757 | goto cutIf1; | ||
3758 | } | ||
3759 | } | ||
3760 | if (YP.greaterThan(Ch, new ListPair(32, Atom.NIL))) | ||
3761 | { | ||
3762 | foreach (bool l3 in rest_symbol(Ch, Chars, NextCh)) | ||
3763 | { | ||
3764 | foreach (bool l4 in read_after_atom4(NextCh, Dict, Tokens, new ListPair(46, Chars))) | ||
3765 | { | ||
3766 | yield return false; | ||
3767 | } | ||
3768 | } | ||
3769 | goto cutIf2; | ||
3770 | } | ||
3771 | if (YP.greaterThanOrEqual(Ch, 0)) | ||
3772 | { | ||
3773 | foreach (bool l3 in YP.unify(Tokens, Atom.NIL)) | ||
3774 | { | ||
3775 | yield return false; | ||
3776 | } | ||
3777 | goto cutIf3; | ||
3778 | } | ||
3779 | foreach (bool l2 in formatError(Atom.a("user_error"), Atom.a("~N** end of file just after full stop~n"), Atom.NIL)) | ||
3780 | { | ||
3781 | } | ||
3782 | cutIf3: | ||
3783 | cutIf2: | ||
3784 | cutIf1: | ||
3785 | { } | ||
3786 | } | ||
3787 | } | ||
3788 | |||
3789 | public static IEnumerable<bool> read_float(object Number, object Dict, object Tokens, object Digits, object Digit) | ||
3790 | { | ||
3791 | { | ||
3792 | Variable Chars = new Variable(); | ||
3793 | Variable Rest = new Variable(); | ||
3794 | Variable NextCh = new Variable(); | ||
3795 | foreach (bool l2 in prepend(Digits, Chars, Rest)) | ||
3796 | { | ||
3797 | foreach (bool l3 in read_float4(Digit, Rest, NextCh, Chars)) | ||
3798 | { | ||
3799 | foreach (bool l4 in YP.number_codes(Number, Chars)) | ||
3800 | { | ||
3801 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
3802 | { | ||
3803 | yield return false; | ||
3804 | } | ||
3805 | } | ||
3806 | } | ||
3807 | } | ||
3808 | } | ||
3809 | } | ||
3810 | |||
3811 | public static IEnumerable<bool> prepend(object arg1, object arg2, object arg3) | ||
3812 | { | ||
3813 | { | ||
3814 | object X = arg3; | ||
3815 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
3816 | { | ||
3817 | foreach (bool l3 in YP.unify(arg2, new ListPair(46, X))) | ||
3818 | { | ||
3819 | yield return false; | ||
3820 | } | ||
3821 | } | ||
3822 | } | ||
3823 | { | ||
3824 | object Y = arg3; | ||
3825 | Variable C = new Variable(); | ||
3826 | Variable Cs = new Variable(); | ||
3827 | Variable X = new Variable(); | ||
3828 | foreach (bool l2 in YP.unify(arg1, new ListPair(C, Cs))) | ||
3829 | { | ||
3830 | foreach (bool l3 in YP.unify(arg2, new ListPair(C, X))) | ||
3831 | { | ||
3832 | foreach (bool l4 in prepend(Cs, X, Y)) | ||
3833 | { | ||
3834 | yield return false; | ||
3835 | } | ||
3836 | } | ||
3837 | } | ||
3838 | } | ||
3839 | } | ||
3840 | |||
3841 | public static IEnumerable<bool> read_float4(object C1, object arg2, object NextCh, object Total) | ||
3842 | { | ||
3843 | { | ||
3844 | Variable Chars = new Variable(); | ||
3845 | Variable C2 = new Variable(); | ||
3846 | Variable C3 = new Variable(); | ||
3847 | Variable C4 = new Variable(); | ||
3848 | Variable More = new Variable(); | ||
3849 | foreach (bool l2 in YP.unify(arg2, new ListPair(C1, Chars))) | ||
3850 | { | ||
3851 | foreach (bool l3 in YP.get_code(C2)) | ||
3852 | { | ||
3853 | if (YP.greaterThanOrEqual(C2, new ListPair(48, Atom.NIL))) | ||
3854 | { | ||
3855 | if (YP.lessThanOrEqual(C2, new ListPair(57, Atom.NIL))) | ||
3856 | { | ||
3857 | foreach (bool l6 in read_float4(C2, Chars, NextCh, Total)) | ||
3858 | { | ||
3859 | yield return false; | ||
3860 | } | ||
3861 | goto cutIf1; | ||
3862 | } | ||
3863 | } | ||
3864 | if (YP.equal(YP.bitwiseOr(C2, 32), new ListPair(101, Atom.NIL))) | ||
3865 | { | ||
3866 | foreach (bool l5 in YP.get_code(C3)) | ||
3867 | { | ||
3868 | if (YP.equal(C3, new ListPair(45, Atom.NIL))) | ||
3869 | { | ||
3870 | foreach (bool l7 in YP.get_code(C4)) | ||
3871 | { | ||
3872 | foreach (bool l8 in YP.unify(Chars, new ListPair(C2, new ListPair(45, More)))) | ||
3873 | { | ||
3874 | if (YP.greaterThanOrEqual(C4, new ListPair(48, Atom.NIL))) | ||
3875 | { | ||
3876 | if (YP.lessThanOrEqual(C4, new ListPair(57, Atom.NIL))) | ||
3877 | { | ||
3878 | foreach (bool l11 in read_exponent(C4, More, NextCh)) | ||
3879 | { | ||
3880 | yield return false; | ||
3881 | } | ||
3882 | goto cutIf4; | ||
3883 | } | ||
3884 | } | ||
3885 | foreach (bool l9 in YP.unify(More, Atom.NIL)) | ||
3886 | { | ||
3887 | foreach (bool l10 in formatError(Atom.a("user_error"), Atom.a("~N** Missing exponent in ~s~n"), new ListPair(Total, Atom.NIL))) | ||
3888 | { | ||
3889 | } | ||
3890 | } | ||
3891 | foreach (bool l9 in YP.unify(More, new ListPair(48, Atom.NIL))) | ||
3892 | { | ||
3893 | foreach (bool l10 in YP.unify(NextCh, C4)) | ||
3894 | { | ||
3895 | yield return false; | ||
3896 | } | ||
3897 | } | ||
3898 | cutIf4: | ||
3899 | { } | ||
3900 | } | ||
3901 | } | ||
3902 | goto cutIf3; | ||
3903 | } | ||
3904 | if (YP.equal(C3, new ListPair(43, Atom.NIL))) | ||
3905 | { | ||
3906 | foreach (bool l7 in YP.get_code(C4)) | ||
3907 | { | ||
3908 | foreach (bool l8 in YP.unify(Chars, new ListPair(C2, More))) | ||
3909 | { | ||
3910 | if (YP.greaterThanOrEqual(C4, new ListPair(48, Atom.NIL))) | ||
3911 | { | ||
3912 | if (YP.lessThanOrEqual(C4, new ListPair(57, Atom.NIL))) | ||
3913 | { | ||
3914 | foreach (bool l11 in read_exponent(C4, More, NextCh)) | ||
3915 | { | ||
3916 | yield return false; | ||
3917 | } | ||
3918 | goto cutIf6; | ||
3919 | } | ||
3920 | } | ||
3921 | foreach (bool l9 in YP.unify(More, Atom.NIL)) | ||
3922 | { | ||
3923 | foreach (bool l10 in formatError(Atom.a("user_error"), Atom.a("~N** Missing exponent in ~s~n"), new ListPair(Total, Atom.NIL))) | ||
3924 | { | ||
3925 | } | ||
3926 | } | ||
3927 | foreach (bool l9 in YP.unify(More, new ListPair(48, Atom.NIL))) | ||
3928 | { | ||
3929 | foreach (bool l10 in YP.unify(NextCh, C4)) | ||
3930 | { | ||
3931 | yield return false; | ||
3932 | } | ||
3933 | } | ||
3934 | cutIf6: | ||
3935 | { } | ||
3936 | } | ||
3937 | } | ||
3938 | goto cutIf5; | ||
3939 | } | ||
3940 | foreach (bool l6 in YP.unify(C4, C3)) | ||
3941 | { | ||
3942 | foreach (bool l7 in YP.unify(Chars, new ListPair(C2, More))) | ||
3943 | { | ||
3944 | if (YP.greaterThanOrEqual(C4, new ListPair(48, Atom.NIL))) | ||
3945 | { | ||
3946 | if (YP.lessThanOrEqual(C4, new ListPair(57, Atom.NIL))) | ||
3947 | { | ||
3948 | foreach (bool l10 in read_exponent(C4, More, NextCh)) | ||
3949 | { | ||
3950 | yield return false; | ||
3951 | } | ||
3952 | goto cutIf7; | ||
3953 | } | ||
3954 | } | ||
3955 | foreach (bool l8 in YP.unify(More, Atom.NIL)) | ||
3956 | { | ||
3957 | foreach (bool l9 in formatError(Atom.a("user_error"), Atom.a("~N** Missing exponent in ~s~n"), new ListPair(Total, Atom.NIL))) | ||
3958 | { | ||
3959 | } | ||
3960 | } | ||
3961 | foreach (bool l8 in YP.unify(More, new ListPair(48, Atom.NIL))) | ||
3962 | { | ||
3963 | foreach (bool l9 in YP.unify(NextCh, C4)) | ||
3964 | { | ||
3965 | yield return false; | ||
3966 | } | ||
3967 | } | ||
3968 | cutIf7: | ||
3969 | { } | ||
3970 | } | ||
3971 | } | ||
3972 | cutIf5: | ||
3973 | cutIf3: | ||
3974 | { } | ||
3975 | } | ||
3976 | goto cutIf2; | ||
3977 | } | ||
3978 | foreach (bool l4 in YP.unify(Chars, Atom.NIL)) | ||
3979 | { | ||
3980 | foreach (bool l5 in YP.unify(NextCh, C2)) | ||
3981 | { | ||
3982 | yield return false; | ||
3983 | } | ||
3984 | } | ||
3985 | cutIf2: | ||
3986 | cutIf1: | ||
3987 | { } | ||
3988 | } | ||
3989 | } | ||
3990 | } | ||
3991 | } | ||
3992 | |||
3993 | public static IEnumerable<bool> read_exponent(object C1, object arg2, object NextCh) | ||
3994 | { | ||
3995 | { | ||
3996 | Variable Chars = new Variable(); | ||
3997 | Variable C2 = new Variable(); | ||
3998 | foreach (bool l2 in YP.unify(arg2, new ListPair(C1, Chars))) | ||
3999 | { | ||
4000 | foreach (bool l3 in YP.get_code(C2)) | ||
4001 | { | ||
4002 | if (YP.greaterThanOrEqual(C2, new ListPair(48, Atom.NIL))) | ||
4003 | { | ||
4004 | if (YP.lessThanOrEqual(C2, new ListPair(57, Atom.NIL))) | ||
4005 | { | ||
4006 | foreach (bool l6 in read_exponent(C2, Chars, NextCh)) | ||
4007 | { | ||
4008 | yield return false; | ||
4009 | } | ||
4010 | goto cutIf1; | ||
4011 | } | ||
4012 | } | ||
4013 | foreach (bool l4 in YP.unify(Chars, Atom.NIL)) | ||
4014 | { | ||
4015 | foreach (bool l5 in YP.unify(NextCh, C2)) | ||
4016 | { | ||
4017 | yield return false; | ||
4018 | } | ||
4019 | } | ||
4020 | cutIf1: | ||
4021 | { } | ||
4022 | } | ||
4023 | } | ||
4024 | } | ||
4025 | } | ||
4026 | |||
4027 | public static IEnumerable<bool> read_number(object C1, object Dict, object arg3) | ||
4028 | { | ||
4029 | { | ||
4030 | Variable Number = new Variable(); | ||
4031 | Variable Tokens = new Variable(); | ||
4032 | Variable C2 = new Variable(); | ||
4033 | Variable N = new Variable(); | ||
4034 | Variable C = new Variable(); | ||
4035 | Variable C3 = new Variable(); | ||
4036 | Variable Digits = new Variable(); | ||
4037 | foreach (bool l2 in YP.unify(arg3, new ListPair(new Functor1("number", Number), Tokens))) | ||
4038 | { | ||
4039 | foreach (bool l3 in read_number4(C1, C2, 0, N)) | ||
4040 | { | ||
4041 | if (YP.equal(C2, 39)) | ||
4042 | { | ||
4043 | if (YP.greaterThanOrEqual(N, 2)) | ||
4044 | { | ||
4045 | if (YP.lessThanOrEqual(N, 36)) | ||
4046 | { | ||
4047 | foreach (bool l7 in read_based(N, 0, Number, C)) | ||
4048 | { | ||
4049 | foreach (bool l8 in read_tokens(C, Dict, Tokens)) | ||
4050 | { | ||
4051 | yield return false; | ||
4052 | } | ||
4053 | } | ||
4054 | goto cutIf2; | ||
4055 | } | ||
4056 | } | ||
4057 | if (YP.equal(N, 0)) | ||
4058 | { | ||
4059 | foreach (bool l6 in YP.get_code(C3)) | ||
4060 | { | ||
4061 | foreach (bool l7 in read_char(C3, -1, Number, C)) | ||
4062 | { | ||
4063 | foreach (bool l8 in read_tokens(C, Dict, Tokens)) | ||
4064 | { | ||
4065 | yield return false; | ||
4066 | } | ||
4067 | } | ||
4068 | } | ||
4069 | goto cutIf3; | ||
4070 | } | ||
4071 | foreach (bool l5 in formatError(Atom.a("user_error"), Atom.a("~N** ~d' read as ~d '~n"), new ListPair(N, new ListPair(N, Atom.NIL)))) | ||
4072 | { | ||
4073 | foreach (bool l6 in YP.unify(Number, N)) | ||
4074 | { | ||
4075 | foreach (bool l7 in YP.unify(C, C2)) | ||
4076 | { | ||
4077 | foreach (bool l8 in read_tokens(C, Dict, Tokens)) | ||
4078 | { | ||
4079 | yield return false; | ||
4080 | } | ||
4081 | } | ||
4082 | } | ||
4083 | } | ||
4084 | cutIf3: | ||
4085 | cutIf2: | ||
4086 | goto cutIf1; | ||
4087 | } | ||
4088 | if (YP.equal(C2, 46)) | ||
4089 | { | ||
4090 | foreach (bool l5 in YP.get_code(C3)) | ||
4091 | { | ||
4092 | if (YP.greaterThanOrEqual(C3, new ListPair(48, Atom.NIL))) | ||
4093 | { | ||
4094 | if (YP.lessThanOrEqual(C3, new ListPair(57, Atom.NIL))) | ||
4095 | { | ||
4096 | foreach (bool l8 in YP.number_codes(N, Digits)) | ||
4097 | { | ||
4098 | foreach (bool l9 in read_float(Number, Dict, Tokens, Digits, C3)) | ||
4099 | { | ||
4100 | yield return false; | ||
4101 | } | ||
4102 | } | ||
4103 | goto cutIf5; | ||
4104 | } | ||
4105 | } | ||
4106 | foreach (bool l6 in YP.unify(Number, N)) | ||
4107 | { | ||
4108 | foreach (bool l7 in read_fullstop(C3, Dict, Tokens)) | ||
4109 | { | ||
4110 | yield return false; | ||
4111 | } | ||
4112 | } | ||
4113 | cutIf5: | ||
4114 | { } | ||
4115 | } | ||
4116 | goto cutIf4; | ||
4117 | } | ||
4118 | foreach (bool l4 in YP.unify(Number, N)) | ||
4119 | { | ||
4120 | foreach (bool l5 in read_tokens(C2, Dict, Tokens)) | ||
4121 | { | ||
4122 | yield return false; | ||
4123 | } | ||
4124 | } | ||
4125 | cutIf4: | ||
4126 | cutIf1: | ||
4127 | { } | ||
4128 | } | ||
4129 | } | ||
4130 | } | ||
4131 | } | ||
4132 | |||
4133 | public static IEnumerable<bool> read_number4(object C0, object C, object N0, object N) | ||
4134 | { | ||
4135 | { | ||
4136 | Variable N1 = new Variable(); | ||
4137 | Variable C1 = new Variable(); | ||
4138 | if (YP.greaterThanOrEqual(C0, new ListPair(48, Atom.NIL))) | ||
4139 | { | ||
4140 | if (YP.lessThanOrEqual(C0, new ListPair(57, Atom.NIL))) | ||
4141 | { | ||
4142 | foreach (bool l4 in YP.unify(N1, YP.add(YP.subtract(YP.multiply(N0, 10), new ListPair(48, Atom.NIL)), C0))) | ||
4143 | { | ||
4144 | foreach (bool l5 in YP.get_code(C1)) | ||
4145 | { | ||
4146 | foreach (bool l6 in read_number4(C1, C, N1, N)) | ||
4147 | { | ||
4148 | yield return false; | ||
4149 | } | ||
4150 | } | ||
4151 | } | ||
4152 | goto cutIf1; | ||
4153 | } | ||
4154 | } | ||
4155 | if (YP.equal(C0, 95)) | ||
4156 | { | ||
4157 | foreach (bool l3 in YP.get_code(C1)) | ||
4158 | { | ||
4159 | foreach (bool l4 in read_number4(C1, C, N0, N)) | ||
4160 | { | ||
4161 | yield return false; | ||
4162 | } | ||
4163 | } | ||
4164 | goto cutIf2; | ||
4165 | } | ||
4166 | foreach (bool l2 in YP.unify(C, C0)) | ||
4167 | { | ||
4168 | foreach (bool l3 in YP.unify(N, N0)) | ||
4169 | { | ||
4170 | yield return false; | ||
4171 | } | ||
4172 | } | ||
4173 | cutIf2: | ||
4174 | cutIf1: | ||
4175 | { } | ||
4176 | } | ||
4177 | } | ||
4178 | |||
4179 | public static IEnumerable<bool> read_based(object Base, object N0, object N, object C) | ||
4180 | { | ||
4181 | { | ||
4182 | Variable C1 = new Variable(); | ||
4183 | Variable Digit = new Variable(); | ||
4184 | Variable N1 = new Variable(); | ||
4185 | foreach (bool l2 in YP.get_code(C1)) | ||
4186 | { | ||
4187 | if (YP.greaterThanOrEqual(C1, new ListPair(48, Atom.NIL))) | ||
4188 | { | ||
4189 | if (YP.lessThanOrEqual(C1, new ListPair(57, Atom.NIL))) | ||
4190 | { | ||
4191 | foreach (bool l5 in YP.unify(Digit, YP.subtract(C1, new ListPair(48, Atom.NIL)))) | ||
4192 | { | ||
4193 | if (YP.lessThan(Digit, Base)) | ||
4194 | { | ||
4195 | foreach (bool l7 in YP.unify(N1, YP.add(YP.multiply(N0, Base), Digit))) | ||
4196 | { | ||
4197 | foreach (bool l8 in read_based(Base, N1, N, C)) | ||
4198 | { | ||
4199 | yield return false; | ||
4200 | } | ||
4201 | } | ||
4202 | goto cutIf2; | ||
4203 | } | ||
4204 | if (YP.equal(C1, new ListPair(95, Atom.NIL))) | ||
4205 | { | ||
4206 | foreach (bool l7 in read_based(Base, N0, N, C)) | ||
4207 | { | ||
4208 | yield return false; | ||
4209 | } | ||
4210 | goto cutIf3; | ||
4211 | } | ||
4212 | foreach (bool l6 in YP.unify(N, N0)) | ||
4213 | { | ||
4214 | foreach (bool l7 in YP.unify(C, C1)) | ||
4215 | { | ||
4216 | yield return false; | ||
4217 | } | ||
4218 | } | ||
4219 | cutIf3: | ||
4220 | cutIf2: | ||
4221 | { } | ||
4222 | } | ||
4223 | goto cutIf1; | ||
4224 | } | ||
4225 | } | ||
4226 | if (YP.greaterThanOrEqual(C1, new ListPair(65, Atom.NIL))) | ||
4227 | { | ||
4228 | if (YP.lessThanOrEqual(C1, new ListPair(90, Atom.NIL))) | ||
4229 | { | ||
4230 | foreach (bool l5 in YP.unify(Digit, YP.subtract(C1, YP.subtract(new ListPair(65, Atom.NIL), 10)))) | ||
4231 | { | ||
4232 | if (YP.lessThan(Digit, Base)) | ||
4233 | { | ||
4234 | foreach (bool l7 in YP.unify(N1, YP.add(YP.multiply(N0, Base), Digit))) | ||
4235 | { | ||
4236 | foreach (bool l8 in read_based(Base, N1, N, C)) | ||
4237 | { | ||
4238 | yield return false; | ||
4239 | } | ||
4240 | } | ||
4241 | goto cutIf5; | ||
4242 | } | ||
4243 | if (YP.equal(C1, new ListPair(95, Atom.NIL))) | ||
4244 | { | ||
4245 | foreach (bool l7 in read_based(Base, N0, N, C)) | ||
4246 | { | ||
4247 | yield return false; | ||
4248 | } | ||
4249 | goto cutIf6; | ||
4250 | } | ||
4251 | foreach (bool l6 in YP.unify(N, N0)) | ||
4252 | { | ||
4253 | foreach (bool l7 in YP.unify(C, C1)) | ||
4254 | { | ||
4255 | yield return false; | ||
4256 | } | ||
4257 | } | ||
4258 | cutIf6: | ||
4259 | cutIf5: | ||
4260 | { } | ||
4261 | } | ||
4262 | goto cutIf4; | ||
4263 | } | ||
4264 | } | ||
4265 | if (YP.greaterThanOrEqual(C1, new ListPair(97, Atom.NIL))) | ||
4266 | { | ||
4267 | if (YP.lessThanOrEqual(C1, new ListPair(122, Atom.NIL))) | ||
4268 | { | ||
4269 | foreach (bool l5 in YP.unify(Digit, YP.subtract(C1, YP.subtract(new ListPair(97, Atom.NIL), 10)))) | ||
4270 | { | ||
4271 | if (YP.lessThan(Digit, Base)) | ||
4272 | { | ||
4273 | foreach (bool l7 in YP.unify(N1, YP.add(YP.multiply(N0, Base), Digit))) | ||
4274 | { | ||
4275 | foreach (bool l8 in read_based(Base, N1, N, C)) | ||
4276 | { | ||
4277 | yield return false; | ||
4278 | } | ||
4279 | } | ||
4280 | goto cutIf8; | ||
4281 | } | ||
4282 | if (YP.equal(C1, new ListPair(95, Atom.NIL))) | ||
4283 | { | ||
4284 | foreach (bool l7 in read_based(Base, N0, N, C)) | ||
4285 | { | ||
4286 | yield return false; | ||
4287 | } | ||
4288 | goto cutIf9; | ||
4289 | } | ||
4290 | foreach (bool l6 in YP.unify(N, N0)) | ||
4291 | { | ||
4292 | foreach (bool l7 in YP.unify(C, C1)) | ||
4293 | { | ||
4294 | yield return false; | ||
4295 | } | ||
4296 | } | ||
4297 | cutIf9: | ||
4298 | cutIf8: | ||
4299 | { } | ||
4300 | } | ||
4301 | goto cutIf7; | ||
4302 | } | ||
4303 | } | ||
4304 | foreach (bool l3 in YP.unify(Digit, 99)) | ||
4305 | { | ||
4306 | if (YP.lessThan(Digit, Base)) | ||
4307 | { | ||
4308 | foreach (bool l5 in YP.unify(N1, YP.add(YP.multiply(N0, Base), Digit))) | ||
4309 | { | ||
4310 | foreach (bool l6 in read_based(Base, N1, N, C)) | ||
4311 | { | ||
4312 | yield return false; | ||
4313 | } | ||
4314 | } | ||
4315 | goto cutIf10; | ||
4316 | } | ||
4317 | if (YP.equal(C1, new ListPair(95, Atom.NIL))) | ||
4318 | { | ||
4319 | foreach (bool l5 in read_based(Base, N0, N, C)) | ||
4320 | { | ||
4321 | yield return false; | ||
4322 | } | ||
4323 | goto cutIf11; | ||
4324 | } | ||
4325 | foreach (bool l4 in YP.unify(N, N0)) | ||
4326 | { | ||
4327 | foreach (bool l5 in YP.unify(C, C1)) | ||
4328 | { | ||
4329 | yield return false; | ||
4330 | } | ||
4331 | } | ||
4332 | cutIf11: | ||
4333 | cutIf10: | ||
4334 | { } | ||
4335 | } | ||
4336 | cutIf7: | ||
4337 | cutIf4: | ||
4338 | cutIf1: | ||
4339 | { } | ||
4340 | } | ||
4341 | } | ||
4342 | } | ||
4343 | |||
4344 | public static IEnumerable<bool> read_char(object Char, object Quote, object Result, object Next) | ||
4345 | { | ||
4346 | { | ||
4347 | Variable C1 = new Variable(); | ||
4348 | Variable C2 = new Variable(); | ||
4349 | Variable C3 = new Variable(); | ||
4350 | Variable Ch = new Variable(); | ||
4351 | if (YP.equal(Char, 92)) | ||
4352 | { | ||
4353 | foreach (bool l3 in YP.get_code(C1)) | ||
4354 | { | ||
4355 | if (YP.lessThan(C1, 0)) | ||
4356 | { | ||
4357 | foreach (bool l5 in formatError(Atom.a("user_error"), Atom.a("~N** end of file in ~cquoted~c~n"), new ListPair(Quote, new ListPair(Quote, Atom.NIL)))) | ||
4358 | { | ||
4359 | foreach (bool l6 in YP.unify(Result, -1)) | ||
4360 | { | ||
4361 | foreach (bool l7 in YP.unify(Next, C1)) | ||
4362 | { | ||
4363 | yield return false; | ||
4364 | } | ||
4365 | } | ||
4366 | } | ||
4367 | goto cutIf2; | ||
4368 | } | ||
4369 | if (YP.lessThanOrEqual(C1, new ListPair(32, Atom.NIL))) | ||
4370 | { | ||
4371 | foreach (bool l5 in YP.get_code(C2)) | ||
4372 | { | ||
4373 | foreach (bool l6 in read_char(C2, Quote, Result, Next)) | ||
4374 | { | ||
4375 | yield return false; | ||
4376 | } | ||
4377 | } | ||
4378 | goto cutIf3; | ||
4379 | } | ||
4380 | if (YP.equal(YP.bitwiseOr(C1, 32), new ListPair(99, Atom.NIL))) | ||
4381 | { | ||
4382 | foreach (bool l5 in YP.get_code(C2)) | ||
4383 | { | ||
4384 | foreach (bool l6 in read_char(C2, Quote, Result, Next)) | ||
4385 | { | ||
4386 | yield return false; | ||
4387 | } | ||
4388 | } | ||
4389 | goto cutIf4; | ||
4390 | } | ||
4391 | if (YP.lessThanOrEqual(C1, new ListPair(55, Atom.NIL))) | ||
4392 | { | ||
4393 | if (YP.greaterThanOrEqual(C1, new ListPair(48, Atom.NIL))) | ||
4394 | { | ||
4395 | foreach (bool l6 in YP.get_code(C2)) | ||
4396 | { | ||
4397 | if (YP.lessThanOrEqual(C2, new ListPair(55, Atom.NIL))) | ||
4398 | { | ||
4399 | if (YP.greaterThanOrEqual(C2, new ListPair(48, Atom.NIL))) | ||
4400 | { | ||
4401 | foreach (bool l9 in YP.get_code(C3)) | ||
4402 | { | ||
4403 | if (YP.lessThanOrEqual(C3, new ListPair(55, Atom.NIL))) | ||
4404 | { | ||
4405 | if (YP.greaterThanOrEqual(C3, new ListPair(48, Atom.NIL))) | ||
4406 | { | ||
4407 | foreach (bool l12 in YP.get_code(Next)) | ||
4408 | { | ||
4409 | foreach (bool l13 in YP.unify(Result, YP.subtract(YP.add(YP.multiply(YP.add(YP.multiply(C1, 8), C2), 8), C3), YP.multiply(73, new ListPair(48, Atom.NIL))))) | ||
4410 | { | ||
4411 | yield return false; | ||
4412 | } | ||
4413 | } | ||
4414 | goto cutIf7; | ||
4415 | } | ||
4416 | } | ||
4417 | foreach (bool l10 in YP.unify(Next, C3)) | ||
4418 | { | ||
4419 | foreach (bool l11 in YP.unify(Result, YP.subtract(YP.add(YP.multiply(C1, 8), C2), YP.multiply(9, new ListPair(48, Atom.NIL))))) | ||
4420 | { | ||
4421 | yield return false; | ||
4422 | } | ||
4423 | } | ||
4424 | cutIf7: | ||
4425 | { } | ||
4426 | } | ||
4427 | goto cutIf6; | ||
4428 | } | ||
4429 | } | ||
4430 | foreach (bool l7 in YP.unify(Next, C2)) | ||
4431 | { | ||
4432 | foreach (bool l8 in YP.unify(Result, YP.subtract(C1, new ListPair(48, Atom.NIL)))) | ||
4433 | { | ||
4434 | yield return false; | ||
4435 | } | ||
4436 | } | ||
4437 | cutIf6: | ||
4438 | { } | ||
4439 | } | ||
4440 | goto cutIf5; | ||
4441 | } | ||
4442 | } | ||
4443 | if (YP.equal(C1, new ListPair(94, Atom.NIL))) | ||
4444 | { | ||
4445 | foreach (bool l5 in YP.get_code(C2)) | ||
4446 | { | ||
4447 | if (YP.lessThan(C2, 0)) | ||
4448 | { | ||
4449 | foreach (bool l7 in formatError(Atom.a("user_error"), Atom.a("~N** end of file in ~c..~c^..~c~n"), ListPair.make(new object[] { Quote, 92, Quote }))) | ||
4450 | { | ||
4451 | foreach (bool l8 in YP.unify(Result, -1)) | ||
4452 | { | ||
4453 | foreach (bool l9 in YP.unify(Next, C2)) | ||
4454 | { | ||
4455 | yield return false; | ||
4456 | } | ||
4457 | } | ||
4458 | } | ||
4459 | goto cutIf9; | ||
4460 | } | ||
4461 | if (YP.equal(C2, new ListPair(63, Atom.NIL))) | ||
4462 | { | ||
4463 | foreach (bool l7 in YP.unify(Result, 127)) | ||
4464 | { | ||
4465 | foreach (bool l8 in YP.get_code(Next)) | ||
4466 | { | ||
4467 | yield return false; | ||
4468 | } | ||
4469 | } | ||
4470 | goto cutIf10; | ||
4471 | } | ||
4472 | foreach (bool l6 in YP.unify(Result, YP.bitwiseAnd(C2, 31))) | ||
4473 | { | ||
4474 | foreach (bool l7 in YP.get_code(Next)) | ||
4475 | { | ||
4476 | yield return false; | ||
4477 | } | ||
4478 | } | ||
4479 | cutIf10: | ||
4480 | cutIf9: | ||
4481 | { } | ||
4482 | } | ||
4483 | goto cutIf8; | ||
4484 | } | ||
4485 | foreach (bool l4 in escape_char(C1, Result)) | ||
4486 | { | ||
4487 | foreach (bool l5 in YP.get_code(Next)) | ||
4488 | { | ||
4489 | yield return false; | ||
4490 | } | ||
4491 | goto cutIf11; | ||
4492 | } | ||
4493 | foreach (bool l4 in YP.unify(Result, C1)) | ||
4494 | { | ||
4495 | foreach (bool l5 in YP.get_code(Next)) | ||
4496 | { | ||
4497 | yield return false; | ||
4498 | } | ||
4499 | } | ||
4500 | cutIf11: | ||
4501 | cutIf8: | ||
4502 | cutIf5: | ||
4503 | cutIf4: | ||
4504 | cutIf3: | ||
4505 | cutIf2: | ||
4506 | { } | ||
4507 | } | ||
4508 | goto cutIf1; | ||
4509 | } | ||
4510 | if (YP.equal(Char, Quote)) | ||
4511 | { | ||
4512 | foreach (bool l3 in YP.get_code(Ch)) | ||
4513 | { | ||
4514 | if (YP.equal(Ch, Quote)) | ||
4515 | { | ||
4516 | foreach (bool l5 in YP.unify(Result, Quote)) | ||
4517 | { | ||
4518 | foreach (bool l6 in YP.get_code(Next)) | ||
4519 | { | ||
4520 | yield return false; | ||
4521 | } | ||
4522 | } | ||
4523 | goto cutIf13; | ||
4524 | } | ||
4525 | foreach (bool l4 in YP.unify(Result, -1)) | ||
4526 | { | ||
4527 | foreach (bool l5 in YP.unify(Next, Ch)) | ||
4528 | { | ||
4529 | yield return false; | ||
4530 | } | ||
4531 | } | ||
4532 | cutIf13: | ||
4533 | { } | ||
4534 | } | ||
4535 | goto cutIf12; | ||
4536 | } | ||
4537 | if (YP.lessThan(Char, new ListPair(32, Atom.NIL))) | ||
4538 | { | ||
4539 | if (YP.notEqual(Char, 9)) | ||
4540 | { | ||
4541 | if (YP.notEqual(Char, 10)) | ||
4542 | { | ||
4543 | if (YP.notEqual(Char, 13)) | ||
4544 | { | ||
4545 | foreach (bool l6 in YP.unify(Result, -1)) | ||
4546 | { | ||
4547 | foreach (bool l7 in YP.unify(Next, Char)) | ||
4548 | { | ||
4549 | foreach (bool l8 in formatError(Atom.a("user_error"), Atom.a("~N** Strange character ~d ends ~ctoken~c~n"), ListPair.make(new object[] { Char, Quote, Quote }))) | ||
4550 | { | ||
4551 | yield return false; | ||
4552 | } | ||
4553 | } | ||
4554 | } | ||
4555 | goto cutIf14; | ||
4556 | } | ||
4557 | } | ||
4558 | } | ||
4559 | } | ||
4560 | foreach (bool l2 in YP.unify(Result, Char)) | ||
4561 | { | ||
4562 | foreach (bool l3 in YP.get_code(Next)) | ||
4563 | { | ||
4564 | yield return false; | ||
4565 | } | ||
4566 | } | ||
4567 | cutIf14: | ||
4568 | cutIf12: | ||
4569 | cutIf1: | ||
4570 | { } | ||
4571 | } | ||
4572 | } | ||
4573 | #pragma warning restore 0168, 0219, 0162 | ||
4574 | } | ||
4575 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/PrologException.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/PrologException.cs deleted file mode 100644 index 9f5ae3d..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/PrologException.cs +++ /dev/null | |||
@@ -1,159 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// A PrologException is used as the exception thrown by YP.throw(Term). | ||
37 | /// </summary> | ||
38 | public class PrologException : Exception | ||
39 | { | ||
40 | public readonly object _term; | ||
41 | |||
42 | /// <summary> | ||
43 | /// Create a PrologException with the given Term. The printable exception message is the full Term. | ||
44 | /// </summary> | ||
45 | /// <param name="Term">the term of the exception</param> | ||
46 | public PrologException(object Term) | ||
47 | : base(YP.getValue(Term).ToString()) | ||
48 | { | ||
49 | _term = YP.makeCopy(Term, new Variable.CopyStore()); | ||
50 | } | ||
51 | |||
52 | /// <summary> | ||
53 | /// Create a PrologException where the Term is error(ErrorTerm, Message). | ||
54 | /// This uses YP.makeCopy to copy the ErrorTerm and Message so that they are valid after unbinding. | ||
55 | /// </summary> | ||
56 | /// <param name="ErrorTerm">the error term of the error</param> | ||
57 | /// <param name="Messsage">the message term of the error. If this is a string, it is converted to an | ||
58 | /// Atom so it can be used by Prolog code. | ||
59 | /// Message, converted to a string, is use as the printable exception message. | ||
60 | /// </param> | ||
61 | public PrologException(object ErrorTerm, object Message) | ||
62 | : base(YP.getValue(Message).ToString()) | ||
63 | { | ||
64 | if (Message is string) | ||
65 | Message = Atom.a((string)Message); | ||
66 | _term = YP.makeCopy(new Functor2(Atom.a("error"), ErrorTerm, Message), new Variable.CopyStore()); | ||
67 | } | ||
68 | |||
69 | public class TypeErrorInfo | ||
70 | { | ||
71 | public readonly Atom _Type; | ||
72 | public readonly object _Culprit; | ||
73 | public readonly object _Message; | ||
74 | |||
75 | public TypeErrorInfo(Atom Type, object Culprit, object Message) | ||
76 | { | ||
77 | _Type = Type; | ||
78 | _Culprit = Culprit; | ||
79 | _Message = Message; | ||
80 | } | ||
81 | } | ||
82 | /// <summary> | ||
83 | /// Return the TypeErrorInfo for this exception, or null if _term does not match | ||
84 | /// error(type_error(Type, Culprit), Message). | ||
85 | /// </summary> | ||
86 | /// <returns></returns> | ||
87 | public TypeErrorInfo getTypeErrorInfo() | ||
88 | { | ||
89 | if (!(_term is Functor2 && ((Functor2)_term)._name._name == "error")) | ||
90 | return null; | ||
91 | object errorTerm = ((Functor2)_term)._arg1; | ||
92 | if (!(errorTerm is Functor2 && ((Functor2)errorTerm)._name._name == "type_error")) | ||
93 | return null; | ||
94 | if (!(((Functor2)errorTerm)._arg1 is Atom)) | ||
95 | return null; | ||
96 | return new TypeErrorInfo | ||
97 | ((Atom)((Functor2)errorTerm)._arg1, ((Functor2)errorTerm)._arg2, ((Functor2)_term)._arg2); | ||
98 | } | ||
99 | |||
100 | public class ExistenceErrorInfo | ||
101 | { | ||
102 | public readonly Atom _Type; | ||
103 | public readonly object _Culprit; | ||
104 | public readonly object _Message; | ||
105 | |||
106 | public ExistenceErrorInfo(Atom Type, object Culprit, object Message) | ||
107 | { | ||
108 | _Type = Type; | ||
109 | _Culprit = Culprit; | ||
110 | _Message = Message; | ||
111 | } | ||
112 | |||
113 | /// <summary> | ||
114 | /// If _Type is procedure and _Culprit is name/artity, return the name. Otherwise return null. | ||
115 | /// </summary> | ||
116 | /// <returns></returns> | ||
117 | public object getProcedureName() | ||
118 | { | ||
119 | if (!(_Type._name == "procedure" && | ||
120 | _Culprit is Functor2 && ((Functor2)_Culprit)._name == Atom.SLASH)) | ||
121 | return null; | ||
122 | return ((Functor2)_Culprit)._arg1; | ||
123 | } | ||
124 | |||
125 | /// <summary> | ||
126 | /// If _Type is procedure and _Culprit is name/arity and arity is an integer, return the arity. | ||
127 | /// Otherwise return -1. | ||
128 | /// </summary> | ||
129 | /// <returns></returns> | ||
130 | public int getProcedureArity() | ||
131 | { | ||
132 | if (!(_Type._name == "procedure" && | ||
133 | _Culprit is Functor2 && ((Functor2)_Culprit)._name == Atom.SLASH)) | ||
134 | return -1; | ||
135 | if (!(((Functor2)_Culprit)._arg2 is int)) | ||
136 | return -1; | ||
137 | return (int)((Functor2)_Culprit)._arg2; | ||
138 | } | ||
139 | } | ||
140 | /// <summary> | ||
141 | /// Return the ExistenceErrorInfo for this exception, or null if _term does not match | ||
142 | /// error(existence_error(Type, Culprit), Message). If the returned ExistenceErrorInfo _Culprit is | ||
143 | /// procedure, you can use its getProcedureName and getProcedureArity. | ||
144 | /// </summary> | ||
145 | /// <returns></returns> | ||
146 | public ExistenceErrorInfo getExistenceErrorInfo() | ||
147 | { | ||
148 | if (!(_term is Functor2 && ((Functor2)_term)._name._name == "error")) | ||
149 | return null; | ||
150 | object errorTerm = ((Functor2)_term)._arg1; | ||
151 | if (!(errorTerm is Functor2 && ((Functor2)errorTerm)._name._name == "existence_error")) | ||
152 | return null; | ||
153 | if (!(((Functor2)errorTerm)._arg1 is Atom)) | ||
154 | return null; | ||
155 | return new ExistenceErrorInfo | ||
156 | ((Atom)((Functor2)errorTerm)._arg1, ((Functor2)errorTerm)._arg2, ((Functor2)_term)._arg2); | ||
157 | } | ||
158 | } | ||
159 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Properties/AssemblyInfo.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Properties/AssemblyInfo.cs deleted file mode 100644 index 342dbff..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Properties/AssemblyInfo.cs +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("OpenSim.Region.ScriptEngine.Shared.YieldProlog")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
12 | [assembly: AssemblyProduct("OpenSim")] | ||
13 | [assembly: AssemblyCopyright("OpenSimulator developers")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("8df98e6b-0425-44d6-8d91-2b3b4c56acdf")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | [assembly: AssemblyVersion("0.7.6.*")] | ||
33 | [assembly: AssemblyFileVersion("1.0.0.0")] | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/UndefinedPredicateException.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/UndefinedPredicateException.cs deleted file mode 100644 index 4b6112f..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/UndefinedPredicateException.cs +++ /dev/null | |||
@@ -1,62 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// An UndefinedPredicateException extends PrologException to create an existence_error exception. | ||
37 | /// </summary> | ||
38 | public class UndefinedPredicateException : PrologException | ||
39 | { | ||
40 | private Atom _predicateName; | ||
41 | private int _arity; | ||
42 | |||
43 | public UndefinedPredicateException(object message, Atom predicateName, int arity) | ||
44 | : base(new Functor2 | ||
45 | (Atom.a("existence_error"), Atom.a("procedure"), new Functor2(Atom.a("/"), predicateName, arity)), | ||
46 | message) | ||
47 | { | ||
48 | _predicateName = predicateName; | ||
49 | _arity = arity; | ||
50 | } | ||
51 | |||
52 | public Atom PredicateName | ||
53 | { | ||
54 | get { return _predicateName; } | ||
55 | } | ||
56 | |||
57 | public int Arity | ||
58 | { | ||
59 | get { return _arity; } | ||
60 | } | ||
61 | } | ||
62 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Variable.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Variable.cs deleted file mode 100644 index ea5b7a6..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Variable.cs +++ /dev/null | |||
@@ -1,222 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections; | ||
33 | using System.Collections.Generic; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
36 | { | ||
37 | public interface IUnifiable | ||
38 | { | ||
39 | IEnumerable<bool> unify(object arg); | ||
40 | void addUniqueVariables(List<Variable> variableSet); | ||
41 | object makeCopy(Variable.CopyStore copyStore); | ||
42 | bool termEqual(object term); | ||
43 | bool ground(); | ||
44 | } | ||
45 | |||
46 | /// <summary> | ||
47 | /// A Variable is passed to a function so that it can be unified with | ||
48 | /// value or another Variable. See getValue and unify for details. | ||
49 | /// </summary> | ||
50 | public class Variable : IUnifiable | ||
51 | { | ||
52 | // Use _isBound separate from _value so that it can be bound to any value, | ||
53 | // including null. | ||
54 | private bool _isBound = false; | ||
55 | private object _value; | ||
56 | |||
57 | /// <summary> | ||
58 | /// If this Variable is unbound, then just return this Variable. | ||
59 | /// Otherwise, if this has been bound to a value with unify, return the value. | ||
60 | /// If the bound value is another Variable, this follows the "variable chain" | ||
61 | /// to the end and returns the final value, or the final Variable if it is unbound. | ||
62 | /// For more details, see http://yieldprolog.sourceforge.net/tutorial1.html | ||
63 | /// </summary> | ||
64 | /// <returns></returns> | ||
65 | public object getValue() | ||
66 | { | ||
67 | if (!_isBound) | ||
68 | return this; | ||
69 | |||
70 | object result = _value; | ||
71 | while (result is Variable) | ||
72 | { | ||
73 | if (!((Variable)result)._isBound) | ||
74 | return result; | ||
75 | |||
76 | // Keep following the Variable chain. | ||
77 | result = ((Variable)result)._value; | ||
78 | } | ||
79 | |||
80 | return result; | ||
81 | } | ||
82 | |||
83 | /// <summary> | ||
84 | /// If this Variable is bound, then just call YP.unify to unify this with arg. | ||
85 | /// (Note that if arg is an unbound Variable, then YP.unify will bind it to | ||
86 | /// this Variable's value.) | ||
87 | /// Otherwise, bind this Variable to YP.getValue(arg) and yield once. After the | ||
88 | /// yield, return this Variable to the unbound state. | ||
89 | /// For more details, see http://yieldprolog.sourceforge.net/tutorial1.html | ||
90 | /// </summary> | ||
91 | /// <param name="arg"></param> | ||
92 | /// <returns></returns> | ||
93 | public IEnumerable<bool> unify(object arg) | ||
94 | { | ||
95 | if (!_isBound) | ||
96 | { | ||
97 | _value = YP.getValue(arg); | ||
98 | if (_value == this) | ||
99 | // We are unifying this unbound variable with itself, so leave it unbound. | ||
100 | yield return false; | ||
101 | else | ||
102 | { | ||
103 | _isBound = true; | ||
104 | try | ||
105 | { | ||
106 | yield return false; | ||
107 | } | ||
108 | finally | ||
109 | { | ||
110 | // Remove the binding. | ||
111 | _isBound = false; | ||
112 | } | ||
113 | } | ||
114 | } | ||
115 | else | ||
116 | { | ||
117 | // disable warning on l1, don't see how we can | ||
118 | // code this differently | ||
119 | #pragma warning disable 0168, 0219 | ||
120 | foreach (bool l1 in YP.unify(this, arg)) | ||
121 | yield return false; | ||
122 | #pragma warning restore 0168, 0219 | ||
123 | } | ||
124 | } | ||
125 | |||
126 | public override string ToString() | ||
127 | { | ||
128 | object value = getValue(); | ||
129 | if (value == this) | ||
130 | return "_Variable"; | ||
131 | else | ||
132 | return getValue().ToString(); | ||
133 | } | ||
134 | |||
135 | /// <summary> | ||
136 | /// If bound, call YP.addUniqueVariables on the value. Otherwise, if this unbound | ||
137 | /// variable is not already in variableSet, add it. | ||
138 | /// </summary> | ||
139 | /// <param name="variableSet"></param> | ||
140 | public void addUniqueVariables(List<Variable> variableSet) | ||
141 | { | ||
142 | if (_isBound) | ||
143 | YP.addUniqueVariables(getValue(), variableSet); | ||
144 | else | ||
145 | { | ||
146 | if (variableSet.IndexOf(this) < 0) | ||
147 | variableSet.Add(this); | ||
148 | } | ||
149 | } | ||
150 | |||
151 | /// <summary> | ||
152 | /// If bound, return YP.makeCopy for the value, else return copyStore.getCopy(this). | ||
153 | /// However, if copyStore is null, just return this. | ||
154 | /// </summary> | ||
155 | /// <param name="copyStore"></param> | ||
156 | /// <returns></returns> | ||
157 | public object makeCopy(Variable.CopyStore copyStore) | ||
158 | { | ||
159 | if (_isBound) | ||
160 | return YP.makeCopy(getValue(), copyStore); | ||
161 | else | ||
162 | return copyStore == null ? this : copyStore.getCopy(this); | ||
163 | } | ||
164 | |||
165 | public bool termEqual(object term) | ||
166 | { | ||
167 | if (_isBound) | ||
168 | return YP.termEqual(getValue(), term); | ||
169 | else | ||
170 | return this == YP.getValue(term); | ||
171 | } | ||
172 | |||
173 | public bool ground() | ||
174 | { | ||
175 | if (_isBound) | ||
176 | // This is usually called by YP.ground which already did getValue, so this | ||
177 | // should never be reached, but check anyway. | ||
178 | return YP.ground(getValue()); | ||
179 | else | ||
180 | return false; | ||
181 | } | ||
182 | |||
183 | /// <summary> | ||
184 | /// A CopyStore is used by makeCopy to track which Variable objects have | ||
185 | /// been copied. | ||
186 | /// </summary> | ||
187 | public class CopyStore | ||
188 | { | ||
189 | private List<Variable> _inVariableSet = new List<Variable>(); | ||
190 | private List<Variable> _outVariableSet = new List<Variable>(); | ||
191 | |||
192 | /// <summary> | ||
193 | /// If inVariable has already been copied, return its copy. Otherwise, | ||
194 | /// return a fresh Variable associated with inVariable. | ||
195 | /// </summary> | ||
196 | /// <param name="inVariable"></param> | ||
197 | /// <returns></returns> | ||
198 | public Variable getCopy(Variable inVariable) | ||
199 | { | ||
200 | int index = _inVariableSet.IndexOf(inVariable); | ||
201 | if (index >= 0) | ||
202 | return _outVariableSet[index]; | ||
203 | else | ||
204 | { | ||
205 | Variable outVariable = new Variable(); | ||
206 | _inVariableSet.Add(inVariable); | ||
207 | _outVariableSet.Add(outVariable); | ||
208 | return outVariable; | ||
209 | } | ||
210 | } | ||
211 | |||
212 | /// <summary> | ||
213 | /// Return the number of unique variables that have been copied. | ||
214 | /// </summary> | ||
215 | /// <returns></returns> | ||
216 | public int getNUniqueVariables() | ||
217 | { | ||
218 | return _inVariableSet.Count; | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YP.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YP.cs deleted file mode 100644 index f2171dd..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YP.cs +++ /dev/null | |||
@@ -1,2701 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections; | ||
33 | using System.Collections.Generic; | ||
34 | using System.IO; | ||
35 | using System.Reflection; | ||
36 | using System.Net.Sockets; | ||
37 | using System.Text; | ||
38 | using System.Text.RegularExpressions; | ||
39 | using log4net; | ||
40 | |||
41 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
42 | { | ||
43 | /// <summary> | ||
44 | /// YP has static methods for general functions in Yield Prolog such as <see cref="getValue"/> | ||
45 | /// and <see cref="unify"/>. | ||
46 | /// </summary> | ||
47 | public class YP | ||
48 | { | ||
49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | private static Fail _fail = new Fail(); | ||
51 | private static Repeat _repeat = new Repeat(); | ||
52 | private static Dictionary<NameArity, List<IClause>> _predicatesStore = | ||
53 | new Dictionary<NameArity, List<IClause>>(); | ||
54 | private static TextWriter _outputStream = System.Console.Out; | ||
55 | private static TextReader _inputStream = System.Console.In; | ||
56 | private static IndexedAnswers _operatorTable = null; | ||
57 | private static Dictionary<string, object> _prologFlags = new Dictionary<string, object>(); | ||
58 | public const int MAX_ARITY = 255; | ||
59 | |||
60 | /// <summary> | ||
61 | /// An IClause is used so that dynamic predicates can call match. | ||
62 | /// </summary> | ||
63 | public interface IClause | ||
64 | { | ||
65 | IEnumerable<bool> match(object[] args); | ||
66 | IEnumerable<bool> clause(object Head, object Body); | ||
67 | } | ||
68 | |||
69 | /// <summary> | ||
70 | /// If value is a Variable, then return its getValue. Otherwise, just | ||
71 | /// return value. You should call YP.getValue on any object that | ||
72 | /// may be a Variable to get the value to pass to other functions in | ||
73 | /// your system that are not part of Yield Prolog, such as math functions | ||
74 | /// or file I/O. | ||
75 | /// For more details, see http://yieldprolog.sourceforge.net/tutorial1.html | ||
76 | /// </summary> | ||
77 | /// <param name="value"></param> | ||
78 | /// <returns></returns> | ||
79 | public static object getValue(object value) | ||
80 | { | ||
81 | if (value is Variable) | ||
82 | return ((Variable)value).getValue(); | ||
83 | else | ||
84 | return value; | ||
85 | } | ||
86 | |||
87 | /// <summary> | ||
88 | /// If arg1 or arg2 is an object with a unify method (such as Variable or | ||
89 | /// Functor) then just call its unify with the other argument. The object's | ||
90 | /// unify method will bind the values or check for equals as needed. | ||
91 | /// Otherwise, both arguments are "normal" (atomic) values so if they | ||
92 | /// are equal then succeed (yield once), else fail (don't yield). | ||
93 | /// For more details, see http://yieldprolog.sourceforge.net/tutorial1.html | ||
94 | /// </summary> | ||
95 | /// <param name="arg1"></param> | ||
96 | /// <param name="arg2"></param> | ||
97 | /// <returns></returns> | ||
98 | public static IEnumerable<bool> unify(object arg1, object arg2) | ||
99 | { | ||
100 | arg1 = getValue(arg1); | ||
101 | arg2 = getValue(arg2); | ||
102 | if (arg1 is IUnifiable) | ||
103 | return ((IUnifiable)arg1).unify(arg2); | ||
104 | else if (arg2 is IUnifiable) | ||
105 | return ((IUnifiable)arg2).unify(arg1); | ||
106 | else | ||
107 | { | ||
108 | // Arguments are "normal" types. | ||
109 | if (arg1.Equals(arg2)) | ||
110 | return new Succeed(); | ||
111 | else | ||
112 | return _fail; | ||
113 | } | ||
114 | } | ||
115 | |||
116 | /// <summary> | ||
117 | /// This is used for the lookup key in _factStore. | ||
118 | /// </summary> | ||
119 | public struct NameArity | ||
120 | { | ||
121 | public readonly Atom _name; | ||
122 | public readonly int _arity; | ||
123 | |||
124 | public NameArity(Atom name, int arity) | ||
125 | { | ||
126 | _name = name; | ||
127 | _arity = arity; | ||
128 | } | ||
129 | |||
130 | public override bool Equals(object obj) | ||
131 | { | ||
132 | if (obj is NameArity) | ||
133 | { | ||
134 | NameArity nameArity = (NameArity)obj; | ||
135 | return nameArity._name.Equals(_name) && nameArity._arity.Equals(_arity); | ||
136 | } | ||
137 | else | ||
138 | { | ||
139 | return false; | ||
140 | } | ||
141 | } | ||
142 | |||
143 | public override int GetHashCode() | ||
144 | { | ||
145 | return _name.GetHashCode() ^ _arity.GetHashCode(); | ||
146 | } | ||
147 | } | ||
148 | |||
149 | /// <summary> | ||
150 | /// Convert term to an int. | ||
151 | /// If term is a single-element List, use its first element | ||
152 | /// (to handle the char types like "a"). | ||
153 | /// If can't convert, throw a PrologException for type_error evaluable (because this is only | ||
154 | /// called from arithmetic functions). | ||
155 | /// </summary> | ||
156 | /// <param name="term"></param> | ||
157 | /// <returns></returns> | ||
158 | public static int convertInt(object term) | ||
159 | { | ||
160 | term = YP.getValue(term); | ||
161 | if (term is Functor2 && ((Functor2)term)._name == Atom.DOT && | ||
162 | YP.getValue(((Functor2)term)._arg2) == Atom.NIL) | ||
163 | // Assume it is a char type like "a". | ||
164 | term = YP.getValue(((Functor2)term)._arg1); | ||
165 | if (term is Variable) | ||
166 | throw new PrologException(Atom.a("instantiation_error"), | ||
167 | "Expected a number but the argument is an unbound variable"); | ||
168 | |||
169 | try | ||
170 | { | ||
171 | return (int)term; | ||
172 | } | ||
173 | catch (InvalidCastException) | ||
174 | { | ||
175 | throw new PrologException | ||
176 | (new Functor2 | ||
177 | ("type_error", Atom.a("evaluable"), | ||
178 | new Functor2(Atom.SLASH, getFunctorName(term), getFunctorArgs(term).Length)), | ||
179 | "Term must be an integer"); | ||
180 | } | ||
181 | } | ||
182 | |||
183 | /// <summary> | ||
184 | /// Convert term to a double. This may convert an int to a double, etc. | ||
185 | /// If term is a single-element List, use its first element | ||
186 | /// (to handle the char types like "a"). | ||
187 | /// If can't convert, throw a PrologException for type_error evaluable (because this is only | ||
188 | /// called from arithmetic functions). | ||
189 | /// </summary> | ||
190 | /// <param name="term"></param> | ||
191 | /// <returns></returns> | ||
192 | public static double convertDouble(object term) | ||
193 | { | ||
194 | term = YP.getValue(term); | ||
195 | if (term is Functor2 && ((Functor2)term)._name == Atom.DOT && | ||
196 | YP.getValue(((Functor2)term)._arg2) == Atom.NIL) | ||
197 | // Assume it is a char type like "a". | ||
198 | term = YP.getValue(((Functor2)term)._arg1); | ||
199 | if (term is Variable) | ||
200 | throw new PrologException(Atom.a("instantiation_error"), | ||
201 | "Expected a number but the argument is an unbound variable"); | ||
202 | |||
203 | try | ||
204 | { | ||
205 | return Convert.ToDouble(term); | ||
206 | } | ||
207 | catch (InvalidCastException) | ||
208 | { | ||
209 | throw new PrologException | ||
210 | (new Functor2 | ||
211 | ("type_error", Atom.a("evaluable"), | ||
212 | new Functor2(Atom.SLASH, getFunctorName(term), getFunctorArgs(term).Length)), | ||
213 | "Term must be an integer"); | ||
214 | } | ||
215 | } | ||
216 | |||
217 | /// <summary> | ||
218 | /// If term is an integer, set intTerm. | ||
219 | /// If term is a single-element List, use its first element | ||
220 | /// (to handle the char types like "a"). Return true for success, false if can't convert. | ||
221 | /// We use a success return value because throwing an exception is inefficient. | ||
222 | /// </summary> | ||
223 | /// <param name="term"></param> | ||
224 | /// <returns></returns> | ||
225 | public static bool getInt(object term, out int intTerm) | ||
226 | { | ||
227 | term = YP.getValue(term); | ||
228 | if (term is Functor2 && ((Functor2)term)._name == Atom.DOT && | ||
229 | YP.getValue(((Functor2)term)._arg2) == Atom.NIL) | ||
230 | // Assume it is a char type like "a". | ||
231 | term = YP.getValue(((Functor2)term)._arg1); | ||
232 | |||
233 | if (term is int) | ||
234 | { | ||
235 | intTerm = (int)term; | ||
236 | return true; | ||
237 | } | ||
238 | |||
239 | intTerm = 0; | ||
240 | return false; | ||
241 | } | ||
242 | |||
243 | public static bool equal(object x, object y) | ||
244 | { | ||
245 | x = YP.getValue(x); | ||
246 | if (x is DateTime) | ||
247 | return (DateTime)x == (DateTime)YP.getValue(y); | ||
248 | // Assume convertDouble converts an int to a double perfectly. | ||
249 | return YP.convertDouble(x) == YP.convertDouble(y); | ||
250 | } | ||
251 | |||
252 | public static bool notEqual(object x, object y) | ||
253 | { | ||
254 | x = YP.getValue(x); | ||
255 | if (x is DateTime) | ||
256 | return (DateTime)x != (DateTime)YP.getValue(y); | ||
257 | // Assume convertDouble converts an int to a double perfectly. | ||
258 | return YP.convertDouble(x) != YP.convertDouble(y); | ||
259 | } | ||
260 | |||
261 | public static bool greaterThan(object x, object y) | ||
262 | { | ||
263 | x = YP.getValue(x); | ||
264 | if (x is DateTime) | ||
265 | return (DateTime)x > (DateTime)YP.getValue(y); | ||
266 | // Assume convertDouble converts an int to a double perfectly. | ||
267 | return YP.convertDouble(x) > YP.convertDouble(y); | ||
268 | } | ||
269 | |||
270 | public static bool lessThan(object x, object y) | ||
271 | { | ||
272 | x = YP.getValue(x); | ||
273 | if (x is DateTime) | ||
274 | return (DateTime)x < (DateTime)YP.getValue(y); | ||
275 | // Assume convertDouble converts an int to a double perfectly. | ||
276 | return YP.convertDouble(x) < YP.convertDouble(y); | ||
277 | } | ||
278 | |||
279 | public static bool greaterThanOrEqual(object x, object y) | ||
280 | { | ||
281 | x = YP.getValue(x); | ||
282 | if (x is DateTime) | ||
283 | return (DateTime)x >= (DateTime)YP.getValue(y); | ||
284 | // Assume convertDouble converts an int to a double perfectly. | ||
285 | return YP.convertDouble(x) >= YP.convertDouble(y); | ||
286 | } | ||
287 | |||
288 | public static bool lessThanOrEqual(object x, object y) | ||
289 | { | ||
290 | x = YP.getValue(x); | ||
291 | if (x is DateTime) | ||
292 | return (DateTime)x <= (DateTime)YP.getValue(y); | ||
293 | // Assume convertDouble converts an int to a double perfectly. | ||
294 | return YP.convertDouble(x) <= YP.convertDouble(y); | ||
295 | } | ||
296 | |||
297 | public static object negate(object x) | ||
298 | { | ||
299 | int intX; | ||
300 | if (getInt(x, out intX)) | ||
301 | return -intX; | ||
302 | return -convertDouble(x); | ||
303 | } | ||
304 | |||
305 | public static object abs(object x) | ||
306 | { | ||
307 | int intX; | ||
308 | if (getInt(x, out intX)) | ||
309 | return Math.Abs(intX); | ||
310 | return Math.Abs(convertDouble(x)); | ||
311 | } | ||
312 | |||
313 | public static object sign(object x) | ||
314 | { | ||
315 | int intX; | ||
316 | if (getInt(x, out intX)) | ||
317 | return Math.Sign(intX); | ||
318 | return Math.Sign(convertDouble(x)); | ||
319 | } | ||
320 | |||
321 | // Use toFloat instead of float because it is a reserved keyword. | ||
322 | public static object toFloat(object x) | ||
323 | { | ||
324 | return convertDouble(x); | ||
325 | } | ||
326 | |||
327 | /// <summary> | ||
328 | /// The ISO standard returns an int. | ||
329 | /// </summary> | ||
330 | /// <param name="x"></param> | ||
331 | /// <returns></returns> | ||
332 | public static object floor(object x) | ||
333 | { | ||
334 | return (int)Math.Floor(convertDouble(x)); | ||
335 | } | ||
336 | |||
337 | /// <summary> | ||
338 | /// The ISO standard returns an int. | ||
339 | /// </summary> | ||
340 | /// <param name="x"></param> | ||
341 | /// <returns></returns> | ||
342 | public static object truncate(object x) | ||
343 | { | ||
344 | return (int)Math.Truncate(convertDouble(x)); | ||
345 | } | ||
346 | |||
347 | /// <summary> | ||
348 | /// The ISO standard returns an int. | ||
349 | /// </summary> | ||
350 | /// <param name="x"></param> | ||
351 | /// <returns></returns> | ||
352 | public static object round(object x) | ||
353 | { | ||
354 | return (int)Math.Round(convertDouble(x)); | ||
355 | } | ||
356 | |||
357 | /// <summary> | ||
358 | /// The ISO standard returns an int. | ||
359 | /// </summary> | ||
360 | /// <param name="x"></param> | ||
361 | /// <returns></returns> | ||
362 | public static object ceiling(object x) | ||
363 | { | ||
364 | return (int)Math.Ceiling(convertDouble(x)); | ||
365 | } | ||
366 | |||
367 | public static object sin(object x) | ||
368 | { | ||
369 | return Math.Sin(YP.convertDouble(x)); | ||
370 | } | ||
371 | |||
372 | public static object cos(object x) | ||
373 | { | ||
374 | return Math.Cos(YP.convertDouble(x)); | ||
375 | } | ||
376 | |||
377 | public static object atan(object x) | ||
378 | { | ||
379 | return Math.Atan(YP.convertDouble(x)); | ||
380 | } | ||
381 | |||
382 | public static object exp(object x) | ||
383 | { | ||
384 | return Math.Exp(YP.convertDouble(x)); | ||
385 | } | ||
386 | |||
387 | public static object log(object x) | ||
388 | { | ||
389 | return Math.Log(YP.convertDouble(x)); | ||
390 | } | ||
391 | |||
392 | public static object sqrt(object x) | ||
393 | { | ||
394 | return Math.Sqrt(convertDouble(x)); | ||
395 | } | ||
396 | |||
397 | public static object bitwiseComplement(object x) | ||
398 | { | ||
399 | return ~YP.convertInt(x); | ||
400 | } | ||
401 | |||
402 | public static object add(object x, object y) | ||
403 | { | ||
404 | int intX, intY; | ||
405 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
406 | return intX + intY; | ||
407 | return convertDouble(x) + convertDouble(y); | ||
408 | } | ||
409 | |||
410 | public static object subtract(object x, object y) | ||
411 | { | ||
412 | int intX, intY; | ||
413 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
414 | return intX - intY; | ||
415 | return convertDouble(x) - convertDouble(y); | ||
416 | } | ||
417 | |||
418 | public static object multiply(object x, object y) | ||
419 | { | ||
420 | int intX, intY; | ||
421 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
422 | return intX * intY; | ||
423 | return convertDouble(x) * convertDouble(y); | ||
424 | } | ||
425 | |||
426 | /// <summary> | ||
427 | /// Return floating point, even if both arguments are integer. | ||
428 | /// </summary> | ||
429 | /// <param name="x"></param> | ||
430 | /// <param name="y"></param> | ||
431 | /// <returns></returns> | ||
432 | public static object divide(object x, object y) | ||
433 | { | ||
434 | return convertDouble(x) / convertDouble(y); | ||
435 | } | ||
436 | |||
437 | public static object intDivide(object x, object y) | ||
438 | { | ||
439 | int intX, intY; | ||
440 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
441 | return intX / intY; | ||
442 | // Still allow passing a double, but treat as an int. | ||
443 | return (int)convertDouble(x) / (int)convertDouble(y); | ||
444 | } | ||
445 | |||
446 | public static object mod(object x, object y) | ||
447 | { | ||
448 | int intX, intY; | ||
449 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
450 | return intX % intY; | ||
451 | // Still allow passing a double, but treat as an int. | ||
452 | return (int)convertDouble(x) % (int)convertDouble(y); | ||
453 | } | ||
454 | |||
455 | public static object pow(object x, object y) | ||
456 | { | ||
457 | return Math.Pow(YP.convertDouble(x), YP.convertDouble(y)); | ||
458 | } | ||
459 | |||
460 | public static object bitwiseShiftRight(object x, object y) | ||
461 | { | ||
462 | return YP.convertInt(x) >> YP.convertInt(y); | ||
463 | } | ||
464 | |||
465 | public static object bitwiseShiftLeft(object x, object y) | ||
466 | { | ||
467 | return YP.convertInt(x) << YP.convertInt(y); | ||
468 | } | ||
469 | |||
470 | public static object bitwiseAnd(object x, object y) | ||
471 | { | ||
472 | return YP.convertInt(x) & YP.convertInt(y); | ||
473 | } | ||
474 | |||
475 | public static object bitwiseOr(object x, object y) | ||
476 | { | ||
477 | return YP.convertInt(x) | YP.convertInt(y); | ||
478 | } | ||
479 | |||
480 | public static object min(object x, object y) | ||
481 | { | ||
482 | int intX, intY; | ||
483 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
484 | return Math.Min(intX, intY); | ||
485 | return Math.Min(convertDouble(x), convertDouble(y)); | ||
486 | } | ||
487 | |||
488 | public static object max(object x, object y) | ||
489 | { | ||
490 | int intX, intY; | ||
491 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
492 | return Math.Max(intX, intY); | ||
493 | return Math.Max(convertDouble(x), convertDouble(y)); | ||
494 | } | ||
495 | |||
496 | public static IEnumerable<bool> copy_term(object inTerm, object outTerm) | ||
497 | { | ||
498 | return YP.unify(outTerm, YP.makeCopy(inTerm, new Variable.CopyStore())); | ||
499 | } | ||
500 | |||
501 | public static void addUniqueVariables(object term, List<Variable> variableSet) | ||
502 | { | ||
503 | term = YP.getValue(term); | ||
504 | if (term is IUnifiable) | ||
505 | ((IUnifiable)term).addUniqueVariables(variableSet); | ||
506 | } | ||
507 | |||
508 | public static object makeCopy(object term, Variable.CopyStore copyStore) | ||
509 | { | ||
510 | term = YP.getValue(term); | ||
511 | if (term is IUnifiable) | ||
512 | return ((IUnifiable)term).makeCopy(copyStore); | ||
513 | else | ||
514 | // term is a "normal" type. Assume it is ground. | ||
515 | return term; | ||
516 | } | ||
517 | |||
518 | /// <summary> | ||
519 | /// Sort the array in place according to termLessThan. This does not remove duplicates | ||
520 | /// </summary> | ||
521 | /// <param name="array"></param> | ||
522 | public static void sortArray(object[] array) | ||
523 | { | ||
524 | Array.Sort(array, YP.compareTerms); | ||
525 | } | ||
526 | |||
527 | /// <summary> | ||
528 | /// Sort the array in place according to termLessThan. This does not remove duplicates | ||
529 | /// </summary> | ||
530 | /// <param name="array"></param> | ||
531 | public static void sortArray(List<object> array) | ||
532 | { | ||
533 | array.Sort(YP.compareTerms); | ||
534 | } | ||
535 | |||
536 | /// <summary> | ||
537 | /// Sort List according to termLessThan, remove duplicates and unify with Sorted. | ||
538 | /// </summary> | ||
539 | /// <param name="List"></param> | ||
540 | /// <param name="Sorted"></param> | ||
541 | /// <returns></returns> | ||
542 | public static IEnumerable<bool> sort(object List, object Sorted) | ||
543 | { | ||
544 | object[] array = ListPair.toArray(List); | ||
545 | if (array == null) | ||
546 | return YP.fail(); | ||
547 | if (array.Length > 1) | ||
548 | sortArray(array); | ||
549 | return YP.unify(Sorted, ListPair.makeWithoutRepeatedTerms(array)); | ||
550 | } | ||
551 | |||
552 | /// <summary> | ||
553 | /// Use YP.unify to unify each of the elements of the two arrays, and yield | ||
554 | /// once if they all unify. | ||
555 | /// </summary> | ||
556 | /// <param name="array1"></param> | ||
557 | /// <param name="array2"></param> | ||
558 | /// <returns></returns> | ||
559 | public static IEnumerable<bool> unifyArrays(object[] array1, object[] array2) | ||
560 | { | ||
561 | if (array1.Length != array2.Length) | ||
562 | yield break; | ||
563 | |||
564 | IEnumerator<bool>[] iterators = new IEnumerator<bool>[array1.Length]; | ||
565 | bool gotMatch = true; | ||
566 | int nIterators = 0; | ||
567 | // Try to bind all the arguments. | ||
568 | for (int i = 0; i < array1.Length; ++i) | ||
569 | { | ||
570 | IEnumerator<bool> iterator = YP.unify(array1[i], array2[i]).GetEnumerator(); | ||
571 | iterators[nIterators++] = iterator; | ||
572 | // MoveNext() is true if YP.unify succeeds. | ||
573 | if (!iterator.MoveNext()) | ||
574 | { | ||
575 | gotMatch = false; | ||
576 | break; | ||
577 | } | ||
578 | } | ||
579 | int z = 0; | ||
580 | try | ||
581 | { | ||
582 | if (gotMatch) | ||
583 | yield return false; | ||
584 | } | ||
585 | finally | ||
586 | { | ||
587 | // Manually finalize all the iterators. | ||
588 | for (z = 0; z < nIterators; ++z) | ||
589 | iterators[z].Dispose(); | ||
590 | } | ||
591 | } | ||
592 | |||
593 | /// <summary> | ||
594 | /// Return an iterator (which you can use in a for-in loop) which does | ||
595 | /// zero iterations. This returns a pre-existing iterator which is | ||
596 | /// more efficient than letting the compiler generate a new one. | ||
597 | /// </summary> | ||
598 | /// <returns></returns> | ||
599 | public static IEnumerable<bool> fail() | ||
600 | { | ||
601 | return _fail; | ||
602 | } | ||
603 | |||
604 | /// <summary> | ||
605 | /// Return an iterator (which you can use in a for-in loop) which does | ||
606 | /// one iteration. This returns a pre-existing iterator which is | ||
607 | /// more efficient than letting the compiler generate a new one. | ||
608 | /// </summary> | ||
609 | /// <returns></returns> | ||
610 | public static IEnumerable<bool> succeed() | ||
611 | { | ||
612 | return new Succeed(); | ||
613 | } | ||
614 | |||
615 | /// <summary> | ||
616 | /// Return an iterator (which you can use in a for-in loop) which repeats | ||
617 | /// indefinitely. This returns a pre-existing iterator which is | ||
618 | /// more efficient than letting the compiler generate a new one. | ||
619 | /// </summary> | ||
620 | /// <returns></returns> | ||
621 | public static IEnumerable<bool> repeat() | ||
622 | { | ||
623 | return _repeat; | ||
624 | } | ||
625 | |||
626 | // disable warning on l1, don't see how we can | ||
627 | // code this differently | ||
628 | #pragma warning disable 0168, 0219 | ||
629 | public static IEnumerable<bool> univ(object Term, object List) | ||
630 | { | ||
631 | Term = YP.getValue(Term); | ||
632 | List = YP.getValue(List); | ||
633 | |||
634 | if (nonvar(Term)) | ||
635 | return YP.unify(new ListPair | ||
636 | (getFunctorName(Term), ListPair.make(getFunctorArgs(Term))), List); | ||
637 | |||
638 | Variable Name = new Variable(); | ||
639 | Variable ArgList = new Variable(); | ||
640 | foreach (bool l1 in new ListPair(Name, ArgList).unify(List)) | ||
641 | { | ||
642 | object[] args = ListPair.toArray(ArgList); | ||
643 | if (args == null) | ||
644 | throw new PrologException | ||
645 | (new Functor2("type_error", Atom.a("list"), ArgList), | ||
646 | "Expected a list. Got: " + ArgList.getValue()); | ||
647 | if (args.Length == 0) | ||
648 | // Return the Name, even if it is not an Atom. | ||
649 | return YP.unify(Term, Name); | ||
650 | if (args.Length > MAX_ARITY) | ||
651 | throw new PrologException | ||
652 | (new Functor1("representation_error", Atom.a("max_arity")), | ||
653 | "Functor arity " + args.Length + " may not be greater than " + MAX_ARITY); | ||
654 | if (!atom(Name)) | ||
655 | throw new PrologException | ||
656 | (new Functor2("type_error", Atom.a("atom"), Name), | ||
657 | "Expected an atom. Got: " + Name.getValue()); | ||
658 | |||
659 | return YP.unify(Term, Functor.make((Atom)YP.getValue(Name), args)); | ||
660 | } | ||
661 | |||
662 | return YP.fail(); | ||
663 | } | ||
664 | |||
665 | public static IEnumerable<bool> functor(object Term, object FunctorName, object Arity) | ||
666 | { | ||
667 | Term = YP.getValue(Term); | ||
668 | FunctorName = YP.getValue(FunctorName); | ||
669 | Arity = YP.getValue(Arity); | ||
670 | |||
671 | if (Term is Variable) | ||
672 | { | ||
673 | if (FunctorName is Variable) | ||
674 | throw new PrologException(Atom.a("instantiation_error"), | ||
675 | "Arg 2 FunctorName is an unbound variable"); | ||
676 | if (Arity is Variable) | ||
677 | throw new PrologException(Atom.a("instantiation_error"), | ||
678 | "Arg 3 Arity is an unbound variable"); | ||
679 | if (!(Arity is int)) | ||
680 | throw new PrologException | ||
681 | (new Functor2("type_error", Atom.a("integer"), Arity), "Arity is not an integer"); | ||
682 | if (!YP.atomic(FunctorName)) | ||
683 | throw new PrologException | ||
684 | (new Functor2("type_error", Atom.a("atomic"), FunctorName), "FunctorName is not atomic"); | ||
685 | |||
686 | if ((int)Arity < 0) | ||
687 | throw new PrologException | ||
688 | (new Functor2("domain_error", Atom.a("not_less_than_zero"), Arity), | ||
689 | "Arity may not be less than zero"); | ||
690 | else if ((int)Arity == 0) | ||
691 | { | ||
692 | // Just unify Term with the atomic FunctorName. | ||
693 | foreach (bool l1 in YP.unify(Term, FunctorName)) | ||
694 | yield return false; | ||
695 | } | ||
696 | else | ||
697 | { | ||
698 | if ((int)Arity > MAX_ARITY) | ||
699 | throw new PrologException | ||
700 | (new Functor1("representation_error", Atom.a("max_arity")), | ||
701 | "Functor arity " + Arity + " may not be greater than " + MAX_ARITY); | ||
702 | if (!(FunctorName is Atom)) | ||
703 | throw new PrologException | ||
704 | (new Functor2("type_error", Atom.a("atom"), FunctorName), "FunctorName is not an atom"); | ||
705 | // Construct a functor with unbound variables. | ||
706 | object[] args = new object[(int)Arity]; | ||
707 | for (int i = 0; i < args.Length; ++i) | ||
708 | args[i] = new Variable(); | ||
709 | foreach (bool l1 in YP.unify(Term, Functor.make((Atom)FunctorName, args))) | ||
710 | yield return false; | ||
711 | } | ||
712 | } | ||
713 | else | ||
714 | { | ||
715 | foreach (bool l1 in YP.unify(FunctorName, getFunctorName(Term))) | ||
716 | { | ||
717 | foreach (bool l2 in YP.unify(Arity, getFunctorArgs(Term).Length)) | ||
718 | yield return false; | ||
719 | } | ||
720 | } | ||
721 | } | ||
722 | |||
723 | public static IEnumerable<bool> arg(object ArgNumber, object Term, object Value) | ||
724 | { | ||
725 | if (var(ArgNumber)) | ||
726 | throw new PrologException(Atom.a("instantiation_error"), "Arg 1 ArgNumber is an unbound variable"); | ||
727 | int argNumberInt; | ||
728 | if (!getInt(ArgNumber, out argNumberInt)) | ||
729 | throw new PrologException | ||
730 | (new Functor2("type_error", Atom.a("integer"), ArgNumber), "Arg 1 ArgNumber must be integer"); | ||
731 | if (argNumberInt < 0) | ||
732 | throw new PrologException | ||
733 | (new Functor2("domain_error", Atom.a("not_less_than_zero"), argNumberInt), | ||
734 | "ArgNumber may not be less than zero"); | ||
735 | |||
736 | if (YP.var(Term)) | ||
737 | throw new PrologException(Atom.a("instantiation_error"), | ||
738 | "Arg 2 Term is an unbound variable"); | ||
739 | if (!YP.compound(Term)) | ||
740 | throw new PrologException | ||
741 | (new Functor2("type_error", Atom.a("compound"), Term), "Arg 2 Term must be compound"); | ||
742 | |||
743 | object[] termArgs = YP.getFunctorArgs(Term); | ||
744 | // Silently fail if argNumberInt is out of range. | ||
745 | if (argNumberInt >= 1 && argNumberInt <= termArgs.Length) | ||
746 | { | ||
747 | // The first ArgNumber is at 1, not 0. | ||
748 | foreach (bool l1 in YP.unify(Value, termArgs[argNumberInt - 1])) | ||
749 | yield return false; | ||
750 | } | ||
751 | } | ||
752 | |||
753 | public static bool termEqual(object Term1, object Term2) | ||
754 | { | ||
755 | Term1 = YP.getValue(Term1); | ||
756 | if (Term1 is IUnifiable) | ||
757 | return ((IUnifiable)Term1).termEqual(Term2); | ||
758 | return Term1.Equals(YP.getValue(Term2)); | ||
759 | } | ||
760 | |||
761 | public static bool termNotEqual(object Term1, object Term2) | ||
762 | { | ||
763 | return !termEqual(Term1, Term2); | ||
764 | } | ||
765 | |||
766 | public static bool termLessThan(object Term1, object Term2) | ||
767 | { | ||
768 | Term1 = YP.getValue(Term1); | ||
769 | Term2 = YP.getValue(Term2); | ||
770 | int term1TypeCode = getTypeCode(Term1); | ||
771 | int term2TypeCode = getTypeCode(Term2); | ||
772 | if (term1TypeCode != term2TypeCode) | ||
773 | return term1TypeCode < term2TypeCode; | ||
774 | |||
775 | // The terms are the same type code. | ||
776 | if (term1TypeCode == -2) | ||
777 | { | ||
778 | // Variable. | ||
779 | // We always check for equality first because we want to be sure | ||
780 | // that less than returns false if the terms are equal, in | ||
781 | // case that the less than check really behaves like less than or equal. | ||
782 | if ((Variable)Term1 != (Variable)Term2) | ||
783 | // The hash code should be unique to a Variable object. | ||
784 | return Term1.GetHashCode() < Term2.GetHashCode(); | ||
785 | return false; | ||
786 | } | ||
787 | if (term1TypeCode == 0) | ||
788 | return ((Atom)Term1)._name.CompareTo(((Atom)Term2)._name) < 0; | ||
789 | if (term1TypeCode == 1) | ||
790 | return ((Functor1)Term1).lessThan((Functor1)Term2); | ||
791 | if (term1TypeCode == 2) | ||
792 | return ((Functor2)Term1).lessThan((Functor2)Term2); | ||
793 | if (term1TypeCode == 3) | ||
794 | return ((Functor3)Term1).lessThan((Functor3)Term2); | ||
795 | if (term1TypeCode == 4) | ||
796 | return ((Functor)Term1).lessThan((Functor)Term2); | ||
797 | |||
798 | // Type code is -1 for general objects. First compare their type names. | ||
799 | // Note that this puts Double before Int32 as required by ISO Prolog. | ||
800 | string term1TypeName = Term1.GetType().ToString(); | ||
801 | string term2TypeName = Term2.GetType().ToString(); | ||
802 | if (term1TypeName != term2TypeName) | ||
803 | return term1TypeName.CompareTo(term2TypeName) < 0; | ||
804 | |||
805 | // The terms are the same type name. | ||
806 | if (Term1 is int) | ||
807 | return (int)Term1 < (int)Term2; | ||
808 | else if (Term1 is double) | ||
809 | return (double)Term1 < (double)Term2; | ||
810 | else if (Term1 is DateTime) | ||
811 | return (DateTime)Term1 < (DateTime)Term2; | ||
812 | else if (Term1 is String) | ||
813 | return ((String)Term1).CompareTo((String)Term2) < 0; | ||
814 | // Debug: Should we try arrays, etc.? | ||
815 | |||
816 | if (!Term1.Equals(Term2)) | ||
817 | // Could be equal or greater than. | ||
818 | return Term1.GetHashCode() < Term2.GetHashCode(); | ||
819 | return false; | ||
820 | } | ||
821 | |||
822 | /// <summary> | ||
823 | /// Type code is -2 if term is a Variable, 0 if it is an Atom, | ||
824 | /// 1 if it is a Functor1, 2 if it is a Functor2, 3 if it is a Functor3, | ||
825 | /// 4 if it is Functor. | ||
826 | /// Otherwise, type code is -1. | ||
827 | /// This does not call YP.getValue(term). | ||
828 | /// </summary> | ||
829 | /// <param name="term"></param> | ||
830 | /// <returns></returns> | ||
831 | private static int getTypeCode(object term) | ||
832 | { | ||
833 | if (term is Variable) | ||
834 | return -2; | ||
835 | else if (term is Atom) | ||
836 | return 0; | ||
837 | else if (term is Functor1) | ||
838 | return 1; | ||
839 | else if (term is Functor2) | ||
840 | return 2; | ||
841 | else if (term is Functor3) | ||
842 | return 3; | ||
843 | else if (term is Functor) | ||
844 | return 4; | ||
845 | else | ||
846 | return -1; | ||
847 | } | ||
848 | |||
849 | public static bool termLessThanOrEqual(object Term1, object Term2) | ||
850 | { | ||
851 | if (YP.termEqual(Term1, Term2)) | ||
852 | return true; | ||
853 | return YP.termLessThan(Term1, Term2); | ||
854 | } | ||
855 | |||
856 | public static bool termGreaterThan(object Term1, object Term2) | ||
857 | { | ||
858 | return !YP.termLessThanOrEqual(Term1, Term2); | ||
859 | } | ||
860 | |||
861 | public static bool termGreaterThanOrEqual(object Term1, object Term2) | ||
862 | { | ||
863 | // termLessThan should ensure that it returns false if terms are equal, | ||
864 | // so that this would return true. | ||
865 | return !YP.termLessThan(Term1, Term2); | ||
866 | } | ||
867 | |||
868 | public static int compareTerms(object Term1, object Term2) | ||
869 | { | ||
870 | if (YP.termEqual(Term1, Term2)) | ||
871 | return 0; | ||
872 | else if (YP.termLessThan(Term1, Term2)) | ||
873 | return -1; | ||
874 | else | ||
875 | return 1; | ||
876 | } | ||
877 | |||
878 | public static bool ground(object Term) | ||
879 | { | ||
880 | Term = YP.getValue(Term); | ||
881 | if (Term is IUnifiable) | ||
882 | return ((IUnifiable)Term).ground(); | ||
883 | return true; | ||
884 | } | ||
885 | |||
886 | public static IEnumerable<bool> current_op | ||
887 | (object Priority, object Specifier, object Operator) | ||
888 | { | ||
889 | if (_operatorTable == null) | ||
890 | { | ||
891 | // Initialize. | ||
892 | _operatorTable = new IndexedAnswers(3); | ||
893 | _operatorTable.addAnswer(new object[] { 1200, Atom.a("xfx"), Atom.a(":-") }); | ||
894 | _operatorTable.addAnswer(new object[] { 1200, Atom.a("xfx"), Atom.a("-->") }); | ||
895 | _operatorTable.addAnswer(new object[] { 1200, Atom.a("fx"), Atom.a(":-") }); | ||
896 | _operatorTable.addAnswer(new object[] { 1200, Atom.a("fx"), Atom.a("?-") }); | ||
897 | _operatorTable.addAnswer(new object[] { 1100, Atom.a("xfy"), Atom.a(";") }); | ||
898 | _operatorTable.addAnswer(new object[] { 1050, Atom.a("xfy"), Atom.a("->") }); | ||
899 | _operatorTable.addAnswer(new object[] { 1000, Atom.a("xfy"), Atom.a(",") }); | ||
900 | _operatorTable.addAnswer(new object[] { 900, Atom.a("fy"), Atom.a("\\+") }); | ||
901 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("=") }); | ||
902 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("\\=") }); | ||
903 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("==") }); | ||
904 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("\\==") }); | ||
905 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("@<") }); | ||
906 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("@=<") }); | ||
907 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("@>") }); | ||
908 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("@>=") }); | ||
909 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("=..") }); | ||
910 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("is") }); | ||
911 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("=:=") }); | ||
912 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("=\\=") }); | ||
913 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("<") }); | ||
914 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("=<") }); | ||
915 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a(">") }); | ||
916 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a(">=") }); | ||
917 | _operatorTable.addAnswer(new object[] { 600, Atom.a("xfy"), Atom.a(":") }); | ||
918 | _operatorTable.addAnswer(new object[] { 500, Atom.a("yfx"), Atom.a("+") }); | ||
919 | _operatorTable.addAnswer(new object[] { 500, Atom.a("yfx"), Atom.a("-") }); | ||
920 | _operatorTable.addAnswer(new object[] { 500, Atom.a("yfx"), Atom.a("/\\") }); | ||
921 | _operatorTable.addAnswer(new object[] { 500, Atom.a("yfx"), Atom.a("\\/") }); | ||
922 | _operatorTable.addAnswer(new object[] { 400, Atom.a("yfx"), Atom.a("*") }); | ||
923 | _operatorTable.addAnswer(new object[] { 400, Atom.a("yfx"), Atom.a("/") }); | ||
924 | _operatorTable.addAnswer(new object[] { 400, Atom.a("yfx"), Atom.a("//") }); | ||
925 | _operatorTable.addAnswer(new object[] { 400, Atom.a("yfx"), Atom.a("rem") }); | ||
926 | _operatorTable.addAnswer(new object[] { 400, Atom.a("yfx"), Atom.a("mod") }); | ||
927 | _operatorTable.addAnswer(new object[] { 400, Atom.a("yfx"), Atom.a("<<") }); | ||
928 | _operatorTable.addAnswer(new object[] { 400, Atom.a("yfx"), Atom.a(">>") }); | ||
929 | _operatorTable.addAnswer(new object[] { 200, Atom.a("xfx"), Atom.a("**") }); | ||
930 | _operatorTable.addAnswer(new object[] { 200, Atom.a("xfy"), Atom.a("^") }); | ||
931 | _operatorTable.addAnswer(new object[] { 200, Atom.a("fy"), Atom.a("-") }); | ||
932 | _operatorTable.addAnswer(new object[] { 200, Atom.a("fy"), Atom.a("\\") }); | ||
933 | // Debug: This is hacked in to run the Prolog test suite until we implement op/3. | ||
934 | _operatorTable.addAnswer(new object[] { 20, Atom.a("xfx"), Atom.a("<--") }); | ||
935 | } | ||
936 | |||
937 | return _operatorTable.match(new object[] { Priority, Specifier, Operator }); | ||
938 | } | ||
939 | |||
940 | public static IEnumerable<bool> atom_length(object atom, object Length) | ||
941 | { | ||
942 | atom = YP.getValue(atom); | ||
943 | Length = YP.getValue(Length); | ||
944 | if (atom is Variable) | ||
945 | throw new PrologException(Atom.a("instantiation_error"), | ||
946 | "Expected atom(Arg1) but it is an unbound variable"); | ||
947 | if (!(atom is Atom)) | ||
948 | throw new PrologException | ||
949 | (new Functor2("type_error", Atom.a("atom"), atom), "Arg 1 Atom is not an atom"); | ||
950 | if (!(Length is Variable)) | ||
951 | { | ||
952 | if (!(Length is int)) | ||
953 | throw new PrologException | ||
954 | (new Functor2("type_error", Atom.a("integer"), Length), "Length must be var or integer"); | ||
955 | if ((int)Length < 0) | ||
956 | throw new PrologException | ||
957 | (new Functor2("domain_error", Atom.a("not_less_than_zero"), Length), | ||
958 | "Length must not be less than zero"); | ||
959 | } | ||
960 | return YP.unify(Length, ((Atom)atom)._name.Length); | ||
961 | } | ||
962 | |||
963 | public static IEnumerable<bool> atom_concat(object Start, object End, object Whole) | ||
964 | { | ||
965 | // Debug: Should we try to preserve the _declaringClass? | ||
966 | Start = YP.getValue(Start); | ||
967 | End = YP.getValue(End); | ||
968 | Whole = YP.getValue(Whole); | ||
969 | if (Whole is Variable) | ||
970 | { | ||
971 | if (Start is Variable) | ||
972 | throw new PrologException(Atom.a("instantiation_error"), | ||
973 | "Arg 1 Start and arg 3 Whole are both var"); | ||
974 | if (End is Variable) | ||
975 | throw new PrologException(Atom.a("instantiation_error"), | ||
976 | "Arg 2 End and arg 3 Whole are both var"); | ||
977 | if (!(Start is Atom)) | ||
978 | throw new PrologException | ||
979 | (new Functor2("type_error", Atom.a("atom"), Start), "Arg 1 Start is not an atom"); | ||
980 | if (!(End is Atom)) | ||
981 | throw new PrologException | ||
982 | (new Functor2("type_error", Atom.a("atom"), End), "Arg 2 End is not an atom"); | ||
983 | |||
984 | foreach (bool l1 in YP.unify(Whole, Atom.a(((Atom)Start)._name + ((Atom)End)._name))) | ||
985 | yield return false; | ||
986 | } | ||
987 | else | ||
988 | { | ||
989 | if (!(Whole is Atom)) | ||
990 | throw new PrologException | ||
991 | (new Functor2("type_error", Atom.a("atom"), Whole), "Arg 3 Whole is not an atom"); | ||
992 | bool gotStartLength = false; | ||
993 | int startLength = 0; | ||
994 | if (!(Start is Variable)) | ||
995 | { | ||
996 | if (!(Start is Atom)) | ||
997 | throw new PrologException | ||
998 | (new Functor2("type_error", Atom.a("atom"), Start), "Arg 1 Start is not var or atom"); | ||
999 | startLength = ((Atom)Start)._name.Length; | ||
1000 | gotStartLength = true; | ||
1001 | } | ||
1002 | |||
1003 | bool gotEndLength = false; | ||
1004 | int endLength = 0; | ||
1005 | if (!(End is Variable)) | ||
1006 | { | ||
1007 | if (!(End is Atom)) | ||
1008 | throw new PrologException | ||
1009 | (new Functor2("type_error", Atom.a("atom"), End), "Arg 2 End is not var or atom"); | ||
1010 | endLength = ((Atom)End)._name.Length; | ||
1011 | gotEndLength = true; | ||
1012 | } | ||
1013 | |||
1014 | // We are doing a search through all possible Start and End which concatenate to Whole. | ||
1015 | string wholeString = ((Atom)Whole)._name; | ||
1016 | for (int i = 0; i <= wholeString.Length; ++i) | ||
1017 | { | ||
1018 | // If we got either startLength or endLength, we know the lengths have to match so check | ||
1019 | // the lengths instead of constructing an Atom to do it. | ||
1020 | if (gotStartLength && startLength != i) | ||
1021 | continue; | ||
1022 | if (gotEndLength && endLength != wholeString.Length - i) | ||
1023 | continue; | ||
1024 | foreach (bool l1 in YP.unify(Start, Atom.a(wholeString.Substring(0, i)))) | ||
1025 | { | ||
1026 | foreach (bool l2 in YP.unify(End, Atom.a(wholeString.Substring(i, wholeString.Length - i)))) | ||
1027 | yield return false; | ||
1028 | } | ||
1029 | } | ||
1030 | } | ||
1031 | } | ||
1032 | |||
1033 | public static IEnumerable<bool> sub_atom | ||
1034 | (object atom, object Before, object Length, object After, object Sub_atom) | ||
1035 | { | ||
1036 | // Debug: Should we try to preserve the _declaringClass? | ||
1037 | atom = YP.getValue(atom); | ||
1038 | Before = YP.getValue(Before); | ||
1039 | Length = YP.getValue(Length); | ||
1040 | After = YP.getValue(After); | ||
1041 | Sub_atom = YP.getValue(Sub_atom); | ||
1042 | if (atom is Variable) | ||
1043 | throw new PrologException(Atom.a("instantiation_error"), | ||
1044 | "Expected atom(Arg1) but it is an unbound variable"); | ||
1045 | if (!(atom is Atom)) | ||
1046 | throw new PrologException | ||
1047 | (new Functor2("type_error", Atom.a("atom"), atom), "Arg 1 Atom is not an atom"); | ||
1048 | if (!(Sub_atom is Variable)) | ||
1049 | { | ||
1050 | if (!(Sub_atom is Atom)) | ||
1051 | throw new PrologException | ||
1052 | (new Functor2("type_error", Atom.a("atom"), Sub_atom), "Sub_atom is not var or atom"); | ||
1053 | } | ||
1054 | |||
1055 | bool beforeIsInt = false; | ||
1056 | bool lengthIsInt = false; | ||
1057 | bool afterIsInt = false; | ||
1058 | if (!(Before is Variable)) | ||
1059 | { | ||
1060 | if (!(Before is int)) | ||
1061 | throw new PrologException | ||
1062 | (new Functor2("type_error", Atom.a("integer"), Before), "Before must be var or integer"); | ||
1063 | beforeIsInt = true; | ||
1064 | if ((int)Before < 0) | ||
1065 | throw new PrologException | ||
1066 | (new Functor2("domain_error", Atom.a("not_less_than_zero"), Before), | ||
1067 | "Before must not be less than zero"); | ||
1068 | } | ||
1069 | if (!(Length is Variable)) | ||
1070 | { | ||
1071 | if (!(Length is int)) | ||
1072 | throw new PrologException | ||
1073 | (new Functor2("type_error", Atom.a("integer"), Length), "Length must be var or integer"); | ||
1074 | lengthIsInt = true; | ||
1075 | if ((int)Length < 0) | ||
1076 | throw new PrologException | ||
1077 | (new Functor2("domain_error", Atom.a("not_less_than_zero"), Length), | ||
1078 | "Length must not be less than zero"); | ||
1079 | } | ||
1080 | if (!(After is Variable)) | ||
1081 | { | ||
1082 | if (!(After is int)) | ||
1083 | throw new PrologException | ||
1084 | (new Functor2("type_error", Atom.a("integer"), After), "After must be var or integer"); | ||
1085 | afterIsInt = true; | ||
1086 | if ((int)After < 0) | ||
1087 | throw new PrologException | ||
1088 | (new Functor2("domain_error", Atom.a("not_less_than_zero"), After), | ||
1089 | "After must not be less than zero"); | ||
1090 | } | ||
1091 | |||
1092 | Atom atomAtom = (Atom)atom; | ||
1093 | int atomLength = atomAtom._name.Length; | ||
1094 | if (beforeIsInt && lengthIsInt) | ||
1095 | { | ||
1096 | // Special case: the caller is just trying to extract a substring, so do it quickly. | ||
1097 | int xAfter = atomLength - (int)Before - (int)Length; | ||
1098 | if (xAfter >= 0) | ||
1099 | { | ||
1100 | foreach (bool l1 in YP.unify(After, xAfter)) | ||
1101 | { | ||
1102 | foreach (bool l2 in YP.unify | ||
1103 | (Sub_atom, Atom.a(atomAtom._name.Substring((int)Before, (int)Length)))) | ||
1104 | yield return false; | ||
1105 | } | ||
1106 | } | ||
1107 | } | ||
1108 | else if (afterIsInt && lengthIsInt) | ||
1109 | { | ||
1110 | // Special case: the caller is just trying to extract a substring, so do it quickly. | ||
1111 | int xBefore = atomLength - (int)After - (int)Length; | ||
1112 | if (xBefore >= 0) | ||
1113 | { | ||
1114 | foreach (bool l1 in YP.unify(Before, xBefore)) | ||
1115 | { | ||
1116 | foreach (bool l2 in YP.unify | ||
1117 | (Sub_atom, Atom.a(atomAtom._name.Substring(xBefore, (int)Length)))) | ||
1118 | yield return false; | ||
1119 | } | ||
1120 | } | ||
1121 | } | ||
1122 | else | ||
1123 | { | ||
1124 | // We are underconstrained and doing a search, so go through all possibilities. | ||
1125 | for (int xBefore = 0; xBefore <= atomLength; ++xBefore) | ||
1126 | { | ||
1127 | foreach (bool l1 in YP.unify(Before, xBefore)) | ||
1128 | { | ||
1129 | for (int xLength = 0; xLength <= (atomLength - xBefore); ++xLength) | ||
1130 | { | ||
1131 | foreach (bool l2 in YP.unify(Length, xLength)) | ||
1132 | { | ||
1133 | foreach (bool l3 in YP.unify(After, atomLength - (xBefore + xLength))) | ||
1134 | { | ||
1135 | foreach (bool l4 in YP.unify | ||
1136 | (Sub_atom, Atom.a(atomAtom._name.Substring(xBefore, xLength)))) | ||
1137 | yield return false; | ||
1138 | } | ||
1139 | } | ||
1140 | } | ||
1141 | } | ||
1142 | } | ||
1143 | } | ||
1144 | } | ||
1145 | |||
1146 | public static IEnumerable<bool> atom_chars(object atom, object List) | ||
1147 | { | ||
1148 | atom = YP.getValue(atom); | ||
1149 | List = YP.getValue(List); | ||
1150 | |||
1151 | if (atom is Variable) | ||
1152 | { | ||
1153 | if (List is Variable) | ||
1154 | throw new PrologException(Atom.a("instantiation_error"), | ||
1155 | "Arg 1 Atom and arg 2 List are both unbound variables"); | ||
1156 | object[] codeArray = ListPair.toArray(List); | ||
1157 | if (codeArray == null) | ||
1158 | throw new PrologException | ||
1159 | (new Functor2("type_error", Atom.a("list"), List), "Arg 2 List is not a list"); | ||
1160 | |||
1161 | char[] charArray = new char[codeArray.Length]; | ||
1162 | for (int i = 0; i < codeArray.Length; ++i) | ||
1163 | { | ||
1164 | object listAtom = YP.getValue(codeArray[i]); | ||
1165 | if (listAtom is Variable) | ||
1166 | throw new PrologException(Atom.a("instantiation_error"), | ||
1167 | "Arg 2 List has an element which is an unbound variable"); | ||
1168 | if (!(listAtom is Atom && ((Atom)listAtom)._name.Length == 1)) | ||
1169 | throw new PrologException | ||
1170 | (new Functor2("type_error", Atom.a("character"), listAtom), | ||
1171 | "Arg 2 List has an element which is not a one character atom"); | ||
1172 | charArray[i] = ((Atom)listAtom)._name[0]; | ||
1173 | } | ||
1174 | return YP.unify(atom, Atom.a(new String(charArray))); | ||
1175 | } | ||
1176 | else | ||
1177 | { | ||
1178 | if (!(atom is Atom)) | ||
1179 | throw new PrologException | ||
1180 | (new Functor2("type_error", Atom.a("atom"), atom), "Arg 1 Atom is not var or atom"); | ||
1181 | |||
1182 | string atomString = ((Atom)atom)._name; | ||
1183 | object charList = Atom.NIL; | ||
1184 | // Start from the back to make the list. | ||
1185 | for (int i = atomString.Length - 1; i >= 0; --i) | ||
1186 | charList = new ListPair(Atom.a(atomString.Substring(i, 1)), charList); | ||
1187 | return YP.unify(List, charList); | ||
1188 | } | ||
1189 | } | ||
1190 | |||
1191 | public static IEnumerable<bool> atom_codes(object atom, object List) | ||
1192 | { | ||
1193 | atom = YP.getValue(atom); | ||
1194 | List = YP.getValue(List); | ||
1195 | |||
1196 | if (atom is Variable) | ||
1197 | { | ||
1198 | if (List is Variable) | ||
1199 | throw new PrologException(Atom.a("instantiation_error"), | ||
1200 | "Arg 1 Atom and arg 2 List are both unbound variables"); | ||
1201 | object[] codeArray = ListPair.toArray(List); | ||
1202 | if (codeArray == null) | ||
1203 | throw new PrologException | ||
1204 | (new Functor2("type_error", Atom.a("list"), List), "Arg 2 List is not a list"); | ||
1205 | |||
1206 | char[] charArray = new char[codeArray.Length]; | ||
1207 | for (int i = 0; i < codeArray.Length; ++i) | ||
1208 | { | ||
1209 | int codeInt; | ||
1210 | if (!getInt(codeArray[i], out codeInt) || codeInt < 0) | ||
1211 | throw new PrologException | ||
1212 | (new Functor1("representation_error", Atom.a("character_code")), | ||
1213 | "Element of Arg 2 List is not a character code"); | ||
1214 | charArray[i] = (char)codeInt; | ||
1215 | } | ||
1216 | return YP.unify(atom, Atom.a(new String(charArray))); | ||
1217 | } | ||
1218 | else | ||
1219 | { | ||
1220 | if (!(atom is Atom)) | ||
1221 | throw new PrologException | ||
1222 | (new Functor2("type_error", Atom.a("atom"), atom), "Arg 1 Atom is not var or atom"); | ||
1223 | |||
1224 | string atomString = ((Atom)atom)._name; | ||
1225 | object codeList = Atom.NIL; | ||
1226 | // Start from the back to make the list. | ||
1227 | for (int i = atomString.Length - 1; i >= 0; --i) | ||
1228 | codeList = new ListPair((int)atomString[i], codeList); | ||
1229 | return YP.unify(List, codeList); | ||
1230 | } | ||
1231 | } | ||
1232 | |||
1233 | public static IEnumerable<bool> number_chars(object Number, object List) | ||
1234 | { | ||
1235 | Number = YP.getValue(Number); | ||
1236 | List = YP.getValue(List); | ||
1237 | |||
1238 | if (Number is Variable) | ||
1239 | { | ||
1240 | if (List is Variable) | ||
1241 | throw new PrologException(Atom.a("instantiation_error"), | ||
1242 | "Arg 1 Number and arg 2 List are both unbound variables"); | ||
1243 | object[] codeArray = ListPair.toArray(List); | ||
1244 | if (codeArray == null) | ||
1245 | throw new PrologException | ||
1246 | (new Functor2("type_error", Atom.a("list"), List), "Arg 2 List is not a list"); | ||
1247 | |||
1248 | char[] charArray = new char[codeArray.Length]; | ||
1249 | for (int i = 0; i < codeArray.Length; ++i) | ||
1250 | { | ||
1251 | object listAtom = YP.getValue(codeArray[i]); | ||
1252 | if (listAtom is Variable) | ||
1253 | throw new PrologException(Atom.a("instantiation_error"), | ||
1254 | "Arg 2 List has an element which is an unbound variable"); | ||
1255 | if (!(listAtom is Atom && ((Atom)listAtom)._name.Length == 1)) | ||
1256 | throw new PrologException | ||
1257 | (new Functor2("type_error", Atom.a("character"), listAtom), | ||
1258 | "Arg 2 List has an element which is not a one character atom"); | ||
1259 | charArray[i] = ((Atom)listAtom)._name[0]; | ||
1260 | } | ||
1261 | return YP.unify(Number, parseNumberString(charArray)); | ||
1262 | } | ||
1263 | else | ||
1264 | { | ||
1265 | string numberString = null; | ||
1266 | // Try converting to an int first. | ||
1267 | int intNumber; | ||
1268 | if (YP.getInt(Number, out intNumber)) | ||
1269 | numberString = intNumber.ToString(); | ||
1270 | else | ||
1271 | { | ||
1272 | if (!YP.number(Number)) | ||
1273 | throw new PrologException | ||
1274 | (new Functor2("type_error", Atom.a("number"), Number), | ||
1275 | "Arg 1 Number is not var or number"); | ||
1276 | // We just checked, so convertDouble shouldn't throw an exception. | ||
1277 | numberString = YP.doubleToString(YP.convertDouble(Number)); | ||
1278 | } | ||
1279 | |||
1280 | object charList = Atom.NIL; | ||
1281 | // Start from the back to make the list. | ||
1282 | for (int i = numberString.Length - 1; i >= 0; --i) | ||
1283 | charList = new ListPair(Atom.a(numberString.Substring(i, 1)), charList); | ||
1284 | return YP.unify(List, charList); | ||
1285 | } | ||
1286 | } | ||
1287 | |||
1288 | public static IEnumerable<bool> number_codes(object Number, object List) | ||
1289 | { | ||
1290 | Number = YP.getValue(Number); | ||
1291 | List = YP.getValue(List); | ||
1292 | |||
1293 | if (Number is Variable) | ||
1294 | { | ||
1295 | if (List is Variable) | ||
1296 | throw new PrologException(Atom.a("instantiation_error"), | ||
1297 | "Arg 1 Number and arg 2 List are both unbound variables"); | ||
1298 | object[] codeArray = ListPair.toArray(List); | ||
1299 | if (codeArray == null) | ||
1300 | throw new PrologException | ||
1301 | (new Functor2("type_error", Atom.a("list"), List), "Arg 2 List is not a list"); | ||
1302 | |||
1303 | char[] charArray = new char[codeArray.Length]; | ||
1304 | for (int i = 0; i < codeArray.Length; ++i) | ||
1305 | { | ||
1306 | int codeInt; | ||
1307 | if (!getInt(codeArray[i], out codeInt) || codeInt < 0) | ||
1308 | throw new PrologException | ||
1309 | (new Functor1("representation_error", Atom.a("character_code")), | ||
1310 | "Element of Arg 2 List is not a character code"); | ||
1311 | charArray[i] = (char)codeInt; | ||
1312 | } | ||
1313 | return YP.unify(Number, parseNumberString(charArray)); | ||
1314 | } | ||
1315 | else | ||
1316 | { | ||
1317 | string numberString = null; | ||
1318 | // Try converting to an int first. | ||
1319 | int intNumber; | ||
1320 | if (YP.getInt(Number, out intNumber)) | ||
1321 | numberString = intNumber.ToString(); | ||
1322 | else | ||
1323 | { | ||
1324 | if (!YP.number(Number)) | ||
1325 | throw new PrologException | ||
1326 | (new Functor2("type_error", Atom.a("number"), Number), | ||
1327 | "Arg 1 Number is not var or number"); | ||
1328 | // We just checked, so convertDouble shouldn't throw an exception. | ||
1329 | numberString = YP.doubleToString(YP.convertDouble(Number)); | ||
1330 | } | ||
1331 | |||
1332 | object codeList = Atom.NIL; | ||
1333 | // Start from the back to make the list. | ||
1334 | for (int i = numberString.Length - 1; i >= 0; --i) | ||
1335 | codeList = new ListPair((int)numberString[i], codeList); | ||
1336 | return YP.unify(List, codeList); | ||
1337 | } | ||
1338 | } | ||
1339 | |||
1340 | /// <summary> | ||
1341 | /// Used by number_chars and number_codes. Return the number in charArray or | ||
1342 | /// throw an exception if can't parse. | ||
1343 | /// </summary> | ||
1344 | /// <param name="numberString"></param> | ||
1345 | /// <returns></returns> | ||
1346 | private static object parseNumberString(char[] charArray) | ||
1347 | { | ||
1348 | string numberString = new String(charArray); | ||
1349 | if (charArray.Length == 3 && numberString.StartsWith("0'")) | ||
1350 | // This is a char code. | ||
1351 | return (int)charArray[2]; | ||
1352 | if (numberString.StartsWith("0x")) | ||
1353 | { | ||
1354 | try | ||
1355 | { | ||
1356 | return Int32.Parse | ||
1357 | (numberString.Substring(2), System.Globalization.NumberStyles.AllowHexSpecifier); | ||
1358 | } | ||
1359 | catch (FormatException) | ||
1360 | { | ||
1361 | throw new PrologException | ||
1362 | (new Functor1("syntax_error", Atom.a("number_format: " + numberString)), | ||
1363 | "Arg 2 List is not a list for a hexadecimal number"); | ||
1364 | } | ||
1365 | } | ||
1366 | // Debug: Is there a way in C# to ask if a string parses as int without throwing an exception? | ||
1367 | try | ||
1368 | { | ||
1369 | // Try an int first. | ||
1370 | return Convert.ToInt32(numberString); | ||
1371 | } | ||
1372 | catch (FormatException) { } | ||
1373 | try | ||
1374 | { | ||
1375 | return Convert.ToDouble(numberString); | ||
1376 | } | ||
1377 | catch (FormatException) | ||
1378 | { | ||
1379 | throw new PrologException | ||
1380 | (new Functor1("syntax_error", Atom.a("number_format: " + numberString)), | ||
1381 | "Arg 2 List is not a list for a number"); | ||
1382 | } | ||
1383 | } | ||
1384 | |||
1385 | public static IEnumerable<bool> char_code(object Char, object Code) | ||
1386 | { | ||
1387 | Char = YP.getValue(Char); | ||
1388 | Code = YP.getValue(Code); | ||
1389 | |||
1390 | int codeInt = 0; | ||
1391 | if (!(Code is Variable)) | ||
1392 | { | ||
1393 | // Get codeInt now so we type check it whether or not Char is Variable. | ||
1394 | if (!getInt(Code, out codeInt)) | ||
1395 | throw new PrologException | ||
1396 | (new Functor2("type_error", Atom.a("integer"), Code), | ||
1397 | "Arg 2 Code is not var or a character code"); | ||
1398 | if (codeInt < 0) | ||
1399 | throw new PrologException | ||
1400 | (new Functor1("representation_error", Atom.a("character_code")), | ||
1401 | "Arg 2 Code is not a character code"); | ||
1402 | } | ||
1403 | |||
1404 | if (Char is Variable) | ||
1405 | { | ||
1406 | if (Code is Variable) | ||
1407 | throw new PrologException(Atom.a("instantiation_error"), | ||
1408 | "Arg 1 Char and arg 2 Code are both unbound variables"); | ||
1409 | |||
1410 | return YP.unify(Char, Atom.a(new String(new char[] {(char)codeInt}))); | ||
1411 | } | ||
1412 | else | ||
1413 | { | ||
1414 | if (!(Char is Atom) || ((Atom)Char)._name.Length != 1) | ||
1415 | throw new PrologException | ||
1416 | (new Functor2("type_error", Atom.a("character"), Char), | ||
1417 | "Arg 1 Char is not var or one-character atom"); | ||
1418 | |||
1419 | if (Code is Variable) | ||
1420 | return YP.unify(Code, (int)((Atom)Char)._name[0]); | ||
1421 | else | ||
1422 | // Use codeInt to handle whether Code is supplied as, e.g., 97 or 0'a . | ||
1423 | return YP.unify(codeInt, (int)((Atom)Char)._name[0]); | ||
1424 | } | ||
1425 | } | ||
1426 | |||
1427 | /// <summary> | ||
1428 | /// If term is an Atom or functor type, return its name. | ||
1429 | /// Otherwise, return term. | ||
1430 | /// </summary> | ||
1431 | /// <param name="term"></param> | ||
1432 | /// <returns></returns> | ||
1433 | public static object getFunctorName(object term) | ||
1434 | { | ||
1435 | term = YP.getValue(term); | ||
1436 | if (term is Functor1) | ||
1437 | return ((Functor1)term)._name; | ||
1438 | else if (term is Functor2) | ||
1439 | return ((Functor2)term)._name; | ||
1440 | else if (term is Functor3) | ||
1441 | return ((Functor3)term)._name; | ||
1442 | else if (term is Functor) | ||
1443 | return ((Functor)term)._name; | ||
1444 | else | ||
1445 | return term; | ||
1446 | } | ||
1447 | |||
1448 | /// <summary> | ||
1449 | /// If term is an Atom or functor type, return an array of its args. | ||
1450 | /// Otherwise, return an empty array. | ||
1451 | /// </summary> | ||
1452 | /// <param name="term"></param> | ||
1453 | /// <returns></returns> | ||
1454 | public static object[] getFunctorArgs(object term) | ||
1455 | { | ||
1456 | term = YP.getValue(term); | ||
1457 | if (term is Functor1) | ||
1458 | { | ||
1459 | Functor1 functor = (Functor1)term; | ||
1460 | return new object[] { functor._arg1 }; | ||
1461 | } | ||
1462 | else if (term is Functor2) | ||
1463 | { | ||
1464 | Functor2 functor = (Functor2)term; | ||
1465 | return new object[] { functor._arg1, functor._arg2 }; | ||
1466 | } | ||
1467 | else if (term is Functor3) | ||
1468 | { | ||
1469 | Functor3 functor = (Functor3)term; | ||
1470 | return new object[] { functor._arg1, functor._arg2, functor._arg3 }; | ||
1471 | } | ||
1472 | else if (term is Functor) { | ||
1473 | Functor functor = (Functor)term; | ||
1474 | return functor._args; | ||
1475 | } | ||
1476 | else | ||
1477 | return new object[0]; | ||
1478 | } | ||
1479 | |||
1480 | public static bool var(object Term) | ||
1481 | { | ||
1482 | return YP.getValue(Term) is Variable; | ||
1483 | } | ||
1484 | |||
1485 | public static bool nonvar(object Term) | ||
1486 | { | ||
1487 | return !YP.var(Term); | ||
1488 | } | ||
1489 | |||
1490 | public static bool atom(object Term) | ||
1491 | { | ||
1492 | return YP.getValue(Term) is Atom; | ||
1493 | } | ||
1494 | |||
1495 | public static bool integer(object Term) | ||
1496 | { | ||
1497 | // Debug: Should exhaustively check for all integer types. | ||
1498 | return getValue(Term) is int; | ||
1499 | } | ||
1500 | |||
1501 | // Use isFloat instead of float because it is a reserved keyword. | ||
1502 | public static bool isFloat(object Term) | ||
1503 | { | ||
1504 | // Debug: Should exhaustively check for all float types. | ||
1505 | return getValue(Term) is double; | ||
1506 | } | ||
1507 | |||
1508 | public static bool number(object Term) | ||
1509 | { | ||
1510 | return YP.integer(Term) || YP.isFloat(Term); | ||
1511 | } | ||
1512 | |||
1513 | public static bool atomic(object Term) | ||
1514 | { | ||
1515 | return YP.atom(Term) || YP.number(Term); | ||
1516 | } | ||
1517 | |||
1518 | public static bool compound(object Term) | ||
1519 | { | ||
1520 | Term = getValue(Term); | ||
1521 | return Term is Functor1 || Term is Functor2 || Term is Functor3 || Term is Functor; | ||
1522 | } | ||
1523 | |||
1524 | /// <summary> | ||
1525 | /// If input is a TextReader, use it. If input is an Atom or String, create a StreamReader with the | ||
1526 | /// input as the filename. If input is a Prolog list, then read character codes from it. | ||
1527 | /// </summary> | ||
1528 | /// <param name="input"></param> | ||
1529 | public static void see(object input) | ||
1530 | { | ||
1531 | input = YP.getValue(input); | ||
1532 | if (input is Variable) | ||
1533 | throw new PrologException(Atom.a("instantiation_error"), "Arg is an unbound variable"); | ||
1534 | |||
1535 | if (input == null) | ||
1536 | { | ||
1537 | _inputStream = null; | ||
1538 | return; | ||
1539 | } | ||
1540 | if (input is TextReader) | ||
1541 | { | ||
1542 | _inputStream = (TextReader)input; | ||
1543 | return; | ||
1544 | } | ||
1545 | else if (input is Atom) | ||
1546 | { | ||
1547 | _inputStream = new StreamReader(((Atom)input)._name); | ||
1548 | return; | ||
1549 | } | ||
1550 | else if (input is String) | ||
1551 | { | ||
1552 | _inputStream = new StreamReader((String)input); | ||
1553 | return; | ||
1554 | } | ||
1555 | else if (input is Functor2 && ((Functor2)input)._name == Atom.DOT) | ||
1556 | { | ||
1557 | _inputStream = new CodeListReader(input); | ||
1558 | return; | ||
1559 | } | ||
1560 | else | ||
1561 | throw new PrologException | ||
1562 | (new Functor2("domain_error", Atom.a("stream_or_alias"), input), | ||
1563 | "Input stream specifier not recognized"); | ||
1564 | } | ||
1565 | |||
1566 | public static void seen() | ||
1567 | { | ||
1568 | if (_inputStream == null) | ||
1569 | return; | ||
1570 | if (_inputStream == Console.In) | ||
1571 | return; | ||
1572 | _inputStream.Close(); | ||
1573 | _inputStream = Console.In; | ||
1574 | } | ||
1575 | |||
1576 | public static IEnumerable<bool> current_input(object Stream) | ||
1577 | { | ||
1578 | return YP.unify(Stream, _inputStream); | ||
1579 | } | ||
1580 | |||
1581 | /// <summary> | ||
1582 | /// If output is a TextWriter, use it. If output is an Atom or a String, create a StreamWriter | ||
1583 | /// with the input as the filename. | ||
1584 | /// </summary> | ||
1585 | /// <param name="output"></param> | ||
1586 | public static void tell(object output) | ||
1587 | { | ||
1588 | output = YP.getValue(output); | ||
1589 | if (output is Variable) | ||
1590 | throw new PrologException(Atom.a("instantiation_error"), "Arg is an unbound variable"); | ||
1591 | |||
1592 | if (output == null) | ||
1593 | { | ||
1594 | _outputStream = null; | ||
1595 | return; | ||
1596 | } | ||
1597 | if (output is TextWriter) | ||
1598 | { | ||
1599 | _outputStream = (TextWriter)output; | ||
1600 | return; | ||
1601 | } | ||
1602 | else if (output is Atom) | ||
1603 | { | ||
1604 | _outputStream = new StreamWriter(((Atom)output)._name); | ||
1605 | return; | ||
1606 | } | ||
1607 | else if (output is String) | ||
1608 | { | ||
1609 | _outputStream = new StreamWriter((String)output); | ||
1610 | return; | ||
1611 | } | ||
1612 | else | ||
1613 | throw new PrologException | ||
1614 | (new Functor2("domain_error", Atom.a("stream_or_alias"), output), | ||
1615 | "Can't open stream for " + output); | ||
1616 | } | ||
1617 | |||
1618 | public static void told() | ||
1619 | { | ||
1620 | if (_outputStream == null) | ||
1621 | return; | ||
1622 | if (_outputStream == Console.Out) | ||
1623 | return; | ||
1624 | _outputStream.Close(); | ||
1625 | _outputStream = Console.Out; | ||
1626 | } | ||
1627 | |||
1628 | public static IEnumerable<bool> current_output(object Stream) | ||
1629 | { | ||
1630 | return YP.unify(Stream, _outputStream); | ||
1631 | } | ||
1632 | |||
1633 | public static void write(object x) | ||
1634 | { | ||
1635 | if (_outputStream == null) | ||
1636 | return; | ||
1637 | x = YP.getValue(x); | ||
1638 | if (x is double) | ||
1639 | _outputStream.Write(doubleToString((double)x)); | ||
1640 | else | ||
1641 | _outputStream.Write(x.ToString()); | ||
1642 | } | ||
1643 | |||
1644 | /// <summary> | ||
1645 | /// Format x as a string, making sure that it won't parse as an int later. I.e., for 1.0, don't just | ||
1646 | /// use "1" which will parse as an int. | ||
1647 | /// </summary> | ||
1648 | /// <param name="x"></param> | ||
1649 | /// <returns></returns> | ||
1650 | private static string doubleToString(double x) | ||
1651 | { | ||
1652 | string xString = x.ToString(); | ||
1653 | // Debug: Is there a way in C# to ask if a string parses as int without throwing an exception? | ||
1654 | try | ||
1655 | { | ||
1656 | Convert.ToInt32(xString); | ||
1657 | // The string will parse as an int, not a double, so re-format so that it does. | ||
1658 | // Use float if possible, else exponential if it would be too big. | ||
1659 | return x.ToString(x >= 100000.0 ? "E1" : "f1"); | ||
1660 | } | ||
1661 | catch (FormatException) | ||
1662 | { | ||
1663 | // Assume it will parse as a double. | ||
1664 | } | ||
1665 | return xString; | ||
1666 | } | ||
1667 | |||
1668 | public static void put_code(object x) | ||
1669 | { | ||
1670 | if (_outputStream == null) | ||
1671 | return; | ||
1672 | if (var(x)) | ||
1673 | throw new PrologException(Atom.a("instantiation_error"), "Arg 1 is an unbound variable"); | ||
1674 | int xInt; | ||
1675 | if (!getInt(x, out xInt)) | ||
1676 | throw new PrologException | ||
1677 | (new Functor2("type_error", Atom.a("integer"), x), "Arg 1 must be integer"); | ||
1678 | _outputStream.Write((char)xInt); | ||
1679 | } | ||
1680 | |||
1681 | public static void nl() | ||
1682 | { | ||
1683 | if (_outputStream == null) | ||
1684 | return; | ||
1685 | _outputStream.WriteLine(); | ||
1686 | } | ||
1687 | |||
1688 | public static IEnumerable<bool> get_code(object code) | ||
1689 | { | ||
1690 | if (_inputStream == null) | ||
1691 | return YP.unify(code, -1); | ||
1692 | else | ||
1693 | return YP.unify(code, _inputStream.Read()); | ||
1694 | } | ||
1695 | |||
1696 | public static void asserta(object Term, Type declaringClass) | ||
1697 | { | ||
1698 | assertDynamic(Term, declaringClass, true); | ||
1699 | } | ||
1700 | |||
1701 | public static void assertz(object Term, Type declaringClass) | ||
1702 | { | ||
1703 | assertDynamic(Term, declaringClass, false); | ||
1704 | } | ||
1705 | |||
1706 | public static void assertDynamic(object Term, Type declaringClass, bool prepend) | ||
1707 | { | ||
1708 | Term = getValue(Term); | ||
1709 | if (Term is Variable) | ||
1710 | throw new PrologException("instantiation_error", "Term to assert is an unbound variable"); | ||
1711 | |||
1712 | Variable.CopyStore copyStore = new Variable.CopyStore(); | ||
1713 | object TermCopy = makeCopy(Term, copyStore); | ||
1714 | object Head, Body; | ||
1715 | if (TermCopy is Functor2 && ((Functor2)TermCopy)._name == Atom.RULE) | ||
1716 | { | ||
1717 | Head = YP.getValue(((Functor2)TermCopy)._arg1); | ||
1718 | Body = YP.getValue(((Functor2)TermCopy)._arg2); | ||
1719 | if (Head is Variable) | ||
1720 | throw new PrologException("instantiation_error", "Head to assert is an unbound variable"); | ||
1721 | if (Body is Variable) | ||
1722 | throw new PrologException("instantiation_error", "Body to assert is an unbound variable"); | ||
1723 | } | ||
1724 | else | ||
1725 | { | ||
1726 | Head = TermCopy; | ||
1727 | Body = Atom.a("true"); | ||
1728 | } | ||
1729 | |||
1730 | Atom name = getFunctorName(Head) as Atom; | ||
1731 | if (name == null) | ||
1732 | // name is a non-Atom, such as a number. | ||
1733 | throw new PrologException | ||
1734 | (new Functor2("type_error", Atom.a("callable"), Head), "Term to assert is not callable"); | ||
1735 | object[] args = getFunctorArgs(Head); | ||
1736 | if (isSystemPredicate(name, args.Length)) | ||
1737 | throw new PrologException | ||
1738 | (new Functor3("permission_error", Atom.a("modify"), Atom.a("static_procedure"), | ||
1739 | new Functor2(Atom.SLASH, name, args.Length)), | ||
1740 | "Assert cannot modify static predicate " + name + "/" + args.Length); | ||
1741 | |||
1742 | if (copyStore.getNUniqueVariables() == 0 && Body == Atom.a("true")) | ||
1743 | { | ||
1744 | // This is a fact with no unbound variables | ||
1745 | // assertFact and prependFact use IndexedAnswers, so don't we don't need to compile. | ||
1746 | if (prepend) | ||
1747 | prependFact(name, args); | ||
1748 | else | ||
1749 | assertFact(name, args); | ||
1750 | |||
1751 | return; | ||
1752 | } | ||
1753 | |||
1754 | IClause clause = YPCompiler.compileAnonymousClause(Head, Body, declaringClass); | ||
1755 | // We expect clause to be a ClauseHeadAndBody (from Compiler.compileAnonymousFunction) | ||
1756 | // so we can set the Head and Body. | ||
1757 | if (clause is ClauseHeadAndBody) | ||
1758 | ((ClauseHeadAndBody)clause).setHeadAndBody(Head, Body); | ||
1759 | |||
1760 | // Add the clause to the entry in _predicatesStore. | ||
1761 | NameArity nameArity = new NameArity(name, args.Length); | ||
1762 | List<IClause> clauses; | ||
1763 | if (!_predicatesStore.TryGetValue(nameArity, out clauses)) | ||
1764 | // Create an entry for the nameArity. | ||
1765 | _predicatesStore[nameArity] = (clauses = new List<IClause>()); | ||
1766 | |||
1767 | if (prepend) | ||
1768 | clauses.Insert(0, clause); | ||
1769 | else | ||
1770 | clauses.Add(clause); | ||
1771 | } | ||
1772 | |||
1773 | private static bool isSystemPredicate(Atom name, int arity) | ||
1774 | { | ||
1775 | if (arity == 2 && (name == Atom.a(",") || name == Atom.a(";") || name == Atom.DOT)) | ||
1776 | return true; | ||
1777 | // Use the same mapping to static predicates in YP as the compiler. | ||
1778 | foreach (bool l1 in YPCompiler.functorCallYPFunctionName(name, arity, new Variable())) | ||
1779 | return true; | ||
1780 | // Debug: Do we need to check if name._module is null? | ||
1781 | return false; | ||
1782 | } | ||
1783 | |||
1784 | /// <summary> | ||
1785 | /// Assert values at the end of the set of facts for the predicate with the | ||
1786 | /// name and with arity values.Length. | ||
1787 | /// </summary> | ||
1788 | /// <param name="name">must be an Atom</param> | ||
1789 | /// <param name="values">the array of arguments to the fact predicate. | ||
1790 | /// It is an error if an value has an unbound variable.</param> | ||
1791 | public static void assertFact(Atom name, object[] values) | ||
1792 | { | ||
1793 | NameArity nameArity = new NameArity(name, values.Length); | ||
1794 | List<IClause> clauses; | ||
1795 | IndexedAnswers indexedAnswers; | ||
1796 | if (!_predicatesStore.TryGetValue(nameArity, out clauses)) | ||
1797 | { | ||
1798 | // Create an IndexedAnswers as the only clause of the predicate. | ||
1799 | _predicatesStore[nameArity] = (clauses = new List<IClause>()); | ||
1800 | clauses.Add(indexedAnswers = new IndexedAnswers(values.Length)); | ||
1801 | } | ||
1802 | else | ||
1803 | { | ||
1804 | indexedAnswers = null; | ||
1805 | if (clauses.Count >= 1) | ||
1806 | indexedAnswers = clauses[clauses.Count - 1] as IndexedAnswers; | ||
1807 | if (indexedAnswers == null) | ||
1808 | // The latest clause is not an IndexedAnswers, so add one. | ||
1809 | clauses.Add(indexedAnswers = new IndexedAnswers(values.Length)); | ||
1810 | } | ||
1811 | |||
1812 | indexedAnswers.addAnswer(values); | ||
1813 | } | ||
1814 | |||
1815 | /// <summary> | ||
1816 | /// Assert values, prepending to the front of the set of facts for the predicate with the | ||
1817 | /// name and with arity values.Length. | ||
1818 | /// </summary> | ||
1819 | /// <param name="name">must be an Atom</param> | ||
1820 | /// <param name="values">the array of arguments to the fact predicate. | ||
1821 | /// It is an error if an value has an unbound variable.</param> | ||
1822 | public static void prependFact(Atom name, object[] values) | ||
1823 | { | ||
1824 | NameArity nameArity = new NameArity(name, values.Length); | ||
1825 | List<IClause> clauses; | ||
1826 | IndexedAnswers indexedAnswers; | ||
1827 | if (!_predicatesStore.TryGetValue(nameArity, out clauses)) | ||
1828 | { | ||
1829 | // Create an IndexedAnswers as the only clause of the predicate. | ||
1830 | _predicatesStore[nameArity] = (clauses = new List<IClause>()); | ||
1831 | clauses.Add(indexedAnswers = new IndexedAnswers(values.Length)); | ||
1832 | } | ||
1833 | else | ||
1834 | { | ||
1835 | indexedAnswers = null; | ||
1836 | if (clauses.Count >= 1) | ||
1837 | indexedAnswers = clauses[0] as IndexedAnswers; | ||
1838 | if (indexedAnswers == null) | ||
1839 | // The first clause is not an IndexedAnswers, so prepend one. | ||
1840 | clauses.Insert(0, indexedAnswers = new IndexedAnswers(values.Length)); | ||
1841 | } | ||
1842 | |||
1843 | indexedAnswers.prependAnswer(values); | ||
1844 | } | ||
1845 | |||
1846 | /// <summary> | ||
1847 | /// Match all clauses of the dynamic predicate with the name and with arity | ||
1848 | /// arguments.Length. | ||
1849 | /// If the predicate is not defined, return the result of YP.unknownPredicate. | ||
1850 | /// </summary> | ||
1851 | /// <param name="name">must be an Atom</param> | ||
1852 | /// <param name="arguments">an array of arity number of arguments</param> | ||
1853 | /// <returns>an iterator which you can use in foreach</returns> | ||
1854 | public static IEnumerable<bool> matchDynamic(Atom name, object[] arguments) | ||
1855 | { | ||
1856 | List<IClause> clauses; | ||
1857 | if (!_predicatesStore.TryGetValue(new NameArity(name, arguments.Length), out clauses)) | ||
1858 | return unknownPredicate(name, arguments.Length, | ||
1859 | "Undefined dynamic predicate: " + name + "/" + arguments.Length); | ||
1860 | |||
1861 | if (clauses.Count == 1) | ||
1862 | // Usually there is only one clause, so return it without needing to wrap it in an iterator. | ||
1863 | return clauses[0].match(arguments); | ||
1864 | else | ||
1865 | return matchAllClauses(clauses, arguments); | ||
1866 | } | ||
1867 | |||
1868 | /// <summary> | ||
1869 | /// Call match(arguments) for each IClause in clauses. We make this a separate | ||
1870 | /// function so that matchDynamic itself does not need to be an iterator object. | ||
1871 | /// </summary> | ||
1872 | /// <param name="clauses"></param> | ||
1873 | /// <param name="arguments"></param> | ||
1874 | /// <returns></returns> | ||
1875 | private static IEnumerable<bool> matchAllClauses(List<IClause> clauses, object[] arguments) | ||
1876 | { | ||
1877 | // Debug: If the caller asserts another clause into this same predicate during yield, the iterator | ||
1878 | // over clauses will be corrupted. Should we take the time to copy clauses? | ||
1879 | foreach (IClause clause in clauses) | ||
1880 | { | ||
1881 | foreach (bool lastCall in clause.match(arguments)) | ||
1882 | { | ||
1883 | yield return false; | ||
1884 | if (lastCall) | ||
1885 | // This happens after a cut in a clause. | ||
1886 | yield break; | ||
1887 | } | ||
1888 | } | ||
1889 | } | ||
1890 | |||
1891 | /// <summary> | ||
1892 | /// If _prologFlags["unknown"] is fail then return fail(), else if | ||
1893 | /// _prologFlags["unknown"] is warning then write the message to YP.write and | ||
1894 | /// return fail(), else throw a PrologException for existence_error. . | ||
1895 | /// </summary> | ||
1896 | /// <param name="name"></param> | ||
1897 | /// <param name="arity"></param> | ||
1898 | /// <param name="message"></param> | ||
1899 | /// <returns></returns> | ||
1900 | public static IEnumerable<bool> unknownPredicate(Atom name, int arity, string message) | ||
1901 | { | ||
1902 | establishPrologFlags(); | ||
1903 | |||
1904 | if (_prologFlags["unknown"] == Atom.a("fail")) | ||
1905 | return fail(); | ||
1906 | else if (_prologFlags["unknown"] == Atom.a("warning")) | ||
1907 | { | ||
1908 | write(message); | ||
1909 | nl(); | ||
1910 | return fail(); | ||
1911 | } | ||
1912 | else | ||
1913 | throw new PrologException | ||
1914 | (new Functor2 | ||
1915 | (Atom.a("existence_error"), Atom.a("procedure"), | ||
1916 | new Functor2(Atom.SLASH, name, arity)), message); | ||
1917 | } | ||
1918 | |||
1919 | /// <summary> | ||
1920 | /// This is deprecated and just calls matchDynamic. This matches all clauses, | ||
1921 | /// not just the ones defined with assertFact. | ||
1922 | /// </summary> | ||
1923 | /// <param name="name"></param> | ||
1924 | /// <param name="arguments"></param> | ||
1925 | /// <returns></returns> | ||
1926 | public static IEnumerable<bool> matchFact(Atom name, object[] arguments) | ||
1927 | { | ||
1928 | return matchDynamic(name, arguments); | ||
1929 | } | ||
1930 | |||
1931 | public static IEnumerable<bool> clause(object Head, object Body) | ||
1932 | { | ||
1933 | Head = getValue(Head); | ||
1934 | Body = getValue(Body); | ||
1935 | if (Head is Variable) | ||
1936 | throw new PrologException("instantiation_error", "Head is an unbound variable"); | ||
1937 | |||
1938 | Atom name = getFunctorName(Head) as Atom; | ||
1939 | if (name == null) | ||
1940 | // name is a non-Atom, such as a number. | ||
1941 | throw new PrologException | ||
1942 | (new Functor2("type_error", Atom.a("callable"), Head), "Head is not callable"); | ||
1943 | object[] args = getFunctorArgs(Head); | ||
1944 | if (isSystemPredicate(name, args.Length)) | ||
1945 | throw new PrologException | ||
1946 | (new Functor3("permission_error", Atom.a("access"), Atom.a("private_procedure"), | ||
1947 | new Functor2(Atom.SLASH, name, args.Length)), | ||
1948 | "clause cannot access private predicate " + name + "/" + args.Length); | ||
1949 | if (!(Body is Variable) && !(YP.getFunctorName(Body) is Atom)) | ||
1950 | throw new PrologException | ||
1951 | (new Functor2("type_error", Atom.a("callable"), Body), "Body is not callable"); | ||
1952 | |||
1953 | List<IClause> clauses; | ||
1954 | if (!_predicatesStore.TryGetValue(new NameArity(name, args.Length), out clauses)) | ||
1955 | yield break; | ||
1956 | // The caller can assert another clause into this same predicate during yield, so we have to | ||
1957 | // make a copy of the clauses. | ||
1958 | foreach (IClause predicateClause in clauses.ToArray()) | ||
1959 | { | ||
1960 | foreach (bool l1 in predicateClause.clause(Head, Body)) | ||
1961 | yield return false; | ||
1962 | } | ||
1963 | } | ||
1964 | |||
1965 | public static IEnumerable<bool> retract(object Term) | ||
1966 | { | ||
1967 | Term = getValue(Term); | ||
1968 | if (Term is Variable) | ||
1969 | throw new PrologException("instantiation_error", "Term to retract is an unbound variable"); | ||
1970 | |||
1971 | object Head, Body; | ||
1972 | if (Term is Functor2 && ((Functor2)Term)._name == Atom.RULE) | ||
1973 | { | ||
1974 | Head = YP.getValue(((Functor2)Term)._arg1); | ||
1975 | Body = YP.getValue(((Functor2)Term)._arg2); | ||
1976 | } | ||
1977 | else | ||
1978 | { | ||
1979 | Head = Term; | ||
1980 | Body = Atom.a("true"); | ||
1981 | } | ||
1982 | if (Head is Variable) | ||
1983 | throw new PrologException("instantiation_error", "Head is an unbound variable"); | ||
1984 | |||
1985 | Atom name = getFunctorName(Head) as Atom; | ||
1986 | if (name == null) | ||
1987 | // name is a non-Atom, such as a number. | ||
1988 | throw new PrologException | ||
1989 | (new Functor2("type_error", Atom.a("callable"), Head), "Head is not callable"); | ||
1990 | object[] args = getFunctorArgs(Head); | ||
1991 | if (isSystemPredicate(name, args.Length)) | ||
1992 | throw new PrologException | ||
1993 | (new Functor3("permission_error", Atom.a("modify"), Atom.a("static_procedure"), | ||
1994 | new Functor2(Atom.SLASH, name, args.Length)), | ||
1995 | "clause cannot access private predicate " + name + "/" + args.Length); | ||
1996 | if (!(Body is Variable) && !(YP.getFunctorName(Body) is Atom)) | ||
1997 | throw new PrologException | ||
1998 | (new Functor2("type_error", Atom.a("callable"), Body), "Body is not callable"); | ||
1999 | |||
2000 | List<IClause> clauses; | ||
2001 | if (!_predicatesStore.TryGetValue(new NameArity(name, args.Length), out clauses)) | ||
2002 | yield break; | ||
2003 | // The caller can assert another clause into this same predicate during yield, so we have to | ||
2004 | // make a copy of the clauses. | ||
2005 | foreach (IClause predicateClause in clauses.ToArray()) | ||
2006 | { | ||
2007 | if (predicateClause is IndexedAnswers) | ||
2008 | { | ||
2009 | // IndexedAnswers handles its own retract. Even if it removes all of its | ||
2010 | // answers, it is OK to leave it empty as one of the elements in clauses. | ||
2011 | foreach (bool l1 in ((IndexedAnswers)predicateClause).retract(Head, Body)) | ||
2012 | yield return false; | ||
2013 | } | ||
2014 | else | ||
2015 | { | ||
2016 | foreach (bool l1 in predicateClause.clause(Head, Body)) | ||
2017 | { | ||
2018 | clauses.Remove(predicateClause); | ||
2019 | yield return false; | ||
2020 | } | ||
2021 | } | ||
2022 | } | ||
2023 | } | ||
2024 | |||
2025 | /// <summary> | ||
2026 | /// This is deprecated for backward compatibility. You should use retractall. | ||
2027 | /// </summary> | ||
2028 | /// <param name="name">must be an Atom</param> | ||
2029 | /// <param name="arguments">an array of arity number of arguments</param> | ||
2030 | public static void retractFact(Atom name, object[] arguments) | ||
2031 | { | ||
2032 | retractall(Functor.make(name, arguments)); | ||
2033 | } | ||
2034 | |||
2035 | /// <summary> | ||
2036 | /// Retract all dynamic clauses which unify with Head. If this matches all clauses in a predicate, | ||
2037 | /// the predicate is still defined. To completely remove the predicate, see abolish. | ||
2038 | /// </summary> | ||
2039 | /// <param name="Head"></param> | ||
2040 | public static void retractall(object Head) | ||
2041 | { | ||
2042 | object name = YP.getFunctorName(Head); | ||
2043 | object[] arguments = getFunctorArgs(Head); | ||
2044 | if (!(name is Atom)) | ||
2045 | return; | ||
2046 | NameArity nameArity = new NameArity((Atom)name, arguments.Length); | ||
2047 | List<IClause> clauses; | ||
2048 | if (!_predicatesStore.TryGetValue(nameArity, out clauses)) | ||
2049 | // Can't find, so ignore. | ||
2050 | return; | ||
2051 | |||
2052 | foreach (object arg in arguments) | ||
2053 | { | ||
2054 | if (!YP.var(arg)) | ||
2055 | throw new InvalidOperationException | ||
2056 | ("Until matching retractall is supported, all arguments must be unbound to retract all clauses"); | ||
2057 | } | ||
2058 | // Clear all clauses. | ||
2059 | _predicatesStore[nameArity] = new List<IClause>(); | ||
2060 | } | ||
2061 | |||
2062 | /// <summary> | ||
2063 | /// If NameSlashArity is var, match with all the dynamic predicates using the | ||
2064 | /// Name/Artity form. | ||
2065 | /// If NameSlashArity is not var, check if the Name/Arity exists as a static or | ||
2066 | /// dynamic predicate. | ||
2067 | /// </summary> | ||
2068 | /// <param name="NameSlashArity"></param> | ||
2069 | /// <param name="declaringClass">if not null, used to resolve references to the default | ||
2070 | /// module Atom.a("")</param> | ||
2071 | /// <returns></returns> | ||
2072 | public static IEnumerable<bool> current_predicate(object NameSlashArity, Type declaringClass) | ||
2073 | { | ||
2074 | NameSlashArity = YP.getValue(NameSlashArity); | ||
2075 | // First check if Name and Arity are nonvar so we can do a direct lookup. | ||
2076 | if (YP.ground(NameSlashArity)) | ||
2077 | { | ||
2078 | Functor2 NameArityFunctor = NameSlashArity as Functor2; | ||
2079 | if (!(NameArityFunctor != null && NameArityFunctor._name == Atom.SLASH)) | ||
2080 | throw new PrologException | ||
2081 | (new Functor2("type_error", Atom.a("predicate_indicator"), NameSlashArity), | ||
2082 | "Must be a name/arity predicate indicator"); | ||
2083 | object name = YP.getValue(NameArityFunctor._arg1); | ||
2084 | object arity = YP.getValue(NameArityFunctor._arg2); | ||
2085 | if (name is Variable || arity is Variable) | ||
2086 | throw new PrologException | ||
2087 | ("instantiation_error", "Predicate indicator name or arity is an unbound variable"); | ||
2088 | if (!(name is Atom && arity is int)) | ||
2089 | throw new PrologException | ||
2090 | (new Functor2("type_error", Atom.a("predicate_indicator"), NameSlashArity), | ||
2091 | "Must be a name/arity predicate indicator"); | ||
2092 | if ((int)arity < 0) | ||
2093 | throw new PrologException | ||
2094 | (new Functor2("domain_error", Atom.a("not_less_than_zero"), arity), | ||
2095 | "Arity may not be less than zero"); | ||
2096 | |||
2097 | if (YPCompiler.isCurrentPredicate((Atom)name, (int)arity, declaringClass)) | ||
2098 | // The predicate is defined. | ||
2099 | yield return false; | ||
2100 | } | ||
2101 | else | ||
2102 | { | ||
2103 | foreach (NameArity key in _predicatesStore.Keys) | ||
2104 | { | ||
2105 | foreach (bool l1 in YP.unify | ||
2106 | (new Functor2(Atom.SLASH, key._name, key._arity), NameSlashArity)) | ||
2107 | yield return false; | ||
2108 | } | ||
2109 | } | ||
2110 | } | ||
2111 | |||
2112 | /// <summary> | ||
2113 | /// Return true if the dynamic predicate store has an entry for the predicate | ||
2114 | /// with name and arity. | ||
2115 | /// </summary> | ||
2116 | /// <param name="name"></param> | ||
2117 | /// <param name="arity"></param> | ||
2118 | /// <returns></returns> | ||
2119 | public static bool isDynamicCurrentPredicate(Atom name, int arity) | ||
2120 | { | ||
2121 | return _predicatesStore.ContainsKey(new NameArity(name, arity)); | ||
2122 | } | ||
2123 | |||
2124 | public static void abolish(object NameSlashArity) | ||
2125 | { | ||
2126 | NameSlashArity = YP.getValue(NameSlashArity); | ||
2127 | if (NameSlashArity is Variable) | ||
2128 | throw new PrologException | ||
2129 | ("instantiation_error", "Predicate indicator is an unbound variable"); | ||
2130 | Functor2 NameArityFunctor = NameSlashArity as Functor2; | ||
2131 | if (!(NameArityFunctor != null && NameArityFunctor._name == Atom.SLASH)) | ||
2132 | throw new PrologException | ||
2133 | (new Functor2("type_error", Atom.a("predicate_indicator"), NameSlashArity), | ||
2134 | "Must be a name/arity predicate indicator"); | ||
2135 | object name = YP.getValue(NameArityFunctor._arg1); | ||
2136 | object arity = YP.getValue(NameArityFunctor._arg2); | ||
2137 | if (name is Variable || arity is Variable) | ||
2138 | throw new PrologException | ||
2139 | ("instantiation_error", "Predicate indicator name or arity is an unbound variable"); | ||
2140 | if (!(name is Atom)) | ||
2141 | throw new PrologException | ||
2142 | (new Functor2("type_error", Atom.a("atom"), name), | ||
2143 | "Predicate indicator name must be an atom"); | ||
2144 | if (!(arity is int)) | ||
2145 | throw new PrologException | ||
2146 | (new Functor2("type_error", Atom.a("integer"), arity), | ||
2147 | "Predicate indicator arity must be an integer"); | ||
2148 | if ((int)arity < 0) | ||
2149 | throw new PrologException | ||
2150 | (new Functor2("domain_error", Atom.a("not_less_than_zero"), arity), | ||
2151 | "Arity may not be less than zero"); | ||
2152 | if ((int)arity > MAX_ARITY) | ||
2153 | throw new PrologException | ||
2154 | (new Functor1("representation_error", Atom.a("max_arity")), | ||
2155 | "Arity may not be greater than " + MAX_ARITY); | ||
2156 | |||
2157 | if (isSystemPredicate((Atom)name, (int)arity)) | ||
2158 | throw new PrologException | ||
2159 | (new Functor3("permission_error", Atom.a("modify"), Atom.a("static_procedure"), | ||
2160 | new Functor2(Atom.SLASH, name, arity)), | ||
2161 | "Abolish cannot modify static predicate " + name + "/" + arity); | ||
2162 | _predicatesStore.Remove(new NameArity((Atom)name, (int)arity)); | ||
2163 | } | ||
2164 | |||
2165 | /// <summary> | ||
2166 | /// If Goal is a simple predicate, call YP.getFunctorName(Goal) using arguments from | ||
2167 | /// YP.getFunctorArgs(Goal). If not found, this throws a PrologException for existence_error. | ||
2168 | /// Otherwise, compile the goal as a single clause predicate and invoke it. | ||
2169 | /// </summary> | ||
2170 | /// <param name="Goal"></param> | ||
2171 | /// <param name="declaringClass">if not null, used to resolve references to the default | ||
2172 | /// module Atom.a("")</param> | ||
2173 | /// <returns></returns> | ||
2174 | public static IEnumerable<bool> getIterator(object Goal, Type declaringClass) | ||
2175 | { | ||
2176 | Atom name; | ||
2177 | object[] args; | ||
2178 | while (true) | ||
2179 | { | ||
2180 | Goal = YP.getValue(Goal); | ||
2181 | if (Goal is Variable) | ||
2182 | throw new PrologException("instantiation_error", "Goal to call is an unbound variable"); | ||
2183 | name = YP.getFunctorName(Goal) as Atom; | ||
2184 | if (name == null) | ||
2185 | throw new PrologException | ||
2186 | (new Functor2("type_error", Atom.a("callable"), Goal), "Goal to call is not callable"); | ||
2187 | args = YP.getFunctorArgs(Goal); | ||
2188 | if (name == Atom.HAT && args.Length == 2) | ||
2189 | // Assume this is called from a bagof operation. Skip the leading qualifiers. | ||
2190 | Goal = YP.getValue(((Functor2)Goal)._arg2); | ||
2191 | else | ||
2192 | break; | ||
2193 | } | ||
2194 | |||
2195 | IEnumerable<bool> simpleIterator = YPCompiler.getSimpleIterator(name, args, declaringClass); | ||
2196 | if (simpleIterator != null) | ||
2197 | // We don't need to compile since the goal is a simple predicate which we call directly. | ||
2198 | return simpleIterator; | ||
2199 | |||
2200 | // Compile the goal as a clause. | ||
2201 | List<Variable> variableSetList = new List<Variable>(); | ||
2202 | addUniqueVariables(Goal, variableSetList); | ||
2203 | Variable[] variableSet = variableSetList.ToArray(); | ||
2204 | |||
2205 | // Use Atom.F since it is ignored. | ||
2206 | return YPCompiler.compileAnonymousClause | ||
2207 | (Functor.make(Atom.F, variableSet), Goal, declaringClass).match(variableSet); | ||
2208 | } | ||
2209 | |||
2210 | public static void throwException(object Term) | ||
2211 | { | ||
2212 | throw new PrologException(Term); | ||
2213 | } | ||
2214 | /// <summary> | ||
2215 | /// This must be called by any function that uses YP._prologFlags to make sure | ||
2216 | /// the initial defaults are loaded. | ||
2217 | /// </summary> | ||
2218 | private static void establishPrologFlags() | ||
2219 | { | ||
2220 | if (_prologFlags.Count > 0) | ||
2221 | // Already established. | ||
2222 | return; | ||
2223 | |||
2224 | // List these in the order they appear in the ISO standard. | ||
2225 | _prologFlags["bounded"] = Atom.a("true"); | ||
2226 | _prologFlags["max_integer"] = Int32.MaxValue; | ||
2227 | _prologFlags["min_integer"] = Int32.MinValue; | ||
2228 | _prologFlags["integer_rounding_function"] = Atom.a("toward_zero"); | ||
2229 | _prologFlags["char_conversion"] = Atom.a("off"); | ||
2230 | _prologFlags["debug"] = Atom.a("off"); | ||
2231 | _prologFlags["max_arity"] = MAX_ARITY; | ||
2232 | _prologFlags["unknown"] = Atom.a("error"); | ||
2233 | _prologFlags["double_quotes"] = Atom.a("codes"); | ||
2234 | } | ||
2235 | |||
2236 | public static IEnumerable<bool> current_prolog_flag(object Key, object Value) | ||
2237 | { | ||
2238 | establishPrologFlags(); | ||
2239 | |||
2240 | Key = YP.getValue(Key); | ||
2241 | Value = YP.getValue(Value); | ||
2242 | |||
2243 | if (Key is Variable) | ||
2244 | { | ||
2245 | // Bind all key values. | ||
2246 | foreach (string key in _prologFlags.Keys) | ||
2247 | { | ||
2248 | foreach (bool l1 in YP.unify(Key, Atom.a(key))) | ||
2249 | { | ||
2250 | foreach (bool l2 in YP.unify(Value, _prologFlags[key])) | ||
2251 | yield return false; | ||
2252 | } | ||
2253 | } | ||
2254 | } | ||
2255 | else | ||
2256 | { | ||
2257 | if (!(Key is Atom)) | ||
2258 | throw new PrologException | ||
2259 | (new Functor2("type_error", Atom.a("atom"), Key), "Arg 1 Key is not an atom"); | ||
2260 | if (!_prologFlags.ContainsKey(((Atom)Key)._name)) | ||
2261 | throw new PrologException | ||
2262 | (new Functor2("domain_error", Atom.a("prolog_flag"), Key), | ||
2263 | "Arg 1 Key is not a recognized flag"); | ||
2264 | |||
2265 | foreach (bool l1 in YP.unify(Value, _prologFlags[((Atom)Key)._name])) | ||
2266 | yield return false; | ||
2267 | } | ||
2268 | } | ||
2269 | |||
2270 | public static void set_prolog_flag(object Key, object Value) | ||
2271 | { | ||
2272 | establishPrologFlags(); | ||
2273 | |||
2274 | Key = YP.getValue(Key); | ||
2275 | Value = YP.getValue(Value); | ||
2276 | |||
2277 | if (Key is Variable) | ||
2278 | throw new PrologException(Atom.a("instantiation_error"), | ||
2279 | "Arg 1 Key is an unbound variable"); | ||
2280 | if (Value is Variable) | ||
2281 | throw new PrologException(Atom.a("instantiation_error"), | ||
2282 | "Arg 1 Key is an unbound variable"); | ||
2283 | if (!(Key is Atom)) | ||
2284 | throw new PrologException | ||
2285 | (new Functor2("type_error", Atom.a("atom"), Key), "Arg 1 Key is not an atom"); | ||
2286 | |||
2287 | string keyName = ((Atom)Key)._name; | ||
2288 | if (!_prologFlags.ContainsKey(keyName)) | ||
2289 | throw new PrologException | ||
2290 | (new Functor2("domain_error", Atom.a("prolog_flag"), Key), | ||
2291 | "Arg 1 Key " + Key + " is not a recognized flag"); | ||
2292 | |||
2293 | bool valueIsOK = false; | ||
2294 | if (keyName == "char_conversion") | ||
2295 | valueIsOK = (Value == _prologFlags[keyName]); | ||
2296 | else if (keyName == "debug") | ||
2297 | valueIsOK = (Value == _prologFlags[keyName]); | ||
2298 | else if (keyName == "unknown") | ||
2299 | valueIsOK = (Value == Atom.a("fail") || Value == Atom.a("warning") || | ||
2300 | Value == Atom.a("error")); | ||
2301 | else if (keyName == "double_quotes") | ||
2302 | valueIsOK = (Value == Atom.a("codes") || Value == Atom.a("chars") || | ||
2303 | Value == Atom.a("atom")); | ||
2304 | else | ||
2305 | throw new PrologException | ||
2306 | (new Functor3("permission_error", Atom.a("modify"), Atom.a("flag"), Key), | ||
2307 | "May not modify Prolog flag " + Key); | ||
2308 | |||
2309 | if (!valueIsOK) | ||
2310 | throw new PrologException | ||
2311 | (new Functor2("domain_error", Atom.a("flag_value"), new Functor2("+", Key, Value)), | ||
2312 | "May not set arg 1 Key " + Key + " to arg 2 Value " + Value); | ||
2313 | |||
2314 | _prologFlags[keyName] = Value; | ||
2315 | } | ||
2316 | /// <summary> | ||
2317 | /// script_event calls hosting script with events as a callback method. | ||
2318 | /// </summary> | ||
2319 | /// <param name="script_event"></param> | ||
2320 | /// <param name="script_params"></param> | ||
2321 | /// <returns></returns> | ||
2322 | public static IEnumerable<bool> script_event(object script_event, object script_params) | ||
2323 | { | ||
2324 | // string function = ((Atom)YP.getValue(script_event))._name; | ||
2325 | object[] array = ListPair.toArray(script_params); | ||
2326 | if (array == null) | ||
2327 | yield return false; // return; // YP.fail(); | ||
2328 | if (array.Length > 1) | ||
2329 | { | ||
2330 | //m_CmdManager.m_ScriptEngine.m_EventQueManager.AddToScriptQueue | ||
2331 | //(localID, itemID, function, array); | ||
2332 | // sortArray(array); | ||
2333 | } | ||
2334 | //return YP.unify(Sorted, ListPair.makeWithoutRepeatedTerms(array)); | ||
2335 | yield return false; | ||
2336 | } | ||
2337 | |||
2338 | /* Non-prolog-ish functions for inline coding */ | ||
2339 | public static string regexString(string inData, string inPattern, string presep,string postsep) | ||
2340 | { | ||
2341 | //string str=cycMessage; | ||
2342 | //string strMatch = @"\. \#\$(.*)\)"; | ||
2343 | string results = ""; | ||
2344 | for (Match m = Regex.Match(inData,inPattern); m.Success; m=m.NextMatch()) | ||
2345 | { | ||
2346 | //m_log.Debug(m); | ||
2347 | results += presep+ m + postsep; | ||
2348 | } | ||
2349 | return results; | ||
2350 | } | ||
2351 | |||
2352 | public static string cycComm(object msgobj) | ||
2353 | { | ||
2354 | string cycInputString = msgobj.ToString(); | ||
2355 | string cycOutputString=""; | ||
2356 | TcpClient socketForServer; | ||
2357 | |||
2358 | try | ||
2359 | { | ||
2360 | socketForServer = new TcpClient("localHost", 3601); | ||
2361 | } | ||
2362 | catch | ||
2363 | { | ||
2364 | m_log.Error("Failed to connect to server at localhost:999"); | ||
2365 | return ""; | ||
2366 | } | ||
2367 | |||
2368 | NetworkStream networkStream = socketForServer.GetStream(); | ||
2369 | |||
2370 | System.IO.StreamReader streamReader = new System.IO.StreamReader(networkStream); | ||
2371 | |||
2372 | System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(networkStream); | ||
2373 | |||
2374 | try | ||
2375 | { | ||
2376 | // read the data from the host and display it | ||
2377 | |||
2378 | { | ||
2379 | |||
2380 | streamWriter.WriteLine(cycInputString); | ||
2381 | streamWriter.Flush(); | ||
2382 | |||
2383 | cycOutputString = streamReader.ReadLine(); | ||
2384 | m_log.Debug("Cycoutput:" + cycOutputString); | ||
2385 | //streamWriter.WriteLine("Client Message"); | ||
2386 | //m_log.Debug("Client Message"); | ||
2387 | streamWriter.Flush(); | ||
2388 | } | ||
2389 | |||
2390 | } | ||
2391 | catch | ||
2392 | { | ||
2393 | m_log.Error("Exception reading from Server"); | ||
2394 | return ""; | ||
2395 | } | ||
2396 | // tidy up | ||
2397 | networkStream.Close(); | ||
2398 | return cycOutputString; | ||
2399 | |||
2400 | } | ||
2401 | //public static void throwException(object Term) | ||
2402 | //{ | ||
2403 | // throw new PrologException(Term); | ||
2404 | //} | ||
2405 | /// <summary> | ||
2406 | /// An enumerator that does zero loops. | ||
2407 | /// </summary> | ||
2408 | private class Fail : IEnumerator<bool>, IEnumerable<bool> | ||
2409 | { | ||
2410 | public bool MoveNext() | ||
2411 | { | ||
2412 | return false; | ||
2413 | } | ||
2414 | |||
2415 | public IEnumerator<bool> GetEnumerator() | ||
2416 | { | ||
2417 | return (IEnumerator<bool>)this; | ||
2418 | } | ||
2419 | |||
2420 | IEnumerator IEnumerable.GetEnumerator() | ||
2421 | { | ||
2422 | return GetEnumerator(); | ||
2423 | } | ||
2424 | |||
2425 | public bool Current | ||
2426 | { | ||
2427 | get { return true; } | ||
2428 | } | ||
2429 | |||
2430 | object IEnumerator.Current | ||
2431 | { | ||
2432 | get { return true; } | ||
2433 | } | ||
2434 | |||
2435 | public void Dispose() | ||
2436 | { | ||
2437 | } | ||
2438 | |||
2439 | public void Reset() | ||
2440 | { | ||
2441 | throw new NotImplementedException(); | ||
2442 | } | ||
2443 | } | ||
2444 | |||
2445 | /// <summary> | ||
2446 | /// An enumerator that does one iteration. | ||
2447 | /// </summary> | ||
2448 | private class Succeed : IEnumerator<bool>, IEnumerable<bool> | ||
2449 | { | ||
2450 | private bool _didIteration = false; | ||
2451 | |||
2452 | public bool MoveNext() | ||
2453 | { | ||
2454 | if (!_didIteration) | ||
2455 | { | ||
2456 | _didIteration = true; | ||
2457 | return true; | ||
2458 | } | ||
2459 | else | ||
2460 | return false; | ||
2461 | } | ||
2462 | |||
2463 | public IEnumerator<bool> GetEnumerator() | ||
2464 | { | ||
2465 | return (IEnumerator<bool>)this; | ||
2466 | } | ||
2467 | |||
2468 | IEnumerator IEnumerable.GetEnumerator() | ||
2469 | { | ||
2470 | return GetEnumerator(); | ||
2471 | } | ||
2472 | |||
2473 | public bool Current | ||
2474 | { | ||
2475 | get { return false; } | ||
2476 | } | ||
2477 | |||
2478 | object IEnumerator.Current | ||
2479 | { | ||
2480 | get { return false; } | ||
2481 | } | ||
2482 | |||
2483 | public void Dispose() | ||
2484 | { | ||
2485 | } | ||
2486 | |||
2487 | public void Reset() | ||
2488 | { | ||
2489 | throw new NotImplementedException(); | ||
2490 | } | ||
2491 | } | ||
2492 | |||
2493 | /// <summary> | ||
2494 | /// An enumerator that repeats forever. | ||
2495 | /// </summary> | ||
2496 | private class Repeat : IEnumerator<bool>, IEnumerable<bool> | ||
2497 | { | ||
2498 | public bool MoveNext() | ||
2499 | { | ||
2500 | return true; | ||
2501 | } | ||
2502 | |||
2503 | public IEnumerator<bool> GetEnumerator() | ||
2504 | { | ||
2505 | return (IEnumerator<bool>)this; | ||
2506 | } | ||
2507 | |||
2508 | IEnumerator IEnumerable.GetEnumerator() | ||
2509 | { | ||
2510 | return GetEnumerator(); | ||
2511 | } | ||
2512 | |||
2513 | public bool Current | ||
2514 | { | ||
2515 | get { return false; } | ||
2516 | } | ||
2517 | |||
2518 | object IEnumerator.Current | ||
2519 | { | ||
2520 | get { return false; } | ||
2521 | } | ||
2522 | |||
2523 | public void Dispose() | ||
2524 | { | ||
2525 | } | ||
2526 | |||
2527 | public void Reset() | ||
2528 | { | ||
2529 | throw new NotImplementedException(); | ||
2530 | } | ||
2531 | } | ||
2532 | |||
2533 | /// <summary> | ||
2534 | /// An enumerator that wraps another enumerator in order to catch a PrologException. | ||
2535 | /// </summary> | ||
2536 | public class Catch : IEnumerator<bool>, IEnumerable<bool> | ||
2537 | { | ||
2538 | private IEnumerator<bool> _enumerator; | ||
2539 | private PrologException _exception = null; | ||
2540 | |||
2541 | /// <summary> | ||
2542 | /// Call YP.getIterator(Goal, declaringClass) and save the returned iterator. | ||
2543 | /// If getIterator throws an exception, save it the same as MoveNext(). | ||
2544 | /// </summary> | ||
2545 | /// <param name="Goal"></param> | ||
2546 | /// <param name="declaringClass"></param> | ||
2547 | public Catch(object Goal, Type declaringClass) | ||
2548 | { | ||
2549 | try | ||
2550 | { | ||
2551 | _enumerator = getIterator(Goal, declaringClass).GetEnumerator(); | ||
2552 | } | ||
2553 | catch (PrologException exception) | ||
2554 | { | ||
2555 | // MoveNext() will check this. | ||
2556 | _exception = exception; | ||
2557 | } | ||
2558 | } | ||
2559 | |||
2560 | /// <summary> | ||
2561 | /// Call _enumerator.MoveNext(). If it throws a PrologException, set _exception | ||
2562 | /// and return false. After this returns false, call unifyExceptionOrThrow. | ||
2563 | /// </summary> | ||
2564 | /// <returns></returns> | ||
2565 | public bool MoveNext() | ||
2566 | { | ||
2567 | if (_exception != null) | ||
2568 | return false; | ||
2569 | |||
2570 | try | ||
2571 | { | ||
2572 | return _enumerator.MoveNext(); | ||
2573 | } | ||
2574 | catch (PrologException exception) | ||
2575 | { | ||
2576 | _exception = exception; | ||
2577 | return false; | ||
2578 | } | ||
2579 | } | ||
2580 | |||
2581 | /// <summary> | ||
2582 | /// Call this after MoveNext() returns false to check for an exception. If | ||
2583 | /// MoveNext did not get a PrologException, don't yield. | ||
2584 | /// Otherwise, unify the exception with Catcher and yield so the caller can | ||
2585 | /// do the handler code. However, if can't unify with Catcher then throw the exception. | ||
2586 | /// </summary> | ||
2587 | /// <param name="Catcher"></param> | ||
2588 | /// <returns></returns> | ||
2589 | public IEnumerable<bool> unifyExceptionOrThrow(object Catcher) | ||
2590 | { | ||
2591 | if (_exception != null) | ||
2592 | { | ||
2593 | bool didUnify = false; | ||
2594 | foreach (bool l1 in YP.unify(_exception._term, Catcher)) | ||
2595 | { | ||
2596 | didUnify = true; | ||
2597 | yield return false; | ||
2598 | } | ||
2599 | if (!didUnify) | ||
2600 | throw _exception; | ||
2601 | } | ||
2602 | } | ||
2603 | |||
2604 | public IEnumerator<bool> GetEnumerator() | ||
2605 | { | ||
2606 | return (IEnumerator<bool>)this; | ||
2607 | } | ||
2608 | |||
2609 | IEnumerator IEnumerable.GetEnumerator() | ||
2610 | { | ||
2611 | return GetEnumerator(); | ||
2612 | } | ||
2613 | |||
2614 | public bool Current | ||
2615 | { | ||
2616 | get { return _enumerator.Current; } | ||
2617 | } | ||
2618 | |||
2619 | object IEnumerator.Current | ||
2620 | { | ||
2621 | get { return _enumerator.Current; } | ||
2622 | } | ||
2623 | |||
2624 | public void Dispose() | ||
2625 | { | ||
2626 | if (_enumerator != null) | ||
2627 | _enumerator.Dispose(); | ||
2628 | } | ||
2629 | |||
2630 | public void Reset() | ||
2631 | { | ||
2632 | throw new NotImplementedException(); | ||
2633 | } | ||
2634 | } | ||
2635 | #pragma warning restore 0168, 0219 | ||
2636 | /// <summary> | ||
2637 | /// A ClauseHeadAndBody is used in Compiler.compileAnonymousFunction as a base class | ||
2638 | /// in order to implement YP.IClause. After creating the object, you must call setHeadAndBody. | ||
2639 | /// </summary> | ||
2640 | public class ClauseHeadAndBody | ||
2641 | { | ||
2642 | private object _Head; | ||
2643 | private object _Body; | ||
2644 | |||
2645 | public void setHeadAndBody(object Head, object Body) | ||
2646 | { | ||
2647 | _Head = Head; | ||
2648 | _Body = Body; | ||
2649 | } | ||
2650 | |||
2651 | public IEnumerable<bool> clause(object Head, object Body) | ||
2652 | { | ||
2653 | if (_Head == null || _Body == null) | ||
2654 | yield break; | ||
2655 | |||
2656 | #pragma warning disable 0168, 0219 | ||
2657 | foreach (bool l1 in YP.unify(Head, _Head)) | ||
2658 | { | ||
2659 | foreach (bool l2 in YP.unify(Body, _Body)) | ||
2660 | yield return false; | ||
2661 | } | ||
2662 | #pragma warning restore 0168, 0219 | ||
2663 | } | ||
2664 | } | ||
2665 | |||
2666 | /// <summary> | ||
2667 | /// CodeListReader extends TextReader and overrides Read to read the next code from | ||
2668 | /// the CodeList which is a Prolog list of integer character codes. | ||
2669 | /// </summary> | ||
2670 | public class CodeListReader : TextReader | ||
2671 | { | ||
2672 | private object _CodeList; | ||
2673 | |||
2674 | public CodeListReader(object CodeList) | ||
2675 | { | ||
2676 | _CodeList = YP.getValue(CodeList); | ||
2677 | } | ||
2678 | |||
2679 | /// <summary> | ||
2680 | /// If the head of _CodeList is an integer, return it and advance the list. Otherwise, | ||
2681 | /// return -1 for end of file. | ||
2682 | /// </summary> | ||
2683 | /// <returns></returns> | ||
2684 | public override int Read() | ||
2685 | { | ||
2686 | Functor2 CodeListPair = _CodeList as Functor2; | ||
2687 | int code; | ||
2688 | if (!(CodeListPair != null && CodeListPair._name == Atom.DOT && | ||
2689 | getInt(CodeListPair._arg1, out code))) | ||
2690 | { | ||
2691 | _CodeList = Atom.NIL; | ||
2692 | return -1; | ||
2693 | } | ||
2694 | |||
2695 | // Advance. | ||
2696 | _CodeList = YP.getValue(CodeListPair._arg2); | ||
2697 | return code; | ||
2698 | } | ||
2699 | } | ||
2700 | } | ||
2701 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YPCompiler.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YPCompiler.cs deleted file mode 100644 index c6a6748..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YPCompiler.cs +++ /dev/null | |||
@@ -1,6382 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.IO; | ||
33 | using System.Collections; | ||
34 | using System.Collections.Generic; | ||
35 | using System.Text; | ||
36 | using System.CodeDom.Compiler; | ||
37 | using System.Reflection; | ||
38 | |||
39 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
40 | { | ||
41 | public class YPCompiler | ||
42 | { | ||
43 | private class CompilerState | ||
44 | { | ||
45 | public IndexedAnswers _pred = new IndexedAnswers(4); | ||
46 | public Dictionary<YP.NameArity, Atom> _moduleForNameArity = new Dictionary<YP.NameArity, Atom>(); | ||
47 | public int _gensymCounter; | ||
48 | public bool _useFinalCutCode; | ||
49 | public Variable _finalCutCode; | ||
50 | public bool _codeUsesYield; | ||
51 | public Atom _determinism; | ||
52 | // a list of '='(Name, Variable) | ||
53 | public List<object> _variableNames; | ||
54 | |||
55 | // Make these static functions that explicitly take the State so Prolog can call it. | ||
56 | |||
57 | /// <summary> | ||
58 | /// Make a new CompilerState and bind it to State. | ||
59 | /// </summary> | ||
60 | /// <param name="State"></param> | ||
61 | /// <returns></returns> | ||
62 | public static IEnumerable<bool> make(object State) | ||
63 | { | ||
64 | return YP.unify(State, new CompilerState()); | ||
65 | } | ||
66 | |||
67 | public static void assertPred(object State, object Pred, object Determinism) | ||
68 | { | ||
69 | State = YP.getValue(State); | ||
70 | object functorName = YP.getFunctorName(Pred); | ||
71 | object[] functorArgs = YP.getFunctorArgs(Pred); | ||
72 | // Debug: Should check if it's already asserted and is the same. | ||
73 | ((CompilerState)State)._pred.addAnswer | ||
74 | (new object[] { functorName, functorArgs.Length, Pred, YP.getValue(Determinism) }); | ||
75 | } | ||
76 | |||
77 | public static void assertModuleForNameArity(object State, object Name, object Arity, object Module) | ||
78 | { | ||
79 | State = YP.getValue(State); | ||
80 | Name = YP.getValue(Name); | ||
81 | Arity = YP.getValue(Arity); | ||
82 | Module = YP.getValue(Module); | ||
83 | // If the Module Atom comes from the parser, it always has null _declaringClass. | ||
84 | if (Module is Atom && ((Atom)Module)._module == null && Name is Atom && Arity is int) | ||
85 | // Replace a previous entry if it exists. | ||
86 | ((CompilerState)State)._moduleForNameArity[new YP.NameArity((Atom)Name, (int)Arity)] = | ||
87 | (Atom)Module; | ||
88 | } | ||
89 | |||
90 | public static void startFunction(object State, object Head) | ||
91 | { | ||
92 | State = YP.getValue(State); | ||
93 | ((CompilerState)State)._gensymCounter = 0; | ||
94 | ((CompilerState)State)._useFinalCutCode = false; | ||
95 | ((CompilerState)State)._finalCutCode = new Variable(); | ||
96 | ((CompilerState)State)._codeUsesYield = false; | ||
97 | if (CompilerState.isDetNoneOut(State, Head)) | ||
98 | ((CompilerState)State)._determinism = Atom.a("detNoneOut"); | ||
99 | else if (CompilerState.isSemidetNoneOut(State, Head)) | ||
100 | ((CompilerState)State)._determinism = Atom.a("semidetNoneOut"); | ||
101 | else | ||
102 | ((CompilerState)State)._determinism = Atom.a("nondet"); | ||
103 | } | ||
104 | |||
105 | public static void setCodeUsesYield(object State) | ||
106 | { | ||
107 | State = YP.getValue(State); | ||
108 | ((CompilerState)State)._codeUsesYield = true; | ||
109 | } | ||
110 | |||
111 | public static bool codeUsesYield(object State) | ||
112 | { | ||
113 | State = YP.getValue(State); | ||
114 | return ((CompilerState)State)._codeUsesYield; | ||
115 | } | ||
116 | |||
117 | public static bool determinismEquals(object State, object Term) | ||
118 | { | ||
119 | State = YP.getValue(State); | ||
120 | return YP.termEqual(((CompilerState)State)._determinism, Term); | ||
121 | } | ||
122 | |||
123 | /// <summary> | ||
124 | /// Set _variableNames to a new list of (Name = Variable) for each unique variable in rule. | ||
125 | /// If the variable is in variableNameSuggestions, use it, otherwise use x1, x2, etc. | ||
126 | /// </summary> | ||
127 | /// <param name="State"></param> | ||
128 | /// <param name="rule"></param> | ||
129 | /// <param name="variableNameSuggestions"></param> | ||
130 | public static void newVariableNames(object State, object Rule, object VariableNameSuggestions) | ||
131 | { | ||
132 | State = YP.getValue(State); | ||
133 | List<Variable> variablesSet = new List<Variable>(); | ||
134 | YP.addUniqueVariables(Rule, variablesSet); | ||
135 | |||
136 | ((CompilerState)State)._variableNames = new List<object>(); | ||
137 | int xCounter = 0; | ||
138 | foreach (Variable variable in variablesSet) | ||
139 | ((CompilerState)State)._variableNames.Add | ||
140 | (new Functor2(Atom.a("="), makeVariableName(variable, VariableNameSuggestions, ++xCounter), | ||
141 | variable)); | ||
142 | } | ||
143 | |||
144 | private static object makeVariableName(object variable, object variableNameSuggestions, int xCounter) | ||
145 | { | ||
146 | // Debug: should require named variables to start with _ or capital. Should | ||
147 | // check for duplicates and clashes with keywords. | ||
148 | for (object element = YP.getValue(variableNameSuggestions); | ||
149 | element is Functor2 && ((Functor2)element)._name == Atom.DOT; | ||
150 | element = YP.getValue(((Functor2)element)._arg2)) | ||
151 | { | ||
152 | object suggestionPair = YP.getValue(((Functor2)element)._arg1); | ||
153 | if (sameVariable(variable, ((Functor2)suggestionPair)._arg2)) | ||
154 | { | ||
155 | Atom suggestion = (Atom)YP.getValue(((Functor2)suggestionPair)._arg1); | ||
156 | if (suggestion.Equals(Atom.a("Atom"))) | ||
157 | suggestion = Atom.a("Atom_1"); | ||
158 | if (suggestion.Equals(Atom.a("Variable"))) | ||
159 | suggestion = Atom.a("Variable_1"); | ||
160 | if (suggestion.Equals(Atom.a("Functor"))) | ||
161 | suggestion = Atom.a("Functor_1"); | ||
162 | return suggestion; | ||
163 | } | ||
164 | } | ||
165 | |||
166 | return Atom.a("x" + xCounter); | ||
167 | } | ||
168 | |||
169 | /// <summary> | ||
170 | /// Unify Result with the name assigned by CompilerState.newVariableNames in State._variableNames | ||
171 | /// for variable. | ||
172 | /// </summary> | ||
173 | /// <param name="variable">a Variable</param> | ||
174 | /// <param name="State"></param> | ||
175 | /// <param name="Result">the assigned Name</param> | ||
176 | public static IEnumerable<bool> getVariableName(object State, object variable, object Result) | ||
177 | { | ||
178 | State = YP.getValue(State); | ||
179 | foreach (object variableInfo in ((CompilerState)State)._variableNames) | ||
180 | { | ||
181 | if (variableInfo is Functor2 && ((Functor2)variableInfo)._name.Equals(Atom.a("="))) | ||
182 | { | ||
183 | if (sameVariable(variable, ((Functor2)variableInfo)._arg2)) | ||
184 | return YP.unify(Result, ((Functor2)variableInfo)._arg1); | ||
185 | } | ||
186 | } | ||
187 | |||
188 | // We set up names for all unique variables, so this should never happen. | ||
189 | throw new PrologException(Atom.a("Can't find entry in _variableNames")); | ||
190 | } | ||
191 | |||
192 | public static IEnumerable<bool> variableNamesList(object State, object VariableNamesList) | ||
193 | { | ||
194 | State = YP.getValue(State); | ||
195 | return YP.unify(VariableNamesList, ListPair.make(((CompilerState)State)._variableNames)); | ||
196 | } | ||
197 | |||
198 | public static IEnumerable<bool> gensym(object State, object Base, object Symbol) | ||
199 | { | ||
200 | State = YP.getValue(State); | ||
201 | return YP.unify(Symbol, Atom.a(Base.ToString() + ++((CompilerState)State)._gensymCounter)); | ||
202 | } | ||
203 | |||
204 | // disable warning on l1, don't see how we can | ||
205 | // code this differently | ||
206 | #pragma warning disable 0168, 0164, 0162, 0219 | ||
207 | public static bool isDetNoneOut(object State, object Term) | ||
208 | { | ||
209 | State = YP.getValue(State); | ||
210 | object functorName = YP.getFunctorName(Term); | ||
211 | object[] functorArgs = YP.getFunctorArgs(Term); | ||
212 | |||
213 | Variable pred = new Variable(); | ||
214 | foreach (bool l1 in ((CompilerState)State)._pred.match | ||
215 | (new object[] { functorName, functorArgs.Length, pred, Atom.a("det") })) | ||
216 | { | ||
217 | if (CompilerState.isNoneOut(YP.getFunctorArgs(pred.getValue()))) | ||
218 | { | ||
219 | return true; | ||
220 | } | ||
221 | } | ||
222 | |||
223 | return false; | ||
224 | } | ||
225 | |||
226 | public static bool isSemidetNoneOut(object State, object Term) | ||
227 | { | ||
228 | State = YP.getValue(State); | ||
229 | object functorName = YP.getFunctorName(Term); | ||
230 | object[] functorArgs = YP.getFunctorArgs(Term); | ||
231 | |||
232 | Variable pred = new Variable(); | ||
233 | foreach (bool l1 in ((CompilerState)State)._pred.match | ||
234 | (new object[] { functorName, functorArgs.Length, pred, Atom.a("semidet") })) | ||
235 | { | ||
236 | if (CompilerState.isNoneOut(YP.getFunctorArgs(pred.getValue()))) | ||
237 | { | ||
238 | return true; | ||
239 | } | ||
240 | } | ||
241 | |||
242 | return false; | ||
243 | } | ||
244 | #pragma warning restore 0168, 0164, 0162, 0219 | ||
245 | |||
246 | /// <summary> | ||
247 | /// Return false if any of args is out, otherwise true. | ||
248 | /// args is an array of ::(Type,Mode) where Mode is in or out. | ||
249 | /// </summary> | ||
250 | /// <param name="args"></param> | ||
251 | /// <returns></returns> | ||
252 | private static bool isNoneOut(object[] args) | ||
253 | { | ||
254 | foreach (object arg in args) | ||
255 | { | ||
256 | if (arg is Functor2 && ((Functor2)arg)._name == Atom.a("::") && | ||
257 | ((Functor2)arg)._arg2 == Atom.a("out")) | ||
258 | return false; | ||
259 | } | ||
260 | return true; | ||
261 | } | ||
262 | |||
263 | public static bool nameArityHasModule(object State, object Name, object Arity, object Module) | ||
264 | { | ||
265 | State = YP.getValue(State); | ||
266 | Name = YP.getValue(Name); | ||
267 | Arity = YP.getValue(Arity); | ||
268 | Module = YP.getValue(Module); | ||
269 | if (Name is Atom && Arity is int) | ||
270 | { | ||
271 | Atom FoundModule; | ||
272 | if (!((CompilerState)State)._moduleForNameArity.TryGetValue | ||
273 | (new YP.NameArity((Atom)Name, (int)Arity), out FoundModule)) | ||
274 | return false; | ||
275 | return FoundModule == Module; | ||
276 | } | ||
277 | return false; | ||
278 | } | ||
279 | } | ||
280 | |||
281 | // disable warning on l1, don't see how we can | ||
282 | // code this differently | ||
283 | #pragma warning disable 0168, 0219,0164,0162 | ||
284 | |||
285 | /// <summary> | ||
286 | /// Use makeFunctionPseudoCode, convertFunctionCSharp and compileAnonymousFunction | ||
287 | /// to return an anonymous YP.IClause for the Head and Body of a rule clause. | ||
288 | /// </summary> | ||
289 | /// <param name="Head">a prolog term such as new Functor2("test1", X, Y). | ||
290 | /// Note that the name of the head is ignored. | ||
291 | /// </param> | ||
292 | /// <param name="Body">a prolog term such as | ||
293 | /// new Functor2(",", new Functor1(Atom.a("test2", Atom.a("")), X), | ||
294 | /// new Functor2("=", Y, X)). | ||
295 | /// This may not be null. (For a head-only clause, set the Body to Atom.a("true"). | ||
296 | /// </param> | ||
297 | /// <param name="declaringClass">if not null, the code is compiled as a subclass of this class | ||
298 | /// to resolve references to the default module Atom.a("")</param> | ||
299 | /// <returns>a new YP.IClause object on which you can call match(object[] args) where | ||
300 | /// args length is the arity of the Head</returns> | ||
301 | public static YP.IClause compileAnonymousClause(object Head, object Body, Type declaringClass) | ||
302 | { | ||
303 | object[] args = YP.getFunctorArgs(Head); | ||
304 | // compileAnonymousFunction wants "function". | ||
305 | object Rule = new Functor2(Atom.RULE, Functor.make("function", args), Body); | ||
306 | object RuleList = ListPair.make(new Functor2(Atom.F, Rule, Atom.NIL)); | ||
307 | |||
308 | StringWriter functionCode = new StringWriter(); | ||
309 | Variable SaveOutputStream = new Variable(); | ||
310 | foreach (bool l1 in YP.current_output(SaveOutputStream)) | ||
311 | { | ||
312 | try | ||
313 | { | ||
314 | YP.tell(functionCode); | ||
315 | Variable PseudoCode = new Variable(); | ||
316 | foreach (bool l2 in makeFunctionPseudoCode(RuleList, PseudoCode)) | ||
317 | { | ||
318 | if (YP.termEqual(PseudoCode, Atom.a("getDeclaringClass"))) | ||
319 | // Ignore getDeclaringClass since we have access to the one passed in. | ||
320 | continue; | ||
321 | |||
322 | convertFunctionCSharp(PseudoCode); | ||
323 | } | ||
324 | YP.told(); | ||
325 | } | ||
326 | finally | ||
327 | { | ||
328 | // Restore after calling tell. | ||
329 | YP.tell(SaveOutputStream.getValue()); | ||
330 | } | ||
331 | } | ||
332 | return YPCompiler.compileAnonymousFunction | ||
333 | (functionCode.ToString(), args.Length, declaringClass); | ||
334 | } | ||
335 | |||
336 | /// <summary> | ||
337 | /// Use CodeDomProvider to compile the functionCode and return a YP.ClauseHeadAndBody | ||
338 | /// which implements YP.IClause. | ||
339 | /// The function name must be "function" and have nArgs arguments. | ||
340 | /// </summary> | ||
341 | /// <param name="functionCode">the code for the iterator, such as | ||
342 | /// "public static IEnumerable<bool> function() { yield return false; }" | ||
343 | /// </param> | ||
344 | /// <param name="nArgs">the number of args in the function</param> | ||
345 | /// <param name="declaringClass">if not null, then use the functionCode inside a class which | ||
346 | /// inherits from contextClass, so that references in functionCode to methods in declaringClass don't | ||
347 | /// have to be qualified</param> | ||
348 | /// <returns>a new YP.IClause object on which you can call match(object[] args) where | ||
349 | /// args length is nArgs</returns> | ||
350 | public static YP.IClause compileAnonymousFunction(string functionCode, int nArgs, Type declaringClass) | ||
351 | { | ||
352 | CompilerParameters parameters = new CompilerParameters(); | ||
353 | // This gets the location of the System assembly. | ||
354 | parameters.ReferencedAssemblies.Add(typeof(System.Int32).Assembly.Location); | ||
355 | // This gets the location of this assembly which also has YieldProlog.YP, etc. | ||
356 | parameters.ReferencedAssemblies.Add(typeof(YPCompiler).Assembly.Location); | ||
357 | if (declaringClass != null) | ||
358 | parameters.ReferencedAssemblies.Add(declaringClass.Assembly.Location); | ||
359 | parameters.GenerateInMemory = true; | ||
360 | |||
361 | StringBuilder sourceCode = new StringBuilder(); | ||
362 | sourceCode.Append(@" | ||
363 | using System; | ||
364 | using System.Collections.Generic; | ||
365 | using OpenSim.Region.ScriptEngine.Shared.YieldProlog; | ||
366 | |||
367 | namespace Temporary { | ||
368 | public class Temporary : YP.ClauseHeadAndBody, YP.IClause {"); | ||
369 | if (declaringClass == null) | ||
370 | // We don't extend a class with getDeclaringClass, so define it. | ||
371 | sourceCode.Append(@" | ||
372 | public class Inner { | ||
373 | public static System.Type getDeclaringClass() { return null; } | ||
374 | "); | ||
375 | else | ||
376 | sourceCode.Append(@" | ||
377 | public class Inner : " + declaringClass.FullName + @" { | ||
378 | "); | ||
379 | sourceCode.Append(functionCode); | ||
380 | // Basically, match applies the args to function. | ||
381 | sourceCode.Append(@" | ||
382 | } | ||
383 | public IEnumerable<bool> match(object[] args) { | ||
384 | return Inner.function("); | ||
385 | if (nArgs >= 1) | ||
386 | sourceCode.Append("args[0]"); | ||
387 | for (int i = 1; i < nArgs; ++i) | ||
388 | sourceCode.Append(", args[" + i + "]"); | ||
389 | sourceCode.Append(@"); | ||
390 | } | ||
391 | } | ||
392 | } | ||
393 | "); | ||
394 | |||
395 | CompilerResults results = CodeDomProvider.CreateProvider | ||
396 | ("CSharp").CompileAssemblyFromSource(parameters, sourceCode.ToString()); | ||
397 | if (results.Errors.Count > 0) | ||
398 | throw new Exception("Error evaluating code: " + results.Errors[0]); | ||
399 | |||
400 | // Return a new Temporary.Temporary object. | ||
401 | return (YP.IClause)results.CompiledAssembly.GetType | ||
402 | ("Temporary.Temporary").GetConstructor(Type.EmptyTypes).Invoke(null); | ||
403 | } | ||
404 | |||
405 | /// <summary> | ||
406 | /// If the functor with name and args can be called directly as determined by | ||
407 | /// functorCallFunctionName, then call it and return its iterator. If the predicate is | ||
408 | /// dynamic and undefined, or if static and the method cannot be found, return | ||
409 | /// the result of YP.unknownPredicate. | ||
410 | /// This returns null if the functor has a special form than needs to be compiled | ||
411 | /// (including ,/2 and ;/2). | ||
412 | /// </summary> | ||
413 | /// <param name="name"></param> | ||
414 | /// <param name="args"></param> | ||
415 | /// <param name="declaringClass">used to resolve references to the default | ||
416 | /// module Atom.a(""). If a declaringClass is needed to resolve the reference but it is | ||
417 | /// null, this throws a PrologException for existence_error</param> | ||
418 | /// <returns></returns> | ||
419 | public static IEnumerable<bool> getSimpleIterator(Atom name, object[] args, Type declaringClass) | ||
420 | { | ||
421 | CompilerState state = new CompilerState(); | ||
422 | Variable FunctionName = new Variable(); | ||
423 | foreach (bool l1 in functorCallFunctionName(state, name, args.Length, FunctionName)) | ||
424 | { | ||
425 | Atom functionNameAtom = ((Atom)FunctionName.getValue()); | ||
426 | if (functionNameAtom == Atom.NIL) | ||
427 | // name is for a dynamic predicate. | ||
428 | return YP.matchDynamic(name, args); | ||
429 | |||
430 | string methodName = functionNameAtom._name; | ||
431 | // Set the default for the method to call. | ||
432 | Type methodClass = declaringClass; | ||
433 | |||
434 | bool checkMode = false; | ||
435 | if (methodName.StartsWith("YP.")) | ||
436 | { | ||
437 | // Assume we only check mode in calls to standard Prolog predicates in YP. | ||
438 | checkMode = true; | ||
439 | |||
440 | // Use the method in class YP. | ||
441 | methodName = methodName.Substring(3); | ||
442 | methodClass = typeof(YP); | ||
443 | } | ||
444 | if (methodName.Contains(".")) | ||
445 | // We don't support calling inner classes, etc. | ||
446 | return null; | ||
447 | |||
448 | if (methodClass == null) | ||
449 | return YP.unknownPredicate | ||
450 | (name, args.Length, | ||
451 | "Cannot find predicate function for: " + name + "/" + args.Length + | ||
452 | " because declaringClass is null. Set declaringClass to the class containing " + | ||
453 | methodName); | ||
454 | try | ||
455 | { | ||
456 | if (checkMode) | ||
457 | { | ||
458 | assertYPPred(state); | ||
459 | object functor = Functor.make(name, args); | ||
460 | if (CompilerState.isDetNoneOut(state, functor)) | ||
461 | { | ||
462 | methodClass.InvokeMember | ||
463 | (methodName, BindingFlags.InvokeMethod, null, null, args); | ||
464 | return YP.succeed(); | ||
465 | } | ||
466 | if (CompilerState.isSemidetNoneOut(state, functor)) | ||
467 | { | ||
468 | if ((bool)methodClass.InvokeMember | ||
469 | (methodName, BindingFlags.InvokeMethod, null, null, args)) | ||
470 | return YP.succeed(); | ||
471 | else | ||
472 | return YP.fail(); | ||
473 | } | ||
474 | |||
475 | } | ||
476 | return (IEnumerable<bool>)methodClass.InvokeMember | ||
477 | (methodName, BindingFlags.InvokeMethod, null, null, args); | ||
478 | } | ||
479 | catch (TargetInvocationException exception) | ||
480 | { | ||
481 | throw exception.InnerException; | ||
482 | } | ||
483 | catch (MissingMethodException) | ||
484 | { | ||
485 | return YP.unknownPredicate | ||
486 | (name, args.Length, | ||
487 | "Cannot find predicate function " + methodName + " for " + name + "/" + args.Length + | ||
488 | " in " + methodClass.FullName); | ||
489 | } | ||
490 | } | ||
491 | |||
492 | return null; | ||
493 | } | ||
494 | |||
495 | /// <summary> | ||
496 | /// Return true if there is a dynamic or static predicate with name and arity. | ||
497 | /// This returns false for built-in predicates. | ||
498 | /// </summary> | ||
499 | /// <param name="name"></param> | ||
500 | /// <param name="arity"></param> | ||
501 | /// <param name="declaringClass">used to resolve references to the default | ||
502 | /// module Atom.a(""). If a declaringClass is needed to resolve the reference but it is | ||
503 | /// null, return false</param> | ||
504 | /// <returns></returns> | ||
505 | public static bool isCurrentPredicate(Atom name, int arity, Type declaringClass) | ||
506 | { | ||
507 | CompilerState state = new CompilerState(); | ||
508 | Variable FunctionName = new Variable(); | ||
509 | foreach (bool l1 in functorCallFunctionName(state, name, arity, FunctionName)) | ||
510 | { | ||
511 | Atom functionNameAtom = ((Atom)FunctionName.getValue()); | ||
512 | if (functionNameAtom == Atom.NIL) | ||
513 | // name is for a dynamic predicate. | ||
514 | return YP.isDynamicCurrentPredicate(name, arity); | ||
515 | |||
516 | string methodName = functionNameAtom._name; | ||
517 | |||
518 | if (methodName.StartsWith("YP.")) | ||
519 | // current_predicate/1 should fail for built-ins. | ||
520 | return false; | ||
521 | if (methodName.Contains(".")) | ||
522 | // We don't support calling inner classes, etc. | ||
523 | return false; | ||
524 | if (declaringClass == null) | ||
525 | return false; | ||
526 | |||
527 | foreach (MemberInfo member in declaringClass.GetMember(methodName)) | ||
528 | { | ||
529 | MethodInfo method = member as MethodInfo; | ||
530 | if (method == null) | ||
531 | continue; | ||
532 | if ((method.Attributes | MethodAttributes.Static) == 0) | ||
533 | // Not a static method. | ||
534 | continue; | ||
535 | if (method.GetParameters().Length == arity) | ||
536 | return true; | ||
537 | } | ||
538 | } | ||
539 | |||
540 | return false; | ||
541 | } | ||
542 | |||
543 | // Compiler output follows. | ||
544 | |||
545 | public class YPInnerClass { } | ||
546 | public static System.Type getDeclaringClass() { return typeof(YPInnerClass).DeclaringType; } | ||
547 | |||
548 | public static void repeatWrite(object arg1, object N) | ||
549 | { | ||
550 | { | ||
551 | object _Value = arg1; | ||
552 | if (YP.termEqual(N, 0)) | ||
553 | { | ||
554 | return; | ||
555 | } | ||
556 | } | ||
557 | { | ||
558 | object Value = arg1; | ||
559 | Variable NextN = new Variable(); | ||
560 | YP.write(Value); | ||
561 | foreach (bool l2 in YP.unify(NextN, YP.subtract(N, 1))) | ||
562 | { | ||
563 | repeatWrite(Value, NextN); | ||
564 | return; | ||
565 | } | ||
566 | } | ||
567 | } | ||
568 | |||
569 | public static bool sameVariable(object Variable1, object Variable2) | ||
570 | { | ||
571 | { | ||
572 | if (YP.var(Variable1)) | ||
573 | { | ||
574 | if (YP.var(Variable2)) | ||
575 | { | ||
576 | if (YP.termEqual(Variable1, Variable2)) | ||
577 | { | ||
578 | return true; | ||
579 | } | ||
580 | } | ||
581 | } | ||
582 | } | ||
583 | return false; | ||
584 | } | ||
585 | |||
586 | public static IEnumerable<bool> makeFunctionPseudoCode(object RuleList, object FunctionCode) | ||
587 | { | ||
588 | { | ||
589 | Variable State = new Variable(); | ||
590 | foreach (bool l2 in CompilerState.make(State)) | ||
591 | { | ||
592 | assertYPPred(State); | ||
593 | processCompilerDirectives(RuleList, State); | ||
594 | foreach (bool l3 in YP.unify(FunctionCode, Atom.a("getDeclaringClass"))) | ||
595 | { | ||
596 | yield return false; | ||
597 | } | ||
598 | foreach (bool l3 in makeFunctionPseudoCode3(RuleList, State, FunctionCode)) | ||
599 | { | ||
600 | yield return false; | ||
601 | } | ||
602 | } | ||
603 | } | ||
604 | } | ||
605 | |||
606 | public static void assertYPPred(object State) | ||
607 | { | ||
608 | { | ||
609 | CompilerState.assertPred(State, Atom.a("nl"), Atom.a("det")); | ||
610 | CompilerState.assertPred(State, new Functor1("write", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
611 | CompilerState.assertPred(State, new Functor1("put_code", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
612 | CompilerState.assertPred(State, new Functor1("see", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
613 | CompilerState.assertPred(State, Atom.a("seen"), Atom.a("det")); | ||
614 | CompilerState.assertPred(State, new Functor1("tell", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
615 | CompilerState.assertPred(State, Atom.a("told"), Atom.a("det")); | ||
616 | CompilerState.assertPred(State, new Functor1("throw", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
617 | CompilerState.assertPred(State, new Functor1("abolish", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
618 | CompilerState.assertPred(State, new Functor1("retractall", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
619 | CompilerState.assertPred(State, new Functor2("set_prolog_flag", new Functor2("::", Atom.a("univ"), Atom.a("in")), new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
620 | CompilerState.assertPred(State, new Functor1("var", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
621 | CompilerState.assertPred(State, new Functor1("nonvar", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
622 | CompilerState.assertPred(State, new Functor1("atom", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
623 | CompilerState.assertPred(State, new Functor1("integer", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
624 | CompilerState.assertPred(State, new Functor1("float", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
625 | CompilerState.assertPred(State, new Functor1("number", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
626 | CompilerState.assertPred(State, new Functor1("atomic", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
627 | CompilerState.assertPred(State, new Functor1("compound", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
628 | CompilerState.assertPred(State, new Functor2("==", new Functor2("::", Atom.a("univ"), Atom.a("in")), new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
629 | CompilerState.assertPred(State, new Functor2("\\==", new Functor2("::", Atom.a("univ"), Atom.a("in")), new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
630 | CompilerState.assertPred(State, new Functor2("@<", new Functor2("::", Atom.a("univ"), Atom.a("in")), new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
631 | CompilerState.assertPred(State, new Functor2("@=<", new Functor2("::", Atom.a("univ"), Atom.a("in")), new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
632 | CompilerState.assertPred(State, new Functor2("@>", new Functor2("::", Atom.a("univ"), Atom.a("in")), new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
633 | CompilerState.assertPred(State, new Functor2("@>=", new Functor2("::", Atom.a("univ"), Atom.a("in")), new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
634 | return; | ||
635 | } | ||
636 | } | ||
637 | |||
638 | public static void processCompilerDirectives(object arg1, object arg2) | ||
639 | { | ||
640 | { | ||
641 | object _State = arg2; | ||
642 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
643 | { | ||
644 | return; | ||
645 | } | ||
646 | } | ||
647 | { | ||
648 | object State = arg2; | ||
649 | Variable Pred = new Variable(); | ||
650 | Variable Determinism = new Variable(); | ||
651 | Variable x3 = new Variable(); | ||
652 | Variable RestRules = new Variable(); | ||
653 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("f", new Functor1(":-", new Functor1("pred", new Functor2("is", Pred, Determinism))), x3), RestRules))) | ||
654 | { | ||
655 | CompilerState.assertPred(State, Pred, Determinism); | ||
656 | processCompilerDirectives(RestRules, State); | ||
657 | return; | ||
658 | } | ||
659 | } | ||
660 | { | ||
661 | object State = arg2; | ||
662 | Variable Module = new Variable(); | ||
663 | Variable PredicateList = new Variable(); | ||
664 | Variable x3 = new Variable(); | ||
665 | Variable RestRules = new Variable(); | ||
666 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("f", new Functor1(":-", new Functor2("import", Module, PredicateList)), x3), RestRules))) | ||
667 | { | ||
668 | foreach (bool l3 in importPredicateList(State, Module, PredicateList)) | ||
669 | { | ||
670 | processCompilerDirectives(RestRules, State); | ||
671 | return; | ||
672 | } | ||
673 | } | ||
674 | } | ||
675 | { | ||
676 | object State = arg2; | ||
677 | Variable x1 = new Variable(); | ||
678 | Variable x2 = new Variable(); | ||
679 | Variable RestRules = new Variable(); | ||
680 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("f", new Functor1(":-", x1), x2), RestRules))) | ||
681 | { | ||
682 | processCompilerDirectives(RestRules, State); | ||
683 | return; | ||
684 | } | ||
685 | } | ||
686 | { | ||
687 | object State = arg2; | ||
688 | Variable Head = new Variable(); | ||
689 | Variable _Body = new Variable(); | ||
690 | Variable x3 = new Variable(); | ||
691 | Variable RestRules = new Variable(); | ||
692 | Variable Name = new Variable(); | ||
693 | Variable Arity = new Variable(); | ||
694 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("f", new Functor2(":-", Head, _Body), x3), RestRules))) | ||
695 | { | ||
696 | foreach (bool l3 in YP.functor(Head, Name, Arity)) | ||
697 | { | ||
698 | CompilerState.assertModuleForNameArity(State, Name, Arity, Atom.a("")); | ||
699 | processCompilerDirectives(RestRules, State); | ||
700 | return; | ||
701 | } | ||
702 | } | ||
703 | } | ||
704 | { | ||
705 | object State = arg2; | ||
706 | Variable Fact = new Variable(); | ||
707 | Variable x2 = new Variable(); | ||
708 | Variable RestRules = new Variable(); | ||
709 | Variable Name = new Variable(); | ||
710 | Variable Arity = new Variable(); | ||
711 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("f", Fact, x2), RestRules))) | ||
712 | { | ||
713 | foreach (bool l3 in YP.functor(Fact, Name, Arity)) | ||
714 | { | ||
715 | CompilerState.assertModuleForNameArity(State, Name, Arity, Atom.a("")); | ||
716 | processCompilerDirectives(RestRules, State); | ||
717 | return; | ||
718 | } | ||
719 | } | ||
720 | } | ||
721 | { | ||
722 | object State = arg2; | ||
723 | Variable x1 = new Variable(); | ||
724 | Variable RestRules = new Variable(); | ||
725 | foreach (bool l2 in YP.unify(arg1, new ListPair(x1, RestRules))) | ||
726 | { | ||
727 | processCompilerDirectives(RestRules, State); | ||
728 | return; | ||
729 | } | ||
730 | } | ||
731 | } | ||
732 | |||
733 | public static IEnumerable<bool> importPredicateList(object arg1, object arg2, object arg3) | ||
734 | { | ||
735 | { | ||
736 | object _State = arg1; | ||
737 | object _Module = arg2; | ||
738 | foreach (bool l2 in YP.unify(arg3, Atom.NIL)) | ||
739 | { | ||
740 | yield return true; | ||
741 | yield break; | ||
742 | } | ||
743 | } | ||
744 | { | ||
745 | object State = arg1; | ||
746 | object Module = arg2; | ||
747 | Variable Name = new Variable(); | ||
748 | Variable Arity = new Variable(); | ||
749 | Variable Rest = new Variable(); | ||
750 | foreach (bool l2 in YP.unify(arg3, new ListPair(new Functor2("/", Name, Arity), Rest))) | ||
751 | { | ||
752 | CompilerState.assertModuleForNameArity(State, Name, Arity, Module); | ||
753 | foreach (bool l3 in importPredicateList(State, Module, Rest)) | ||
754 | { | ||
755 | yield return true; | ||
756 | yield break; | ||
757 | } | ||
758 | } | ||
759 | } | ||
760 | { | ||
761 | object State = arg1; | ||
762 | object Module = arg2; | ||
763 | Variable x3 = new Variable(); | ||
764 | Variable Rest = new Variable(); | ||
765 | foreach (bool l2 in YP.unify(arg3, new ListPair(x3, Rest))) | ||
766 | { | ||
767 | foreach (bool l3 in importPredicateList(State, Module, Rest)) | ||
768 | { | ||
769 | yield return true; | ||
770 | yield break; | ||
771 | } | ||
772 | } | ||
773 | } | ||
774 | } | ||
775 | |||
776 | public static IEnumerable<bool> makeFunctionPseudoCode3(object RuleList, object State, object FunctionCode) | ||
777 | { | ||
778 | { | ||
779 | Variable SamePredicateRuleList = new Variable(); | ||
780 | Variable RestRules = new Variable(); | ||
781 | foreach (bool l2 in samePredicateRuleList(RuleList, SamePredicateRuleList, RestRules)) | ||
782 | { | ||
783 | if (YP.termNotEqual(SamePredicateRuleList, Atom.NIL)) | ||
784 | { | ||
785 | foreach (bool l4 in compileSamePredicateFunction(SamePredicateRuleList, State, FunctionCode)) | ||
786 | { | ||
787 | yield return false; | ||
788 | } | ||
789 | foreach (bool l4 in makeFunctionPseudoCode3(RestRules, State, FunctionCode)) | ||
790 | { | ||
791 | yield return false; | ||
792 | } | ||
793 | } | ||
794 | } | ||
795 | } | ||
796 | } | ||
797 | |||
798 | public static IEnumerable<bool> compileSamePredicateFunction(object SamePredicateRuleList, object State, object FunctionCode) | ||
799 | { | ||
800 | { | ||
801 | Variable FirstRule = new Variable(); | ||
802 | Variable x5 = new Variable(); | ||
803 | Variable x6 = new Variable(); | ||
804 | Variable x7 = new Variable(); | ||
805 | Variable Head = new Variable(); | ||
806 | Variable x9 = new Variable(); | ||
807 | Variable ArgAssignments = new Variable(); | ||
808 | Variable Calls = new Variable(); | ||
809 | Variable Rule = new Variable(); | ||
810 | Variable VariableNameSuggestions = new Variable(); | ||
811 | Variable ClauseBag = new Variable(); | ||
812 | Variable Name = new Variable(); | ||
813 | Variable ArgsList = new Variable(); | ||
814 | Variable FunctionArgNames = new Variable(); | ||
815 | Variable MergedArgName = new Variable(); | ||
816 | Variable ArgName = new Variable(); | ||
817 | Variable MergedArgNames = new Variable(); | ||
818 | Variable FunctionArgs = new Variable(); | ||
819 | Variable BodyCode = new Variable(); | ||
820 | Variable ReturnType = new Variable(); | ||
821 | Variable BodyWithReturn = new Variable(); | ||
822 | foreach (bool l2 in YP.unify(new ListPair(new Functor2("f", FirstRule, x5), x6), SamePredicateRuleList)) | ||
823 | { | ||
824 | foreach (bool l3 in YP.unify(FirstRule, new Functor1(":-", x7))) | ||
825 | { | ||
826 | goto cutIf1; | ||
827 | } | ||
828 | foreach (bool l3 in YP.unify(new Functor2(":-", Head, x9), FirstRule)) | ||
829 | { | ||
830 | CompilerState.startFunction(State, Head); | ||
831 | FindallAnswers findallAnswers3 = new FindallAnswers(new Functor2("f", ArgAssignments, Calls)); | ||
832 | foreach (bool l4 in member(new Functor2("f", Rule, VariableNameSuggestions), SamePredicateRuleList)) | ||
833 | { | ||
834 | foreach (bool l5 in compileBodyWithHeadBindings(Rule, VariableNameSuggestions, State, ArgAssignments, Calls)) | ||
835 | { | ||
836 | findallAnswers3.add(); | ||
837 | } | ||
838 | } | ||
839 | foreach (bool l4 in findallAnswers3.result(ClauseBag)) | ||
840 | { | ||
841 | foreach (bool l5 in YP.univ(Head, new ListPair(Name, ArgsList))) | ||
842 | { | ||
843 | foreach (bool l6 in getFunctionArgNames(ArgsList, 1, FunctionArgNames)) | ||
844 | { | ||
845 | FindallAnswers findallAnswers4 = new FindallAnswers(MergedArgName); | ||
846 | foreach (bool l7 in member(ArgName, FunctionArgNames)) | ||
847 | { | ||
848 | foreach (bool l8 in argAssignedAll(ArgName, ClauseBag, MergedArgName)) | ||
849 | { | ||
850 | findallAnswers4.add(); | ||
851 | goto cutIf5; | ||
852 | } | ||
853 | foreach (bool l8 in YP.unify(MergedArgName, ArgName)) | ||
854 | { | ||
855 | findallAnswers4.add(); | ||
856 | } | ||
857 | cutIf5: | ||
858 | { } | ||
859 | } | ||
860 | foreach (bool l7 in findallAnswers4.result(MergedArgNames)) | ||
861 | { | ||
862 | foreach (bool l8 in maplist_arg(MergedArgNames, FunctionArgs)) | ||
863 | { | ||
864 | foreach (bool l9 in maplist_compileClause(ClauseBag, MergedArgNames, BodyCode)) | ||
865 | { | ||
866 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
867 | { | ||
868 | foreach (bool l11 in YP.unify(ReturnType, Atom.a("void"))) | ||
869 | { | ||
870 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
871 | { | ||
872 | foreach (bool l13 in append(BodyCode, new ListPair(Atom.a("returnfalse"), Atom.NIL), BodyWithReturn)) | ||
873 | { | ||
874 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
875 | { | ||
876 | yield return false; | ||
877 | } | ||
878 | } | ||
879 | goto cutIf7; | ||
880 | } | ||
881 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
882 | { | ||
883 | foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) | ||
884 | { | ||
885 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
886 | { | ||
887 | yield return false; | ||
888 | } | ||
889 | } | ||
890 | goto cutIf8; | ||
891 | } | ||
892 | if (CompilerState.codeUsesYield(State)) | ||
893 | { | ||
894 | foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) | ||
895 | { | ||
896 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
897 | { | ||
898 | yield return false; | ||
899 | } | ||
900 | } | ||
901 | goto cutIf9; | ||
902 | } | ||
903 | foreach (bool l12 in append(BodyCode, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.fail"), Atom.NIL), new ListPair(Atom.a("yieldfalse"), Atom.NIL)), Atom.NIL), BodyWithReturn)) | ||
904 | { | ||
905 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
906 | { | ||
907 | yield return false; | ||
908 | } | ||
909 | } | ||
910 | cutIf9: | ||
911 | cutIf8: | ||
912 | cutIf7: | ||
913 | { } | ||
914 | } | ||
915 | goto cutIf6; | ||
916 | } | ||
917 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
918 | { | ||
919 | foreach (bool l11 in YP.unify(ReturnType, Atom.a("bool"))) | ||
920 | { | ||
921 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
922 | { | ||
923 | foreach (bool l13 in append(BodyCode, new ListPair(Atom.a("returnfalse"), Atom.NIL), BodyWithReturn)) | ||
924 | { | ||
925 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
926 | { | ||
927 | yield return false; | ||
928 | } | ||
929 | } | ||
930 | goto cutIf11; | ||
931 | } | ||
932 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
933 | { | ||
934 | foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) | ||
935 | { | ||
936 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
937 | { | ||
938 | yield return false; | ||
939 | } | ||
940 | } | ||
941 | goto cutIf12; | ||
942 | } | ||
943 | if (CompilerState.codeUsesYield(State)) | ||
944 | { | ||
945 | foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) | ||
946 | { | ||
947 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
948 | { | ||
949 | yield return false; | ||
950 | } | ||
951 | } | ||
952 | goto cutIf13; | ||
953 | } | ||
954 | foreach (bool l12 in append(BodyCode, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.fail"), Atom.NIL), new ListPair(Atom.a("yieldfalse"), Atom.NIL)), Atom.NIL), BodyWithReturn)) | ||
955 | { | ||
956 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
957 | { | ||
958 | yield return false; | ||
959 | } | ||
960 | } | ||
961 | cutIf13: | ||
962 | cutIf12: | ||
963 | cutIf11: | ||
964 | { } | ||
965 | } | ||
966 | goto cutIf10; | ||
967 | } | ||
968 | foreach (bool l10 in YP.unify(ReturnType, Atom.a("IEnumerable<bool>"))) | ||
969 | { | ||
970 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
971 | { | ||
972 | foreach (bool l12 in append(BodyCode, new ListPair(Atom.a("returnfalse"), Atom.NIL), BodyWithReturn)) | ||
973 | { | ||
974 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
975 | { | ||
976 | yield return false; | ||
977 | } | ||
978 | } | ||
979 | goto cutIf14; | ||
980 | } | ||
981 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
982 | { | ||
983 | foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) | ||
984 | { | ||
985 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
986 | { | ||
987 | yield return false; | ||
988 | } | ||
989 | } | ||
990 | goto cutIf15; | ||
991 | } | ||
992 | if (CompilerState.codeUsesYield(State)) | ||
993 | { | ||
994 | foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) | ||
995 | { | ||
996 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
997 | { | ||
998 | yield return false; | ||
999 | } | ||
1000 | } | ||
1001 | goto cutIf16; | ||
1002 | } | ||
1003 | foreach (bool l11 in append(BodyCode, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.fail"), Atom.NIL), new ListPair(Atom.a("yieldfalse"), Atom.NIL)), Atom.NIL), BodyWithReturn)) | ||
1004 | { | ||
1005 | foreach (bool l12 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1006 | { | ||
1007 | yield return false; | ||
1008 | } | ||
1009 | } | ||
1010 | cutIf16: | ||
1011 | cutIf15: | ||
1012 | cutIf14: | ||
1013 | { } | ||
1014 | } | ||
1015 | cutIf10: | ||
1016 | cutIf6: | ||
1017 | { } | ||
1018 | } | ||
1019 | } | ||
1020 | } | ||
1021 | } | ||
1022 | } | ||
1023 | } | ||
1024 | goto cutIf2; | ||
1025 | } | ||
1026 | foreach (bool l3 in YP.unify(Head, FirstRule)) | ||
1027 | { | ||
1028 | CompilerState.startFunction(State, Head); | ||
1029 | FindallAnswers findallAnswers17 = new FindallAnswers(new Functor2("f", ArgAssignments, Calls)); | ||
1030 | foreach (bool l4 in member(new Functor2("f", Rule, VariableNameSuggestions), SamePredicateRuleList)) | ||
1031 | { | ||
1032 | foreach (bool l5 in compileBodyWithHeadBindings(Rule, VariableNameSuggestions, State, ArgAssignments, Calls)) | ||
1033 | { | ||
1034 | findallAnswers17.add(); | ||
1035 | } | ||
1036 | } | ||
1037 | foreach (bool l4 in findallAnswers17.result(ClauseBag)) | ||
1038 | { | ||
1039 | foreach (bool l5 in YP.univ(Head, new ListPair(Name, ArgsList))) | ||
1040 | { | ||
1041 | foreach (bool l6 in getFunctionArgNames(ArgsList, 1, FunctionArgNames)) | ||
1042 | { | ||
1043 | FindallAnswers findallAnswers18 = new FindallAnswers(MergedArgName); | ||
1044 | foreach (bool l7 in member(ArgName, FunctionArgNames)) | ||
1045 | { | ||
1046 | foreach (bool l8 in argAssignedAll(ArgName, ClauseBag, MergedArgName)) | ||
1047 | { | ||
1048 | findallAnswers18.add(); | ||
1049 | goto cutIf19; | ||
1050 | } | ||
1051 | foreach (bool l8 in YP.unify(MergedArgName, ArgName)) | ||
1052 | { | ||
1053 | findallAnswers18.add(); | ||
1054 | } | ||
1055 | cutIf19: | ||
1056 | { } | ||
1057 | } | ||
1058 | foreach (bool l7 in findallAnswers18.result(MergedArgNames)) | ||
1059 | { | ||
1060 | foreach (bool l8 in maplist_arg(MergedArgNames, FunctionArgs)) | ||
1061 | { | ||
1062 | foreach (bool l9 in maplist_compileClause(ClauseBag, MergedArgNames, BodyCode)) | ||
1063 | { | ||
1064 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
1065 | { | ||
1066 | foreach (bool l11 in YP.unify(ReturnType, Atom.a("void"))) | ||
1067 | { | ||
1068 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
1069 | { | ||
1070 | foreach (bool l13 in append(BodyCode, new ListPair(Atom.a("returnfalse"), Atom.NIL), BodyWithReturn)) | ||
1071 | { | ||
1072 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1073 | { | ||
1074 | yield return false; | ||
1075 | } | ||
1076 | } | ||
1077 | goto cutIf21; | ||
1078 | } | ||
1079 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
1080 | { | ||
1081 | foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) | ||
1082 | { | ||
1083 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1084 | { | ||
1085 | yield return false; | ||
1086 | } | ||
1087 | } | ||
1088 | goto cutIf22; | ||
1089 | } | ||
1090 | if (CompilerState.codeUsesYield(State)) | ||
1091 | { | ||
1092 | foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) | ||
1093 | { | ||
1094 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1095 | { | ||
1096 | yield return false; | ||
1097 | } | ||
1098 | } | ||
1099 | goto cutIf23; | ||
1100 | } | ||
1101 | foreach (bool l12 in append(BodyCode, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.fail"), Atom.NIL), new ListPair(Atom.a("yieldfalse"), Atom.NIL)), Atom.NIL), BodyWithReturn)) | ||
1102 | { | ||
1103 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1104 | { | ||
1105 | yield return false; | ||
1106 | } | ||
1107 | } | ||
1108 | cutIf23: | ||
1109 | cutIf22: | ||
1110 | cutIf21: | ||
1111 | { } | ||
1112 | } | ||
1113 | goto cutIf20; | ||
1114 | } | ||
1115 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
1116 | { | ||
1117 | foreach (bool l11 in YP.unify(ReturnType, Atom.a("bool"))) | ||
1118 | { | ||
1119 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
1120 | { | ||
1121 | foreach (bool l13 in append(BodyCode, new ListPair(Atom.a("returnfalse"), Atom.NIL), BodyWithReturn)) | ||
1122 | { | ||
1123 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1124 | { | ||
1125 | yield return false; | ||
1126 | } | ||
1127 | } | ||
1128 | goto cutIf25; | ||
1129 | } | ||
1130 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
1131 | { | ||
1132 | foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) | ||
1133 | { | ||
1134 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1135 | { | ||
1136 | yield return false; | ||
1137 | } | ||
1138 | } | ||
1139 | goto cutIf26; | ||
1140 | } | ||
1141 | if (CompilerState.codeUsesYield(State)) | ||
1142 | { | ||
1143 | foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) | ||
1144 | { | ||
1145 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1146 | { | ||
1147 | yield return false; | ||
1148 | } | ||
1149 | } | ||
1150 | goto cutIf27; | ||
1151 | } | ||
1152 | foreach (bool l12 in append(BodyCode, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.fail"), Atom.NIL), new ListPair(Atom.a("yieldfalse"), Atom.NIL)), Atom.NIL), BodyWithReturn)) | ||
1153 | { | ||
1154 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1155 | { | ||
1156 | yield return false; | ||
1157 | } | ||
1158 | } | ||
1159 | cutIf27: | ||
1160 | cutIf26: | ||
1161 | cutIf25: | ||
1162 | { } | ||
1163 | } | ||
1164 | goto cutIf24; | ||
1165 | } | ||
1166 | foreach (bool l10 in YP.unify(ReturnType, Atom.a("IEnumerable<bool>"))) | ||
1167 | { | ||
1168 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
1169 | { | ||
1170 | foreach (bool l12 in append(BodyCode, new ListPair(Atom.a("returnfalse"), Atom.NIL), BodyWithReturn)) | ||
1171 | { | ||
1172 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1173 | { | ||
1174 | yield return false; | ||
1175 | } | ||
1176 | } | ||
1177 | goto cutIf28; | ||
1178 | } | ||
1179 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
1180 | { | ||
1181 | foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) | ||
1182 | { | ||
1183 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1184 | { | ||
1185 | yield return false; | ||
1186 | } | ||
1187 | } | ||
1188 | goto cutIf29; | ||
1189 | } | ||
1190 | if (CompilerState.codeUsesYield(State)) | ||
1191 | { | ||
1192 | foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) | ||
1193 | { | ||
1194 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1195 | { | ||
1196 | yield return false; | ||
1197 | } | ||
1198 | } | ||
1199 | goto cutIf30; | ||
1200 | } | ||
1201 | foreach (bool l11 in append(BodyCode, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.fail"), Atom.NIL), new ListPair(Atom.a("yieldfalse"), Atom.NIL)), Atom.NIL), BodyWithReturn)) | ||
1202 | { | ||
1203 | foreach (bool l12 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1204 | { | ||
1205 | yield return false; | ||
1206 | } | ||
1207 | } | ||
1208 | cutIf30: | ||
1209 | cutIf29: | ||
1210 | cutIf28: | ||
1211 | { } | ||
1212 | } | ||
1213 | cutIf24: | ||
1214 | cutIf20: | ||
1215 | { } | ||
1216 | } | ||
1217 | } | ||
1218 | } | ||
1219 | } | ||
1220 | } | ||
1221 | } | ||
1222 | } | ||
1223 | cutIf2: | ||
1224 | cutIf1: | ||
1225 | { } | ||
1226 | } | ||
1227 | } | ||
1228 | } | ||
1229 | |||
1230 | public static IEnumerable<bool> samePredicateRuleList(object arg1, object arg2, object arg3) | ||
1231 | { | ||
1232 | { | ||
1233 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1234 | { | ||
1235 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
1236 | { | ||
1237 | foreach (bool l4 in YP.unify(arg3, Atom.NIL)) | ||
1238 | { | ||
1239 | yield return true; | ||
1240 | yield break; | ||
1241 | } | ||
1242 | } | ||
1243 | } | ||
1244 | } | ||
1245 | { | ||
1246 | Variable First = new Variable(); | ||
1247 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Atom.NIL))) | ||
1248 | { | ||
1249 | foreach (bool l3 in YP.unify(arg2, new ListPair(First, Atom.NIL))) | ||
1250 | { | ||
1251 | foreach (bool l4 in YP.unify(arg3, Atom.NIL)) | ||
1252 | { | ||
1253 | yield return true; | ||
1254 | yield break; | ||
1255 | } | ||
1256 | } | ||
1257 | } | ||
1258 | } | ||
1259 | { | ||
1260 | object SamePredicateRuleList = arg2; | ||
1261 | object RestRules = arg3; | ||
1262 | Variable First = new Variable(); | ||
1263 | Variable Rest = new Variable(); | ||
1264 | Variable FirstRule = new Variable(); | ||
1265 | Variable x6 = new Variable(); | ||
1266 | Variable SecondRule = new Variable(); | ||
1267 | Variable x8 = new Variable(); | ||
1268 | Variable x9 = new Variable(); | ||
1269 | Variable FirstHead = new Variable(); | ||
1270 | Variable x11 = new Variable(); | ||
1271 | Variable SecondHead = new Variable(); | ||
1272 | Variable x13 = new Variable(); | ||
1273 | Variable Name = new Variable(); | ||
1274 | Variable Arity = new Variable(); | ||
1275 | Variable RestSamePredicates = new Variable(); | ||
1276 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) | ||
1277 | { | ||
1278 | foreach (bool l3 in YP.unify(new Functor2("f", FirstRule, x6), First)) | ||
1279 | { | ||
1280 | foreach (bool l4 in YP.unify(new ListPair(new Functor2("f", SecondRule, x8), x9), Rest)) | ||
1281 | { | ||
1282 | foreach (bool l5 in YP.unify(new Functor2(":-", FirstHead, x11), FirstRule)) | ||
1283 | { | ||
1284 | foreach (bool l6 in YP.unify(new Functor2(":-", SecondHead, x13), SecondRule)) | ||
1285 | { | ||
1286 | foreach (bool l7 in YP.functor(FirstHead, Name, Arity)) | ||
1287 | { | ||
1288 | foreach (bool l8 in YP.functor(SecondHead, Name, Arity)) | ||
1289 | { | ||
1290 | foreach (bool l9 in samePredicateRuleList(Rest, RestSamePredicates, RestRules)) | ||
1291 | { | ||
1292 | foreach (bool l10 in YP.unify(SamePredicateRuleList, new ListPair(First, RestSamePredicates))) | ||
1293 | { | ||
1294 | yield return true; | ||
1295 | yield break; | ||
1296 | } | ||
1297 | } | ||
1298 | goto cutIf3; | ||
1299 | } | ||
1300 | foreach (bool l8 in YP.unify(SamePredicateRuleList, new ListPair(First, Atom.NIL))) | ||
1301 | { | ||
1302 | foreach (bool l9 in YP.unify(RestRules, Rest)) | ||
1303 | { | ||
1304 | yield return true; | ||
1305 | yield break; | ||
1306 | } | ||
1307 | } | ||
1308 | cutIf3: | ||
1309 | { } | ||
1310 | } | ||
1311 | goto cutIf2; | ||
1312 | } | ||
1313 | foreach (bool l6 in YP.unify(SecondHead, SecondRule)) | ||
1314 | { | ||
1315 | foreach (bool l7 in YP.functor(FirstHead, Name, Arity)) | ||
1316 | { | ||
1317 | foreach (bool l8 in YP.functor(SecondHead, Name, Arity)) | ||
1318 | { | ||
1319 | foreach (bool l9 in samePredicateRuleList(Rest, RestSamePredicates, RestRules)) | ||
1320 | { | ||
1321 | foreach (bool l10 in YP.unify(SamePredicateRuleList, new ListPair(First, RestSamePredicates))) | ||
1322 | { | ||
1323 | yield return true; | ||
1324 | yield break; | ||
1325 | } | ||
1326 | } | ||
1327 | goto cutIf4; | ||
1328 | } | ||
1329 | foreach (bool l8 in YP.unify(SamePredicateRuleList, new ListPair(First, Atom.NIL))) | ||
1330 | { | ||
1331 | foreach (bool l9 in YP.unify(RestRules, Rest)) | ||
1332 | { | ||
1333 | yield return true; | ||
1334 | yield break; | ||
1335 | } | ||
1336 | } | ||
1337 | cutIf4: | ||
1338 | { } | ||
1339 | } | ||
1340 | } | ||
1341 | cutIf2: | ||
1342 | goto cutIf1; | ||
1343 | } | ||
1344 | foreach (bool l5 in YP.unify(FirstHead, FirstRule)) | ||
1345 | { | ||
1346 | foreach (bool l6 in YP.unify(new Functor2(":-", SecondHead, x13), SecondRule)) | ||
1347 | { | ||
1348 | foreach (bool l7 in YP.functor(FirstHead, Name, Arity)) | ||
1349 | { | ||
1350 | foreach (bool l8 in YP.functor(SecondHead, Name, Arity)) | ||
1351 | { | ||
1352 | foreach (bool l9 in samePredicateRuleList(Rest, RestSamePredicates, RestRules)) | ||
1353 | { | ||
1354 | foreach (bool l10 in YP.unify(SamePredicateRuleList, new ListPair(First, RestSamePredicates))) | ||
1355 | { | ||
1356 | yield return true; | ||
1357 | yield break; | ||
1358 | } | ||
1359 | } | ||
1360 | goto cutIf6; | ||
1361 | } | ||
1362 | foreach (bool l8 in YP.unify(SamePredicateRuleList, new ListPair(First, Atom.NIL))) | ||
1363 | { | ||
1364 | foreach (bool l9 in YP.unify(RestRules, Rest)) | ||
1365 | { | ||
1366 | yield return true; | ||
1367 | yield break; | ||
1368 | } | ||
1369 | } | ||
1370 | cutIf6: | ||
1371 | { } | ||
1372 | } | ||
1373 | goto cutIf5; | ||
1374 | } | ||
1375 | foreach (bool l6 in YP.unify(SecondHead, SecondRule)) | ||
1376 | { | ||
1377 | foreach (bool l7 in YP.functor(FirstHead, Name, Arity)) | ||
1378 | { | ||
1379 | foreach (bool l8 in YP.functor(SecondHead, Name, Arity)) | ||
1380 | { | ||
1381 | foreach (bool l9 in samePredicateRuleList(Rest, RestSamePredicates, RestRules)) | ||
1382 | { | ||
1383 | foreach (bool l10 in YP.unify(SamePredicateRuleList, new ListPair(First, RestSamePredicates))) | ||
1384 | { | ||
1385 | yield return true; | ||
1386 | yield break; | ||
1387 | } | ||
1388 | } | ||
1389 | goto cutIf7; | ||
1390 | } | ||
1391 | foreach (bool l8 in YP.unify(SamePredicateRuleList, new ListPair(First, Atom.NIL))) | ||
1392 | { | ||
1393 | foreach (bool l9 in YP.unify(RestRules, Rest)) | ||
1394 | { | ||
1395 | yield return true; | ||
1396 | yield break; | ||
1397 | } | ||
1398 | } | ||
1399 | cutIf7: | ||
1400 | { } | ||
1401 | } | ||
1402 | } | ||
1403 | cutIf5: | ||
1404 | { } | ||
1405 | } | ||
1406 | cutIf1: | ||
1407 | { } | ||
1408 | } | ||
1409 | } | ||
1410 | } | ||
1411 | } | ||
1412 | } | ||
1413 | |||
1414 | public static IEnumerable<bool> maplist_compileClause(object arg1, object arg2, object arg3) | ||
1415 | { | ||
1416 | { | ||
1417 | object _MergedArgNames = arg2; | ||
1418 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1419 | { | ||
1420 | foreach (bool l3 in YP.unify(arg3, Atom.NIL)) | ||
1421 | { | ||
1422 | yield return true; | ||
1423 | yield break; | ||
1424 | } | ||
1425 | } | ||
1426 | } | ||
1427 | { | ||
1428 | object MergedArgNames = arg2; | ||
1429 | Variable ArgAssignments = new Variable(); | ||
1430 | Variable Calls = new Variable(); | ||
1431 | Variable Rest = new Variable(); | ||
1432 | Variable ClauseCode = new Variable(); | ||
1433 | Variable RestResults = new Variable(); | ||
1434 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("f", ArgAssignments, Calls), Rest))) | ||
1435 | { | ||
1436 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor1("blockScope", ClauseCode), RestResults))) | ||
1437 | { | ||
1438 | foreach (bool l4 in prependArgAssignments(ArgAssignments, Calls, MergedArgNames, ClauseCode)) | ||
1439 | { | ||
1440 | foreach (bool l5 in maplist_compileClause(Rest, MergedArgNames, RestResults)) | ||
1441 | { | ||
1442 | yield return true; | ||
1443 | yield break; | ||
1444 | } | ||
1445 | } | ||
1446 | } | ||
1447 | } | ||
1448 | } | ||
1449 | } | ||
1450 | |||
1451 | public static IEnumerable<bool> prependArgAssignments(object arg1, object arg2, object arg3, object arg4) | ||
1452 | { | ||
1453 | { | ||
1454 | object _MergedArgNames = arg3; | ||
1455 | Variable In = new Variable(); | ||
1456 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1457 | { | ||
1458 | foreach (bool l3 in YP.unify(arg2, In)) | ||
1459 | { | ||
1460 | foreach (bool l4 in YP.unify(arg4, In)) | ||
1461 | { | ||
1462 | yield return true; | ||
1463 | yield break; | ||
1464 | } | ||
1465 | } | ||
1466 | } | ||
1467 | } | ||
1468 | { | ||
1469 | object In = arg2; | ||
1470 | object MergedArgNames = arg3; | ||
1471 | object ClauseCode = arg4; | ||
1472 | Variable VariableName = new Variable(); | ||
1473 | Variable ArgName = new Variable(); | ||
1474 | Variable RestArgAssignments = new Variable(); | ||
1475 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("f", VariableName, ArgName), RestArgAssignments))) | ||
1476 | { | ||
1477 | foreach (bool l3 in member(VariableName, MergedArgNames)) | ||
1478 | { | ||
1479 | foreach (bool l4 in prependArgAssignments(RestArgAssignments, In, MergedArgNames, ClauseCode)) | ||
1480 | { | ||
1481 | yield return true; | ||
1482 | yield break; | ||
1483 | } | ||
1484 | goto cutIf1; | ||
1485 | } | ||
1486 | foreach (bool l3 in prependArgAssignments(RestArgAssignments, new ListPair(new Functor3("declare", Atom.a("object"), VariableName, new Functor1("var", ArgName)), In), MergedArgNames, ClauseCode)) | ||
1487 | { | ||
1488 | yield return true; | ||
1489 | yield break; | ||
1490 | } | ||
1491 | cutIf1: | ||
1492 | { } | ||
1493 | } | ||
1494 | } | ||
1495 | } | ||
1496 | |||
1497 | public static IEnumerable<bool> argAssignedAll(object arg1, object arg2, object VariableName) | ||
1498 | { | ||
1499 | { | ||
1500 | object _ArgName = arg1; | ||
1501 | foreach (bool l2 in YP.unify(arg2, Atom.NIL)) | ||
1502 | { | ||
1503 | if (YP.nonvar(VariableName)) | ||
1504 | { | ||
1505 | yield return true; | ||
1506 | yield break; | ||
1507 | } | ||
1508 | } | ||
1509 | } | ||
1510 | { | ||
1511 | object ArgName = arg1; | ||
1512 | Variable ArgAssignments = new Variable(); | ||
1513 | Variable _Calls = new Variable(); | ||
1514 | Variable RestClauseBag = new Variable(); | ||
1515 | foreach (bool l2 in YP.unify(arg2, new ListPair(new Functor2("f", ArgAssignments, _Calls), RestClauseBag))) | ||
1516 | { | ||
1517 | foreach (bool l3 in member(new Functor2("f", VariableName, ArgName), ArgAssignments)) | ||
1518 | { | ||
1519 | foreach (bool l4 in argAssignedAll(ArgName, RestClauseBag, VariableName)) | ||
1520 | { | ||
1521 | yield return false; | ||
1522 | } | ||
1523 | } | ||
1524 | } | ||
1525 | } | ||
1526 | } | ||
1527 | |||
1528 | public static IEnumerable<bool> maplist_arg(object arg1, object arg2) | ||
1529 | { | ||
1530 | { | ||
1531 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1532 | { | ||
1533 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
1534 | { | ||
1535 | yield return true; | ||
1536 | yield break; | ||
1537 | } | ||
1538 | } | ||
1539 | } | ||
1540 | { | ||
1541 | Variable First = new Variable(); | ||
1542 | Variable Rest = new Variable(); | ||
1543 | Variable RestResults = new Variable(); | ||
1544 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) | ||
1545 | { | ||
1546 | foreach (bool l3 in YP.unify(arg2, new ListPair(new Functor1("arg", First), RestResults))) | ||
1547 | { | ||
1548 | foreach (bool l4 in maplist_arg(Rest, RestResults)) | ||
1549 | { | ||
1550 | yield return true; | ||
1551 | yield break; | ||
1552 | } | ||
1553 | } | ||
1554 | } | ||
1555 | } | ||
1556 | } | ||
1557 | |||
1558 | public static IEnumerable<bool> getFunctionArgNames(object arg1, object arg2, object arg3) | ||
1559 | { | ||
1560 | { | ||
1561 | object _StartArgNumber = arg2; | ||
1562 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1563 | { | ||
1564 | foreach (bool l3 in YP.unify(arg3, Atom.NIL)) | ||
1565 | { | ||
1566 | yield return true; | ||
1567 | yield break; | ||
1568 | } | ||
1569 | } | ||
1570 | } | ||
1571 | { | ||
1572 | object StartArgNumber = arg2; | ||
1573 | Variable x1 = new Variable(); | ||
1574 | Variable Rest = new Variable(); | ||
1575 | Variable ArgName = new Variable(); | ||
1576 | Variable RestFunctionArgs = new Variable(); | ||
1577 | Variable NumberCodes = new Variable(); | ||
1578 | Variable NumberAtom = new Variable(); | ||
1579 | Variable NextArgNumber = new Variable(); | ||
1580 | foreach (bool l2 in YP.unify(arg1, new ListPair(x1, Rest))) | ||
1581 | { | ||
1582 | foreach (bool l3 in YP.unify(arg3, new ListPair(ArgName, RestFunctionArgs))) | ||
1583 | { | ||
1584 | foreach (bool l4 in YP.number_codes(StartArgNumber, NumberCodes)) | ||
1585 | { | ||
1586 | foreach (bool l5 in YP.atom_codes(NumberAtom, NumberCodes)) | ||
1587 | { | ||
1588 | foreach (bool l6 in YP.atom_concat(Atom.a("arg"), NumberAtom, ArgName)) | ||
1589 | { | ||
1590 | foreach (bool l7 in YP.unify(NextArgNumber, YP.add(StartArgNumber, 1))) | ||
1591 | { | ||
1592 | foreach (bool l8 in getFunctionArgNames(Rest, NextArgNumber, RestFunctionArgs)) | ||
1593 | { | ||
1594 | yield return true; | ||
1595 | yield break; | ||
1596 | } | ||
1597 | } | ||
1598 | } | ||
1599 | } | ||
1600 | } | ||
1601 | } | ||
1602 | } | ||
1603 | } | ||
1604 | } | ||
1605 | |||
1606 | public static IEnumerable<bool> compileBodyWithHeadBindings(object Rule, object VariableNameSuggestions, object State, object ArgAssignments, object Calls) | ||
1607 | { | ||
1608 | { | ||
1609 | Variable Head = new Variable(); | ||
1610 | Variable Body = new Variable(); | ||
1611 | Variable x8 = new Variable(); | ||
1612 | Variable HeadArgs = new Variable(); | ||
1613 | Variable CompiledHeadArgs = new Variable(); | ||
1614 | Variable BodyCode = new Variable(); | ||
1615 | Variable VariableNamesList = new Variable(); | ||
1616 | Variable ArgUnifications = new Variable(); | ||
1617 | foreach (bool l2 in YP.unify(new Functor2(":-", Head, Body), Rule)) | ||
1618 | { | ||
1619 | CompilerState.newVariableNames(State, Rule, VariableNameSuggestions); | ||
1620 | foreach (bool l3 in YP.univ(Head, new ListPair(x8, HeadArgs))) | ||
1621 | { | ||
1622 | foreach (bool l4 in maplist_compileTerm(HeadArgs, State, CompiledHeadArgs)) | ||
1623 | { | ||
1624 | foreach (bool l5 in compileRuleBody(Body, State, BodyCode)) | ||
1625 | { | ||
1626 | foreach (bool l6 in CompilerState.variableNamesList(State, VariableNamesList)) | ||
1627 | { | ||
1628 | foreach (bool l7 in compileArgUnifications(HeadArgs, CompiledHeadArgs, 1, HeadArgs, BodyCode, ArgUnifications)) | ||
1629 | { | ||
1630 | foreach (bool l8 in compileDeclarations(VariableNamesList, HeadArgs, Atom.NIL, ArgAssignments, ArgUnifications, Calls)) | ||
1631 | { | ||
1632 | yield return true; | ||
1633 | yield break; | ||
1634 | } | ||
1635 | } | ||
1636 | } | ||
1637 | } | ||
1638 | } | ||
1639 | } | ||
1640 | } | ||
1641 | } | ||
1642 | { | ||
1643 | foreach (bool l2 in compileBodyWithHeadBindings(new Functor2(":-", Rule, Atom.a("true")), VariableNameSuggestions, State, ArgAssignments, Calls)) | ||
1644 | { | ||
1645 | yield return true; | ||
1646 | yield break; | ||
1647 | } | ||
1648 | } | ||
1649 | } | ||
1650 | |||
1651 | public static IEnumerable<bool> compileArgUnifications(object arg1, object arg2, object arg3, object arg4, object arg5, object arg6) | ||
1652 | { | ||
1653 | { | ||
1654 | object x1 = arg2; | ||
1655 | object x2 = arg3; | ||
1656 | object x3 = arg4; | ||
1657 | Variable BodyCode = new Variable(); | ||
1658 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1659 | { | ||
1660 | foreach (bool l3 in YP.unify(arg5, BodyCode)) | ||
1661 | { | ||
1662 | foreach (bool l4 in YP.unify(arg6, BodyCode)) | ||
1663 | { | ||
1664 | yield return true; | ||
1665 | yield break; | ||
1666 | } | ||
1667 | } | ||
1668 | } | ||
1669 | } | ||
1670 | { | ||
1671 | object Index = arg3; | ||
1672 | object AllHeadArgs = arg4; | ||
1673 | object BodyCode = arg5; | ||
1674 | object ArgUnifications = arg6; | ||
1675 | Variable HeadArg = new Variable(); | ||
1676 | Variable RestHeadArgs = new Variable(); | ||
1677 | Variable x3 = new Variable(); | ||
1678 | Variable RestCompiledHeadArgs = new Variable(); | ||
1679 | Variable _ArgIndex1 = new Variable(); | ||
1680 | Variable NextIndex = new Variable(); | ||
1681 | foreach (bool l2 in YP.unify(arg1, new ListPair(HeadArg, RestHeadArgs))) | ||
1682 | { | ||
1683 | foreach (bool l3 in YP.unify(arg2, new ListPair(x3, RestCompiledHeadArgs))) | ||
1684 | { | ||
1685 | foreach (bool l4 in getVariableArgIndex1(HeadArg, AllHeadArgs, _ArgIndex1)) | ||
1686 | { | ||
1687 | foreach (bool l5 in YP.unify(NextIndex, YP.add(Index, 1))) | ||
1688 | { | ||
1689 | foreach (bool l6 in compileArgUnifications(RestHeadArgs, RestCompiledHeadArgs, NextIndex, AllHeadArgs, BodyCode, ArgUnifications)) | ||
1690 | { | ||
1691 | yield return true; | ||
1692 | yield break; | ||
1693 | } | ||
1694 | } | ||
1695 | } | ||
1696 | } | ||
1697 | } | ||
1698 | } | ||
1699 | { | ||
1700 | object Index = arg3; | ||
1701 | object AllHeadArgs = arg4; | ||
1702 | object BodyCode = arg5; | ||
1703 | Variable _HeadArg = new Variable(); | ||
1704 | Variable RestHeadArgs = new Variable(); | ||
1705 | Variable CompiledHeadArg = new Variable(); | ||
1706 | Variable RestCompiledHeadArgs = new Variable(); | ||
1707 | Variable ArgName = new Variable(); | ||
1708 | Variable RestArgUnifications = new Variable(); | ||
1709 | Variable NumberCodes = new Variable(); | ||
1710 | Variable NumberAtom = new Variable(); | ||
1711 | Variable NextIndex = new Variable(); | ||
1712 | foreach (bool l2 in YP.unify(arg1, new ListPair(_HeadArg, RestHeadArgs))) | ||
1713 | { | ||
1714 | foreach (bool l3 in YP.unify(arg2, new ListPair(CompiledHeadArg, RestCompiledHeadArgs))) | ||
1715 | { | ||
1716 | foreach (bool l4 in YP.unify(arg6, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.unify"), new ListPair(new Functor1("var", ArgName), new ListPair(CompiledHeadArg, Atom.NIL))), RestArgUnifications), Atom.NIL))) | ||
1717 | { | ||
1718 | foreach (bool l5 in YP.number_codes(Index, NumberCodes)) | ||
1719 | { | ||
1720 | foreach (bool l6 in YP.atom_codes(NumberAtom, NumberCodes)) | ||
1721 | { | ||
1722 | foreach (bool l7 in YP.atom_concat(Atom.a("arg"), NumberAtom, ArgName)) | ||
1723 | { | ||
1724 | foreach (bool l8 in YP.unify(NextIndex, YP.add(Index, 1))) | ||
1725 | { | ||
1726 | foreach (bool l9 in compileArgUnifications(RestHeadArgs, RestCompiledHeadArgs, NextIndex, AllHeadArgs, BodyCode, RestArgUnifications)) | ||
1727 | { | ||
1728 | yield return true; | ||
1729 | yield break; | ||
1730 | } | ||
1731 | } | ||
1732 | } | ||
1733 | } | ||
1734 | } | ||
1735 | } | ||
1736 | } | ||
1737 | } | ||
1738 | } | ||
1739 | } | ||
1740 | |||
1741 | public static IEnumerable<bool> compileDeclarations(object arg1, object arg2, object arg3, object arg4, object arg5, object arg6) | ||
1742 | { | ||
1743 | { | ||
1744 | object _HeadArgs = arg2; | ||
1745 | Variable ArgAssignmentsIn = new Variable(); | ||
1746 | Variable DeclarationsIn = new Variable(); | ||
1747 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1748 | { | ||
1749 | foreach (bool l3 in YP.unify(arg3, ArgAssignmentsIn)) | ||
1750 | { | ||
1751 | foreach (bool l4 in YP.unify(arg4, ArgAssignmentsIn)) | ||
1752 | { | ||
1753 | foreach (bool l5 in YP.unify(arg5, DeclarationsIn)) | ||
1754 | { | ||
1755 | foreach (bool l6 in YP.unify(arg6, DeclarationsIn)) | ||
1756 | { | ||
1757 | yield return true; | ||
1758 | yield break; | ||
1759 | } | ||
1760 | } | ||
1761 | } | ||
1762 | } | ||
1763 | } | ||
1764 | } | ||
1765 | { | ||
1766 | object HeadArgs = arg2; | ||
1767 | object ArgAssignmentsIn = arg3; | ||
1768 | object ArgAssignmentsOut = arg4; | ||
1769 | object DeclarationsIn = arg5; | ||
1770 | object DeclarationsOut = arg6; | ||
1771 | Variable VariableName = new Variable(); | ||
1772 | Variable Var = new Variable(); | ||
1773 | Variable RestVariableNames = new Variable(); | ||
1774 | Variable ArgIndex1 = new Variable(); | ||
1775 | Variable NumberCodes = new Variable(); | ||
1776 | Variable NumberAtom = new Variable(); | ||
1777 | Variable ArgName = new Variable(); | ||
1778 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("=", VariableName, Var), RestVariableNames))) | ||
1779 | { | ||
1780 | foreach (bool l3 in getVariableArgIndex1(Var, HeadArgs, ArgIndex1)) | ||
1781 | { | ||
1782 | foreach (bool l4 in YP.number_codes(ArgIndex1, NumberCodes)) | ||
1783 | { | ||
1784 | foreach (bool l5 in YP.atom_codes(NumberAtom, NumberCodes)) | ||
1785 | { | ||
1786 | foreach (bool l6 in YP.atom_concat(Atom.a("arg"), NumberAtom, ArgName)) | ||
1787 | { | ||
1788 | foreach (bool l7 in compileDeclarations(RestVariableNames, HeadArgs, new ListPair(new Functor2("f", VariableName, ArgName), ArgAssignmentsIn), ArgAssignmentsOut, DeclarationsIn, DeclarationsOut)) | ||
1789 | { | ||
1790 | yield return true; | ||
1791 | yield break; | ||
1792 | } | ||
1793 | } | ||
1794 | } | ||
1795 | } | ||
1796 | } | ||
1797 | } | ||
1798 | } | ||
1799 | { | ||
1800 | object HeadArgs = arg2; | ||
1801 | object ArgAssignmentsIn = arg3; | ||
1802 | object ArgAssignmentsOut = arg4; | ||
1803 | object DeclarationsIn = arg5; | ||
1804 | Variable VariableName = new Variable(); | ||
1805 | Variable _Var = new Variable(); | ||
1806 | Variable RestVariableNames = new Variable(); | ||
1807 | Variable DeclarationsOut = new Variable(); | ||
1808 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("=", VariableName, _Var), RestVariableNames))) | ||
1809 | { | ||
1810 | foreach (bool l3 in YP.unify(arg6, new ListPair(new Functor3("declare", Atom.a("Variable"), VariableName, new Functor2("new", Atom.a("Variable"), Atom.NIL)), DeclarationsOut))) | ||
1811 | { | ||
1812 | foreach (bool l4 in compileDeclarations(RestVariableNames, HeadArgs, ArgAssignmentsIn, ArgAssignmentsOut, DeclarationsIn, DeclarationsOut)) | ||
1813 | { | ||
1814 | yield return true; | ||
1815 | yield break; | ||
1816 | } | ||
1817 | } | ||
1818 | } | ||
1819 | } | ||
1820 | } | ||
1821 | |||
1822 | public static IEnumerable<bool> getVariableArgIndex1(object Var, object arg2, object arg3) | ||
1823 | { | ||
1824 | { | ||
1825 | Variable FirstHeadArgs = new Variable(); | ||
1826 | Variable RestHeadArgs = new Variable(); | ||
1827 | Variable x4 = new Variable(); | ||
1828 | foreach (bool l2 in YP.unify(arg2, new ListPair(FirstHeadArgs, RestHeadArgs))) | ||
1829 | { | ||
1830 | foreach (bool l3 in YP.unify(arg3, 1)) | ||
1831 | { | ||
1832 | if (sameVariable(Var, FirstHeadArgs)) | ||
1833 | { | ||
1834 | foreach (bool l5 in getVariableArgIndex1(Var, RestHeadArgs, x4)) | ||
1835 | { | ||
1836 | goto cutIf1; | ||
1837 | } | ||
1838 | yield return false; | ||
1839 | cutIf1: | ||
1840 | yield break; | ||
1841 | } | ||
1842 | } | ||
1843 | } | ||
1844 | } | ||
1845 | { | ||
1846 | object Index = arg3; | ||
1847 | Variable x2 = new Variable(); | ||
1848 | Variable RestHeadArgs = new Variable(); | ||
1849 | Variable RestIndex = new Variable(); | ||
1850 | foreach (bool l2 in YP.unify(arg2, new ListPair(x2, RestHeadArgs))) | ||
1851 | { | ||
1852 | foreach (bool l3 in getVariableArgIndex1(Var, RestHeadArgs, RestIndex)) | ||
1853 | { | ||
1854 | foreach (bool l4 in YP.unify(Index, YP.add(1, RestIndex))) | ||
1855 | { | ||
1856 | yield return true; | ||
1857 | yield break; | ||
1858 | } | ||
1859 | } | ||
1860 | } | ||
1861 | } | ||
1862 | } | ||
1863 | |||
1864 | public static IEnumerable<bool> compileRuleBody(object arg1, object arg2, object arg3) | ||
1865 | { | ||
1866 | { | ||
1867 | object A = arg1; | ||
1868 | object State = arg2; | ||
1869 | object PseudoCode = arg3; | ||
1870 | if (YP.var(A)) | ||
1871 | { | ||
1872 | foreach (bool l3 in compileRuleBody(new Functor2(",", new Functor1("call", A), Atom.a("true")), State, PseudoCode)) | ||
1873 | { | ||
1874 | yield return true; | ||
1875 | yield break; | ||
1876 | } | ||
1877 | } | ||
1878 | } | ||
1879 | { | ||
1880 | object State = arg2; | ||
1881 | object PseudoCode = arg3; | ||
1882 | Variable A = new Variable(); | ||
1883 | Variable B = new Variable(); | ||
1884 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", A, B))) | ||
1885 | { | ||
1886 | if (YP.var(A)) | ||
1887 | { | ||
1888 | foreach (bool l4 in compileRuleBody(new Functor2(",", new Functor1("call", A), B), State, PseudoCode)) | ||
1889 | { | ||
1890 | yield return true; | ||
1891 | yield break; | ||
1892 | } | ||
1893 | } | ||
1894 | } | ||
1895 | } | ||
1896 | { | ||
1897 | object State = arg2; | ||
1898 | object PseudoCode = arg3; | ||
1899 | Variable A = new Variable(); | ||
1900 | Variable B = new Variable(); | ||
1901 | Variable ACode = new Variable(); | ||
1902 | Variable BCode = new Variable(); | ||
1903 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", A, B))) | ||
1904 | { | ||
1905 | foreach (bool l3 in compileFunctorCall(A, State, ACode)) | ||
1906 | { | ||
1907 | if (CompilerState.isDetNoneOut(State, A)) | ||
1908 | { | ||
1909 | foreach (bool l5 in compileRuleBody(B, State, BCode)) | ||
1910 | { | ||
1911 | foreach (bool l6 in YP.unify(PseudoCode, new ListPair(ACode, BCode))) | ||
1912 | { | ||
1913 | yield return true; | ||
1914 | yield break; | ||
1915 | } | ||
1916 | } | ||
1917 | } | ||
1918 | if (CompilerState.isSemidetNoneOut(State, A)) | ||
1919 | { | ||
1920 | foreach (bool l5 in compileRuleBody(B, State, BCode)) | ||
1921 | { | ||
1922 | foreach (bool l6 in YP.unify(PseudoCode, new ListPair(new Functor2("if", ACode, BCode), Atom.NIL))) | ||
1923 | { | ||
1924 | yield return true; | ||
1925 | yield break; | ||
1926 | } | ||
1927 | } | ||
1928 | } | ||
1929 | foreach (bool l4 in compileRuleBody(B, State, BCode)) | ||
1930 | { | ||
1931 | foreach (bool l5 in YP.unify(PseudoCode, new ListPair(new Functor2("foreach", ACode, BCode), Atom.NIL))) | ||
1932 | { | ||
1933 | yield return true; | ||
1934 | yield break; | ||
1935 | } | ||
1936 | } | ||
1937 | } | ||
1938 | } | ||
1939 | } | ||
1940 | { | ||
1941 | object State = arg2; | ||
1942 | object PseudoCode = arg3; | ||
1943 | Variable A = new Variable(); | ||
1944 | Variable T = new Variable(); | ||
1945 | Variable B = new Variable(); | ||
1946 | Variable C = new Variable(); | ||
1947 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor2(";", new Functor2("->", A, T), B), C))) | ||
1948 | { | ||
1949 | foreach (bool l3 in compileRuleBody(new Functor2(";", new Functor2("->", A, new Functor2(",", T, C)), new Functor2(",", B, C)), State, PseudoCode)) | ||
1950 | { | ||
1951 | yield return true; | ||
1952 | yield break; | ||
1953 | } | ||
1954 | } | ||
1955 | } | ||
1956 | { | ||
1957 | object State = arg2; | ||
1958 | object PseudoCode = arg3; | ||
1959 | Variable A = new Variable(); | ||
1960 | Variable B = new Variable(); | ||
1961 | Variable C = new Variable(); | ||
1962 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor2(";", A, B), C))) | ||
1963 | { | ||
1964 | foreach (bool l3 in compileRuleBody(new Functor2(";", new Functor2(",", A, C), new Functor2(",", B, C)), State, PseudoCode)) | ||
1965 | { | ||
1966 | yield return true; | ||
1967 | yield break; | ||
1968 | } | ||
1969 | } | ||
1970 | } | ||
1971 | { | ||
1972 | object State = arg2; | ||
1973 | Variable A = new Variable(); | ||
1974 | Variable B = new Variable(); | ||
1975 | Variable ACode = new Variable(); | ||
1976 | Variable BCode = new Variable(); | ||
1977 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("\\+", A), B))) | ||
1978 | { | ||
1979 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("if", new Functor1("not", ACode), BCode), Atom.NIL))) | ||
1980 | { | ||
1981 | if (CompilerState.isSemidetNoneOut(State, A)) | ||
1982 | { | ||
1983 | foreach (bool l5 in compileFunctorCall(A, State, ACode)) | ||
1984 | { | ||
1985 | foreach (bool l6 in compileRuleBody(B, State, BCode)) | ||
1986 | { | ||
1987 | yield return true; | ||
1988 | yield break; | ||
1989 | } | ||
1990 | } | ||
1991 | } | ||
1992 | } | ||
1993 | } | ||
1994 | } | ||
1995 | { | ||
1996 | object State = arg2; | ||
1997 | object PseudoCode = arg3; | ||
1998 | Variable A = new Variable(); | ||
1999 | Variable B = new Variable(); | ||
2000 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("\\+", A), B))) | ||
2001 | { | ||
2002 | foreach (bool l3 in compileRuleBody(new Functor2(",", new Functor2(";", new Functor2("->", A, Atom.a("fail")), Atom.a("true")), B), State, PseudoCode)) | ||
2003 | { | ||
2004 | yield return true; | ||
2005 | yield break; | ||
2006 | } | ||
2007 | } | ||
2008 | } | ||
2009 | { | ||
2010 | object State = arg2; | ||
2011 | object PseudoCode = arg3; | ||
2012 | Variable A = new Variable(); | ||
2013 | Variable B = new Variable(); | ||
2014 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("once", A), B))) | ||
2015 | { | ||
2016 | foreach (bool l3 in compileRuleBody(new Functor2(",", new Functor2(";", new Functor2("->", A, Atom.a("true")), Atom.a("fail")), B), State, PseudoCode)) | ||
2017 | { | ||
2018 | yield return true; | ||
2019 | yield break; | ||
2020 | } | ||
2021 | } | ||
2022 | } | ||
2023 | { | ||
2024 | object State = arg2; | ||
2025 | object PseudoCode = arg3; | ||
2026 | Variable A = new Variable(); | ||
2027 | Variable T = new Variable(); | ||
2028 | Variable B = new Variable(); | ||
2029 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor2("->", A, T), B))) | ||
2030 | { | ||
2031 | foreach (bool l3 in compileRuleBody(new Functor2(",", new Functor2(";", new Functor2("->", A, T), Atom.a("fail")), B), State, PseudoCode)) | ||
2032 | { | ||
2033 | yield return true; | ||
2034 | yield break; | ||
2035 | } | ||
2036 | } | ||
2037 | } | ||
2038 | { | ||
2039 | object State = arg2; | ||
2040 | object PseudoCode = arg3; | ||
2041 | Variable A = new Variable(); | ||
2042 | Variable B = new Variable(); | ||
2043 | Variable C = new Variable(); | ||
2044 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor2("\\=", A, B), C))) | ||
2045 | { | ||
2046 | foreach (bool l3 in compileRuleBody(new Functor2(",", new Functor1("\\+", new Functor2("=", A, B)), C), State, PseudoCode)) | ||
2047 | { | ||
2048 | yield return true; | ||
2049 | yield break; | ||
2050 | } | ||
2051 | } | ||
2052 | } | ||
2053 | { | ||
2054 | object State = arg2; | ||
2055 | object PseudoCode = arg3; | ||
2056 | Variable A = new Variable(); | ||
2057 | Variable ACode = new Variable(); | ||
2058 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", Atom.a("!"), A))) | ||
2059 | { | ||
2060 | foreach (bool l3 in compileRuleBody(A, State, ACode)) | ||
2061 | { | ||
2062 | foreach (bool l4 in append(ACode, new ListPair(Atom.a("yieldbreak"), Atom.NIL), PseudoCode)) | ||
2063 | { | ||
2064 | yield return true; | ||
2065 | yield break; | ||
2066 | } | ||
2067 | } | ||
2068 | } | ||
2069 | } | ||
2070 | { | ||
2071 | object State = arg2; | ||
2072 | object PseudoCode = arg3; | ||
2073 | Variable Name = new Variable(); | ||
2074 | Variable A = new Variable(); | ||
2075 | Variable ACode = new Variable(); | ||
2076 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("$CUTIF", Name), A))) | ||
2077 | { | ||
2078 | foreach (bool l3 in compileRuleBody(A, State, ACode)) | ||
2079 | { | ||
2080 | foreach (bool l4 in append(ACode, new ListPair(new Functor1("breakBlock", Name), Atom.NIL), PseudoCode)) | ||
2081 | { | ||
2082 | yield return true; | ||
2083 | yield break; | ||
2084 | } | ||
2085 | } | ||
2086 | } | ||
2087 | } | ||
2088 | { | ||
2089 | object _State = arg2; | ||
2090 | Variable x1 = new Variable(); | ||
2091 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", Atom.a("fail"), x1))) | ||
2092 | { | ||
2093 | foreach (bool l3 in YP.unify(arg3, Atom.NIL)) | ||
2094 | { | ||
2095 | yield return true; | ||
2096 | yield break; | ||
2097 | } | ||
2098 | } | ||
2099 | } | ||
2100 | { | ||
2101 | object State = arg2; | ||
2102 | object PseudoCode = arg3; | ||
2103 | Variable A = new Variable(); | ||
2104 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", Atom.a("true"), A))) | ||
2105 | { | ||
2106 | foreach (bool l3 in compileRuleBody(A, State, PseudoCode)) | ||
2107 | { | ||
2108 | yield return true; | ||
2109 | yield break; | ||
2110 | } | ||
2111 | } | ||
2112 | } | ||
2113 | { | ||
2114 | object State = arg2; | ||
2115 | Variable A = new Variable(); | ||
2116 | Variable Term = new Variable(); | ||
2117 | Variable B = new Variable(); | ||
2118 | Variable ACode = new Variable(); | ||
2119 | Variable TermCode = new Variable(); | ||
2120 | Variable BCode = new Variable(); | ||
2121 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor2("is", A, Term), B))) | ||
2122 | { | ||
2123 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.unify"), new ListPair(ACode, new ListPair(TermCode, Atom.NIL))), BCode), Atom.NIL))) | ||
2124 | { | ||
2125 | foreach (bool l4 in compileTerm(A, State, ACode)) | ||
2126 | { | ||
2127 | foreach (bool l5 in compileExpression(Term, State, TermCode)) | ||
2128 | { | ||
2129 | foreach (bool l6 in compileRuleBody(B, State, BCode)) | ||
2130 | { | ||
2131 | yield return true; | ||
2132 | yield break; | ||
2133 | } | ||
2134 | } | ||
2135 | } | ||
2136 | } | ||
2137 | } | ||
2138 | } | ||
2139 | { | ||
2140 | object State = arg2; | ||
2141 | Variable ACode = new Variable(); | ||
2142 | Variable B = new Variable(); | ||
2143 | Variable BCode = new Variable(); | ||
2144 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("$DET_NONE_OUT", ACode), B))) | ||
2145 | { | ||
2146 | foreach (bool l3 in YP.unify(arg3, new ListPair(ACode, BCode))) | ||
2147 | { | ||
2148 | foreach (bool l4 in compileRuleBody(B, State, BCode)) | ||
2149 | { | ||
2150 | yield return true; | ||
2151 | yield break; | ||
2152 | } | ||
2153 | } | ||
2154 | } | ||
2155 | } | ||
2156 | { | ||
2157 | object State = arg2; | ||
2158 | Variable A = new Variable(); | ||
2159 | Variable B = new Variable(); | ||
2160 | Variable FunctionName = new Variable(); | ||
2161 | Variable X1Code = new Variable(); | ||
2162 | Variable X2Code = new Variable(); | ||
2163 | Variable BCode = new Variable(); | ||
2164 | Variable Name = new Variable(); | ||
2165 | Variable X1 = new Variable(); | ||
2166 | Variable X2 = new Variable(); | ||
2167 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", A, B))) | ||
2168 | { | ||
2169 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("if", new Functor2("call", FunctionName, new ListPair(X1Code, new ListPair(X2Code, Atom.NIL))), BCode), Atom.NIL))) | ||
2170 | { | ||
2171 | foreach (bool l4 in YP.univ(A, ListPair.make(new object[] { Name, X1, X2 }))) | ||
2172 | { | ||
2173 | foreach (bool l5 in binaryExpressionConditional(Name, FunctionName)) | ||
2174 | { | ||
2175 | foreach (bool l6 in compileExpression(X1, State, X1Code)) | ||
2176 | { | ||
2177 | foreach (bool l7 in compileExpression(X2, State, X2Code)) | ||
2178 | { | ||
2179 | foreach (bool l8 in compileRuleBody(B, State, BCode)) | ||
2180 | { | ||
2181 | yield return true; | ||
2182 | yield break; | ||
2183 | } | ||
2184 | } | ||
2185 | } | ||
2186 | } | ||
2187 | } | ||
2188 | } | ||
2189 | } | ||
2190 | } | ||
2191 | { | ||
2192 | object State = arg2; | ||
2193 | object PseudoCode = arg3; | ||
2194 | Variable Template = new Variable(); | ||
2195 | Variable Goal = new Variable(); | ||
2196 | Variable Bag = new Variable(); | ||
2197 | Variable B = new Variable(); | ||
2198 | Variable TemplateCode = new Variable(); | ||
2199 | Variable FindallAnswers = new Variable(); | ||
2200 | Variable GoalAndAddCode = new Variable(); | ||
2201 | Variable BagCode = new Variable(); | ||
2202 | Variable BCode = new Variable(); | ||
2203 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor3("findall", Template, Goal, Bag), B))) | ||
2204 | { | ||
2205 | foreach (bool l3 in compileTerm(Template, State, TemplateCode)) | ||
2206 | { | ||
2207 | foreach (bool l4 in CompilerState.gensym(State, Atom.a("findallAnswers"), FindallAnswers)) | ||
2208 | { | ||
2209 | foreach (bool l5 in compileRuleBody(new Functor2(",", Goal, new Functor2(",", new Functor1("$DET_NONE_OUT", new Functor3("callMember", new Functor1("var", FindallAnswers), Atom.a("add"), Atom.NIL)), Atom.a("fail"))), State, GoalAndAddCode)) | ||
2210 | { | ||
2211 | foreach (bool l6 in compileTerm(Bag, State, BagCode)) | ||
2212 | { | ||
2213 | foreach (bool l7 in compileRuleBody(B, State, BCode)) | ||
2214 | { | ||
2215 | foreach (bool l8 in append(new ListPair(new Functor3("declare", Atom.a("FindallAnswers"), FindallAnswers, new Functor2("new", Atom.a("FindallAnswers"), new ListPair(TemplateCode, Atom.NIL))), GoalAndAddCode), new ListPair(new Functor2("foreach", new Functor3("callMember", new Functor1("var", FindallAnswers), Atom.a("result"), new ListPair(BagCode, Atom.NIL)), BCode), Atom.NIL), PseudoCode)) | ||
2216 | { | ||
2217 | yield return true; | ||
2218 | yield break; | ||
2219 | } | ||
2220 | } | ||
2221 | } | ||
2222 | } | ||
2223 | } | ||
2224 | } | ||
2225 | } | ||
2226 | } | ||
2227 | { | ||
2228 | object State = arg2; | ||
2229 | object PseudoCode = arg3; | ||
2230 | Variable Template = new Variable(); | ||
2231 | Variable Goal = new Variable(); | ||
2232 | Variable Bag = new Variable(); | ||
2233 | Variable B = new Variable(); | ||
2234 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor3("bagof", Template, Goal, Bag), B))) | ||
2235 | { | ||
2236 | foreach (bool l3 in compileBagof(Atom.a("result"), Template, Goal, Bag, B, State, PseudoCode)) | ||
2237 | { | ||
2238 | yield return true; | ||
2239 | yield break; | ||
2240 | } | ||
2241 | } | ||
2242 | } | ||
2243 | { | ||
2244 | object State = arg2; | ||
2245 | object PseudoCode = arg3; | ||
2246 | Variable Template = new Variable(); | ||
2247 | Variable Goal = new Variable(); | ||
2248 | Variable Bag = new Variable(); | ||
2249 | Variable B = new Variable(); | ||
2250 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor3("setof", Template, Goal, Bag), B))) | ||
2251 | { | ||
2252 | foreach (bool l3 in compileBagof(Atom.a("resultSet"), Template, Goal, Bag, B, State, PseudoCode)) | ||
2253 | { | ||
2254 | yield return true; | ||
2255 | yield break; | ||
2256 | } | ||
2257 | } | ||
2258 | } | ||
2259 | { | ||
2260 | object State = arg2; | ||
2261 | Variable A = new Variable(); | ||
2262 | Variable B = new Variable(); | ||
2263 | Variable ATermCode = new Variable(); | ||
2264 | Variable BCode = new Variable(); | ||
2265 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("call", A), B))) | ||
2266 | { | ||
2267 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.getIterator"), new ListPair(ATermCode, new ListPair(new Functor2("call", Atom.a("getDeclaringClass"), Atom.NIL), Atom.NIL))), BCode), Atom.NIL))) | ||
2268 | { | ||
2269 | foreach (bool l4 in compileTerm(A, State, ATermCode)) | ||
2270 | { | ||
2271 | foreach (bool l5 in compileRuleBody(B, State, BCode)) | ||
2272 | { | ||
2273 | yield return true; | ||
2274 | yield break; | ||
2275 | } | ||
2276 | } | ||
2277 | } | ||
2278 | } | ||
2279 | } | ||
2280 | { | ||
2281 | object State = arg2; | ||
2282 | Variable A = new Variable(); | ||
2283 | Variable B = new Variable(); | ||
2284 | Variable ATermCode = new Variable(); | ||
2285 | Variable BCode = new Variable(); | ||
2286 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("current_predicate", A), B))) | ||
2287 | { | ||
2288 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.current_predicate"), new ListPair(ATermCode, new ListPair(new Functor2("call", Atom.a("getDeclaringClass"), Atom.NIL), Atom.NIL))), BCode), Atom.NIL))) | ||
2289 | { | ||
2290 | foreach (bool l4 in compileTerm(A, State, ATermCode)) | ||
2291 | { | ||
2292 | foreach (bool l5 in compileRuleBody(B, State, BCode)) | ||
2293 | { | ||
2294 | yield return true; | ||
2295 | yield break; | ||
2296 | } | ||
2297 | } | ||
2298 | } | ||
2299 | } | ||
2300 | } | ||
2301 | { | ||
2302 | object State = arg2; | ||
2303 | Variable A = new Variable(); | ||
2304 | Variable B = new Variable(); | ||
2305 | Variable ATermCode = new Variable(); | ||
2306 | Variable BCode = new Variable(); | ||
2307 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("asserta", A), B))) | ||
2308 | { | ||
2309 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("call", Atom.a("YP.asserta"), new ListPair(ATermCode, new ListPair(new Functor2("call", Atom.a("getDeclaringClass"), Atom.NIL), Atom.NIL))), BCode))) | ||
2310 | { | ||
2311 | foreach (bool l4 in compileTerm(A, State, ATermCode)) | ||
2312 | { | ||
2313 | foreach (bool l5 in compileRuleBody(B, State, BCode)) | ||
2314 | { | ||
2315 | yield return true; | ||
2316 | yield break; | ||
2317 | } | ||
2318 | } | ||
2319 | } | ||
2320 | } | ||
2321 | } | ||
2322 | { | ||
2323 | object State = arg2; | ||
2324 | Variable A = new Variable(); | ||
2325 | Variable B = new Variable(); | ||
2326 | Variable ATermCode = new Variable(); | ||
2327 | Variable BCode = new Variable(); | ||
2328 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("assertz", A), B))) | ||
2329 | { | ||
2330 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("call", Atom.a("YP.assertz"), new ListPair(ATermCode, new ListPair(new Functor2("call", Atom.a("getDeclaringClass"), Atom.NIL), Atom.NIL))), BCode))) | ||
2331 | { | ||
2332 | foreach (bool l4 in compileTerm(A, State, ATermCode)) | ||
2333 | { | ||
2334 | foreach (bool l5 in compileRuleBody(B, State, BCode)) | ||
2335 | { | ||
2336 | yield return true; | ||
2337 | yield break; | ||
2338 | } | ||
2339 | } | ||
2340 | } | ||
2341 | } | ||
2342 | } | ||
2343 | { | ||
2344 | object State = arg2; | ||
2345 | object PseudoCode = arg3; | ||
2346 | Variable A = new Variable(); | ||
2347 | Variable B = new Variable(); | ||
2348 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("assert", A), B))) | ||
2349 | { | ||
2350 | foreach (bool l3 in compileRuleBody(new Functor2(",", new Functor1("assertz", A), B), State, PseudoCode)) | ||
2351 | { | ||
2352 | yield return true; | ||
2353 | yield break; | ||
2354 | } | ||
2355 | } | ||
2356 | } | ||
2357 | { | ||
2358 | object State = arg2; | ||
2359 | Variable Goal = new Variable(); | ||
2360 | Variable Catcher = new Variable(); | ||
2361 | Variable Handler = new Variable(); | ||
2362 | Variable B = new Variable(); | ||
2363 | Variable CatchGoal = new Variable(); | ||
2364 | Variable GoalTermCode = new Variable(); | ||
2365 | Variable BCode = new Variable(); | ||
2366 | Variable CatcherTermCode = new Variable(); | ||
2367 | Variable HandlerAndBCode = new Variable(); | ||
2368 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor3("catch", Goal, Catcher, Handler), B))) | ||
2369 | { | ||
2370 | foreach (bool l3 in YP.unify(arg3, ListPair.make(new object[] { new Functor3("declare", Atom.a("YP.Catch"), CatchGoal, new Functor2("new", Atom.a("YP.Catch"), new ListPair(GoalTermCode, new ListPair(new Functor2("call", Atom.a("getDeclaringClass"), Atom.NIL), Atom.NIL)))), new Functor2("foreach", new Functor1("var", CatchGoal), BCode), new Functor2("foreach", new Functor3("callMember", new Functor1("var", CatchGoal), Atom.a("unifyExceptionOrThrow"), new ListPair(CatcherTermCode, Atom.NIL)), HandlerAndBCode) }))) | ||
2371 | { | ||
2372 | foreach (bool l4 in CompilerState.gensym(State, Atom.a("catchGoal"), CatchGoal)) | ||
2373 | { | ||
2374 | foreach (bool l5 in compileTerm(Goal, State, GoalTermCode)) | ||
2375 | { | ||
2376 | foreach (bool l6 in compileTerm(Catcher, State, CatcherTermCode)) | ||
2377 | { | ||
2378 | foreach (bool l7 in compileRuleBody(B, State, BCode)) | ||
2379 | { | ||
2380 | foreach (bool l8 in compileRuleBody(new Functor2(",", Handler, B), State, HandlerAndBCode)) | ||
2381 | { | ||
2382 | yield return true; | ||
2383 | yield break; | ||
2384 | } | ||
2385 | } | ||
2386 | } | ||
2387 | } | ||
2388 | } | ||
2389 | } | ||
2390 | } | ||
2391 | } | ||
2392 | { | ||
2393 | object State = arg2; | ||
2394 | object PseudoCode = arg3; | ||
2395 | Variable A = new Variable(); | ||
2396 | Variable B = new Variable(); | ||
2397 | Variable C = new Variable(); | ||
2398 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor2(",", A, B), C))) | ||
2399 | { | ||
2400 | foreach (bool l3 in compileRuleBody(new Functor2(",", A, new Functor2(",", B, C)), State, PseudoCode)) | ||
2401 | { | ||
2402 | yield return true; | ||
2403 | yield break; | ||
2404 | } | ||
2405 | } | ||
2406 | } | ||
2407 | { | ||
2408 | object State = arg2; | ||
2409 | object PseudoCode = arg3; | ||
2410 | Variable A = new Variable(); | ||
2411 | Variable B = new Variable(); | ||
2412 | foreach (bool l2 in YP.unify(arg1, new Functor2(";", A, B))) | ||
2413 | { | ||
2414 | if (YP.var(A)) | ||
2415 | { | ||
2416 | foreach (bool l4 in compileRuleBody(new Functor2(";", new Functor1("call", A), B), State, PseudoCode)) | ||
2417 | { | ||
2418 | yield return true; | ||
2419 | yield break; | ||
2420 | } | ||
2421 | } | ||
2422 | } | ||
2423 | } | ||
2424 | { | ||
2425 | object State = arg2; | ||
2426 | Variable A = new Variable(); | ||
2427 | Variable T = new Variable(); | ||
2428 | Variable B = new Variable(); | ||
2429 | Variable CutIfLabel = new Variable(); | ||
2430 | Variable Code = new Variable(); | ||
2431 | foreach (bool l2 in YP.unify(arg1, new Functor2(";", new Functor2("->", A, T), B))) | ||
2432 | { | ||
2433 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("breakableBlock", CutIfLabel, Code), Atom.NIL))) | ||
2434 | { | ||
2435 | foreach (bool l4 in CompilerState.gensym(State, Atom.a("cutIf"), CutIfLabel)) | ||
2436 | { | ||
2437 | foreach (bool l5 in compileRuleBody(new Functor2(";", new Functor2(",", A, new Functor2(",", new Functor1("$CUTIF", CutIfLabel), T)), B), State, Code)) | ||
2438 | { | ||
2439 | yield return true; | ||
2440 | yield break; | ||
2441 | } | ||
2442 | } | ||
2443 | } | ||
2444 | } | ||
2445 | } | ||
2446 | { | ||
2447 | object State = arg2; | ||
2448 | object PseudoCode = arg3; | ||
2449 | Variable _B = new Variable(); | ||
2450 | foreach (bool l2 in YP.unify(arg1, new Functor2(";", Atom.a("!"), _B))) | ||
2451 | { | ||
2452 | foreach (bool l3 in compileRuleBody(Atom.a("!"), State, PseudoCode)) | ||
2453 | { | ||
2454 | yield return true; | ||
2455 | yield break; | ||
2456 | } | ||
2457 | } | ||
2458 | } | ||
2459 | { | ||
2460 | object State = arg2; | ||
2461 | object PseudoCode = arg3; | ||
2462 | Variable A = new Variable(); | ||
2463 | Variable B = new Variable(); | ||
2464 | Variable ACode = new Variable(); | ||
2465 | Variable BCode = new Variable(); | ||
2466 | foreach (bool l2 in YP.unify(arg1, new Functor2(";", A, B))) | ||
2467 | { | ||
2468 | foreach (bool l3 in compileRuleBody(A, State, ACode)) | ||
2469 | { | ||
2470 | foreach (bool l4 in compileRuleBody(B, State, BCode)) | ||
2471 | { | ||
2472 | foreach (bool l5 in append(ACode, BCode, PseudoCode)) | ||
2473 | { | ||
2474 | yield return true; | ||
2475 | yield break; | ||
2476 | } | ||
2477 | } | ||
2478 | } | ||
2479 | } | ||
2480 | } | ||
2481 | { | ||
2482 | object State = arg2; | ||
2483 | foreach (bool l2 in YP.unify(arg1, Atom.a("!"))) | ||
2484 | { | ||
2485 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("return"), Atom.NIL))) | ||
2486 | { | ||
2487 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
2488 | { | ||
2489 | yield return true; | ||
2490 | yield break; | ||
2491 | } | ||
2492 | } | ||
2493 | } | ||
2494 | } | ||
2495 | { | ||
2496 | object State = arg2; | ||
2497 | foreach (bool l2 in YP.unify(arg1, Atom.a("!"))) | ||
2498 | { | ||
2499 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("returntrue"), Atom.NIL))) | ||
2500 | { | ||
2501 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
2502 | { | ||
2503 | yield return true; | ||
2504 | yield break; | ||
2505 | } | ||
2506 | } | ||
2507 | } | ||
2508 | } | ||
2509 | { | ||
2510 | object State = arg2; | ||
2511 | foreach (bool l2 in YP.unify(arg1, Atom.a("!"))) | ||
2512 | { | ||
2513 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("yieldtrue"), new ListPair(Atom.a("yieldbreak"), Atom.NIL)))) | ||
2514 | { | ||
2515 | CompilerState.setCodeUsesYield(State); | ||
2516 | yield return true; | ||
2517 | yield break; | ||
2518 | } | ||
2519 | } | ||
2520 | } | ||
2521 | { | ||
2522 | object _State = arg2; | ||
2523 | Variable Name = new Variable(); | ||
2524 | foreach (bool l2 in YP.unify(arg1, new Functor1("$CUTIF", Name))) | ||
2525 | { | ||
2526 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor1("breakBlock", Name), Atom.NIL))) | ||
2527 | { | ||
2528 | yield return true; | ||
2529 | yield break; | ||
2530 | } | ||
2531 | } | ||
2532 | } | ||
2533 | { | ||
2534 | object State = arg2; | ||
2535 | foreach (bool l2 in YP.unify(arg1, Atom.a("true"))) | ||
2536 | { | ||
2537 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("return"), Atom.NIL))) | ||
2538 | { | ||
2539 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
2540 | { | ||
2541 | yield return true; | ||
2542 | yield break; | ||
2543 | } | ||
2544 | } | ||
2545 | } | ||
2546 | } | ||
2547 | { | ||
2548 | object State = arg2; | ||
2549 | foreach (bool l2 in YP.unify(arg1, Atom.a("true"))) | ||
2550 | { | ||
2551 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("returntrue"), Atom.NIL))) | ||
2552 | { | ||
2553 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
2554 | { | ||
2555 | yield return true; | ||
2556 | yield break; | ||
2557 | } | ||
2558 | } | ||
2559 | } | ||
2560 | } | ||
2561 | { | ||
2562 | object State = arg2; | ||
2563 | foreach (bool l2 in YP.unify(arg1, Atom.a("true"))) | ||
2564 | { | ||
2565 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("yieldfalse"), Atom.NIL))) | ||
2566 | { | ||
2567 | CompilerState.setCodeUsesYield(State); | ||
2568 | yield return true; | ||
2569 | yield break; | ||
2570 | } | ||
2571 | } | ||
2572 | } | ||
2573 | { | ||
2574 | object A = arg1; | ||
2575 | object State = arg2; | ||
2576 | object PseudoCode = arg3; | ||
2577 | foreach (bool l2 in compileRuleBody(new Functor2(",", A, Atom.a("true")), State, PseudoCode)) | ||
2578 | { | ||
2579 | yield return true; | ||
2580 | yield break; | ||
2581 | } | ||
2582 | } | ||
2583 | } | ||
2584 | |||
2585 | public static IEnumerable<bool> compileBagof(object ResultMethod, object Template, object Goal, object Bag, object B, object State, object PseudoCode) | ||
2586 | { | ||
2587 | { | ||
2588 | Variable TemplateCode = new Variable(); | ||
2589 | Variable GoalTermCode = new Variable(); | ||
2590 | Variable UnqualifiedGoal = new Variable(); | ||
2591 | Variable BagofAnswers = new Variable(); | ||
2592 | Variable GoalAndAddCode = new Variable(); | ||
2593 | Variable BagCode = new Variable(); | ||
2594 | Variable BCode = new Variable(); | ||
2595 | foreach (bool l2 in compileTerm(Template, State, TemplateCode)) | ||
2596 | { | ||
2597 | foreach (bool l3 in compileTerm(Goal, State, GoalTermCode)) | ||
2598 | { | ||
2599 | foreach (bool l4 in unqualifiedGoal(Goal, UnqualifiedGoal)) | ||
2600 | { | ||
2601 | foreach (bool l5 in CompilerState.gensym(State, Atom.a("bagofAnswers"), BagofAnswers)) | ||
2602 | { | ||
2603 | foreach (bool l6 in compileRuleBody(new Functor2(",", UnqualifiedGoal, new Functor2(",", new Functor1("$DET_NONE_OUT", new Functor3("callMember", new Functor1("var", BagofAnswers), Atom.a("add"), Atom.NIL)), Atom.a("fail"))), State, GoalAndAddCode)) | ||
2604 | { | ||
2605 | foreach (bool l7 in compileTerm(Bag, State, BagCode)) | ||
2606 | { | ||
2607 | foreach (bool l8 in compileRuleBody(B, State, BCode)) | ||
2608 | { | ||
2609 | foreach (bool l9 in append(new ListPair(new Functor3("declare", Atom.a("BagofAnswers"), BagofAnswers, new Functor2("new", Atom.a("BagofAnswers"), new ListPair(TemplateCode, new ListPair(GoalTermCode, Atom.NIL)))), GoalAndAddCode), new ListPair(new Functor2("foreach", new Functor3("callMember", new Functor1("var", BagofAnswers), ResultMethod, new ListPair(BagCode, Atom.NIL)), BCode), Atom.NIL), PseudoCode)) | ||
2610 | { | ||
2611 | yield return true; | ||
2612 | yield break; | ||
2613 | } | ||
2614 | } | ||
2615 | } | ||
2616 | } | ||
2617 | } | ||
2618 | } | ||
2619 | } | ||
2620 | } | ||
2621 | } | ||
2622 | } | ||
2623 | |||
2624 | public static IEnumerable<bool> unqualifiedGoal(object arg1, object arg2) | ||
2625 | { | ||
2626 | { | ||
2627 | object Goal = arg1; | ||
2628 | foreach (bool l2 in YP.unify(arg2, new Functor1("call", Goal))) | ||
2629 | { | ||
2630 | if (YP.var(Goal)) | ||
2631 | { | ||
2632 | yield return true; | ||
2633 | yield break; | ||
2634 | } | ||
2635 | } | ||
2636 | } | ||
2637 | { | ||
2638 | object UnqualifiedGoal = arg2; | ||
2639 | Variable x1 = new Variable(); | ||
2640 | Variable Goal = new Variable(); | ||
2641 | foreach (bool l2 in YP.unify(arg1, new Functor2("^", x1, Goal))) | ||
2642 | { | ||
2643 | foreach (bool l3 in unqualifiedGoal(Goal, UnqualifiedGoal)) | ||
2644 | { | ||
2645 | yield return true; | ||
2646 | yield break; | ||
2647 | } | ||
2648 | } | ||
2649 | } | ||
2650 | { | ||
2651 | Variable UnqualifiedGoal = new Variable(); | ||
2652 | foreach (bool l2 in YP.unify(arg1, UnqualifiedGoal)) | ||
2653 | { | ||
2654 | foreach (bool l3 in YP.unify(arg2, UnqualifiedGoal)) | ||
2655 | { | ||
2656 | yield return true; | ||
2657 | yield break; | ||
2658 | } | ||
2659 | } | ||
2660 | } | ||
2661 | } | ||
2662 | |||
2663 | public static IEnumerable<bool> binaryExpressionConditional(object arg1, object arg2) | ||
2664 | { | ||
2665 | { | ||
2666 | foreach (bool l2 in YP.unify(arg1, Atom.a("=:="))) | ||
2667 | { | ||
2668 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.equal"))) | ||
2669 | { | ||
2670 | yield return true; | ||
2671 | yield break; | ||
2672 | } | ||
2673 | } | ||
2674 | } | ||
2675 | { | ||
2676 | foreach (bool l2 in YP.unify(arg1, Atom.a("=\\="))) | ||
2677 | { | ||
2678 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.notEqual"))) | ||
2679 | { | ||
2680 | yield return true; | ||
2681 | yield break; | ||
2682 | } | ||
2683 | } | ||
2684 | } | ||
2685 | { | ||
2686 | foreach (bool l2 in YP.unify(arg1, Atom.a(">"))) | ||
2687 | { | ||
2688 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.greaterThan"))) | ||
2689 | { | ||
2690 | yield return true; | ||
2691 | yield break; | ||
2692 | } | ||
2693 | } | ||
2694 | } | ||
2695 | { | ||
2696 | foreach (bool l2 in YP.unify(arg1, Atom.a("<"))) | ||
2697 | { | ||
2698 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.lessThan"))) | ||
2699 | { | ||
2700 | yield return true; | ||
2701 | yield break; | ||
2702 | } | ||
2703 | } | ||
2704 | } | ||
2705 | { | ||
2706 | foreach (bool l2 in YP.unify(arg1, Atom.a(">="))) | ||
2707 | { | ||
2708 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.greaterThanOrEqual"))) | ||
2709 | { | ||
2710 | yield return true; | ||
2711 | yield break; | ||
2712 | } | ||
2713 | } | ||
2714 | } | ||
2715 | { | ||
2716 | foreach (bool l2 in YP.unify(arg1, Atom.a("=<"))) | ||
2717 | { | ||
2718 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.lessThanOrEqual"))) | ||
2719 | { | ||
2720 | yield return true; | ||
2721 | yield break; | ||
2722 | } | ||
2723 | } | ||
2724 | } | ||
2725 | } | ||
2726 | |||
2727 | public static IEnumerable<bool> compileFunctorCall(object Functor_1, object State, object PseudoCode) | ||
2728 | { | ||
2729 | { | ||
2730 | Variable FunctorName = new Variable(); | ||
2731 | Variable FunctorArgs = new Variable(); | ||
2732 | Variable x6 = new Variable(); | ||
2733 | Variable Arity = new Variable(); | ||
2734 | Variable FunctionName = new Variable(); | ||
2735 | Variable CompiledArgs = new Variable(); | ||
2736 | foreach (bool l2 in YP.univ(Functor_1, new ListPair(FunctorName, FunctorArgs))) | ||
2737 | { | ||
2738 | foreach (bool l3 in YP.functor(Functor_1, x6, Arity)) | ||
2739 | { | ||
2740 | foreach (bool l4 in functorCallFunctionName(State, FunctorName, Arity, FunctionName)) | ||
2741 | { | ||
2742 | foreach (bool l5 in maplist_compileTerm(FunctorArgs, State, CompiledArgs)) | ||
2743 | { | ||
2744 | if (YP.termEqual(FunctionName, Atom.NIL)) | ||
2745 | { | ||
2746 | foreach (bool l7 in YP.unify(PseudoCode, new Functor2("call", Atom.a("YP.matchDynamic"), new ListPair(new Functor2("call", Atom.a("Atom.a"), new ListPair(new Functor1("object", FunctorName), Atom.NIL)), new ListPair(new Functor1("objectArray", CompiledArgs), Atom.NIL))))) | ||
2747 | { | ||
2748 | yield return true; | ||
2749 | yield break; | ||
2750 | } | ||
2751 | goto cutIf1; | ||
2752 | } | ||
2753 | foreach (bool l6 in YP.unify(PseudoCode, new Functor3("functorCall", FunctionName, FunctorArgs, CompiledArgs))) | ||
2754 | { | ||
2755 | yield return true; | ||
2756 | yield break; | ||
2757 | } | ||
2758 | cutIf1: | ||
2759 | { } | ||
2760 | } | ||
2761 | } | ||
2762 | } | ||
2763 | } | ||
2764 | } | ||
2765 | } | ||
2766 | |||
2767 | public static IEnumerable<bool> functorCallFunctionName(object arg1, object arg2, object arg3, object arg4) | ||
2768 | { | ||
2769 | { | ||
2770 | object _State = arg1; | ||
2771 | object Name = arg2; | ||
2772 | object Arity = arg3; | ||
2773 | object x4 = arg4; | ||
2774 | if (functorCallIsSpecialForm(Name, Arity)) | ||
2775 | { | ||
2776 | yield break; | ||
2777 | } | ||
2778 | } | ||
2779 | { | ||
2780 | object x1 = arg1; | ||
2781 | object Name = arg2; | ||
2782 | object Arity = arg3; | ||
2783 | object FunctionName = arg4; | ||
2784 | foreach (bool l2 in functorCallYPFunctionName(Name, Arity, FunctionName)) | ||
2785 | { | ||
2786 | yield return true; | ||
2787 | yield break; | ||
2788 | } | ||
2789 | } | ||
2790 | { | ||
2791 | object State = arg1; | ||
2792 | object Arity = arg3; | ||
2793 | Variable Name = new Variable(); | ||
2794 | foreach (bool l2 in YP.unify(arg2, Name)) | ||
2795 | { | ||
2796 | foreach (bool l3 in YP.unify(arg4, Name)) | ||
2797 | { | ||
2798 | if (CompilerState.nameArityHasModule(State, Name, Arity, Atom.a(""))) | ||
2799 | { | ||
2800 | yield return true; | ||
2801 | yield break; | ||
2802 | } | ||
2803 | } | ||
2804 | } | ||
2805 | } | ||
2806 | { | ||
2807 | object _State = arg1; | ||
2808 | object _Arity = arg3; | ||
2809 | Variable Name = new Variable(); | ||
2810 | foreach (bool l2 in YP.unify(arg2, Name)) | ||
2811 | { | ||
2812 | foreach (bool l3 in YP.unify(arg4, Name)) | ||
2813 | { | ||
2814 | foreach (bool l4 in Atom.module(Name, Atom.a(""))) | ||
2815 | { | ||
2816 | yield return true; | ||
2817 | yield break; | ||
2818 | } | ||
2819 | } | ||
2820 | } | ||
2821 | } | ||
2822 | { | ||
2823 | object _State = arg1; | ||
2824 | object Name = arg2; | ||
2825 | object _Arity = arg3; | ||
2826 | foreach (bool l2 in YP.unify(arg4, Atom.NIL)) | ||
2827 | { | ||
2828 | foreach (bool l3 in Atom.module(Name, Atom.NIL)) | ||
2829 | { | ||
2830 | yield return true; | ||
2831 | yield break; | ||
2832 | } | ||
2833 | } | ||
2834 | } | ||
2835 | { | ||
2836 | object _State = arg1; | ||
2837 | object Name = arg2; | ||
2838 | object Arity = arg3; | ||
2839 | object x4 = arg4; | ||
2840 | Variable Module = new Variable(); | ||
2841 | Variable Message = new Variable(); | ||
2842 | foreach (bool l2 in Atom.module(Name, Module)) | ||
2843 | { | ||
2844 | foreach (bool l3 in YP.atom_concat(Atom.a("Not supporting calls to external module: "), Module, Message)) | ||
2845 | { | ||
2846 | YP.throwException(new Functor2("error", new Functor2("type_error", Atom.a("callable"), new Functor2("/", Name, Arity)), Message)); | ||
2847 | yield return true; | ||
2848 | yield break; | ||
2849 | } | ||
2850 | } | ||
2851 | } | ||
2852 | { | ||
2853 | object _State = arg1; | ||
2854 | object Name = arg2; | ||
2855 | object _Arity = arg3; | ||
2856 | object x4 = arg4; | ||
2857 | YP.throwException(new Functor2("error", new Functor2("type_error", Atom.a("callable"), Name), Atom.a("Term is not callable"))); | ||
2858 | yield return true; | ||
2859 | yield break; | ||
2860 | } | ||
2861 | } | ||
2862 | |||
2863 | public static bool functorCallIsSpecialForm(object Name, object Arity) | ||
2864 | { | ||
2865 | { | ||
2866 | Variable x3 = new Variable(); | ||
2867 | if (YP.termEqual(Arity, 0)) | ||
2868 | { | ||
2869 | if (YP.termEqual(Name, Atom.a("!"))) | ||
2870 | { | ||
2871 | return true; | ||
2872 | } | ||
2873 | if (YP.termEqual(Name, Atom.a("fail"))) | ||
2874 | { | ||
2875 | return true; | ||
2876 | } | ||
2877 | if (YP.termEqual(Name, Atom.a("true"))) | ||
2878 | { | ||
2879 | return true; | ||
2880 | } | ||
2881 | } | ||
2882 | if (YP.termEqual(Arity, 1)) | ||
2883 | { | ||
2884 | if (YP.termEqual(Name, Atom.a("\\+"))) | ||
2885 | { | ||
2886 | return true; | ||
2887 | } | ||
2888 | if (YP.termEqual(Name, Atom.a("once"))) | ||
2889 | { | ||
2890 | return true; | ||
2891 | } | ||
2892 | if (YP.termEqual(Name, Atom.a("$CUTIF"))) | ||
2893 | { | ||
2894 | return true; | ||
2895 | } | ||
2896 | if (YP.termEqual(Name, Atom.a("$DET_NONE_OUT"))) | ||
2897 | { | ||
2898 | return true; | ||
2899 | } | ||
2900 | if (YP.termEqual(Name, Atom.a("call"))) | ||
2901 | { | ||
2902 | return true; | ||
2903 | } | ||
2904 | if (YP.termEqual(Name, Atom.a("current_predicate"))) | ||
2905 | { | ||
2906 | return true; | ||
2907 | } | ||
2908 | if (YP.termEqual(Name, Atom.a("asserta"))) | ||
2909 | { | ||
2910 | return true; | ||
2911 | } | ||
2912 | if (YP.termEqual(Name, Atom.a("assertz"))) | ||
2913 | { | ||
2914 | return true; | ||
2915 | } | ||
2916 | if (YP.termEqual(Name, Atom.a("assert"))) | ||
2917 | { | ||
2918 | return true; | ||
2919 | } | ||
2920 | } | ||
2921 | if (YP.termEqual(Arity, 2)) | ||
2922 | { | ||
2923 | if (YP.termEqual(Name, Atom.a(";"))) | ||
2924 | { | ||
2925 | return true; | ||
2926 | } | ||
2927 | if (YP.termEqual(Name, Atom.a(","))) | ||
2928 | { | ||
2929 | return true; | ||
2930 | } | ||
2931 | if (YP.termEqual(Name, Atom.a("->"))) | ||
2932 | { | ||
2933 | return true; | ||
2934 | } | ||
2935 | if (YP.termEqual(Name, Atom.a("\\="))) | ||
2936 | { | ||
2937 | return true; | ||
2938 | } | ||
2939 | if (YP.termEqual(Name, Atom.a("is"))) | ||
2940 | { | ||
2941 | return true; | ||
2942 | } | ||
2943 | foreach (bool l3 in binaryExpressionConditional(Name, x3)) | ||
2944 | { | ||
2945 | return true; | ||
2946 | } | ||
2947 | } | ||
2948 | if (YP.termEqual(Arity, 3)) | ||
2949 | { | ||
2950 | if (YP.termEqual(Name, Atom.a("findall"))) | ||
2951 | { | ||
2952 | return true; | ||
2953 | } | ||
2954 | if (YP.termEqual(Name, Atom.a("bagof"))) | ||
2955 | { | ||
2956 | return true; | ||
2957 | } | ||
2958 | if (YP.termEqual(Name, Atom.a("setof"))) | ||
2959 | { | ||
2960 | return true; | ||
2961 | } | ||
2962 | if (YP.termEqual(Name, Atom.a("catch"))) | ||
2963 | { | ||
2964 | return true; | ||
2965 | } | ||
2966 | } | ||
2967 | } | ||
2968 | return false; | ||
2969 | } | ||
2970 | |||
2971 | public static IEnumerable<bool> functorCallYPFunctionName(object arg1, object arg2, object arg3) | ||
2972 | { | ||
2973 | { | ||
2974 | foreach (bool l2 in YP.unify(arg1, Atom.a("="))) | ||
2975 | { | ||
2976 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
2977 | { | ||
2978 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.unify"))) | ||
2979 | { | ||
2980 | yield return true; | ||
2981 | yield break; | ||
2982 | } | ||
2983 | } | ||
2984 | } | ||
2985 | } | ||
2986 | { | ||
2987 | foreach (bool l2 in YP.unify(arg1, Atom.a("=.."))) | ||
2988 | { | ||
2989 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
2990 | { | ||
2991 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.univ"))) | ||
2992 | { | ||
2993 | yield return true; | ||
2994 | yield break; | ||
2995 | } | ||
2996 | } | ||
2997 | } | ||
2998 | } | ||
2999 | { | ||
3000 | foreach (bool l2 in YP.unify(arg1, Atom.a("var"))) | ||
3001 | { | ||
3002 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3003 | { | ||
3004 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.var"))) | ||
3005 | { | ||
3006 | yield return true; | ||
3007 | yield break; | ||
3008 | } | ||
3009 | } | ||
3010 | } | ||
3011 | } | ||
3012 | { | ||
3013 | foreach (bool l2 in YP.unify(arg1, Atom.a("nonvar"))) | ||
3014 | { | ||
3015 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3016 | { | ||
3017 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.nonvar"))) | ||
3018 | { | ||
3019 | yield return true; | ||
3020 | yield break; | ||
3021 | } | ||
3022 | } | ||
3023 | } | ||
3024 | } | ||
3025 | { | ||
3026 | foreach (bool l2 in YP.unify(arg1, Atom.a("arg"))) | ||
3027 | { | ||
3028 | foreach (bool l3 in YP.unify(arg2, 3)) | ||
3029 | { | ||
3030 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.arg"))) | ||
3031 | { | ||
3032 | yield return true; | ||
3033 | yield break; | ||
3034 | } | ||
3035 | } | ||
3036 | } | ||
3037 | } | ||
3038 | { | ||
3039 | foreach (bool l2 in YP.unify(arg1, Atom.a("functor"))) | ||
3040 | { | ||
3041 | foreach (bool l3 in YP.unify(arg2, 3)) | ||
3042 | { | ||
3043 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.functor"))) | ||
3044 | { | ||
3045 | yield return true; | ||
3046 | yield break; | ||
3047 | } | ||
3048 | } | ||
3049 | } | ||
3050 | } | ||
3051 | { | ||
3052 | foreach (bool l2 in YP.unify(arg1, Atom.a("repeat"))) | ||
3053 | { | ||
3054 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
3055 | { | ||
3056 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.repeat"))) | ||
3057 | { | ||
3058 | yield return true; | ||
3059 | yield break; | ||
3060 | } | ||
3061 | } | ||
3062 | } | ||
3063 | } | ||
3064 | { | ||
3065 | foreach (bool l2 in YP.unify(arg1, Atom.a("get_code"))) | ||
3066 | { | ||
3067 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3068 | { | ||
3069 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.get_code"))) | ||
3070 | { | ||
3071 | yield return true; | ||
3072 | yield break; | ||
3073 | } | ||
3074 | } | ||
3075 | } | ||
3076 | } | ||
3077 | { | ||
3078 | foreach (bool l2 in YP.unify(arg1, Atom.a("current_op"))) | ||
3079 | { | ||
3080 | foreach (bool l3 in YP.unify(arg2, 3)) | ||
3081 | { | ||
3082 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.current_op"))) | ||
3083 | { | ||
3084 | yield return true; | ||
3085 | yield break; | ||
3086 | } | ||
3087 | } | ||
3088 | } | ||
3089 | } | ||
3090 | { | ||
3091 | foreach (bool l2 in YP.unify(arg1, Atom.a("atom_length"))) | ||
3092 | { | ||
3093 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3094 | { | ||
3095 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.atom_length"))) | ||
3096 | { | ||
3097 | yield return true; | ||
3098 | yield break; | ||
3099 | } | ||
3100 | } | ||
3101 | } | ||
3102 | } | ||
3103 | { | ||
3104 | foreach (bool l2 in YP.unify(arg1, Atom.a("atom_concat"))) | ||
3105 | { | ||
3106 | foreach (bool l3 in YP.unify(arg2, 3)) | ||
3107 | { | ||
3108 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.atom_concat"))) | ||
3109 | { | ||
3110 | yield return true; | ||
3111 | yield break; | ||
3112 | } | ||
3113 | } | ||
3114 | } | ||
3115 | } | ||
3116 | { | ||
3117 | foreach (bool l2 in YP.unify(arg1, Atom.a("sub_atom"))) | ||
3118 | { | ||
3119 | foreach (bool l3 in YP.unify(arg2, 5)) | ||
3120 | { | ||
3121 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.sub_atom"))) | ||
3122 | { | ||
3123 | yield return true; | ||
3124 | yield break; | ||
3125 | } | ||
3126 | } | ||
3127 | } | ||
3128 | } | ||
3129 | { | ||
3130 | foreach (bool l2 in YP.unify(arg1, Atom.a("atom_chars"))) | ||
3131 | { | ||
3132 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3133 | { | ||
3134 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.atom_chars"))) | ||
3135 | { | ||
3136 | yield return true; | ||
3137 | yield break; | ||
3138 | } | ||
3139 | } | ||
3140 | } | ||
3141 | } | ||
3142 | { | ||
3143 | foreach (bool l2 in YP.unify(arg1, Atom.a("atom_codes"))) | ||
3144 | { | ||
3145 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3146 | { | ||
3147 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.atom_codes"))) | ||
3148 | { | ||
3149 | yield return true; | ||
3150 | yield break; | ||
3151 | } | ||
3152 | } | ||
3153 | } | ||
3154 | } | ||
3155 | { | ||
3156 | foreach (bool l2 in YP.unify(arg1, Atom.a("char_code"))) | ||
3157 | { | ||
3158 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3159 | { | ||
3160 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.char_code"))) | ||
3161 | { | ||
3162 | yield return true; | ||
3163 | yield break; | ||
3164 | } | ||
3165 | } | ||
3166 | } | ||
3167 | } | ||
3168 | { | ||
3169 | foreach (bool l2 in YP.unify(arg1, Atom.a("number_chars"))) | ||
3170 | { | ||
3171 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3172 | { | ||
3173 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.number_chars"))) | ||
3174 | { | ||
3175 | yield return true; | ||
3176 | yield break; | ||
3177 | } | ||
3178 | } | ||
3179 | } | ||
3180 | } | ||
3181 | { | ||
3182 | foreach (bool l2 in YP.unify(arg1, Atom.a("number_codes"))) | ||
3183 | { | ||
3184 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3185 | { | ||
3186 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.number_codes"))) | ||
3187 | { | ||
3188 | yield return true; | ||
3189 | yield break; | ||
3190 | } | ||
3191 | } | ||
3192 | } | ||
3193 | } | ||
3194 | { | ||
3195 | foreach (bool l2 in YP.unify(arg1, Atom.a("copy_term"))) | ||
3196 | { | ||
3197 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3198 | { | ||
3199 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.copy_term"))) | ||
3200 | { | ||
3201 | yield return true; | ||
3202 | yield break; | ||
3203 | } | ||
3204 | } | ||
3205 | } | ||
3206 | } | ||
3207 | { | ||
3208 | foreach (bool l2 in YP.unify(arg1, Atom.a("sort"))) | ||
3209 | { | ||
3210 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3211 | { | ||
3212 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.sort"))) | ||
3213 | { | ||
3214 | yield return true; | ||
3215 | yield break; | ||
3216 | } | ||
3217 | } | ||
3218 | } | ||
3219 | } | ||
3220 | { | ||
3221 | // Manually included : script_event for callback to LSL/C# | ||
3222 | |||
3223 | //object x1 = arg1; | ||
3224 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"script_event"))) | ||
3225 | { | ||
3226 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3227 | { | ||
3228 | foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.script_event"))) | ||
3229 | { | ||
3230 | yield return true; | ||
3231 | yield break; | ||
3232 | } | ||
3233 | } | ||
3234 | } | ||
3235 | } | ||
3236 | { | ||
3237 | foreach (bool l2 in YP.unify(arg1, Atom.a("nl"))) | ||
3238 | { | ||
3239 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
3240 | { | ||
3241 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.nl"))) | ||
3242 | { | ||
3243 | yield return true; | ||
3244 | yield break; | ||
3245 | } | ||
3246 | } | ||
3247 | } | ||
3248 | } | ||
3249 | { | ||
3250 | foreach (bool l2 in YP.unify(arg1, Atom.a("write"))) | ||
3251 | { | ||
3252 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3253 | { | ||
3254 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.write"))) | ||
3255 | { | ||
3256 | yield return true; | ||
3257 | yield break; | ||
3258 | } | ||
3259 | } | ||
3260 | } | ||
3261 | } | ||
3262 | { | ||
3263 | foreach (bool l2 in YP.unify(arg1, Atom.a("put_code"))) | ||
3264 | { | ||
3265 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3266 | { | ||
3267 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.put_code"))) | ||
3268 | { | ||
3269 | yield return true; | ||
3270 | yield break; | ||
3271 | } | ||
3272 | } | ||
3273 | } | ||
3274 | } | ||
3275 | { | ||
3276 | foreach (bool l2 in YP.unify(arg1, Atom.a("see"))) | ||
3277 | { | ||
3278 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3279 | { | ||
3280 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.see"))) | ||
3281 | { | ||
3282 | yield return true; | ||
3283 | yield break; | ||
3284 | } | ||
3285 | } | ||
3286 | } | ||
3287 | } | ||
3288 | { | ||
3289 | foreach (bool l2 in YP.unify(arg1, Atom.a("seen"))) | ||
3290 | { | ||
3291 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
3292 | { | ||
3293 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.seen"))) | ||
3294 | { | ||
3295 | yield return true; | ||
3296 | yield break; | ||
3297 | } | ||
3298 | } | ||
3299 | } | ||
3300 | } | ||
3301 | { | ||
3302 | foreach (bool l2 in YP.unify(arg1, Atom.a("tell"))) | ||
3303 | { | ||
3304 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3305 | { | ||
3306 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.tell"))) | ||
3307 | { | ||
3308 | yield return true; | ||
3309 | yield break; | ||
3310 | } | ||
3311 | } | ||
3312 | } | ||
3313 | } | ||
3314 | { | ||
3315 | foreach (bool l2 in YP.unify(arg1, Atom.a("told"))) | ||
3316 | { | ||
3317 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
3318 | { | ||
3319 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.told"))) | ||
3320 | { | ||
3321 | yield return true; | ||
3322 | yield break; | ||
3323 | } | ||
3324 | } | ||
3325 | } | ||
3326 | } | ||
3327 | { | ||
3328 | foreach (bool l2 in YP.unify(arg1, Atom.a("clause"))) | ||
3329 | { | ||
3330 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3331 | { | ||
3332 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.clause"))) | ||
3333 | { | ||
3334 | yield return true; | ||
3335 | yield break; | ||
3336 | } | ||
3337 | } | ||
3338 | } | ||
3339 | } | ||
3340 | { | ||
3341 | foreach (bool l2 in YP.unify(arg1, Atom.a("retract"))) | ||
3342 | { | ||
3343 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3344 | { | ||
3345 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.retract"))) | ||
3346 | { | ||
3347 | yield return true; | ||
3348 | yield break; | ||
3349 | } | ||
3350 | } | ||
3351 | } | ||
3352 | } | ||
3353 | { | ||
3354 | foreach (bool l2 in YP.unify(arg1, Atom.a("abolish"))) | ||
3355 | { | ||
3356 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3357 | { | ||
3358 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.abolish"))) | ||
3359 | { | ||
3360 | yield return true; | ||
3361 | yield break; | ||
3362 | } | ||
3363 | } | ||
3364 | } | ||
3365 | } | ||
3366 | { | ||
3367 | foreach (bool l2 in YP.unify(arg1, Atom.a("retractall"))) | ||
3368 | { | ||
3369 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3370 | { | ||
3371 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.retractall"))) | ||
3372 | { | ||
3373 | yield return true; | ||
3374 | yield break; | ||
3375 | } | ||
3376 | } | ||
3377 | } | ||
3378 | } | ||
3379 | { | ||
3380 | foreach (bool l2 in YP.unify(arg1, Atom.a("atom"))) | ||
3381 | { | ||
3382 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3383 | { | ||
3384 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.atom"))) | ||
3385 | { | ||
3386 | yield return true; | ||
3387 | yield break; | ||
3388 | } | ||
3389 | } | ||
3390 | } | ||
3391 | } | ||
3392 | { | ||
3393 | foreach (bool l2 in YP.unify(arg1, Atom.a("integer"))) | ||
3394 | { | ||
3395 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3396 | { | ||
3397 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.integer"))) | ||
3398 | { | ||
3399 | yield return true; | ||
3400 | yield break; | ||
3401 | } | ||
3402 | } | ||
3403 | } | ||
3404 | } | ||
3405 | { | ||
3406 | foreach (bool l2 in YP.unify(arg1, Atom.a("float"))) | ||
3407 | { | ||
3408 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3409 | { | ||
3410 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.isFloat"))) | ||
3411 | { | ||
3412 | yield return true; | ||
3413 | yield break; | ||
3414 | } | ||
3415 | } | ||
3416 | } | ||
3417 | } | ||
3418 | { | ||
3419 | foreach (bool l2 in YP.unify(arg1, Atom.a("number"))) | ||
3420 | { | ||
3421 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3422 | { | ||
3423 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.number"))) | ||
3424 | { | ||
3425 | yield return true; | ||
3426 | yield break; | ||
3427 | } | ||
3428 | } | ||
3429 | } | ||
3430 | } | ||
3431 | { | ||
3432 | foreach (bool l2 in YP.unify(arg1, Atom.a("atomic"))) | ||
3433 | { | ||
3434 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3435 | { | ||
3436 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.atomic"))) | ||
3437 | { | ||
3438 | yield return true; | ||
3439 | yield break; | ||
3440 | } | ||
3441 | } | ||
3442 | } | ||
3443 | } | ||
3444 | { | ||
3445 | foreach (bool l2 in YP.unify(arg1, Atom.a("compound"))) | ||
3446 | { | ||
3447 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3448 | { | ||
3449 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.compound"))) | ||
3450 | { | ||
3451 | yield return true; | ||
3452 | yield break; | ||
3453 | } | ||
3454 | } | ||
3455 | } | ||
3456 | } | ||
3457 | { | ||
3458 | foreach (bool l2 in YP.unify(arg1, Atom.a("=="))) | ||
3459 | { | ||
3460 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3461 | { | ||
3462 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.termEqual"))) | ||
3463 | { | ||
3464 | yield return true; | ||
3465 | yield break; | ||
3466 | } | ||
3467 | } | ||
3468 | } | ||
3469 | } | ||
3470 | { | ||
3471 | foreach (bool l2 in YP.unify(arg1, Atom.a("\\=="))) | ||
3472 | { | ||
3473 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3474 | { | ||
3475 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.termNotEqual"))) | ||
3476 | { | ||
3477 | yield return true; | ||
3478 | yield break; | ||
3479 | } | ||
3480 | } | ||
3481 | } | ||
3482 | } | ||
3483 | { | ||
3484 | foreach (bool l2 in YP.unify(arg1, Atom.a("@<"))) | ||
3485 | { | ||
3486 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3487 | { | ||
3488 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.termLessThan"))) | ||
3489 | { | ||
3490 | yield return true; | ||
3491 | yield break; | ||
3492 | } | ||
3493 | } | ||
3494 | } | ||
3495 | } | ||
3496 | { | ||
3497 | foreach (bool l2 in YP.unify(arg1, Atom.a("@=<"))) | ||
3498 | { | ||
3499 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3500 | { | ||
3501 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.termLessThanOrEqual"))) | ||
3502 | { | ||
3503 | yield return true; | ||
3504 | yield break; | ||
3505 | } | ||
3506 | } | ||
3507 | } | ||
3508 | } | ||
3509 | { | ||
3510 | foreach (bool l2 in YP.unify(arg1, Atom.a("@>"))) | ||
3511 | { | ||
3512 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3513 | { | ||
3514 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.termGreaterThan"))) | ||
3515 | { | ||
3516 | yield return true; | ||
3517 | yield break; | ||
3518 | } | ||
3519 | } | ||
3520 | } | ||
3521 | } | ||
3522 | { | ||
3523 | foreach (bool l2 in YP.unify(arg1, Atom.a("@>="))) | ||
3524 | { | ||
3525 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3526 | { | ||
3527 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.termGreaterThanOrEqual"))) | ||
3528 | { | ||
3529 | yield return true; | ||
3530 | yield break; | ||
3531 | } | ||
3532 | } | ||
3533 | } | ||
3534 | } | ||
3535 | { | ||
3536 | foreach (bool l2 in YP.unify(arg1, Atom.a("throw"))) | ||
3537 | { | ||
3538 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3539 | { | ||
3540 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.throwException"))) | ||
3541 | { | ||
3542 | yield return true; | ||
3543 | yield break; | ||
3544 | } | ||
3545 | } | ||
3546 | } | ||
3547 | } | ||
3548 | { | ||
3549 | foreach (bool l2 in YP.unify(arg1, Atom.a("current_prolog_flag"))) | ||
3550 | { | ||
3551 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3552 | { | ||
3553 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.current_prolog_flag"))) | ||
3554 | { | ||
3555 | yield return true; | ||
3556 | yield break; | ||
3557 | } | ||
3558 | } | ||
3559 | } | ||
3560 | } | ||
3561 | { | ||
3562 | foreach (bool l2 in YP.unify(arg1, Atom.a("set_prolog_flag"))) | ||
3563 | { | ||
3564 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3565 | { | ||
3566 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.set_prolog_flag"))) | ||
3567 | { | ||
3568 | yield return true; | ||
3569 | yield break; | ||
3570 | } | ||
3571 | } | ||
3572 | } | ||
3573 | } | ||
3574 | { | ||
3575 | foreach (bool l2 in YP.unify(arg1, Atom.a("current_input"))) | ||
3576 | { | ||
3577 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3578 | { | ||
3579 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.current_input"))) | ||
3580 | { | ||
3581 | yield return true; | ||
3582 | yield break; | ||
3583 | } | ||
3584 | } | ||
3585 | } | ||
3586 | } | ||
3587 | { | ||
3588 | foreach (bool l2 in YP.unify(arg1, Atom.a("current_output"))) | ||
3589 | { | ||
3590 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3591 | { | ||
3592 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.current_output"))) | ||
3593 | { | ||
3594 | yield return true; | ||
3595 | yield break; | ||
3596 | } | ||
3597 | } | ||
3598 | } | ||
3599 | } | ||
3600 | { | ||
3601 | foreach (bool l2 in YP.unify(arg1, Atom.a("read_term"))) | ||
3602 | { | ||
3603 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3604 | { | ||
3605 | foreach (bool l4 in YP.unify(arg3, Atom.a("Parser.read_term2"))) | ||
3606 | { | ||
3607 | yield return true; | ||
3608 | yield break; | ||
3609 | } | ||
3610 | } | ||
3611 | } | ||
3612 | } | ||
3613 | { | ||
3614 | foreach (bool l2 in YP.unify(arg1, Atom.a("read_term"))) | ||
3615 | { | ||
3616 | foreach (bool l3 in YP.unify(arg2, 3)) | ||
3617 | { | ||
3618 | foreach (bool l4 in YP.unify(arg3, Atom.a("Parser.read_term3"))) | ||
3619 | { | ||
3620 | yield return true; | ||
3621 | yield break; | ||
3622 | } | ||
3623 | } | ||
3624 | } | ||
3625 | } | ||
3626 | { | ||
3627 | foreach (bool l2 in YP.unify(arg1, Atom.a("read"))) | ||
3628 | { | ||
3629 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3630 | { | ||
3631 | foreach (bool l4 in YP.unify(arg3, Atom.a("Parser.read1"))) | ||
3632 | { | ||
3633 | yield return true; | ||
3634 | yield break; | ||
3635 | } | ||
3636 | } | ||
3637 | } | ||
3638 | } | ||
3639 | { | ||
3640 | foreach (bool l2 in YP.unify(arg1, Atom.a("read"))) | ||
3641 | { | ||
3642 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3643 | { | ||
3644 | foreach (bool l4 in YP.unify(arg3, Atom.a("Parser.read2"))) | ||
3645 | { | ||
3646 | yield return true; | ||
3647 | yield break; | ||
3648 | } | ||
3649 | } | ||
3650 | } | ||
3651 | } | ||
3652 | } | ||
3653 | |||
3654 | public static IEnumerable<bool> compileTerm(object arg1, object arg2, object arg3) | ||
3655 | { | ||
3656 | { | ||
3657 | object Term = arg1; | ||
3658 | object State = arg2; | ||
3659 | Variable VariableName = new Variable(); | ||
3660 | foreach (bool l2 in YP.unify(arg3, new Functor1("var", VariableName))) | ||
3661 | { | ||
3662 | if (YP.var(Term)) | ||
3663 | { | ||
3664 | foreach (bool l4 in CompilerState.getVariableName(State, Term, VariableName)) | ||
3665 | { | ||
3666 | yield return true; | ||
3667 | yield break; | ||
3668 | } | ||
3669 | } | ||
3670 | } | ||
3671 | } | ||
3672 | { | ||
3673 | object _State = arg2; | ||
3674 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
3675 | { | ||
3676 | foreach (bool l3 in YP.unify(arg3, new Functor1("var", Atom.a("Atom.NIL")))) | ||
3677 | { | ||
3678 | yield return true; | ||
3679 | yield break; | ||
3680 | } | ||
3681 | } | ||
3682 | } | ||
3683 | { | ||
3684 | object Term = arg1; | ||
3685 | object State = arg2; | ||
3686 | object Code = arg3; | ||
3687 | Variable ModuleCode = new Variable(); | ||
3688 | if (YP.atom(Term)) | ||
3689 | { | ||
3690 | foreach (bool l3 in compileAtomModule(Term, 0, State, ModuleCode)) | ||
3691 | { | ||
3692 | foreach (bool l4 in YP.unify(Code, new Functor2("call", Atom.a("Atom.a"), new ListPair(new Functor1("object", Term), new ListPair(ModuleCode, Atom.NIL))))) | ||
3693 | { | ||
3694 | yield return true; | ||
3695 | yield break; | ||
3696 | } | ||
3697 | goto cutIf1; | ||
3698 | } | ||
3699 | foreach (bool l3 in YP.unify(Code, new Functor2("call", Atom.a("Atom.a"), new ListPair(new Functor1("object", Term), Atom.NIL)))) | ||
3700 | { | ||
3701 | yield return true; | ||
3702 | yield break; | ||
3703 | } | ||
3704 | cutIf1: | ||
3705 | { } | ||
3706 | } | ||
3707 | } | ||
3708 | { | ||
3709 | object State = arg2; | ||
3710 | Variable First = new Variable(); | ||
3711 | Variable Rest = new Variable(); | ||
3712 | Variable CompiledList = new Variable(); | ||
3713 | Variable x5 = new Variable(); | ||
3714 | Variable Rest2 = new Variable(); | ||
3715 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) | ||
3716 | { | ||
3717 | foreach (bool l3 in YP.unify(arg3, new Functor2("call", Atom.a("ListPair.make"), new ListPair(new Functor1("objectArray", CompiledList), Atom.NIL)))) | ||
3718 | { | ||
3719 | if (YP.nonvar(Rest)) | ||
3720 | { | ||
3721 | foreach (bool l5 in YP.unify(Rest, new ListPair(x5, Rest2))) | ||
3722 | { | ||
3723 | if (YP.termNotEqual(Rest2, Atom.NIL)) | ||
3724 | { | ||
3725 | foreach (bool l7 in maplist_compileTerm(new ListPair(First, Rest), State, CompiledList)) | ||
3726 | { | ||
3727 | yield return true; | ||
3728 | yield break; | ||
3729 | } | ||
3730 | } | ||
3731 | } | ||
3732 | } | ||
3733 | } | ||
3734 | } | ||
3735 | } | ||
3736 | { | ||
3737 | object State = arg2; | ||
3738 | Variable First = new Variable(); | ||
3739 | Variable Rest = new Variable(); | ||
3740 | Variable Arg1 = new Variable(); | ||
3741 | Variable Arg2 = new Variable(); | ||
3742 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) | ||
3743 | { | ||
3744 | foreach (bool l3 in YP.unify(arg3, new Functor2("new", Atom.a("ListPair"), new ListPair(Arg1, new ListPair(Arg2, Atom.NIL))))) | ||
3745 | { | ||
3746 | foreach (bool l4 in compileTerm(First, State, Arg1)) | ||
3747 | { | ||
3748 | foreach (bool l5 in compileTerm(Rest, State, Arg2)) | ||
3749 | { | ||
3750 | yield return true; | ||
3751 | yield break; | ||
3752 | } | ||
3753 | } | ||
3754 | } | ||
3755 | } | ||
3756 | } | ||
3757 | { | ||
3758 | object Term = arg1; | ||
3759 | object State = arg2; | ||
3760 | object Result = arg3; | ||
3761 | Variable Name = new Variable(); | ||
3762 | Variable TermArgs = new Variable(); | ||
3763 | Variable x6 = new Variable(); | ||
3764 | Variable Arity = new Variable(); | ||
3765 | Variable ModuleCode = new Variable(); | ||
3766 | Variable NameCode = new Variable(); | ||
3767 | Variable X1 = new Variable(); | ||
3768 | Variable Arg1 = new Variable(); | ||
3769 | Variable X2 = new Variable(); | ||
3770 | Variable Arg2 = new Variable(); | ||
3771 | Variable X3 = new Variable(); | ||
3772 | Variable Arg3 = new Variable(); | ||
3773 | Variable Args = new Variable(); | ||
3774 | foreach (bool l2 in YP.univ(Term, new ListPair(Name, TermArgs))) | ||
3775 | { | ||
3776 | if (YP.termEqual(TermArgs, Atom.NIL)) | ||
3777 | { | ||
3778 | foreach (bool l4 in YP.unify(Result, new Functor1("object", Name))) | ||
3779 | { | ||
3780 | yield return true; | ||
3781 | yield break; | ||
3782 | } | ||
3783 | goto cutIf2; | ||
3784 | } | ||
3785 | foreach (bool l3 in YP.functor(Term, x6, Arity)) | ||
3786 | { | ||
3787 | foreach (bool l4 in compileAtomModule(Name, Arity, State, ModuleCode)) | ||
3788 | { | ||
3789 | foreach (bool l5 in YP.unify(NameCode, new Functor2("call", Atom.a("Atom.a"), new ListPair(new Functor1("object", Name), new ListPair(ModuleCode, Atom.NIL))))) | ||
3790 | { | ||
3791 | foreach (bool l6 in YP.unify(TermArgs, new ListPair(X1, Atom.NIL))) | ||
3792 | { | ||
3793 | foreach (bool l7 in compileTerm(X1, State, Arg1)) | ||
3794 | { | ||
3795 | foreach (bool l8 in YP.unify(Result, new Functor2("new", Atom.a("Functor1"), new ListPair(NameCode, new ListPair(Arg1, Atom.NIL))))) | ||
3796 | { | ||
3797 | yield return true; | ||
3798 | yield break; | ||
3799 | } | ||
3800 | } | ||
3801 | goto cutIf4; | ||
3802 | } | ||
3803 | foreach (bool l6 in YP.unify(TermArgs, new ListPair(X1, new ListPair(X2, Atom.NIL)))) | ||
3804 | { | ||
3805 | foreach (bool l7 in compileTerm(X1, State, Arg1)) | ||
3806 | { | ||
3807 | foreach (bool l8 in compileTerm(X2, State, Arg2)) | ||
3808 | { | ||
3809 | foreach (bool l9 in YP.unify(Result, new Functor2("new", Atom.a("Functor2"), ListPair.make(new object[] { NameCode, Arg1, Arg2 })))) | ||
3810 | { | ||
3811 | yield return true; | ||
3812 | yield break; | ||
3813 | } | ||
3814 | } | ||
3815 | } | ||
3816 | goto cutIf5; | ||
3817 | } | ||
3818 | foreach (bool l6 in YP.unify(TermArgs, ListPair.make(new object[] { X1, X2, X3 }))) | ||
3819 | { | ||
3820 | foreach (bool l7 in compileTerm(X1, State, Arg1)) | ||
3821 | { | ||
3822 | foreach (bool l8 in compileTerm(X2, State, Arg2)) | ||
3823 | { | ||
3824 | foreach (bool l9 in compileTerm(X3, State, Arg3)) | ||
3825 | { | ||
3826 | foreach (bool l10 in YP.unify(Result, new Functor2("new", Atom.a("Functor3"), ListPair.make(new object[] { NameCode, Arg1, Arg2, Arg3 })))) | ||
3827 | { | ||
3828 | yield return true; | ||
3829 | yield break; | ||
3830 | } | ||
3831 | } | ||
3832 | } | ||
3833 | } | ||
3834 | } | ||
3835 | foreach (bool l6 in maplist_compileTerm(TermArgs, State, Args)) | ||
3836 | { | ||
3837 | foreach (bool l7 in YP.unify(Result, new Functor2("new", Atom.a("Functor"), new ListPair(NameCode, new ListPair(new Functor1("objectArray", Args), Atom.NIL))))) | ||
3838 | { | ||
3839 | yield return true; | ||
3840 | yield break; | ||
3841 | } | ||
3842 | } | ||
3843 | cutIf5: | ||
3844 | cutIf4: | ||
3845 | { } | ||
3846 | } | ||
3847 | goto cutIf3; | ||
3848 | } | ||
3849 | foreach (bool l4 in YP.unify(NameCode, new Functor1("object", Name))) | ||
3850 | { | ||
3851 | foreach (bool l5 in YP.unify(TermArgs, new ListPair(X1, Atom.NIL))) | ||
3852 | { | ||
3853 | foreach (bool l6 in compileTerm(X1, State, Arg1)) | ||
3854 | { | ||
3855 | foreach (bool l7 in YP.unify(Result, new Functor2("new", Atom.a("Functor1"), new ListPair(NameCode, new ListPair(Arg1, Atom.NIL))))) | ||
3856 | { | ||
3857 | yield return true; | ||
3858 | yield break; | ||
3859 | } | ||
3860 | } | ||
3861 | goto cutIf6; | ||
3862 | } | ||
3863 | foreach (bool l5 in YP.unify(TermArgs, new ListPair(X1, new ListPair(X2, Atom.NIL)))) | ||
3864 | { | ||
3865 | foreach (bool l6 in compileTerm(X1, State, Arg1)) | ||
3866 | { | ||
3867 | foreach (bool l7 in compileTerm(X2, State, Arg2)) | ||
3868 | { | ||
3869 | foreach (bool l8 in YP.unify(Result, new Functor2("new", Atom.a("Functor2"), ListPair.make(new object[] { NameCode, Arg1, Arg2 })))) | ||
3870 | { | ||
3871 | yield return true; | ||
3872 | yield break; | ||
3873 | } | ||
3874 | } | ||
3875 | } | ||
3876 | goto cutIf7; | ||
3877 | } | ||
3878 | foreach (bool l5 in YP.unify(TermArgs, ListPair.make(new object[] { X1, X2, X3 }))) | ||
3879 | { | ||
3880 | foreach (bool l6 in compileTerm(X1, State, Arg1)) | ||
3881 | { | ||
3882 | foreach (bool l7 in compileTerm(X2, State, Arg2)) | ||
3883 | { | ||
3884 | foreach (bool l8 in compileTerm(X3, State, Arg3)) | ||
3885 | { | ||
3886 | foreach (bool l9 in YP.unify(Result, new Functor2("new", Atom.a("Functor3"), ListPair.make(new object[] { NameCode, Arg1, Arg2, Arg3 })))) | ||
3887 | { | ||
3888 | yield return true; | ||
3889 | yield break; | ||
3890 | } | ||
3891 | } | ||
3892 | } | ||
3893 | } | ||
3894 | } | ||
3895 | foreach (bool l5 in maplist_compileTerm(TermArgs, State, Args)) | ||
3896 | { | ||
3897 | foreach (bool l6 in YP.unify(Result, new Functor2("new", Atom.a("Functor"), new ListPair(NameCode, new ListPair(new Functor1("objectArray", Args), Atom.NIL))))) | ||
3898 | { | ||
3899 | yield return true; | ||
3900 | yield break; | ||
3901 | } | ||
3902 | } | ||
3903 | cutIf7: | ||
3904 | cutIf6: | ||
3905 | { } | ||
3906 | } | ||
3907 | cutIf3: | ||
3908 | { } | ||
3909 | } | ||
3910 | cutIf2: | ||
3911 | { } | ||
3912 | } | ||
3913 | } | ||
3914 | } | ||
3915 | |||
3916 | public static IEnumerable<bool> compileAtomModule(object Name, object arg2, object arg3, object ModuleCode) | ||
3917 | { | ||
3918 | { | ||
3919 | object Arity = arg2; | ||
3920 | object State = arg3; | ||
3921 | if (CompilerState.nameArityHasModule(State, Name, Arity, Atom.a(""))) | ||
3922 | { | ||
3923 | foreach (bool l3 in YP.unify(ModuleCode, new Functor2("call", Atom.a("Atom.a"), new ListPair(new Functor1("object", Atom.a("")), Atom.NIL)))) | ||
3924 | { | ||
3925 | yield return true; | ||
3926 | yield break; | ||
3927 | } | ||
3928 | } | ||
3929 | } | ||
3930 | { | ||
3931 | object _Arity = arg2; | ||
3932 | object _State = arg3; | ||
3933 | Variable Module = new Variable(); | ||
3934 | foreach (bool l2 in Atom.module(Name, Module)) | ||
3935 | { | ||
3936 | if (YP.termNotEqual(Module, Atom.NIL)) | ||
3937 | { | ||
3938 | foreach (bool l4 in YP.unify(ModuleCode, new Functor2("call", Atom.a("Atom.a"), new ListPair(new Functor1("object", Module), Atom.NIL)))) | ||
3939 | { | ||
3940 | yield return true; | ||
3941 | yield break; | ||
3942 | } | ||
3943 | } | ||
3944 | } | ||
3945 | } | ||
3946 | } | ||
3947 | |||
3948 | public static IEnumerable<bool> maplist_compileTerm(object arg1, object arg2, object arg3) | ||
3949 | { | ||
3950 | { | ||
3951 | object _State = arg2; | ||
3952 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
3953 | { | ||
3954 | foreach (bool l3 in YP.unify(arg3, Atom.NIL)) | ||
3955 | { | ||
3956 | yield return true; | ||
3957 | yield break; | ||
3958 | } | ||
3959 | } | ||
3960 | } | ||
3961 | { | ||
3962 | object State = arg2; | ||
3963 | Variable First = new Variable(); | ||
3964 | Variable Rest = new Variable(); | ||
3965 | Variable FirstResult = new Variable(); | ||
3966 | Variable RestResults = new Variable(); | ||
3967 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) | ||
3968 | { | ||
3969 | foreach (bool l3 in YP.unify(arg3, new ListPair(FirstResult, RestResults))) | ||
3970 | { | ||
3971 | if (YP.nonvar(Rest)) | ||
3972 | { | ||
3973 | foreach (bool l5 in compileTerm(First, State, FirstResult)) | ||
3974 | { | ||
3975 | foreach (bool l6 in maplist_compileTerm(Rest, State, RestResults)) | ||
3976 | { | ||
3977 | yield return true; | ||
3978 | yield break; | ||
3979 | } | ||
3980 | } | ||
3981 | } | ||
3982 | } | ||
3983 | } | ||
3984 | } | ||
3985 | } | ||
3986 | |||
3987 | public static IEnumerable<bool> compileExpression(object Term, object State, object Result) | ||
3988 | { | ||
3989 | { | ||
3990 | Variable Name = new Variable(); | ||
3991 | Variable TermArgs = new Variable(); | ||
3992 | Variable X1 = new Variable(); | ||
3993 | Variable FunctionName = new Variable(); | ||
3994 | Variable Arg1 = new Variable(); | ||
3995 | Variable x9 = new Variable(); | ||
3996 | Variable X2 = new Variable(); | ||
3997 | Variable Arg2 = new Variable(); | ||
3998 | Variable x12 = new Variable(); | ||
3999 | Variable Arity = new Variable(); | ||
4000 | if (YP.nonvar(Term)) | ||
4001 | { | ||
4002 | foreach (bool l3 in YP.univ(Term, new ListPair(Name, TermArgs))) | ||
4003 | { | ||
4004 | if (YP.atom(Name)) | ||
4005 | { | ||
4006 | foreach (bool l5 in YP.unify(TermArgs, new ListPair(X1, Atom.NIL))) | ||
4007 | { | ||
4008 | foreach (bool l6 in unaryFunction(Name, FunctionName)) | ||
4009 | { | ||
4010 | foreach (bool l7 in compileExpression(X1, State, Arg1)) | ||
4011 | { | ||
4012 | foreach (bool l8 in YP.unify(Result, new Functor2("call", FunctionName, new ListPair(Arg1, Atom.NIL)))) | ||
4013 | { | ||
4014 | yield return true; | ||
4015 | yield break; | ||
4016 | } | ||
4017 | } | ||
4018 | goto cutIf1; | ||
4019 | } | ||
4020 | } | ||
4021 | foreach (bool l5 in YP.unify(Term, new ListPair(x9, Atom.NIL))) | ||
4022 | { | ||
4023 | foreach (bool l6 in compileTerm(Term, State, Result)) | ||
4024 | { | ||
4025 | yield return true; | ||
4026 | yield break; | ||
4027 | } | ||
4028 | goto cutIf2; | ||
4029 | } | ||
4030 | foreach (bool l5 in YP.unify(TermArgs, new ListPair(X1, new ListPair(X2, Atom.NIL)))) | ||
4031 | { | ||
4032 | foreach (bool l6 in binaryFunction(Name, FunctionName)) | ||
4033 | { | ||
4034 | foreach (bool l7 in compileExpression(X1, State, Arg1)) | ||
4035 | { | ||
4036 | foreach (bool l8 in compileExpression(X2, State, Arg2)) | ||
4037 | { | ||
4038 | foreach (bool l9 in YP.unify(Result, new Functor2("call", FunctionName, new ListPair(Arg1, new ListPair(Arg2, Atom.NIL))))) | ||
4039 | { | ||
4040 | yield return true; | ||
4041 | yield break; | ||
4042 | } | ||
4043 | } | ||
4044 | } | ||
4045 | goto cutIf3; | ||
4046 | } | ||
4047 | } | ||
4048 | foreach (bool l5 in YP.functor(Term, x12, Arity)) | ||
4049 | { | ||
4050 | YP.throwException(new Functor2("error", new Functor2("type_error", Atom.a("evaluable"), new Functor2("/", Name, Arity)), Atom.a("Not an expression function"))); | ||
4051 | yield return false; | ||
4052 | } | ||
4053 | cutIf3: | ||
4054 | cutIf2: | ||
4055 | cutIf1: | ||
4056 | { } | ||
4057 | } | ||
4058 | } | ||
4059 | } | ||
4060 | } | ||
4061 | { | ||
4062 | foreach (bool l2 in compileTerm(Term, State, Result)) | ||
4063 | { | ||
4064 | yield return true; | ||
4065 | yield break; | ||
4066 | } | ||
4067 | } | ||
4068 | } | ||
4069 | |||
4070 | public static IEnumerable<bool> unaryFunction(object arg1, object arg2) | ||
4071 | { | ||
4072 | { | ||
4073 | foreach (bool l2 in YP.unify(arg1, Atom.a("-"))) | ||
4074 | { | ||
4075 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.negate"))) | ||
4076 | { | ||
4077 | yield return true; | ||
4078 | yield break; | ||
4079 | } | ||
4080 | } | ||
4081 | } | ||
4082 | { | ||
4083 | foreach (bool l2 in YP.unify(arg1, Atom.a("abs"))) | ||
4084 | { | ||
4085 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.abs"))) | ||
4086 | { | ||
4087 | yield return true; | ||
4088 | yield break; | ||
4089 | } | ||
4090 | } | ||
4091 | } | ||
4092 | { | ||
4093 | foreach (bool l2 in YP.unify(arg1, Atom.a("sign"))) | ||
4094 | { | ||
4095 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.sign"))) | ||
4096 | { | ||
4097 | yield return true; | ||
4098 | yield break; | ||
4099 | } | ||
4100 | } | ||
4101 | } | ||
4102 | { | ||
4103 | foreach (bool l2 in YP.unify(arg1, Atom.a("float"))) | ||
4104 | { | ||
4105 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.toFloat"))) | ||
4106 | { | ||
4107 | yield return true; | ||
4108 | yield break; | ||
4109 | } | ||
4110 | } | ||
4111 | } | ||
4112 | { | ||
4113 | foreach (bool l2 in YP.unify(arg1, Atom.a("floor"))) | ||
4114 | { | ||
4115 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.floor"))) | ||
4116 | { | ||
4117 | yield return true; | ||
4118 | yield break; | ||
4119 | } | ||
4120 | } | ||
4121 | } | ||
4122 | { | ||
4123 | foreach (bool l2 in YP.unify(arg1, Atom.a("truncate"))) | ||
4124 | { | ||
4125 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.truncate"))) | ||
4126 | { | ||
4127 | yield return true; | ||
4128 | yield break; | ||
4129 | } | ||
4130 | } | ||
4131 | } | ||
4132 | { | ||
4133 | foreach (bool l2 in YP.unify(arg1, Atom.a("round"))) | ||
4134 | { | ||
4135 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.round"))) | ||
4136 | { | ||
4137 | yield return true; | ||
4138 | yield break; | ||
4139 | } | ||
4140 | } | ||
4141 | } | ||
4142 | { | ||
4143 | foreach (bool l2 in YP.unify(arg1, Atom.a("ceiling"))) | ||
4144 | { | ||
4145 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.ceiling"))) | ||
4146 | { | ||
4147 | yield return true; | ||
4148 | yield break; | ||
4149 | } | ||
4150 | } | ||
4151 | } | ||
4152 | { | ||
4153 | foreach (bool l2 in YP.unify(arg1, Atom.a("sin"))) | ||
4154 | { | ||
4155 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.sin"))) | ||
4156 | { | ||
4157 | yield return true; | ||
4158 | yield break; | ||
4159 | } | ||
4160 | } | ||
4161 | } | ||
4162 | { | ||
4163 | foreach (bool l2 in YP.unify(arg1, Atom.a("cos"))) | ||
4164 | { | ||
4165 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.cos"))) | ||
4166 | { | ||
4167 | yield return true; | ||
4168 | yield break; | ||
4169 | } | ||
4170 | } | ||
4171 | } | ||
4172 | { | ||
4173 | foreach (bool l2 in YP.unify(arg1, Atom.a("atan"))) | ||
4174 | { | ||
4175 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.atan"))) | ||
4176 | { | ||
4177 | yield return true; | ||
4178 | yield break; | ||
4179 | } | ||
4180 | } | ||
4181 | } | ||
4182 | { | ||
4183 | foreach (bool l2 in YP.unify(arg1, Atom.a("exp"))) | ||
4184 | { | ||
4185 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.exp"))) | ||
4186 | { | ||
4187 | yield return true; | ||
4188 | yield break; | ||
4189 | } | ||
4190 | } | ||
4191 | } | ||
4192 | { | ||
4193 | foreach (bool l2 in YP.unify(arg1, Atom.a("log"))) | ||
4194 | { | ||
4195 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.log"))) | ||
4196 | { | ||
4197 | yield return true; | ||
4198 | yield break; | ||
4199 | } | ||
4200 | } | ||
4201 | } | ||
4202 | { | ||
4203 | foreach (bool l2 in YP.unify(arg1, Atom.a("sqrt"))) | ||
4204 | { | ||
4205 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.sqrt"))) | ||
4206 | { | ||
4207 | yield return true; | ||
4208 | yield break; | ||
4209 | } | ||
4210 | } | ||
4211 | } | ||
4212 | { | ||
4213 | foreach (bool l2 in YP.unify(arg1, Atom.a("\\"))) | ||
4214 | { | ||
4215 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.bitwiseComplement"))) | ||
4216 | { | ||
4217 | yield return true; | ||
4218 | yield break; | ||
4219 | } | ||
4220 | } | ||
4221 | } | ||
4222 | } | ||
4223 | |||
4224 | public static IEnumerable<bool> binaryFunction(object arg1, object arg2) | ||
4225 | { | ||
4226 | { | ||
4227 | foreach (bool l2 in YP.unify(arg1, Atom.a("+"))) | ||
4228 | { | ||
4229 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.add"))) | ||
4230 | { | ||
4231 | yield return true; | ||
4232 | yield break; | ||
4233 | } | ||
4234 | } | ||
4235 | } | ||
4236 | { | ||
4237 | foreach (bool l2 in YP.unify(arg1, Atom.a("-"))) | ||
4238 | { | ||
4239 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.subtract"))) | ||
4240 | { | ||
4241 | yield return true; | ||
4242 | yield break; | ||
4243 | } | ||
4244 | } | ||
4245 | } | ||
4246 | { | ||
4247 | foreach (bool l2 in YP.unify(arg1, Atom.a("*"))) | ||
4248 | { | ||
4249 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.multiply"))) | ||
4250 | { | ||
4251 | yield return true; | ||
4252 | yield break; | ||
4253 | } | ||
4254 | } | ||
4255 | } | ||
4256 | { | ||
4257 | foreach (bool l2 in YP.unify(arg1, Atom.a("/"))) | ||
4258 | { | ||
4259 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.divide"))) | ||
4260 | { | ||
4261 | yield return true; | ||
4262 | yield break; | ||
4263 | } | ||
4264 | } | ||
4265 | } | ||
4266 | { | ||
4267 | foreach (bool l2 in YP.unify(arg1, Atom.a("//"))) | ||
4268 | { | ||
4269 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.intDivide"))) | ||
4270 | { | ||
4271 | yield return true; | ||
4272 | yield break; | ||
4273 | } | ||
4274 | } | ||
4275 | } | ||
4276 | { | ||
4277 | foreach (bool l2 in YP.unify(arg1, Atom.a("mod"))) | ||
4278 | { | ||
4279 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.mod"))) | ||
4280 | { | ||
4281 | yield return true; | ||
4282 | yield break; | ||
4283 | } | ||
4284 | } | ||
4285 | } | ||
4286 | { | ||
4287 | foreach (bool l2 in YP.unify(arg1, Atom.a("**"))) | ||
4288 | { | ||
4289 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.pow"))) | ||
4290 | { | ||
4291 | yield return true; | ||
4292 | yield break; | ||
4293 | } | ||
4294 | } | ||
4295 | } | ||
4296 | { | ||
4297 | foreach (bool l2 in YP.unify(arg1, Atom.a(">>"))) | ||
4298 | { | ||
4299 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.bitwiseShiftRight"))) | ||
4300 | { | ||
4301 | yield return true; | ||
4302 | yield break; | ||
4303 | } | ||
4304 | } | ||
4305 | } | ||
4306 | { | ||
4307 | foreach (bool l2 in YP.unify(arg1, Atom.a("<<"))) | ||
4308 | { | ||
4309 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.bitwiseShiftLeft"))) | ||
4310 | { | ||
4311 | yield return true; | ||
4312 | yield break; | ||
4313 | } | ||
4314 | } | ||
4315 | } | ||
4316 | { | ||
4317 | foreach (bool l2 in YP.unify(arg1, Atom.a("/\\"))) | ||
4318 | { | ||
4319 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.bitwiseAnd"))) | ||
4320 | { | ||
4321 | yield return true; | ||
4322 | yield break; | ||
4323 | } | ||
4324 | } | ||
4325 | } | ||
4326 | { | ||
4327 | foreach (bool l2 in YP.unify(arg1, Atom.a("\\/"))) | ||
4328 | { | ||
4329 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.bitwiseOr"))) | ||
4330 | { | ||
4331 | yield return true; | ||
4332 | yield break; | ||
4333 | } | ||
4334 | } | ||
4335 | } | ||
4336 | { | ||
4337 | foreach (bool l2 in YP.unify(arg1, Atom.a("min"))) | ||
4338 | { | ||
4339 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.min"))) | ||
4340 | { | ||
4341 | yield return true; | ||
4342 | yield break; | ||
4343 | } | ||
4344 | } | ||
4345 | } | ||
4346 | { | ||
4347 | foreach (bool l2 in YP.unify(arg1, Atom.a("max"))) | ||
4348 | { | ||
4349 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.max"))) | ||
4350 | { | ||
4351 | yield return true; | ||
4352 | yield break; | ||
4353 | } | ||
4354 | } | ||
4355 | } | ||
4356 | } | ||
4357 | |||
4358 | public static void convertFunctionCSharp(object arg1) | ||
4359 | { | ||
4360 | { | ||
4361 | foreach (bool l2 in YP.unify(arg1, Atom.a("getDeclaringClass"))) | ||
4362 | { | ||
4363 | YP.write(Atom.a("public class YPInnerClass {}")); | ||
4364 | YP.nl(); | ||
4365 | YP.write(Atom.a("public static System.Type getDeclaringClass() { return typeof(YPInnerClass).DeclaringType; }")); | ||
4366 | YP.nl(); | ||
4367 | YP.nl(); | ||
4368 | return; | ||
4369 | } | ||
4370 | } | ||
4371 | { | ||
4372 | Variable ReturnType = new Variable(); | ||
4373 | Variable Name = new Variable(); | ||
4374 | Variable ArgList = new Variable(); | ||
4375 | Variable Body = new Variable(); | ||
4376 | Variable Level = new Variable(); | ||
4377 | foreach (bool l2 in YP.unify(arg1, new Functor("function", new object[] { ReturnType, Name, ArgList, Body }))) | ||
4378 | { | ||
4379 | YP.write(Atom.a("public static ")); | ||
4380 | YP.write(ReturnType); | ||
4381 | YP.write(Atom.a(" ")); | ||
4382 | YP.write(Name); | ||
4383 | YP.write(Atom.a("(")); | ||
4384 | convertArgListCSharp(ArgList); | ||
4385 | YP.write(Atom.a(") {")); | ||
4386 | YP.nl(); | ||
4387 | foreach (bool l3 in YP.unify(Level, 1)) | ||
4388 | { | ||
4389 | convertStatementListCSharp(Body, Level); | ||
4390 | YP.write(Atom.a("}")); | ||
4391 | YP.nl(); | ||
4392 | YP.nl(); | ||
4393 | return; | ||
4394 | } | ||
4395 | } | ||
4396 | } | ||
4397 | } | ||
4398 | |||
4399 | public static IEnumerable<bool> convertStatementListCSharp(object arg1, object x1, object x2) | ||
4400 | { | ||
4401 | { | ||
4402 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
4403 | { | ||
4404 | yield return true; | ||
4405 | yield break; | ||
4406 | } | ||
4407 | } | ||
4408 | } | ||
4409 | |||
4410 | public static void convertStatementListCSharp(object arg1, object Level) | ||
4411 | { | ||
4412 | { | ||
4413 | Variable Name = new Variable(); | ||
4414 | Variable Body = new Variable(); | ||
4415 | Variable RestStatements = new Variable(); | ||
4416 | Variable NewStatements = new Variable(); | ||
4417 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("breakableBlock", Name, Body), RestStatements))) | ||
4418 | { | ||
4419 | foreach (bool l3 in append(Body, new ListPair(new Functor1("label", Name), RestStatements), NewStatements)) | ||
4420 | { | ||
4421 | convertStatementListCSharp(NewStatements, Level); | ||
4422 | return; | ||
4423 | } | ||
4424 | } | ||
4425 | } | ||
4426 | { | ||
4427 | Variable Type = new Variable(); | ||
4428 | Variable Name = new Variable(); | ||
4429 | Variable Expression = new Variable(); | ||
4430 | Variable RestStatements = new Variable(); | ||
4431 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("declare", Type, Name, Expression), RestStatements))) | ||
4432 | { | ||
4433 | convertIndentationCSharp(Level); | ||
4434 | YP.write(Type); | ||
4435 | YP.write(Atom.a(" ")); | ||
4436 | YP.write(Name); | ||
4437 | YP.write(Atom.a(" = ")); | ||
4438 | convertExpressionCSharp(Expression); | ||
4439 | YP.write(Atom.a(";")); | ||
4440 | YP.nl(); | ||
4441 | convertStatementListCSharp(RestStatements, Level); | ||
4442 | return; | ||
4443 | } | ||
4444 | } | ||
4445 | { | ||
4446 | Variable Name = new Variable(); | ||
4447 | Variable Expression = new Variable(); | ||
4448 | Variable RestStatements = new Variable(); | ||
4449 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("assign", Name, Expression), RestStatements))) | ||
4450 | { | ||
4451 | convertIndentationCSharp(Level); | ||
4452 | YP.write(Name); | ||
4453 | YP.write(Atom.a(" = ")); | ||
4454 | convertExpressionCSharp(Expression); | ||
4455 | YP.write(Atom.a(";")); | ||
4456 | YP.nl(); | ||
4457 | convertStatementListCSharp(RestStatements, Level); | ||
4458 | return; | ||
4459 | } | ||
4460 | } | ||
4461 | { | ||
4462 | Variable RestStatements = new Variable(); | ||
4463 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldtrue"), RestStatements))) | ||
4464 | { | ||
4465 | convertIndentationCSharp(Level); | ||
4466 | YP.write(Atom.a("yield return true;")); | ||
4467 | YP.nl(); | ||
4468 | convertStatementListCSharp(RestStatements, Level); | ||
4469 | return; | ||
4470 | } | ||
4471 | } | ||
4472 | { | ||
4473 | Variable RestStatements = new Variable(); | ||
4474 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldfalse"), RestStatements))) | ||
4475 | { | ||
4476 | convertIndentationCSharp(Level); | ||
4477 | YP.write(Atom.a("yield return false;")); | ||
4478 | YP.nl(); | ||
4479 | convertStatementListCSharp(RestStatements, Level); | ||
4480 | return; | ||
4481 | } | ||
4482 | } | ||
4483 | { | ||
4484 | Variable RestStatements = new Variable(); | ||
4485 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldbreak"), RestStatements))) | ||
4486 | { | ||
4487 | convertIndentationCSharp(Level); | ||
4488 | YP.write(Atom.a("yield break;")); | ||
4489 | YP.nl(); | ||
4490 | convertStatementListCSharp(RestStatements, Level); | ||
4491 | return; | ||
4492 | } | ||
4493 | } | ||
4494 | { | ||
4495 | Variable RestStatements = new Variable(); | ||
4496 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("return"), RestStatements))) | ||
4497 | { | ||
4498 | convertIndentationCSharp(Level); | ||
4499 | YP.write(Atom.a("return;")); | ||
4500 | YP.nl(); | ||
4501 | convertStatementListCSharp(RestStatements, Level); | ||
4502 | return; | ||
4503 | } | ||
4504 | } | ||
4505 | { | ||
4506 | Variable RestStatements = new Variable(); | ||
4507 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("returntrue"), RestStatements))) | ||
4508 | { | ||
4509 | convertIndentationCSharp(Level); | ||
4510 | YP.write(Atom.a("return true;")); | ||
4511 | YP.nl(); | ||
4512 | convertStatementListCSharp(RestStatements, Level); | ||
4513 | return; | ||
4514 | } | ||
4515 | } | ||
4516 | { | ||
4517 | Variable RestStatements = new Variable(); | ||
4518 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("returnfalse"), RestStatements))) | ||
4519 | { | ||
4520 | convertIndentationCSharp(Level); | ||
4521 | YP.write(Atom.a("return false;")); | ||
4522 | YP.nl(); | ||
4523 | convertStatementListCSharp(RestStatements, Level); | ||
4524 | return; | ||
4525 | } | ||
4526 | } | ||
4527 | { | ||
4528 | Variable Name = new Variable(); | ||
4529 | Variable RestStatements = new Variable(); | ||
4530 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("label", Name), RestStatements))) | ||
4531 | { | ||
4532 | convertIndentationCSharp(Level); | ||
4533 | YP.write(Name); | ||
4534 | YP.write(Atom.a(":")); | ||
4535 | YP.nl(); | ||
4536 | if (YP.termEqual(RestStatements, Atom.NIL)) | ||
4537 | { | ||
4538 | convertIndentationCSharp(Level); | ||
4539 | YP.write(Atom.a("{}")); | ||
4540 | YP.nl(); | ||
4541 | convertStatementListCSharp(RestStatements, Level); | ||
4542 | return; | ||
4543 | goto cutIf1; | ||
4544 | } | ||
4545 | convertStatementListCSharp(RestStatements, Level); | ||
4546 | return; | ||
4547 | cutIf1: | ||
4548 | { } | ||
4549 | } | ||
4550 | } | ||
4551 | { | ||
4552 | Variable Name = new Variable(); | ||
4553 | Variable RestStatements = new Variable(); | ||
4554 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("breakBlock", Name), RestStatements))) | ||
4555 | { | ||
4556 | convertIndentationCSharp(Level); | ||
4557 | YP.write(Atom.a("goto ")); | ||
4558 | YP.write(Name); | ||
4559 | YP.write(Atom.a(";")); | ||
4560 | YP.nl(); | ||
4561 | convertStatementListCSharp(RestStatements, Level); | ||
4562 | return; | ||
4563 | } | ||
4564 | } | ||
4565 | { | ||
4566 | Variable Name = new Variable(); | ||
4567 | Variable ArgList = new Variable(); | ||
4568 | Variable RestStatements = new Variable(); | ||
4569 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("call", Name, ArgList), RestStatements))) | ||
4570 | { | ||
4571 | convertIndentationCSharp(Level); | ||
4572 | YP.write(Name); | ||
4573 | YP.write(Atom.a("(")); | ||
4574 | convertArgListCSharp(ArgList); | ||
4575 | YP.write(Atom.a(");")); | ||
4576 | YP.nl(); | ||
4577 | convertStatementListCSharp(RestStatements, Level); | ||
4578 | return; | ||
4579 | } | ||
4580 | } | ||
4581 | { | ||
4582 | Variable Name = new Variable(); | ||
4583 | Variable _FunctorArgs = new Variable(); | ||
4584 | Variable ArgList = new Variable(); | ||
4585 | Variable RestStatements = new Variable(); | ||
4586 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("functorCall", Name, _FunctorArgs, ArgList), RestStatements))) | ||
4587 | { | ||
4588 | convertStatementListCSharp(new ListPair(new Functor2("call", Name, ArgList), RestStatements), Level); | ||
4589 | return; | ||
4590 | } | ||
4591 | } | ||
4592 | { | ||
4593 | Variable Obj = new Variable(); | ||
4594 | Variable Name = new Variable(); | ||
4595 | Variable ArgList = new Variable(); | ||
4596 | Variable RestStatements = new Variable(); | ||
4597 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("callMember", new Functor1("var", Obj), Name, ArgList), RestStatements))) | ||
4598 | { | ||
4599 | convertIndentationCSharp(Level); | ||
4600 | YP.write(Obj); | ||
4601 | YP.write(Atom.a(".")); | ||
4602 | YP.write(Name); | ||
4603 | YP.write(Atom.a("(")); | ||
4604 | convertArgListCSharp(ArgList); | ||
4605 | YP.write(Atom.a(");")); | ||
4606 | YP.nl(); | ||
4607 | convertStatementListCSharp(RestStatements, Level); | ||
4608 | return; | ||
4609 | } | ||
4610 | } | ||
4611 | { | ||
4612 | Variable Body = new Variable(); | ||
4613 | Variable RestStatements = new Variable(); | ||
4614 | Variable NextLevel = new Variable(); | ||
4615 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("blockScope", Body), RestStatements))) | ||
4616 | { | ||
4617 | convertIndentationCSharp(Level); | ||
4618 | YP.write(Atom.a("{")); | ||
4619 | YP.nl(); | ||
4620 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
4621 | { | ||
4622 | convertStatementListCSharp(Body, NextLevel); | ||
4623 | convertIndentationCSharp(Level); | ||
4624 | YP.write(Atom.a("}")); | ||
4625 | YP.nl(); | ||
4626 | convertStatementListCSharp(RestStatements, Level); | ||
4627 | return; | ||
4628 | } | ||
4629 | } | ||
4630 | } | ||
4631 | { | ||
4632 | Variable Expression = new Variable(); | ||
4633 | Variable Body = new Variable(); | ||
4634 | Variable RestStatements = new Variable(); | ||
4635 | Variable NextLevel = new Variable(); | ||
4636 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("if", Expression, Body), RestStatements))) | ||
4637 | { | ||
4638 | convertIndentationCSharp(Level); | ||
4639 | YP.write(Atom.a("if (")); | ||
4640 | convertExpressionCSharp(Expression); | ||
4641 | YP.write(Atom.a(") {")); | ||
4642 | YP.nl(); | ||
4643 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
4644 | { | ||
4645 | convertStatementListCSharp(Body, NextLevel); | ||
4646 | convertIndentationCSharp(Level); | ||
4647 | YP.write(Atom.a("}")); | ||
4648 | YP.nl(); | ||
4649 | convertStatementListCSharp(RestStatements, Level); | ||
4650 | return; | ||
4651 | } | ||
4652 | } | ||
4653 | } | ||
4654 | { | ||
4655 | Variable Expression = new Variable(); | ||
4656 | Variable Body = new Variable(); | ||
4657 | Variable RestStatements = new Variable(); | ||
4658 | Variable NextLevel = new Variable(); | ||
4659 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("foreach", Expression, Body), RestStatements))) | ||
4660 | { | ||
4661 | convertIndentationCSharp(Level); | ||
4662 | YP.write(Atom.a("foreach (bool l")); | ||
4663 | YP.write(Level); | ||
4664 | YP.write(Atom.a(" in ")); | ||
4665 | convertExpressionCSharp(Expression); | ||
4666 | YP.write(Atom.a(") {")); | ||
4667 | YP.nl(); | ||
4668 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
4669 | { | ||
4670 | convertStatementListCSharp(Body, NextLevel); | ||
4671 | convertIndentationCSharp(Level); | ||
4672 | YP.write(Atom.a("}")); | ||
4673 | YP.nl(); | ||
4674 | convertStatementListCSharp(RestStatements, Level); | ||
4675 | return; | ||
4676 | } | ||
4677 | } | ||
4678 | } | ||
4679 | { | ||
4680 | Variable Expression = new Variable(); | ||
4681 | Variable RestStatements = new Variable(); | ||
4682 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("throw", Expression), RestStatements))) | ||
4683 | { | ||
4684 | convertIndentationCSharp(Level); | ||
4685 | YP.write(Atom.a("throw ")); | ||
4686 | convertExpressionCSharp(Expression); | ||
4687 | YP.write(Atom.a(";")); | ||
4688 | YP.nl(); | ||
4689 | convertStatementListCSharp(RestStatements, Level); | ||
4690 | return; | ||
4691 | } | ||
4692 | } | ||
4693 | } | ||
4694 | |||
4695 | public static void convertIndentationCSharp(object Level) | ||
4696 | { | ||
4697 | { | ||
4698 | Variable N = new Variable(); | ||
4699 | foreach (bool l2 in YP.unify(N, YP.multiply(Level, 2))) | ||
4700 | { | ||
4701 | repeatWrite(Atom.a(" "), N); | ||
4702 | return; | ||
4703 | } | ||
4704 | } | ||
4705 | } | ||
4706 | |||
4707 | public static void convertArgListCSharp(object arg1) | ||
4708 | { | ||
4709 | { | ||
4710 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
4711 | { | ||
4712 | return; | ||
4713 | } | ||
4714 | } | ||
4715 | { | ||
4716 | Variable Head = new Variable(); | ||
4717 | Variable Tail = new Variable(); | ||
4718 | foreach (bool l2 in YP.unify(arg1, new ListPair(Head, Tail))) | ||
4719 | { | ||
4720 | convertExpressionCSharp(Head); | ||
4721 | if (YP.termNotEqual(Tail, Atom.NIL)) | ||
4722 | { | ||
4723 | YP.write(Atom.a(", ")); | ||
4724 | convertArgListCSharp(Tail); | ||
4725 | return; | ||
4726 | goto cutIf1; | ||
4727 | } | ||
4728 | convertArgListCSharp(Tail); | ||
4729 | return; | ||
4730 | cutIf1: | ||
4731 | { } | ||
4732 | } | ||
4733 | } | ||
4734 | } | ||
4735 | |||
4736 | public static void convertExpressionCSharp(object arg1) | ||
4737 | { | ||
4738 | { | ||
4739 | Variable X = new Variable(); | ||
4740 | foreach (bool l2 in YP.unify(arg1, new Functor1("arg", X))) | ||
4741 | { | ||
4742 | YP.write(Atom.a("object ")); | ||
4743 | YP.write(X); | ||
4744 | return; | ||
4745 | } | ||
4746 | } | ||
4747 | { | ||
4748 | Variable Name = new Variable(); | ||
4749 | Variable ArgList = new Variable(); | ||
4750 | foreach (bool l2 in YP.unify(arg1, new Functor2("call", Name, ArgList))) | ||
4751 | { | ||
4752 | YP.write(Name); | ||
4753 | YP.write(Atom.a("(")); | ||
4754 | convertArgListCSharp(ArgList); | ||
4755 | YP.write(Atom.a(")")); | ||
4756 | return; | ||
4757 | } | ||
4758 | } | ||
4759 | { | ||
4760 | Variable Name = new Variable(); | ||
4761 | Variable _FunctorArgs = new Variable(); | ||
4762 | Variable ArgList = new Variable(); | ||
4763 | foreach (bool l2 in YP.unify(arg1, new Functor3("functorCall", Name, _FunctorArgs, ArgList))) | ||
4764 | { | ||
4765 | convertExpressionCSharp(new Functor2("call", Name, ArgList)); | ||
4766 | return; | ||
4767 | } | ||
4768 | } | ||
4769 | { | ||
4770 | Variable Obj = new Variable(); | ||
4771 | Variable Name = new Variable(); | ||
4772 | Variable ArgList = new Variable(); | ||
4773 | foreach (bool l2 in YP.unify(arg1, new Functor3("callMember", new Functor1("var", Obj), Name, ArgList))) | ||
4774 | { | ||
4775 | YP.write(Obj); | ||
4776 | YP.write(Atom.a(".")); | ||
4777 | YP.write(Name); | ||
4778 | YP.write(Atom.a("(")); | ||
4779 | convertArgListCSharp(ArgList); | ||
4780 | YP.write(Atom.a(")")); | ||
4781 | return; | ||
4782 | } | ||
4783 | } | ||
4784 | { | ||
4785 | Variable Name = new Variable(); | ||
4786 | Variable ArgList = new Variable(); | ||
4787 | foreach (bool l2 in YP.unify(arg1, new Functor2("new", Name, ArgList))) | ||
4788 | { | ||
4789 | YP.write(Atom.a("new ")); | ||
4790 | YP.write(Name); | ||
4791 | YP.write(Atom.a("(")); | ||
4792 | convertArgListCSharp(ArgList); | ||
4793 | YP.write(Atom.a(")")); | ||
4794 | return; | ||
4795 | } | ||
4796 | } | ||
4797 | { | ||
4798 | Variable Name = new Variable(); | ||
4799 | foreach (bool l2 in YP.unify(arg1, new Functor1("var", Name))) | ||
4800 | { | ||
4801 | YP.write(Name); | ||
4802 | return; | ||
4803 | } | ||
4804 | } | ||
4805 | { | ||
4806 | foreach (bool l2 in YP.unify(arg1, Atom.a("null"))) | ||
4807 | { | ||
4808 | YP.write(Atom.a("null")); | ||
4809 | return; | ||
4810 | } | ||
4811 | } | ||
4812 | { | ||
4813 | Variable X = new Variable(); | ||
4814 | foreach (bool l2 in YP.unify(arg1, new Functor1("not", X))) | ||
4815 | { | ||
4816 | YP.write(Atom.a("!(")); | ||
4817 | convertExpressionCSharp(X); | ||
4818 | YP.write(Atom.a(")")); | ||
4819 | return; | ||
4820 | } | ||
4821 | } | ||
4822 | { | ||
4823 | Variable X = new Variable(); | ||
4824 | Variable Y = new Variable(); | ||
4825 | foreach (bool l2 in YP.unify(arg1, new Functor2("and", X, Y))) | ||
4826 | { | ||
4827 | YP.write(Atom.a("(")); | ||
4828 | convertExpressionCSharp(X); | ||
4829 | YP.write(Atom.a(") && (")); | ||
4830 | convertExpressionCSharp(Y); | ||
4831 | YP.write(Atom.a(")")); | ||
4832 | return; | ||
4833 | } | ||
4834 | } | ||
4835 | { | ||
4836 | Variable ArgList = new Variable(); | ||
4837 | foreach (bool l2 in YP.unify(arg1, new Functor1("objectArray", ArgList))) | ||
4838 | { | ||
4839 | YP.write(Atom.a("new object[] {")); | ||
4840 | convertArgListCSharp(ArgList); | ||
4841 | YP.write(Atom.a("}")); | ||
4842 | return; | ||
4843 | } | ||
4844 | } | ||
4845 | { | ||
4846 | Variable X = new Variable(); | ||
4847 | Variable Codes = new Variable(); | ||
4848 | foreach (bool l2 in YP.unify(arg1, new Functor1("object", X))) | ||
4849 | { | ||
4850 | if (YP.atom(X)) | ||
4851 | { | ||
4852 | YP.write(Atom.a("\"")); | ||
4853 | foreach (bool l4 in YP.atom_codes(X, Codes)) | ||
4854 | { | ||
4855 | convertStringCodesCSharp(Codes); | ||
4856 | YP.write(Atom.a("\"")); | ||
4857 | return; | ||
4858 | } | ||
4859 | } | ||
4860 | } | ||
4861 | } | ||
4862 | { | ||
4863 | Variable X = new Variable(); | ||
4864 | foreach (bool l2 in YP.unify(arg1, new Functor1("object", X))) | ||
4865 | { | ||
4866 | YP.write(X); | ||
4867 | return; | ||
4868 | } | ||
4869 | } | ||
4870 | } | ||
4871 | |||
4872 | public static void convertStringCodesCSharp(object arg1) | ||
4873 | { | ||
4874 | { | ||
4875 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
4876 | { | ||
4877 | return; | ||
4878 | } | ||
4879 | } | ||
4880 | { | ||
4881 | Variable Code = new Variable(); | ||
4882 | Variable RestCodes = new Variable(); | ||
4883 | foreach (bool l2 in YP.unify(arg1, new ListPair(Code, RestCodes))) | ||
4884 | { | ||
4885 | foreach (bool l3 in putCStringCode(Code)) | ||
4886 | { | ||
4887 | convertStringCodesCSharp(RestCodes); | ||
4888 | return; | ||
4889 | } | ||
4890 | } | ||
4891 | } | ||
4892 | } | ||
4893 | |||
4894 | public static void convertFunctionJavascript(object arg1) | ||
4895 | { | ||
4896 | { | ||
4897 | foreach (bool l2 in YP.unify(arg1, Atom.a("getDeclaringClass"))) | ||
4898 | { | ||
4899 | YP.write(Atom.a("function getDeclaringClass() { return null; }")); | ||
4900 | YP.nl(); | ||
4901 | YP.nl(); | ||
4902 | return; | ||
4903 | } | ||
4904 | } | ||
4905 | { | ||
4906 | Variable x1 = new Variable(); | ||
4907 | Variable Name = new Variable(); | ||
4908 | Variable ArgList = new Variable(); | ||
4909 | Variable Body = new Variable(); | ||
4910 | foreach (bool l2 in YP.unify(arg1, new Functor("function", new object[] { x1, Name, ArgList, Body }))) | ||
4911 | { | ||
4912 | YP.write(Atom.a("function ")); | ||
4913 | YP.write(Name); | ||
4914 | YP.write(Atom.a("(")); | ||
4915 | convertArgListJavascript(ArgList); | ||
4916 | YP.write(Atom.a(") {")); | ||
4917 | YP.nl(); | ||
4918 | convertStatementListJavascript(Body, 1); | ||
4919 | YP.write(Atom.a("}")); | ||
4920 | YP.nl(); | ||
4921 | YP.nl(); | ||
4922 | return; | ||
4923 | } | ||
4924 | } | ||
4925 | } | ||
4926 | |||
4927 | public static void convertStatementListJavascript(object arg1, object arg2) | ||
4928 | { | ||
4929 | { | ||
4930 | object x1 = arg2; | ||
4931 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
4932 | { | ||
4933 | return; | ||
4934 | } | ||
4935 | } | ||
4936 | { | ||
4937 | object Level = arg2; | ||
4938 | Variable Name = new Variable(); | ||
4939 | Variable Body = new Variable(); | ||
4940 | Variable RestStatements = new Variable(); | ||
4941 | Variable NextLevel = new Variable(); | ||
4942 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("breakableBlock", Name, Body), RestStatements))) | ||
4943 | { | ||
4944 | convertIndentationJavascript(Level); | ||
4945 | YP.write(Name); | ||
4946 | YP.write(Atom.a(":")); | ||
4947 | YP.nl(); | ||
4948 | convertIndentationJavascript(Level); | ||
4949 | YP.write(Atom.a("{")); | ||
4950 | YP.nl(); | ||
4951 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
4952 | { | ||
4953 | convertStatementListJavascript(Body, NextLevel); | ||
4954 | convertIndentationJavascript(Level); | ||
4955 | YP.write(Atom.a("}")); | ||
4956 | YP.nl(); | ||
4957 | convertStatementListJavascript(RestStatements, Level); | ||
4958 | return; | ||
4959 | } | ||
4960 | } | ||
4961 | } | ||
4962 | { | ||
4963 | object Level = arg2; | ||
4964 | Variable _Type = new Variable(); | ||
4965 | Variable Name = new Variable(); | ||
4966 | Variable Expression = new Variable(); | ||
4967 | Variable RestStatements = new Variable(); | ||
4968 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("declare", _Type, Name, Expression), RestStatements))) | ||
4969 | { | ||
4970 | convertIndentationJavascript(Level); | ||
4971 | YP.write(Atom.a("var ")); | ||
4972 | YP.write(Name); | ||
4973 | YP.write(Atom.a(" = ")); | ||
4974 | convertExpressionJavascript(Expression); | ||
4975 | YP.write(Atom.a(";")); | ||
4976 | YP.nl(); | ||
4977 | convertStatementListJavascript(RestStatements, Level); | ||
4978 | return; | ||
4979 | } | ||
4980 | } | ||
4981 | { | ||
4982 | object Level = arg2; | ||
4983 | Variable Name = new Variable(); | ||
4984 | Variable Expression = new Variable(); | ||
4985 | Variable RestStatements = new Variable(); | ||
4986 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("assign", Name, Expression), RestStatements))) | ||
4987 | { | ||
4988 | convertIndentationJavascript(Level); | ||
4989 | YP.write(Name); | ||
4990 | YP.write(Atom.a(" = ")); | ||
4991 | convertExpressionJavascript(Expression); | ||
4992 | YP.write(Atom.a(";")); | ||
4993 | YP.nl(); | ||
4994 | convertStatementListJavascript(RestStatements, Level); | ||
4995 | return; | ||
4996 | } | ||
4997 | } | ||
4998 | { | ||
4999 | object Level = arg2; | ||
5000 | Variable RestStatements = new Variable(); | ||
5001 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldtrue"), RestStatements))) | ||
5002 | { | ||
5003 | convertIndentationJavascript(Level); | ||
5004 | YP.write(Atom.a("yield true;")); | ||
5005 | YP.nl(); | ||
5006 | convertStatementListJavascript(RestStatements, Level); | ||
5007 | return; | ||
5008 | } | ||
5009 | } | ||
5010 | { | ||
5011 | object Level = arg2; | ||
5012 | Variable RestStatements = new Variable(); | ||
5013 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldfalse"), RestStatements))) | ||
5014 | { | ||
5015 | convertIndentationJavascript(Level); | ||
5016 | YP.write(Atom.a("yield false;")); | ||
5017 | YP.nl(); | ||
5018 | convertStatementListJavascript(RestStatements, Level); | ||
5019 | return; | ||
5020 | } | ||
5021 | } | ||
5022 | { | ||
5023 | object Level = arg2; | ||
5024 | Variable RestStatements = new Variable(); | ||
5025 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldbreak"), RestStatements))) | ||
5026 | { | ||
5027 | convertIndentationJavascript(Level); | ||
5028 | YP.write(Atom.a("return;")); | ||
5029 | YP.nl(); | ||
5030 | convertStatementListJavascript(RestStatements, Level); | ||
5031 | return; | ||
5032 | } | ||
5033 | } | ||
5034 | { | ||
5035 | object Level = arg2; | ||
5036 | Variable RestStatements = new Variable(); | ||
5037 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("return"), RestStatements))) | ||
5038 | { | ||
5039 | convertIndentationJavascript(Level); | ||
5040 | YP.write(Atom.a("return;")); | ||
5041 | YP.nl(); | ||
5042 | convertStatementListJavascript(RestStatements, Level); | ||
5043 | return; | ||
5044 | } | ||
5045 | } | ||
5046 | { | ||
5047 | object Level = arg2; | ||
5048 | Variable RestStatements = new Variable(); | ||
5049 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("returntrue"), RestStatements))) | ||
5050 | { | ||
5051 | convertIndentationJavascript(Level); | ||
5052 | YP.write(Atom.a("return true;")); | ||
5053 | YP.nl(); | ||
5054 | convertStatementListJavascript(RestStatements, Level); | ||
5055 | return; | ||
5056 | } | ||
5057 | } | ||
5058 | { | ||
5059 | object Level = arg2; | ||
5060 | Variable RestStatements = new Variable(); | ||
5061 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("returnfalse"), RestStatements))) | ||
5062 | { | ||
5063 | convertIndentationJavascript(Level); | ||
5064 | YP.write(Atom.a("return false;")); | ||
5065 | YP.nl(); | ||
5066 | convertStatementListJavascript(RestStatements, Level); | ||
5067 | return; | ||
5068 | } | ||
5069 | } | ||
5070 | { | ||
5071 | object Level = arg2; | ||
5072 | Variable Name = new Variable(); | ||
5073 | Variable RestStatements = new Variable(); | ||
5074 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("breakBlock", Name), RestStatements))) | ||
5075 | { | ||
5076 | convertIndentationJavascript(Level); | ||
5077 | YP.write(Atom.a("break ")); | ||
5078 | YP.write(Name); | ||
5079 | YP.write(Atom.a(";")); | ||
5080 | YP.nl(); | ||
5081 | convertStatementListJavascript(RestStatements, Level); | ||
5082 | return; | ||
5083 | } | ||
5084 | } | ||
5085 | { | ||
5086 | object Level = arg2; | ||
5087 | Variable Name = new Variable(); | ||
5088 | Variable ArgList = new Variable(); | ||
5089 | Variable RestStatements = new Variable(); | ||
5090 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("call", Name, ArgList), RestStatements))) | ||
5091 | { | ||
5092 | convertIndentationJavascript(Level); | ||
5093 | YP.write(Name); | ||
5094 | YP.write(Atom.a("(")); | ||
5095 | convertArgListJavascript(ArgList); | ||
5096 | YP.write(Atom.a(");")); | ||
5097 | YP.nl(); | ||
5098 | convertStatementListJavascript(RestStatements, Level); | ||
5099 | return; | ||
5100 | } | ||
5101 | } | ||
5102 | { | ||
5103 | object Level = arg2; | ||
5104 | Variable Name = new Variable(); | ||
5105 | Variable _FunctorArgs = new Variable(); | ||
5106 | Variable ArgList = new Variable(); | ||
5107 | Variable RestStatements = new Variable(); | ||
5108 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("functorCall", Name, _FunctorArgs, ArgList), RestStatements))) | ||
5109 | { | ||
5110 | convertStatementListJavascript(new ListPair(new Functor2("call", Name, ArgList), RestStatements), Level); | ||
5111 | return; | ||
5112 | } | ||
5113 | } | ||
5114 | { | ||
5115 | object Level = arg2; | ||
5116 | Variable Obj = new Variable(); | ||
5117 | Variable Name = new Variable(); | ||
5118 | Variable ArgList = new Variable(); | ||
5119 | Variable RestStatements = new Variable(); | ||
5120 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("callMember", new Functor1("var", Obj), Name, ArgList), RestStatements))) | ||
5121 | { | ||
5122 | convertIndentationJavascript(Level); | ||
5123 | YP.write(Obj); | ||
5124 | YP.write(Atom.a(".")); | ||
5125 | YP.write(Name); | ||
5126 | YP.write(Atom.a("(")); | ||
5127 | convertArgListJavascript(ArgList); | ||
5128 | YP.write(Atom.a(");")); | ||
5129 | YP.nl(); | ||
5130 | convertStatementListJavascript(RestStatements, Level); | ||
5131 | return; | ||
5132 | } | ||
5133 | } | ||
5134 | { | ||
5135 | object Level = arg2; | ||
5136 | Variable Body = new Variable(); | ||
5137 | Variable RestStatements = new Variable(); | ||
5138 | Variable NextLevel = new Variable(); | ||
5139 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("blockScope", Body), RestStatements))) | ||
5140 | { | ||
5141 | convertIndentationJavascript(Level); | ||
5142 | YP.write(Atom.a("{")); | ||
5143 | YP.nl(); | ||
5144 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
5145 | { | ||
5146 | convertStatementListJavascript(Body, NextLevel); | ||
5147 | convertIndentationJavascript(Level); | ||
5148 | YP.write(Atom.a("}")); | ||
5149 | YP.nl(); | ||
5150 | convertStatementListJavascript(RestStatements, Level); | ||
5151 | return; | ||
5152 | } | ||
5153 | } | ||
5154 | } | ||
5155 | { | ||
5156 | object Level = arg2; | ||
5157 | Variable Expression = new Variable(); | ||
5158 | Variable Body = new Variable(); | ||
5159 | Variable RestStatements = new Variable(); | ||
5160 | Variable NextLevel = new Variable(); | ||
5161 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("if", Expression, Body), RestStatements))) | ||
5162 | { | ||
5163 | convertIndentationJavascript(Level); | ||
5164 | YP.write(Atom.a("if (")); | ||
5165 | convertExpressionJavascript(Expression); | ||
5166 | YP.write(Atom.a(") {")); | ||
5167 | YP.nl(); | ||
5168 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
5169 | { | ||
5170 | convertStatementListJavascript(Body, NextLevel); | ||
5171 | convertIndentationJavascript(Level); | ||
5172 | YP.write(Atom.a("}")); | ||
5173 | YP.nl(); | ||
5174 | convertStatementListJavascript(RestStatements, Level); | ||
5175 | return; | ||
5176 | } | ||
5177 | } | ||
5178 | } | ||
5179 | { | ||
5180 | object Level = arg2; | ||
5181 | Variable Expression = new Variable(); | ||
5182 | Variable Body = new Variable(); | ||
5183 | Variable RestStatements = new Variable(); | ||
5184 | Variable NextLevel = new Variable(); | ||
5185 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("foreach", Expression, Body), RestStatements))) | ||
5186 | { | ||
5187 | convertIndentationJavascript(Level); | ||
5188 | YP.write(Atom.a("for each (var l")); | ||
5189 | YP.write(Level); | ||
5190 | YP.write(Atom.a(" in ")); | ||
5191 | convertExpressionJavascript(Expression); | ||
5192 | YP.write(Atom.a(") {")); | ||
5193 | YP.nl(); | ||
5194 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
5195 | { | ||
5196 | convertStatementListJavascript(Body, NextLevel); | ||
5197 | convertIndentationJavascript(Level); | ||
5198 | YP.write(Atom.a("}")); | ||
5199 | YP.nl(); | ||
5200 | convertStatementListJavascript(RestStatements, Level); | ||
5201 | return; | ||
5202 | } | ||
5203 | } | ||
5204 | } | ||
5205 | { | ||
5206 | object Level = arg2; | ||
5207 | Variable Expression = new Variable(); | ||
5208 | Variable RestStatements = new Variable(); | ||
5209 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("throw", Expression), RestStatements))) | ||
5210 | { | ||
5211 | convertIndentationJavascript(Level); | ||
5212 | YP.write(Atom.a("throw ")); | ||
5213 | convertExpressionJavascript(Expression); | ||
5214 | YP.write(Atom.a(";")); | ||
5215 | YP.nl(); | ||
5216 | convertStatementListJavascript(RestStatements, Level); | ||
5217 | return; | ||
5218 | } | ||
5219 | } | ||
5220 | } | ||
5221 | |||
5222 | public static void convertIndentationJavascript(object Level) | ||
5223 | { | ||
5224 | { | ||
5225 | Variable N = new Variable(); | ||
5226 | foreach (bool l2 in YP.unify(N, YP.multiply(Level, 2))) | ||
5227 | { | ||
5228 | repeatWrite(Atom.a(" "), N); | ||
5229 | return; | ||
5230 | } | ||
5231 | } | ||
5232 | } | ||
5233 | |||
5234 | public static void convertArgListJavascript(object arg1) | ||
5235 | { | ||
5236 | { | ||
5237 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
5238 | { | ||
5239 | return; | ||
5240 | } | ||
5241 | } | ||
5242 | { | ||
5243 | Variable Head = new Variable(); | ||
5244 | Variable Tail = new Variable(); | ||
5245 | foreach (bool l2 in YP.unify(arg1, new ListPair(Head, Tail))) | ||
5246 | { | ||
5247 | convertExpressionJavascript(Head); | ||
5248 | if (YP.termNotEqual(Tail, Atom.NIL)) | ||
5249 | { | ||
5250 | YP.write(Atom.a(", ")); | ||
5251 | convertArgListJavascript(Tail); | ||
5252 | return; | ||
5253 | goto cutIf1; | ||
5254 | } | ||
5255 | convertArgListJavascript(Tail); | ||
5256 | return; | ||
5257 | cutIf1: | ||
5258 | { } | ||
5259 | } | ||
5260 | } | ||
5261 | } | ||
5262 | |||
5263 | public static void convertExpressionJavascript(object arg1) | ||
5264 | { | ||
5265 | { | ||
5266 | Variable X = new Variable(); | ||
5267 | foreach (bool l2 in YP.unify(arg1, new Functor1("arg", X))) | ||
5268 | { | ||
5269 | YP.write(X); | ||
5270 | return; | ||
5271 | } | ||
5272 | } | ||
5273 | { | ||
5274 | Variable Name = new Variable(); | ||
5275 | Variable ArgList = new Variable(); | ||
5276 | foreach (bool l2 in YP.unify(arg1, new Functor2("call", Name, ArgList))) | ||
5277 | { | ||
5278 | YP.write(Name); | ||
5279 | YP.write(Atom.a("(")); | ||
5280 | convertArgListJavascript(ArgList); | ||
5281 | YP.write(Atom.a(")")); | ||
5282 | return; | ||
5283 | } | ||
5284 | } | ||
5285 | { | ||
5286 | Variable Name = new Variable(); | ||
5287 | Variable _FunctorArgs = new Variable(); | ||
5288 | Variable ArgList = new Variable(); | ||
5289 | foreach (bool l2 in YP.unify(arg1, new Functor3("functorCall", Name, _FunctorArgs, ArgList))) | ||
5290 | { | ||
5291 | convertExpressionJavascript(new Functor2("call", Name, ArgList)); | ||
5292 | return; | ||
5293 | } | ||
5294 | } | ||
5295 | { | ||
5296 | Variable Obj = new Variable(); | ||
5297 | Variable Name = new Variable(); | ||
5298 | Variable ArgList = new Variable(); | ||
5299 | foreach (bool l2 in YP.unify(arg1, new Functor3("callMember", new Functor1("var", Obj), Name, ArgList))) | ||
5300 | { | ||
5301 | YP.write(Obj); | ||
5302 | YP.write(Atom.a(".")); | ||
5303 | YP.write(Name); | ||
5304 | YP.write(Atom.a("(")); | ||
5305 | convertArgListJavascript(ArgList); | ||
5306 | YP.write(Atom.a(")")); | ||
5307 | return; | ||
5308 | } | ||
5309 | } | ||
5310 | { | ||
5311 | Variable Name = new Variable(); | ||
5312 | Variable ArgList = new Variable(); | ||
5313 | foreach (bool l2 in YP.unify(arg1, new Functor2("new", Name, ArgList))) | ||
5314 | { | ||
5315 | YP.write(Atom.a("new ")); | ||
5316 | YP.write(Name); | ||
5317 | YP.write(Atom.a("(")); | ||
5318 | convertArgListJavascript(ArgList); | ||
5319 | YP.write(Atom.a(")")); | ||
5320 | return; | ||
5321 | } | ||
5322 | } | ||
5323 | { | ||
5324 | Variable Name = new Variable(); | ||
5325 | foreach (bool l2 in YP.unify(arg1, new Functor1("var", Name))) | ||
5326 | { | ||
5327 | YP.write(Name); | ||
5328 | return; | ||
5329 | } | ||
5330 | } | ||
5331 | { | ||
5332 | foreach (bool l2 in YP.unify(arg1, Atom.a("null"))) | ||
5333 | { | ||
5334 | YP.write(Atom.a("null")); | ||
5335 | return; | ||
5336 | } | ||
5337 | } | ||
5338 | { | ||
5339 | Variable X = new Variable(); | ||
5340 | foreach (bool l2 in YP.unify(arg1, new Functor1("not", X))) | ||
5341 | { | ||
5342 | YP.write(Atom.a("!(")); | ||
5343 | convertExpressionJavascript(X); | ||
5344 | YP.write(Atom.a(")")); | ||
5345 | return; | ||
5346 | } | ||
5347 | } | ||
5348 | { | ||
5349 | Variable X = new Variable(); | ||
5350 | Variable Y = new Variable(); | ||
5351 | foreach (bool l2 in YP.unify(arg1, new Functor2("and", X, Y))) | ||
5352 | { | ||
5353 | YP.write(Atom.a("(")); | ||
5354 | convertExpressionJavascript(X); | ||
5355 | YP.write(Atom.a(") && (")); | ||
5356 | convertExpressionJavascript(Y); | ||
5357 | YP.write(Atom.a(")")); | ||
5358 | return; | ||
5359 | } | ||
5360 | } | ||
5361 | { | ||
5362 | Variable ArgList = new Variable(); | ||
5363 | foreach (bool l2 in YP.unify(arg1, new Functor1("objectArray", ArgList))) | ||
5364 | { | ||
5365 | YP.write(Atom.a("[")); | ||
5366 | convertArgListJavascript(ArgList); | ||
5367 | YP.write(Atom.a("]")); | ||
5368 | return; | ||
5369 | } | ||
5370 | } | ||
5371 | { | ||
5372 | Variable X = new Variable(); | ||
5373 | Variable Codes = new Variable(); | ||
5374 | foreach (bool l2 in YP.unify(arg1, new Functor1("object", X))) | ||
5375 | { | ||
5376 | if (YP.atom(X)) | ||
5377 | { | ||
5378 | YP.write(Atom.a("\"")); | ||
5379 | foreach (bool l4 in YP.atom_codes(X, Codes)) | ||
5380 | { | ||
5381 | convertStringCodesJavascript(Codes); | ||
5382 | YP.write(Atom.a("\"")); | ||
5383 | return; | ||
5384 | } | ||
5385 | } | ||
5386 | } | ||
5387 | } | ||
5388 | { | ||
5389 | Variable X = new Variable(); | ||
5390 | foreach (bool l2 in YP.unify(arg1, new Functor1("object", X))) | ||
5391 | { | ||
5392 | YP.write(X); | ||
5393 | return; | ||
5394 | } | ||
5395 | } | ||
5396 | } | ||
5397 | |||
5398 | public static void convertStringCodesJavascript(object arg1) | ||
5399 | { | ||
5400 | { | ||
5401 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
5402 | { | ||
5403 | return; | ||
5404 | } | ||
5405 | } | ||
5406 | { | ||
5407 | Variable Code = new Variable(); | ||
5408 | Variable RestCodes = new Variable(); | ||
5409 | foreach (bool l2 in YP.unify(arg1, new ListPair(Code, RestCodes))) | ||
5410 | { | ||
5411 | foreach (bool l3 in putCStringCode(Code)) | ||
5412 | { | ||
5413 | convertStringCodesJavascript(RestCodes); | ||
5414 | return; | ||
5415 | } | ||
5416 | } | ||
5417 | } | ||
5418 | } | ||
5419 | |||
5420 | public static void convertFunctionPython(object arg1) | ||
5421 | { | ||
5422 | { | ||
5423 | foreach (bool l2 in YP.unify(arg1, Atom.a("getDeclaringClass"))) | ||
5424 | { | ||
5425 | YP.write(Atom.a("def getDeclaringClass():")); | ||
5426 | YP.nl(); | ||
5427 | YP.write(Atom.a(" return None")); | ||
5428 | YP.nl(); | ||
5429 | YP.nl(); | ||
5430 | return; | ||
5431 | } | ||
5432 | } | ||
5433 | { | ||
5434 | Variable x1 = new Variable(); | ||
5435 | Variable Name = new Variable(); | ||
5436 | Variable ArgList = new Variable(); | ||
5437 | Variable Body = new Variable(); | ||
5438 | Variable Level = new Variable(); | ||
5439 | Variable HasBreakableBlock = new Variable(); | ||
5440 | foreach (bool l2 in YP.unify(arg1, new Functor("function", new object[] { x1, Name, ArgList, Body }))) | ||
5441 | { | ||
5442 | YP.write(Atom.a("def ")); | ||
5443 | YP.write(Name); | ||
5444 | YP.write(Atom.a("(")); | ||
5445 | convertArgListPython(ArgList); | ||
5446 | YP.write(Atom.a("):")); | ||
5447 | YP.nl(); | ||
5448 | foreach (bool l3 in YP.unify(Level, 1)) | ||
5449 | { | ||
5450 | if (hasBreakableBlockPython(Body)) | ||
5451 | { | ||
5452 | foreach (bool l5 in YP.unify(HasBreakableBlock, 1)) | ||
5453 | { | ||
5454 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
5455 | { | ||
5456 | convertIndentationPython(Level); | ||
5457 | YP.write(Atom.a("doBreak = False")); | ||
5458 | YP.nl(); | ||
5459 | foreach (bool l7 in convertStatementListPython(Body, Level, HasBreakableBlock)) | ||
5460 | { | ||
5461 | YP.nl(); | ||
5462 | return; | ||
5463 | } | ||
5464 | goto cutIf2; | ||
5465 | } | ||
5466 | foreach (bool l6 in convertStatementListPython(Body, Level, HasBreakableBlock)) | ||
5467 | { | ||
5468 | YP.nl(); | ||
5469 | return; | ||
5470 | } | ||
5471 | cutIf2: | ||
5472 | { } | ||
5473 | } | ||
5474 | goto cutIf1; | ||
5475 | } | ||
5476 | foreach (bool l4 in YP.unify(HasBreakableBlock, 0)) | ||
5477 | { | ||
5478 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
5479 | { | ||
5480 | convertIndentationPython(Level); | ||
5481 | YP.write(Atom.a("doBreak = False")); | ||
5482 | YP.nl(); | ||
5483 | foreach (bool l6 in convertStatementListPython(Body, Level, HasBreakableBlock)) | ||
5484 | { | ||
5485 | YP.nl(); | ||
5486 | return; | ||
5487 | } | ||
5488 | goto cutIf3; | ||
5489 | } | ||
5490 | foreach (bool l5 in convertStatementListPython(Body, Level, HasBreakableBlock)) | ||
5491 | { | ||
5492 | YP.nl(); | ||
5493 | return; | ||
5494 | } | ||
5495 | cutIf3: | ||
5496 | { } | ||
5497 | } | ||
5498 | cutIf1: | ||
5499 | { } | ||
5500 | } | ||
5501 | } | ||
5502 | } | ||
5503 | } | ||
5504 | |||
5505 | public static bool hasBreakableBlockPython(object arg1) | ||
5506 | { | ||
5507 | { | ||
5508 | Variable _Name = new Variable(); | ||
5509 | Variable _Body = new Variable(); | ||
5510 | Variable _RestStatements = new Variable(); | ||
5511 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("breakableBlock", _Name, _Body), _RestStatements))) | ||
5512 | { | ||
5513 | return true; | ||
5514 | } | ||
5515 | } | ||
5516 | { | ||
5517 | Variable Body = new Variable(); | ||
5518 | Variable _RestStatements = new Variable(); | ||
5519 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("blockScope", Body), _RestStatements))) | ||
5520 | { | ||
5521 | if (hasBreakableBlockPython(Body)) | ||
5522 | { | ||
5523 | return true; | ||
5524 | } | ||
5525 | } | ||
5526 | } | ||
5527 | { | ||
5528 | Variable _Expression = new Variable(); | ||
5529 | Variable Body = new Variable(); | ||
5530 | Variable _RestStatements = new Variable(); | ||
5531 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("if", _Expression, Body), _RestStatements))) | ||
5532 | { | ||
5533 | if (hasBreakableBlockPython(Body)) | ||
5534 | { | ||
5535 | return true; | ||
5536 | } | ||
5537 | } | ||
5538 | } | ||
5539 | { | ||
5540 | Variable _Expression = new Variable(); | ||
5541 | Variable Body = new Variable(); | ||
5542 | Variable _RestStatements = new Variable(); | ||
5543 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("foreach", _Expression, Body), _RestStatements))) | ||
5544 | { | ||
5545 | if (hasBreakableBlockPython(Body)) | ||
5546 | { | ||
5547 | return true; | ||
5548 | } | ||
5549 | } | ||
5550 | } | ||
5551 | { | ||
5552 | Variable x1 = new Variable(); | ||
5553 | Variable RestStatements = new Variable(); | ||
5554 | foreach (bool l2 in YP.unify(arg1, new ListPair(x1, RestStatements))) | ||
5555 | { | ||
5556 | if (hasBreakableBlockPython(RestStatements)) | ||
5557 | { | ||
5558 | return true; | ||
5559 | } | ||
5560 | } | ||
5561 | } | ||
5562 | return false; | ||
5563 | } | ||
5564 | |||
5565 | public static IEnumerable<bool> convertStatementListPython(object arg1, object arg2, object arg3) | ||
5566 | { | ||
5567 | { | ||
5568 | object x1 = arg2; | ||
5569 | object x2 = arg3; | ||
5570 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
5571 | { | ||
5572 | yield return true; | ||
5573 | yield break; | ||
5574 | } | ||
5575 | } | ||
5576 | { | ||
5577 | object Level = arg2; | ||
5578 | object HasBreakableBlock = arg3; | ||
5579 | Variable Name = new Variable(); | ||
5580 | Variable Body = new Variable(); | ||
5581 | Variable RestStatements = new Variable(); | ||
5582 | Variable NextLevel = new Variable(); | ||
5583 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("breakableBlock", Name, Body), RestStatements))) | ||
5584 | { | ||
5585 | convertIndentationPython(Level); | ||
5586 | YP.write(Name); | ||
5587 | YP.write(Atom.a(" = False")); | ||
5588 | YP.nl(); | ||
5589 | convertIndentationPython(Level); | ||
5590 | YP.write(Atom.a("for _ in [1]:")); | ||
5591 | YP.nl(); | ||
5592 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
5593 | { | ||
5594 | foreach (bool l4 in convertStatementListPython(Body, NextLevel, HasBreakableBlock)) | ||
5595 | { | ||
5596 | convertIndentationPython(Level); | ||
5597 | YP.write(Atom.a("if ")); | ||
5598 | YP.write(Name); | ||
5599 | YP.write(Atom.a(":")); | ||
5600 | YP.nl(); | ||
5601 | convertIndentationPython(NextLevel); | ||
5602 | YP.write(Atom.a("doBreak = False")); | ||
5603 | YP.nl(); | ||
5604 | convertIndentationPython(Level); | ||
5605 | YP.write(Atom.a("if doBreak:")); | ||
5606 | YP.nl(); | ||
5607 | convertIndentationPython(NextLevel); | ||
5608 | YP.write(Atom.a("break")); | ||
5609 | YP.nl(); | ||
5610 | foreach (bool l5 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5611 | { | ||
5612 | yield return true; | ||
5613 | yield break; | ||
5614 | } | ||
5615 | } | ||
5616 | } | ||
5617 | } | ||
5618 | } | ||
5619 | { | ||
5620 | object Level = arg2; | ||
5621 | object HasBreakableBlock = arg3; | ||
5622 | Variable _Type = new Variable(); | ||
5623 | Variable Name = new Variable(); | ||
5624 | Variable Expression = new Variable(); | ||
5625 | Variable RestStatements = new Variable(); | ||
5626 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("declare", _Type, Name, Expression), RestStatements))) | ||
5627 | { | ||
5628 | convertIndentationPython(Level); | ||
5629 | YP.write(Name); | ||
5630 | YP.write(Atom.a(" = ")); | ||
5631 | convertExpressionPython(Expression); | ||
5632 | YP.nl(); | ||
5633 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5634 | { | ||
5635 | yield return true; | ||
5636 | yield break; | ||
5637 | } | ||
5638 | } | ||
5639 | } | ||
5640 | { | ||
5641 | object Level = arg2; | ||
5642 | object HasBreakableBlock = arg3; | ||
5643 | Variable Name = new Variable(); | ||
5644 | Variable Expression = new Variable(); | ||
5645 | Variable RestStatements = new Variable(); | ||
5646 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("assign", Name, Expression), RestStatements))) | ||
5647 | { | ||
5648 | convertIndentationPython(Level); | ||
5649 | YP.write(Name); | ||
5650 | YP.write(Atom.a(" = ")); | ||
5651 | convertExpressionPython(Expression); | ||
5652 | YP.nl(); | ||
5653 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5654 | { | ||
5655 | yield return true; | ||
5656 | yield break; | ||
5657 | } | ||
5658 | } | ||
5659 | } | ||
5660 | { | ||
5661 | object Level = arg2; | ||
5662 | object HasBreakableBlock = arg3; | ||
5663 | Variable RestStatements = new Variable(); | ||
5664 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldtrue"), RestStatements))) | ||
5665 | { | ||
5666 | convertIndentationPython(Level); | ||
5667 | YP.write(Atom.a("yield True")); | ||
5668 | YP.nl(); | ||
5669 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5670 | { | ||
5671 | yield return true; | ||
5672 | yield break; | ||
5673 | } | ||
5674 | } | ||
5675 | } | ||
5676 | { | ||
5677 | object Level = arg2; | ||
5678 | object HasBreakableBlock = arg3; | ||
5679 | Variable RestStatements = new Variable(); | ||
5680 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldfalse"), RestStatements))) | ||
5681 | { | ||
5682 | convertIndentationPython(Level); | ||
5683 | YP.write(Atom.a("yield False")); | ||
5684 | YP.nl(); | ||
5685 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5686 | { | ||
5687 | yield return true; | ||
5688 | yield break; | ||
5689 | } | ||
5690 | } | ||
5691 | } | ||
5692 | { | ||
5693 | object Level = arg2; | ||
5694 | object HasBreakableBlock = arg3; | ||
5695 | Variable RestStatements = new Variable(); | ||
5696 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldbreak"), RestStatements))) | ||
5697 | { | ||
5698 | convertIndentationPython(Level); | ||
5699 | YP.write(Atom.a("return")); | ||
5700 | YP.nl(); | ||
5701 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5702 | { | ||
5703 | yield return true; | ||
5704 | yield break; | ||
5705 | } | ||
5706 | } | ||
5707 | } | ||
5708 | { | ||
5709 | object Level = arg2; | ||
5710 | object HasBreakableBlock = arg3; | ||
5711 | Variable RestStatements = new Variable(); | ||
5712 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("return"), RestStatements))) | ||
5713 | { | ||
5714 | convertIndentationPython(Level); | ||
5715 | YP.write(Atom.a("return")); | ||
5716 | YP.nl(); | ||
5717 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5718 | { | ||
5719 | yield return true; | ||
5720 | yield break; | ||
5721 | } | ||
5722 | } | ||
5723 | } | ||
5724 | { | ||
5725 | object Level = arg2; | ||
5726 | object HasBreakableBlock = arg3; | ||
5727 | Variable RestStatements = new Variable(); | ||
5728 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("returntrue"), RestStatements))) | ||
5729 | { | ||
5730 | convertIndentationPython(Level); | ||
5731 | YP.write(Atom.a("return True")); | ||
5732 | YP.nl(); | ||
5733 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5734 | { | ||
5735 | yield return true; | ||
5736 | yield break; | ||
5737 | } | ||
5738 | } | ||
5739 | } | ||
5740 | { | ||
5741 | object Level = arg2; | ||
5742 | object HasBreakableBlock = arg3; | ||
5743 | Variable RestStatements = new Variable(); | ||
5744 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("returnfalse"), RestStatements))) | ||
5745 | { | ||
5746 | convertIndentationPython(Level); | ||
5747 | YP.write(Atom.a("return False")); | ||
5748 | YP.nl(); | ||
5749 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5750 | { | ||
5751 | yield return true; | ||
5752 | yield break; | ||
5753 | } | ||
5754 | } | ||
5755 | } | ||
5756 | { | ||
5757 | object Level = arg2; | ||
5758 | object HasBreakableBlock = arg3; | ||
5759 | Variable Name = new Variable(); | ||
5760 | Variable RestStatements = new Variable(); | ||
5761 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("breakBlock", Name), RestStatements))) | ||
5762 | { | ||
5763 | convertIndentationPython(Level); | ||
5764 | YP.write(Name); | ||
5765 | YP.write(Atom.a(" = True")); | ||
5766 | YP.nl(); | ||
5767 | convertIndentationPython(Level); | ||
5768 | YP.write(Atom.a("doBreak = True")); | ||
5769 | YP.nl(); | ||
5770 | convertIndentationPython(Level); | ||
5771 | YP.write(Atom.a("break")); | ||
5772 | YP.nl(); | ||
5773 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5774 | { | ||
5775 | yield return true; | ||
5776 | yield break; | ||
5777 | } | ||
5778 | } | ||
5779 | } | ||
5780 | { | ||
5781 | object Level = arg2; | ||
5782 | object HasBreakableBlock = arg3; | ||
5783 | Variable Name = new Variable(); | ||
5784 | Variable ArgList = new Variable(); | ||
5785 | Variable RestStatements = new Variable(); | ||
5786 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("call", Name, ArgList), RestStatements))) | ||
5787 | { | ||
5788 | convertIndentationPython(Level); | ||
5789 | YP.write(Name); | ||
5790 | YP.write(Atom.a("(")); | ||
5791 | convertArgListPython(ArgList); | ||
5792 | YP.write(Atom.a(")")); | ||
5793 | YP.nl(); | ||
5794 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5795 | { | ||
5796 | yield return true; | ||
5797 | yield break; | ||
5798 | } | ||
5799 | } | ||
5800 | } | ||
5801 | { | ||
5802 | object Level = arg2; | ||
5803 | object HasBreakableBlock = arg3; | ||
5804 | Variable Name = new Variable(); | ||
5805 | Variable _FunctorArgs = new Variable(); | ||
5806 | Variable ArgList = new Variable(); | ||
5807 | Variable RestStatements = new Variable(); | ||
5808 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("functorCall", Name, _FunctorArgs, ArgList), RestStatements))) | ||
5809 | { | ||
5810 | foreach (bool l3 in convertStatementListPython(new ListPair(new Functor2("call", Name, ArgList), RestStatements), Level, HasBreakableBlock)) | ||
5811 | { | ||
5812 | yield return true; | ||
5813 | yield break; | ||
5814 | } | ||
5815 | } | ||
5816 | } | ||
5817 | { | ||
5818 | object Level = arg2; | ||
5819 | object HasBreakableBlock = arg3; | ||
5820 | Variable Obj = new Variable(); | ||
5821 | Variable Name = new Variable(); | ||
5822 | Variable ArgList = new Variable(); | ||
5823 | Variable RestStatements = new Variable(); | ||
5824 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("callMember", new Functor1("var", Obj), Name, ArgList), RestStatements))) | ||
5825 | { | ||
5826 | convertIndentationPython(Level); | ||
5827 | YP.write(Obj); | ||
5828 | YP.write(Atom.a(".")); | ||
5829 | YP.write(Name); | ||
5830 | YP.write(Atom.a("(")); | ||
5831 | convertArgListPython(ArgList); | ||
5832 | YP.write(Atom.a(")")); | ||
5833 | YP.nl(); | ||
5834 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5835 | { | ||
5836 | yield return true; | ||
5837 | yield break; | ||
5838 | } | ||
5839 | } | ||
5840 | } | ||
5841 | { | ||
5842 | object Level = arg2; | ||
5843 | object HasBreakableBlock = arg3; | ||
5844 | Variable Body = new Variable(); | ||
5845 | Variable RestStatements = new Variable(); | ||
5846 | Variable NextLevel = new Variable(); | ||
5847 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("blockScope", Body), RestStatements))) | ||
5848 | { | ||
5849 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
5850 | { | ||
5851 | convertIndentationPython(Level); | ||
5852 | YP.write(Atom.a("for _ in [1]:")); | ||
5853 | YP.nl(); | ||
5854 | foreach (bool l4 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
5855 | { | ||
5856 | foreach (bool l5 in convertStatementListPython(Body, NextLevel, HasBreakableBlock)) | ||
5857 | { | ||
5858 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
5859 | { | ||
5860 | if (YP.greaterThan(Level, 1)) | ||
5861 | { | ||
5862 | convertIndentationPython(Level); | ||
5863 | YP.write(Atom.a("if doBreak:")); | ||
5864 | YP.nl(); | ||
5865 | convertIndentationPython(NextLevel); | ||
5866 | YP.write(Atom.a("break")); | ||
5867 | YP.nl(); | ||
5868 | foreach (bool l8 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5869 | { | ||
5870 | yield return true; | ||
5871 | yield break; | ||
5872 | } | ||
5873 | goto cutIf3; | ||
5874 | } | ||
5875 | foreach (bool l7 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5876 | { | ||
5877 | yield return true; | ||
5878 | yield break; | ||
5879 | } | ||
5880 | cutIf3: | ||
5881 | goto cutIf2; | ||
5882 | } | ||
5883 | foreach (bool l6 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5884 | { | ||
5885 | yield return true; | ||
5886 | yield break; | ||
5887 | } | ||
5888 | cutIf2: | ||
5889 | { } | ||
5890 | } | ||
5891 | } | ||
5892 | goto cutIf1; | ||
5893 | } | ||
5894 | foreach (bool l3 in YP.unify(NextLevel, Level)) | ||
5895 | { | ||
5896 | foreach (bool l4 in convertStatementListPython(Body, NextLevel, HasBreakableBlock)) | ||
5897 | { | ||
5898 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
5899 | { | ||
5900 | if (YP.greaterThan(Level, 1)) | ||
5901 | { | ||
5902 | convertIndentationPython(Level); | ||
5903 | YP.write(Atom.a("if doBreak:")); | ||
5904 | YP.nl(); | ||
5905 | convertIndentationPython(NextLevel); | ||
5906 | YP.write(Atom.a("break")); | ||
5907 | YP.nl(); | ||
5908 | foreach (bool l7 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5909 | { | ||
5910 | yield return true; | ||
5911 | yield break; | ||
5912 | } | ||
5913 | goto cutIf5; | ||
5914 | } | ||
5915 | foreach (bool l6 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5916 | { | ||
5917 | yield return true; | ||
5918 | yield break; | ||
5919 | } | ||
5920 | cutIf5: | ||
5921 | goto cutIf4; | ||
5922 | } | ||
5923 | foreach (bool l5 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5924 | { | ||
5925 | yield return true; | ||
5926 | yield break; | ||
5927 | } | ||
5928 | cutIf4: | ||
5929 | { } | ||
5930 | } | ||
5931 | } | ||
5932 | cutIf1: | ||
5933 | { } | ||
5934 | } | ||
5935 | } | ||
5936 | { | ||
5937 | object Level = arg2; | ||
5938 | object HasBreakableBlock = arg3; | ||
5939 | Variable Expression = new Variable(); | ||
5940 | Variable Body = new Variable(); | ||
5941 | Variable RestStatements = new Variable(); | ||
5942 | Variable NextLevel = new Variable(); | ||
5943 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("if", Expression, Body), RestStatements))) | ||
5944 | { | ||
5945 | convertIndentationPython(Level); | ||
5946 | YP.write(Atom.a("if ")); | ||
5947 | convertExpressionPython(Expression); | ||
5948 | YP.write(Atom.a(":")); | ||
5949 | YP.nl(); | ||
5950 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
5951 | { | ||
5952 | foreach (bool l4 in convertStatementListPython(Body, NextLevel, HasBreakableBlock)) | ||
5953 | { | ||
5954 | foreach (bool l5 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5955 | { | ||
5956 | yield return true; | ||
5957 | yield break; | ||
5958 | } | ||
5959 | } | ||
5960 | } | ||
5961 | } | ||
5962 | } | ||
5963 | { | ||
5964 | object Level = arg2; | ||
5965 | object HasBreakableBlock = arg3; | ||
5966 | Variable Expression = new Variable(); | ||
5967 | Variable Body = new Variable(); | ||
5968 | Variable RestStatements = new Variable(); | ||
5969 | Variable NextLevel = new Variable(); | ||
5970 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("foreach", Expression, Body), RestStatements))) | ||
5971 | { | ||
5972 | convertIndentationPython(Level); | ||
5973 | YP.write(Atom.a("for l")); | ||
5974 | YP.write(Level); | ||
5975 | YP.write(Atom.a(" in ")); | ||
5976 | convertExpressionPython(Expression); | ||
5977 | YP.write(Atom.a(":")); | ||
5978 | YP.nl(); | ||
5979 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
5980 | { | ||
5981 | foreach (bool l4 in convertStatementListPython(Body, NextLevel, HasBreakableBlock)) | ||
5982 | { | ||
5983 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
5984 | { | ||
5985 | convertIndentationPython(Level); | ||
5986 | YP.write(Atom.a("if doBreak:")); | ||
5987 | YP.nl(); | ||
5988 | convertIndentationPython(NextLevel); | ||
5989 | YP.write(Atom.a("break")); | ||
5990 | YP.nl(); | ||
5991 | foreach (bool l6 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5992 | { | ||
5993 | yield return true; | ||
5994 | yield break; | ||
5995 | } | ||
5996 | goto cutIf6; | ||
5997 | } | ||
5998 | foreach (bool l5 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5999 | { | ||
6000 | yield return true; | ||
6001 | yield break; | ||
6002 | } | ||
6003 | cutIf6: | ||
6004 | { } | ||
6005 | } | ||
6006 | } | ||
6007 | } | ||
6008 | } | ||
6009 | { | ||
6010 | object Level = arg2; | ||
6011 | object HasBreakableBlock = arg3; | ||
6012 | Variable Expression = new Variable(); | ||
6013 | Variable RestStatements = new Variable(); | ||
6014 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("throw", Expression), RestStatements))) | ||
6015 | { | ||
6016 | convertIndentationPython(Level); | ||
6017 | YP.write(Atom.a("raise ")); | ||
6018 | convertExpressionPython(Expression); | ||
6019 | YP.nl(); | ||
6020 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
6021 | { | ||
6022 | yield return true; | ||
6023 | yield break; | ||
6024 | } | ||
6025 | } | ||
6026 | } | ||
6027 | } | ||
6028 | |||
6029 | public static void convertIndentationPython(object Level) | ||
6030 | { | ||
6031 | { | ||
6032 | Variable N = new Variable(); | ||
6033 | foreach (bool l2 in YP.unify(N, YP.multiply(Level, 2))) | ||
6034 | { | ||
6035 | repeatWrite(Atom.a(" "), N); | ||
6036 | return; | ||
6037 | } | ||
6038 | } | ||
6039 | } | ||
6040 | |||
6041 | public static void convertArgListPython(object arg1) | ||
6042 | { | ||
6043 | { | ||
6044 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
6045 | { | ||
6046 | return; | ||
6047 | } | ||
6048 | } | ||
6049 | { | ||
6050 | Variable Head = new Variable(); | ||
6051 | Variable Tail = new Variable(); | ||
6052 | foreach (bool l2 in YP.unify(arg1, new ListPair(Head, Tail))) | ||
6053 | { | ||
6054 | convertExpressionPython(Head); | ||
6055 | if (YP.termNotEqual(Tail, Atom.NIL)) | ||
6056 | { | ||
6057 | YP.write(Atom.a(", ")); | ||
6058 | convertArgListPython(Tail); | ||
6059 | return; | ||
6060 | goto cutIf1; | ||
6061 | } | ||
6062 | convertArgListPython(Tail); | ||
6063 | return; | ||
6064 | cutIf1: | ||
6065 | { } | ||
6066 | } | ||
6067 | } | ||
6068 | } | ||
6069 | |||
6070 | public static void convertExpressionPython(object arg1) | ||
6071 | { | ||
6072 | { | ||
6073 | Variable X = new Variable(); | ||
6074 | foreach (bool l2 in YP.unify(arg1, new Functor1("arg", X))) | ||
6075 | { | ||
6076 | YP.write(X); | ||
6077 | return; | ||
6078 | } | ||
6079 | } | ||
6080 | { | ||
6081 | Variable Name = new Variable(); | ||
6082 | Variable ArgList = new Variable(); | ||
6083 | foreach (bool l2 in YP.unify(arg1, new Functor2("call", Name, ArgList))) | ||
6084 | { | ||
6085 | YP.write(Name); | ||
6086 | YP.write(Atom.a("(")); | ||
6087 | convertArgListPython(ArgList); | ||
6088 | YP.write(Atom.a(")")); | ||
6089 | return; | ||
6090 | } | ||
6091 | } | ||
6092 | { | ||
6093 | Variable Name = new Variable(); | ||
6094 | Variable _FunctorArgs = new Variable(); | ||
6095 | Variable ArgList = new Variable(); | ||
6096 | foreach (bool l2 in YP.unify(arg1, new Functor3("functorCall", Name, _FunctorArgs, ArgList))) | ||
6097 | { | ||
6098 | convertExpressionPython(new Functor2("call", Name, ArgList)); | ||
6099 | return; | ||
6100 | } | ||
6101 | } | ||
6102 | { | ||
6103 | Variable Obj = new Variable(); | ||
6104 | Variable Name = new Variable(); | ||
6105 | Variable ArgList = new Variable(); | ||
6106 | foreach (bool l2 in YP.unify(arg1, new Functor3("callMember", new Functor1("var", Obj), Name, ArgList))) | ||
6107 | { | ||
6108 | YP.write(Obj); | ||
6109 | YP.write(Atom.a(".")); | ||
6110 | YP.write(Name); | ||
6111 | YP.write(Atom.a("(")); | ||
6112 | convertArgListPython(ArgList); | ||
6113 | YP.write(Atom.a(")")); | ||
6114 | return; | ||
6115 | } | ||
6116 | } | ||
6117 | { | ||
6118 | Variable Name = new Variable(); | ||
6119 | Variable ArgList = new Variable(); | ||
6120 | foreach (bool l2 in YP.unify(arg1, new Functor2("new", Name, ArgList))) | ||
6121 | { | ||
6122 | YP.write(Name); | ||
6123 | YP.write(Atom.a("(")); | ||
6124 | convertArgListPython(ArgList); | ||
6125 | YP.write(Atom.a(")")); | ||
6126 | return; | ||
6127 | } | ||
6128 | } | ||
6129 | { | ||
6130 | Variable Name = new Variable(); | ||
6131 | foreach (bool l2 in YP.unify(arg1, new Functor1("var", Name))) | ||
6132 | { | ||
6133 | YP.write(Name); | ||
6134 | return; | ||
6135 | } | ||
6136 | } | ||
6137 | { | ||
6138 | foreach (bool l2 in YP.unify(arg1, Atom.a("null"))) | ||
6139 | { | ||
6140 | YP.write(Atom.a("None")); | ||
6141 | return; | ||
6142 | } | ||
6143 | } | ||
6144 | { | ||
6145 | Variable X = new Variable(); | ||
6146 | foreach (bool l2 in YP.unify(arg1, new Functor1("not", X))) | ||
6147 | { | ||
6148 | YP.write(Atom.a("not (")); | ||
6149 | convertExpressionPython(X); | ||
6150 | YP.write(Atom.a(")")); | ||
6151 | return; | ||
6152 | } | ||
6153 | } | ||
6154 | { | ||
6155 | Variable X = new Variable(); | ||
6156 | Variable Y = new Variable(); | ||
6157 | foreach (bool l2 in YP.unify(arg1, new Functor2("and", X, Y))) | ||
6158 | { | ||
6159 | YP.write(Atom.a("(")); | ||
6160 | convertExpressionPython(X); | ||
6161 | YP.write(Atom.a(") and (")); | ||
6162 | convertExpressionPython(Y); | ||
6163 | YP.write(Atom.a(")")); | ||
6164 | return; | ||
6165 | } | ||
6166 | } | ||
6167 | { | ||
6168 | Variable ArgList = new Variable(); | ||
6169 | foreach (bool l2 in YP.unify(arg1, new Functor1("objectArray", ArgList))) | ||
6170 | { | ||
6171 | YP.write(Atom.a("[")); | ||
6172 | convertArgListPython(ArgList); | ||
6173 | YP.write(Atom.a("]")); | ||
6174 | return; | ||
6175 | } | ||
6176 | } | ||
6177 | { | ||
6178 | Variable X = new Variable(); | ||
6179 | Variable Codes = new Variable(); | ||
6180 | foreach (bool l2 in YP.unify(arg1, new Functor1("object", X))) | ||
6181 | { | ||
6182 | if (YP.atom(X)) | ||
6183 | { | ||
6184 | YP.write(Atom.a("\"")); | ||
6185 | foreach (bool l4 in YP.atom_codes(X, Codes)) | ||
6186 | { | ||
6187 | convertStringCodesPython(Codes); | ||
6188 | YP.write(Atom.a("\"")); | ||
6189 | return; | ||
6190 | } | ||
6191 | } | ||
6192 | } | ||
6193 | } | ||
6194 | { | ||
6195 | Variable X = new Variable(); | ||
6196 | foreach (bool l2 in YP.unify(arg1, new Functor1("object", X))) | ||
6197 | { | ||
6198 | YP.write(X); | ||
6199 | return; | ||
6200 | } | ||
6201 | } | ||
6202 | } | ||
6203 | |||
6204 | public static void convertStringCodesPython(object arg1) | ||
6205 | { | ||
6206 | { | ||
6207 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
6208 | { | ||
6209 | return; | ||
6210 | } | ||
6211 | } | ||
6212 | { | ||
6213 | Variable Code = new Variable(); | ||
6214 | Variable RestCodes = new Variable(); | ||
6215 | foreach (bool l2 in YP.unify(arg1, new ListPair(Code, RestCodes))) | ||
6216 | { | ||
6217 | if (YP.termEqual(Code, 34)) | ||
6218 | { | ||
6219 | YP.put_code(92); | ||
6220 | YP.put_code(Code); | ||
6221 | convertStringCodesPython(RestCodes); | ||
6222 | return; | ||
6223 | goto cutIf1; | ||
6224 | } | ||
6225 | if (YP.termEqual(Code, 92)) | ||
6226 | { | ||
6227 | YP.put_code(92); | ||
6228 | YP.put_code(Code); | ||
6229 | convertStringCodesPython(RestCodes); | ||
6230 | return; | ||
6231 | goto cutIf1; | ||
6232 | } | ||
6233 | YP.put_code(Code); | ||
6234 | convertStringCodesPython(RestCodes); | ||
6235 | return; | ||
6236 | cutIf1: | ||
6237 | { } | ||
6238 | } | ||
6239 | } | ||
6240 | } | ||
6241 | |||
6242 | public static IEnumerable<bool> putCStringCode(object Code) | ||
6243 | { | ||
6244 | { | ||
6245 | Variable HexDigit = new Variable(); | ||
6246 | Variable HexChar = new Variable(); | ||
6247 | if (YP.lessThanOrEqual(Code, 31)) | ||
6248 | { | ||
6249 | if (YP.lessThanOrEqual(Code, 15)) | ||
6250 | { | ||
6251 | YP.write(Atom.a("\\u000")); | ||
6252 | foreach (bool l4 in YP.unify(HexDigit, Code)) | ||
6253 | { | ||
6254 | if (YP.lessThanOrEqual(HexDigit, 9)) | ||
6255 | { | ||
6256 | foreach (bool l6 in YP.unify(HexChar, YP.add(HexDigit, 48))) | ||
6257 | { | ||
6258 | YP.put_code(HexChar); | ||
6259 | yield return true; | ||
6260 | yield break; | ||
6261 | } | ||
6262 | goto cutIf2; | ||
6263 | } | ||
6264 | foreach (bool l5 in YP.unify(HexChar, YP.add(HexDigit, 55))) | ||
6265 | { | ||
6266 | YP.put_code(HexChar); | ||
6267 | yield return true; | ||
6268 | yield break; | ||
6269 | } | ||
6270 | cutIf2: | ||
6271 | { } | ||
6272 | } | ||
6273 | goto cutIf1; | ||
6274 | } | ||
6275 | YP.write(Atom.a("\\u001")); | ||
6276 | foreach (bool l3 in YP.unify(HexDigit, YP.subtract(Code, 16))) | ||
6277 | { | ||
6278 | if (YP.lessThanOrEqual(HexDigit, 9)) | ||
6279 | { | ||
6280 | foreach (bool l5 in YP.unify(HexChar, YP.add(HexDigit, 48))) | ||
6281 | { | ||
6282 | YP.put_code(HexChar); | ||
6283 | yield return true; | ||
6284 | yield break; | ||
6285 | } | ||
6286 | goto cutIf3; | ||
6287 | } | ||
6288 | foreach (bool l4 in YP.unify(HexChar, YP.add(HexDigit, 55))) | ||
6289 | { | ||
6290 | YP.put_code(HexChar); | ||
6291 | yield return true; | ||
6292 | yield break; | ||
6293 | } | ||
6294 | cutIf3: | ||
6295 | { } | ||
6296 | } | ||
6297 | cutIf1: | ||
6298 | { } | ||
6299 | } | ||
6300 | } | ||
6301 | { | ||
6302 | if (YP.termEqual(Code, 34)) | ||
6303 | { | ||
6304 | YP.put_code(92); | ||
6305 | YP.put_code(34); | ||
6306 | yield return true; | ||
6307 | yield break; | ||
6308 | } | ||
6309 | } | ||
6310 | { | ||
6311 | if (YP.termEqual(Code, 92)) | ||
6312 | { | ||
6313 | YP.put_code(92); | ||
6314 | YP.put_code(92); | ||
6315 | yield return true; | ||
6316 | yield break; | ||
6317 | } | ||
6318 | } | ||
6319 | { | ||
6320 | YP.put_code(Code); | ||
6321 | yield return true; | ||
6322 | yield break; | ||
6323 | } | ||
6324 | } | ||
6325 | |||
6326 | public static IEnumerable<bool> member(object X, object arg2) | ||
6327 | { | ||
6328 | { | ||
6329 | Variable x2 = new Variable(); | ||
6330 | foreach (bool l2 in YP.unify(arg2, new ListPair(X, x2))) | ||
6331 | { | ||
6332 | yield return false; | ||
6333 | } | ||
6334 | } | ||
6335 | { | ||
6336 | Variable x2 = new Variable(); | ||
6337 | Variable Rest = new Variable(); | ||
6338 | foreach (bool l2 in YP.unify(arg2, new ListPair(x2, Rest))) | ||
6339 | { | ||
6340 | foreach (bool l3 in member(X, Rest)) | ||
6341 | { | ||
6342 | yield return false; | ||
6343 | } | ||
6344 | } | ||
6345 | } | ||
6346 | } | ||
6347 | |||
6348 | public static IEnumerable<bool> append(object arg1, object arg2, object arg3) | ||
6349 | { | ||
6350 | { | ||
6351 | Variable List = new Variable(); | ||
6352 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
6353 | { | ||
6354 | foreach (bool l3 in YP.unify(arg2, List)) | ||
6355 | { | ||
6356 | foreach (bool l4 in YP.unify(arg3, List)) | ||
6357 | { | ||
6358 | yield return false; | ||
6359 | } | ||
6360 | } | ||
6361 | } | ||
6362 | } | ||
6363 | { | ||
6364 | object List2 = arg2; | ||
6365 | Variable X = new Variable(); | ||
6366 | Variable List1 = new Variable(); | ||
6367 | Variable List12 = new Variable(); | ||
6368 | foreach (bool l2 in YP.unify(arg1, new ListPair(X, List1))) | ||
6369 | { | ||
6370 | foreach (bool l3 in YP.unify(arg3, new ListPair(X, List12))) | ||
6371 | { | ||
6372 | foreach (bool l4 in append(List1, List2, List12)) | ||
6373 | { | ||
6374 | yield return false; | ||
6375 | } | ||
6376 | } | ||
6377 | } | ||
6378 | } | ||
6379 | } | ||
6380 | #pragma warning restore 0168, 0219, 0164,0162 | ||
6381 | } | ||
6382 | } | ||