diff options
author | Charles Krinke | 2008-05-31 17:52:44 +0000 |
---|---|---|
committer | Charles Krinke | 2008-05-31 17:52:44 +0000 |
commit | 25b7d9944d5875e1887eed156f31dd5779761265 (patch) | |
tree | 2c4f6f066ef2b5f60d399ab4862ed7b9dbe0c78f | |
parent | * Implements UserServer logoff in a few situations (diff) | |
download | opensim-SC-25b7d9944d5875e1887eed156f31dd5779761265.zip opensim-SC-25b7d9944d5875e1887eed156f31dd5779761265.tar.gz opensim-SC-25b7d9944d5875e1887eed156f31dd5779761265.tar.bz2 opensim-SC-25b7d9944d5875e1887eed156f31dd5779761265.tar.xz |
Mantis#1314. Thank you kindly, Kinoc for YieldProlog.
I have added everything *except* the patch to
.../LSL/Compiler.cs. The Compiler.cs patch has a
namespace issue. Lets make a second patch to close
the gap.
Diffstat (limited to '')
17 files changed, 13548 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/YP2CSConverter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/YP2CSConverter.cs new file mode 100644 index 0000000..3766246 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/YP2CSConverter.cs | |||
@@ -0,0 +1,85 @@ | |||
1 | ?using System; | ||
2 | using System.IO; | ||
3 | using System.Collections.Generic; | ||
4 | using System.Text; | ||
5 | using System.Text.RegularExpressions; | ||
6 | using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog; | ||
7 | |||
8 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
9 | { | ||
10 | public class YP2CSConverter | ||
11 | { | ||
12 | public YP2CSConverter() | ||
13 | { | ||
14 | } | ||
15 | |||
16 | public string Convert(string Script) | ||
17 | { | ||
18 | string CS_code = GenCode(Script); | ||
19 | return CS_code; | ||
20 | } | ||
21 | |||
22 | |||
23 | static string GenCode(string myCode) | ||
24 | { | ||
25 | Variable TermList = new Variable(); | ||
26 | Variable FunctionCode = new Variable(); | ||
27 | |||
28 | string CS_code = ""; | ||
29 | |||
30 | int cs_pointer = myCode.IndexOf("\n//cs"); | ||
31 | if (cs_pointer > 0) | ||
32 | { | ||
33 | CS_code = myCode.Substring(cs_pointer); // CS code comes after | ||
34 | myCode = myCode.Substring(0, cs_pointer); | ||
35 | } | ||
36 | myCode.Replace("//yp", "%YPCode"); | ||
37 | |||
38 | |||
39 | StringWriter myCS_SW = new StringWriter(); | ||
40 | StringReader myCode_SR = new StringReader(" yp_nop_header_nop. \n "+myCode + "\n"); | ||
41 | |||
42 | YP.see(myCode_SR); | ||
43 | YP.tell(myCS_SW); | ||
44 | |||
45 | //Console.WriteLine("Mycode\n ===================================\n" + myCode+"\n"); | ||
46 | foreach (bool l1 in Parser.parseInput(TermList)) | ||
47 | { | ||
48 | foreach (bool l2 in YPCompiler.makeFunctionPseudoCode(TermList, FunctionCode)) | ||
49 | { | ||
50 | ListPair VFC = new ListPair(FunctionCode, new Variable()); | ||
51 | //Console.WriteLine("-------------------------") | ||
52 | //Console.WriteLine( FunctionCode.ToString()) | ||
53 | //Console.WriteLine("-------------------------") | ||
54 | YPCompiler.convertFunctionCSharp(FunctionCode); | ||
55 | //YPCompiler.convertStringCodesCSharp(VFC); | ||
56 | |||
57 | } | ||
58 | } | ||
59 | YP.seen(); | ||
60 | myCS_SW.Close(); | ||
61 | YP.told(); | ||
62 | StringBuilder bu = myCS_SW.GetStringBuilder(); | ||
63 | string finalcode = "//YPEncoded\n" + bu.ToString(); | ||
64 | // FIX script events (we're in the same script) | ||
65 | // 'YP.script_event(Atom.a(@"sayit"),' ==> 'sayit(' | ||
66 | finalcode = Regex.Replace(finalcode, | ||
67 | @"YP.script_event\(Atom.a\(\@\""(.*?)""\)\,", | ||
68 | @"this.$1(", | ||
69 | RegexOptions.Compiled | RegexOptions.Singleline); | ||
70 | finalcode = Regex.Replace(finalcode, | ||
71 | @" static ", | ||
72 | @" ", | ||
73 | RegexOptions.Compiled | RegexOptions.Singleline); | ||
74 | |||
75 | finalcode = CS_code+"\n\r"+ finalcode; | ||
76 | finalcode = Regex.Replace(finalcode, | ||
77 | @"PrologCallback", | ||
78 | @"public IEnumerable<bool> ", | ||
79 | RegexOptions.Compiled | RegexOptions.Singleline); | ||
80 | return finalcode; | ||
81 | } | ||
82 | |||
83 | |||
84 | } | ||
85 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Atom.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Atom.cs new file mode 100644 index 0000000..9b4ca6a --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Atom.cs | |||
@@ -0,0 +1,218 @@ | |||
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.DotNetEngine.Compiler.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/DotNetEngine/Compiler/YieldProlog/BagofAnswers.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/BagofAnswers.cs new file mode 100644 index 0000000..6aea6f7 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/BagofAnswers.cs | |||
@@ -0,0 +1,234 @@ | |||
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.DotNetEngine.Compiler.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 | /// <summary> | ||
117 | /// For each result, unify the _freeVariables and unify bagArrayVariable with the associated bag. | ||
118 | /// </summary> | ||
119 | /// <param name="bagArrayVariable">this is unified with the List<object> of matches for template that | ||
120 | /// corresponds to the bindings for freeVariables. Be very careful: this does not unify with a Prolog | ||
121 | /// list.</param> | ||
122 | /// <returns></returns> | ||
123 | public IEnumerable<bool> resultArray(Variable bagArrayVariable) | ||
124 | { | ||
125 | if (_freeVariables == null) | ||
126 | { | ||
127 | // No unbound free variables, so we only filled one bag. If empty, bagof fails. | ||
128 | if (_findallBagArray.Count > 0) | ||
129 | { | ||
130 | foreach (bool l1 in bagArrayVariable.unify(_findallBagArray)) | ||
131 | yield return false; | ||
132 | } | ||
133 | } | ||
134 | else | ||
135 | { | ||
136 | foreach (KeyValuePair<object[], List<object>> valuesAndBag in _bagForFreeVariables) | ||
137 | { | ||
138 | foreach (bool l1 in YP.unifyArrays(_freeVariables, valuesAndBag.Key)) | ||
139 | { | ||
140 | foreach (bool l2 in bagArrayVariable.unify(valuesAndBag.Value)) | ||
141 | yield return false; | ||
142 | } | ||
143 | // Debug: Should we free memory of the answers already returned? | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | |||
148 | /// <summary> | ||
149 | /// For each result, unify the _freeVariables and unify Bag with the associated bag. | ||
150 | /// </summary> | ||
151 | /// <param name="Bag"></param> | ||
152 | /// <returns></returns> | ||
153 | public IEnumerable<bool> result(object Bag) | ||
154 | { | ||
155 | Variable bagArrayVariable = new Variable(); | ||
156 | foreach (bool l1 in resultArray(bagArrayVariable)) | ||
157 | { | ||
158 | foreach (bool l2 in YP.unify(Bag, ListPair.make((List<object>)bagArrayVariable.getValue()))) | ||
159 | yield return false; | ||
160 | } | ||
161 | } | ||
162 | |||
163 | /// <summary> | ||
164 | /// For each result, unify the _freeVariables and unify Bag with the associated bag which is sorted | ||
165 | /// with duplicates removed, as in setof. | ||
166 | /// </summary> | ||
167 | /// <param name="Bag"></param> | ||
168 | /// <returns></returns> | ||
169 | public IEnumerable<bool> resultSet(object Bag) | ||
170 | { | ||
171 | Variable bagArrayVariable = new Variable(); | ||
172 | foreach (bool l1 in resultArray(bagArrayVariable)) | ||
173 | { | ||
174 | List<object> bagArray = (List<object>)bagArrayVariable.getValue(); | ||
175 | YP.sortArray(bagArray); | ||
176 | foreach (bool l2 in YP.unify(Bag, ListPair.makeWithoutRepeatedTerms(bagArray))) | ||
177 | yield return false; | ||
178 | } | ||
179 | } | ||
180 | |||
181 | public static IEnumerable<bool> bagofArray | ||
182 | (object Template, object Goal, IEnumerable<bool> goalIterator, Variable bagArrayVariable) | ||
183 | { | ||
184 | BagofAnswers bagOfAnswers = new BagofAnswers(Template, Goal); | ||
185 | foreach (bool l1 in goalIterator) | ||
186 | bagOfAnswers.add(); | ||
187 | return bagOfAnswers.resultArray(bagArrayVariable); | ||
188 | } | ||
189 | |||
190 | public static IEnumerable<bool> bagof | ||
191 | (object Template, object Goal, IEnumerable<bool> goalIterator, object Bag) | ||
192 | { | ||
193 | BagofAnswers bagOfAnswers = new BagofAnswers(Template, Goal); | ||
194 | foreach (bool l1 in goalIterator) | ||
195 | bagOfAnswers.add(); | ||
196 | return bagOfAnswers.result(Bag); | ||
197 | } | ||
198 | |||
199 | public static IEnumerable<bool> setof | ||
200 | (object Template, object Goal, IEnumerable<bool> goalIterator, object Bag) | ||
201 | { | ||
202 | BagofAnswers bagOfAnswers = new BagofAnswers(Template, Goal); | ||
203 | foreach (bool l1 in goalIterator) | ||
204 | bagOfAnswers.add(); | ||
205 | return bagOfAnswers.resultSet(Bag); | ||
206 | } | ||
207 | |||
208 | /// <summary> | ||
209 | /// A TermArrayEqualityComparer implements IEqualityComparer to compare two object arrays using YP.termEqual. | ||
210 | /// </summary> | ||
211 | private class TermArrayEqualityComparer : IEqualityComparer<object[]> | ||
212 | { | ||
213 | public bool Equals(object[] array1, object[] array2) | ||
214 | { | ||
215 | if (array1.Length != array2.Length) | ||
216 | return false; | ||
217 | for (int i = 0; i < array1.Length; ++i) | ||
218 | { | ||
219 | if (!YP.termEqual(array1[i], array2[i])) | ||
220 | return false; | ||
221 | } | ||
222 | return true; | ||
223 | } | ||
224 | |||
225 | public int GetHashCode(object[] array) | ||
226 | { | ||
227 | int hashCode = 0; | ||
228 | for (int i = 0; i < array.Length; ++i) | ||
229 | hashCode ^= array[i].GetHashCode(); | ||
230 | return hashCode; | ||
231 | } | ||
232 | } | ||
233 | } | ||
234 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/FindallAnswers.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/FindallAnswers.cs new file mode 100644 index 0000000..2978cee --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/FindallAnswers.cs | |||
@@ -0,0 +1,103 @@ | |||
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.DotNetEngine.Compiler.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 | /// <summary> | ||
75 | /// This is a simplified findall when the goal is a single call. | ||
76 | /// </summary> | ||
77 | /// <param name="Template"></param> | ||
78 | /// <param name="goal"></param> | ||
79 | /// <param name="Bag"></param> | ||
80 | /// <returns></returns> | ||
81 | public static IEnumerable<bool> findall(object Template, IEnumerable<bool> goal, object Bag) | ||
82 | { | ||
83 | FindallAnswers findallAnswers = new FindallAnswers(Template); | ||
84 | foreach (bool l1 in goal) | ||
85 | findallAnswers.add(); | ||
86 | return findallAnswers.result(Bag); | ||
87 | } | ||
88 | |||
89 | /// <summary> | ||
90 | /// Like findall, except return an array of the results. | ||
91 | /// </summary> | ||
92 | /// <param name="template"></param> | ||
93 | /// <param name="goal"></param> | ||
94 | /// <returns></returns> | ||
95 | public static List<object> findallArray(object Template, IEnumerable<bool> goal) | ||
96 | { | ||
97 | FindallAnswers findallAnswers = new FindallAnswers(Template); | ||
98 | foreach (bool l1 in goal) | ||
99 | findallAnswers.add(); | ||
100 | return findallAnswers.resultArray(); | ||
101 | } | ||
102 | } | ||
103 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor.cs new file mode 100644 index 0000000..3ba1021 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor.cs | |||
@@ -0,0 +1,188 @@ | |||
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.DotNetEngine.Compiler.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 | public IEnumerable<bool> unify(object arg) | ||
102 | { | ||
103 | arg = YP.getValue(arg); | ||
104 | if (arg is Functor) | ||
105 | { | ||
106 | Functor argFunctor = (Functor)arg; | ||
107 | if (_name.Equals(argFunctor._name)) | ||
108 | return YP.unifyArrays(_args, argFunctor._args); | ||
109 | else | ||
110 | return YP.fail(); | ||
111 | } | ||
112 | else if (arg is Variable) | ||
113 | return ((Variable)arg).unify(this); | ||
114 | else | ||
115 | return YP.fail(); | ||
116 | } | ||
117 | |||
118 | public override string ToString() | ||
119 | { | ||
120 | string result = _name + "(" + YP.getValue(_args[0]); | ||
121 | for (int i = 1; i < _args.Length; ++i) | ||
122 | result += ", " + YP.getValue(_args[i]); | ||
123 | result += ")"; | ||
124 | return result; | ||
125 | } | ||
126 | |||
127 | public bool termEqual(object term) | ||
128 | { | ||
129 | term = YP.getValue(term); | ||
130 | if (term is Functor) | ||
131 | { | ||
132 | Functor termFunctor = (Functor)term; | ||
133 | if (_name.Equals(termFunctor._name) && _args.Length == termFunctor._args.Length) | ||
134 | { | ||
135 | for (int i = 0; i < _args.Length; ++i) | ||
136 | { | ||
137 | if (!YP.termEqual(_args[i], termFunctor._args[i])) | ||
138 | return false; | ||
139 | } | ||
140 | return true; | ||
141 | } | ||
142 | } | ||
143 | return false; | ||
144 | } | ||
145 | |||
146 | public bool lessThan(Functor functor) | ||
147 | { | ||
148 | // Do the equal check first since it is faster. | ||
149 | if (!_name.Equals(functor._name)) | ||
150 | return _name.lessThan(functor._name); | ||
151 | |||
152 | if (_args.Length != functor._args.Length) | ||
153 | return _args.Length < functor._args.Length; | ||
154 | |||
155 | for (int i = 0; i < _args.Length; ++i) | ||
156 | { | ||
157 | if (!YP.termEqual(_args[i], functor._args[i])) | ||
158 | return YP.termLessThan(_args[i], functor._args[i]); | ||
159 | } | ||
160 | |||
161 | return false; | ||
162 | } | ||
163 | |||
164 | public bool ground() | ||
165 | { | ||
166 | for (int i = 0; i < _args.Length; ++i) | ||
167 | { | ||
168 | if (!YP.ground(_args[i])) | ||
169 | return false; | ||
170 | } | ||
171 | return true; | ||
172 | } | ||
173 | |||
174 | public void addUniqueVariables(List<Variable> variableSet) | ||
175 | { | ||
176 | for (int i = 0; i < _args.Length; ++i) | ||
177 | YP.addUniqueVariables(_args[i], variableSet); | ||
178 | } | ||
179 | |||
180 | public object makeCopy(Variable.CopyStore copyStore) | ||
181 | { | ||
182 | object[] argsCopy = new object[_args.Length]; | ||
183 | for (int i = 0; i < _args.Length; ++i) | ||
184 | argsCopy[i] = YP.makeCopy(_args[i], copyStore); | ||
185 | return new Functor(_name, argsCopy); | ||
186 | } | ||
187 | } | ||
188 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor1.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor1.cs new file mode 100644 index 0000000..33e2a32 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor1.cs | |||
@@ -0,0 +1,111 @@ | |||
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.DotNetEngine.Compiler.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 | public IEnumerable<bool> unify(object arg) | ||
53 | { | ||
54 | arg = YP.getValue(arg); | ||
55 | if (arg is Functor1) | ||
56 | { | ||
57 | Functor1 argFunctor = (Functor1)arg; | ||
58 | if (_name.Equals(argFunctor._name)) | ||
59 | { | ||
60 | foreach (bool l1 in YP.unify(_arg1, argFunctor._arg1)) | ||
61 | yield return false; | ||
62 | } | ||
63 | } | ||
64 | else if (arg is Variable) | ||
65 | { | ||
66 | foreach (bool l1 in ((Variable)arg).unify(this)) | ||
67 | yield return false; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | public override string ToString() | ||
72 | { | ||
73 | return _name + "(" + YP.getValue(_arg1) + ")"; | ||
74 | } | ||
75 | |||
76 | public bool termEqual(object term) | ||
77 | { | ||
78 | term = YP.getValue(term); | ||
79 | if (term is Functor1) | ||
80 | { | ||
81 | Functor1 termFunctor = (Functor1)term; | ||
82 | return _name.Equals(termFunctor._name) && YP.termEqual(_arg1, termFunctor._arg1); | ||
83 | } | ||
84 | return false; | ||
85 | } | ||
86 | |||
87 | public bool lessThan(Functor1 functor) | ||
88 | { | ||
89 | // Do the equal check first since it is faster. | ||
90 | if (!_name.Equals(functor._name)) | ||
91 | return _name.lessThan(functor._name); | ||
92 | |||
93 | return YP.termLessThan(_arg1, functor._arg1); | ||
94 | } | ||
95 | |||
96 | public bool ground() | ||
97 | { | ||
98 | return YP.ground(_arg1); | ||
99 | } | ||
100 | |||
101 | public void addUniqueVariables(List<Variable> variableSet) | ||
102 | { | ||
103 | YP.addUniqueVariables(_arg1, variableSet); | ||
104 | } | ||
105 | |||
106 | public object makeCopy(Variable.CopyStore copyStore) | ||
107 | { | ||
108 | return new Functor1(_name, YP.makeCopy(_arg1, copyStore)); | ||
109 | } | ||
110 | } | ||
111 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor2.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor2.cs new file mode 100644 index 0000000..87c5f1b --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor2.cs | |||
@@ -0,0 +1,154 @@ | |||
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.DotNetEngine.Compiler.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 | public IEnumerable<bool> unify(object arg) | ||
55 | { | ||
56 | arg = YP.getValue(arg); | ||
57 | if (arg is Functor2) | ||
58 | { | ||
59 | Functor2 argFunctor = (Functor2)arg; | ||
60 | if (_name.Equals(argFunctor._name)) | ||
61 | { | ||
62 | foreach (bool l1 in YP.unify(_arg1, argFunctor._arg1)) | ||
63 | { | ||
64 | foreach (bool l2 in YP.unify(_arg2, argFunctor._arg2)) | ||
65 | yield return false; | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | else if (arg is Variable) | ||
70 | { | ||
71 | foreach (bool l1 in ((Variable)arg).unify(this)) | ||
72 | yield return false; | ||
73 | } | ||
74 | } | ||
75 | |||
76 | public override string ToString() | ||
77 | { | ||
78 | if (_name == Atom.DOT) | ||
79 | return listPairToString(this); | ||
80 | else | ||
81 | return _name + "(" + YP.getValue(_arg1) + ", " + YP.getValue(_arg2) + ")"; | ||
82 | } | ||
83 | |||
84 | public bool termEqual(object term) | ||
85 | { | ||
86 | term = YP.getValue(term); | ||
87 | if (term is Functor2) | ||
88 | { | ||
89 | Functor2 termFunctor = (Functor2)term; | ||
90 | return _name.Equals(termFunctor._name) && YP.termEqual(_arg1, termFunctor._arg1) | ||
91 | && YP.termEqual(_arg2, termFunctor._arg2); | ||
92 | } | ||
93 | return false; | ||
94 | } | ||
95 | |||
96 | public bool lessThan(Functor2 functor) | ||
97 | { | ||
98 | // Do the equal check first since it is faster. | ||
99 | if (!_name.Equals(functor._name)) | ||
100 | return _name.lessThan(functor._name); | ||
101 | |||
102 | if (!YP.termEqual(_arg1, functor._arg1)) | ||
103 | return YP.termLessThan(_arg1, functor._arg1); | ||
104 | |||
105 | return YP.termLessThan(_arg2, functor._arg2); | ||
106 | } | ||
107 | |||
108 | public bool ground() | ||
109 | { | ||
110 | return YP.ground(_arg1) && YP.ground(_arg2); | ||
111 | } | ||
112 | |||
113 | public void addUniqueVariables(List<Variable> variableSet) | ||
114 | { | ||
115 | YP.addUniqueVariables(_arg1, variableSet); | ||
116 | YP.addUniqueVariables(_arg2, variableSet); | ||
117 | } | ||
118 | |||
119 | public object makeCopy(Variable.CopyStore copyStore) | ||
120 | { | ||
121 | return new Functor2(_name, YP.makeCopy(_arg1, copyStore), | ||
122 | YP.makeCopy(_arg2, copyStore)); | ||
123 | } | ||
124 | |||
125 | private static string listPairToString(Functor2 listPair) | ||
126 | { | ||
127 | string result = "["; | ||
128 | while (true) | ||
129 | { | ||
130 | object head = YP.getValue(listPair._arg1); | ||
131 | object tail = YP.getValue(listPair._arg2); | ||
132 | if (tail == (object)Atom.NIL) | ||
133 | { | ||
134 | result += head; | ||
135 | break; | ||
136 | } | ||
137 | else if (tail is Functor2 && ((Functor2)tail)._name == Atom.DOT) | ||
138 | { | ||
139 | result += head + ", "; | ||
140 | listPair = (Functor2)tail; | ||
141 | // Loop again. | ||
142 | } | ||
143 | else | ||
144 | { | ||
145 | // The list is not terminated with NIL. | ||
146 | result += head + "|" + tail; | ||
147 | break; | ||
148 | } | ||
149 | } | ||
150 | result += "]"; | ||
151 | return result; | ||
152 | } | ||
153 | } | ||
154 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor3.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor3.cs new file mode 100644 index 0000000..74418c4 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor3.cs | |||
@@ -0,0 +1,133 @@ | |||
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.DotNetEngine.Compiler.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 | public IEnumerable<bool> unify(object arg) | ||
57 | { | ||
58 | arg = YP.getValue(arg); | ||
59 | if (arg is Functor3) | ||
60 | { | ||
61 | Functor3 argFunctor = (Functor3)arg; | ||
62 | if (_name.Equals(argFunctor._name)) | ||
63 | { | ||
64 | foreach (bool l1 in YP.unify(_arg1, argFunctor._arg1)) | ||
65 | { | ||
66 | foreach (bool l2 in YP.unify(_arg2, argFunctor._arg2)) | ||
67 | { | ||
68 | foreach (bool l3 in YP.unify(_arg3, argFunctor._arg3)) | ||
69 | yield return false; | ||
70 | } | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | else if (arg is Variable) | ||
75 | { | ||
76 | foreach (bool l1 in ((Variable)arg).unify(this)) | ||
77 | yield return false; | ||
78 | } | ||
79 | } | ||
80 | |||
81 | public override string ToString() | ||
82 | { | ||
83 | return _name + "(" + YP.getValue(_arg1) + ", " + YP.getValue(_arg2) + ", " + | ||
84 | YP.getValue(_arg3) + ")"; | ||
85 | } | ||
86 | |||
87 | public bool termEqual(object term) | ||
88 | { | ||
89 | term = YP.getValue(term); | ||
90 | if (term is Functor3) | ||
91 | { | ||
92 | Functor3 termFunctor = (Functor3)term; | ||
93 | return _name.Equals(termFunctor._name) && YP.termEqual(_arg1, termFunctor._arg1) | ||
94 | && YP.termEqual(_arg2, termFunctor._arg2) | ||
95 | && YP.termEqual(_arg3, termFunctor._arg3); | ||
96 | } | ||
97 | return false; | ||
98 | } | ||
99 | |||
100 | public bool lessThan(Functor3 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 | if (!YP.termEqual(_arg1, functor._arg1)) | ||
107 | return YP.termLessThan(_arg1, functor._arg1); | ||
108 | |||
109 | if (!YP.termEqual(_arg2, functor._arg2)) | ||
110 | return YP.termLessThan(_arg2, functor._arg2); | ||
111 | |||
112 | return YP.termLessThan(_arg3, functor._arg3); | ||
113 | } | ||
114 | |||
115 | public bool ground() | ||
116 | { | ||
117 | return YP.ground(_arg1) && YP.ground(_arg2) && YP.ground(_arg3); | ||
118 | } | ||
119 | |||
120 | public void addUniqueVariables(List<Variable> variableSet) | ||
121 | { | ||
122 | YP.addUniqueVariables(_arg1, variableSet); | ||
123 | YP.addUniqueVariables(_arg2, variableSet); | ||
124 | YP.addUniqueVariables(_arg3, variableSet); | ||
125 | } | ||
126 | |||
127 | public object makeCopy(Variable.CopyStore copyStore) | ||
128 | { | ||
129 | return new Functor3(_name, YP.makeCopy(_arg1, copyStore), | ||
130 | YP.makeCopy(_arg2, copyStore), YP.makeCopy(_arg3, copyStore)); | ||
131 | } | ||
132 | } | ||
133 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/IndexedAnswers.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/IndexedAnswers.cs new file mode 100644 index 0000000..3eac5fa --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/IndexedAnswers.cs | |||
@@ -0,0 +1,288 @@ | |||
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.DotNetEngine.Compiler.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 | // addAnswer adds the answer here and indexes it later. | ||
43 | private List<object[]> _allAnswers = new List<object[]>(); | ||
44 | // The key has the arity of answers with non-null values for each indexed arg. The value | ||
45 | // is a list of the matching answers. The signature is implicit in the pattern on non-null index args. | ||
46 | private Dictionary<HashedList, List<object[]>> _indexedAnswers = | ||
47 | new Dictionary<HashedList, List<object[]>>(); | ||
48 | // Keeps track of whether we have started adding entries to _indexedAnswers for the signature. | ||
49 | private Dictionary<int, object> _gotAnswersForSignature = new Dictionary<int, object>(); | ||
50 | private const int MAX_INDEX_ARGS = 31; | ||
51 | |||
52 | public IndexedAnswers() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | /// <summary> | ||
57 | /// Elements of answer must be ground, since arguments with unbound variables make this | ||
58 | /// into a dynamic rule which we don't index. | ||
59 | /// </summary> | ||
60 | /// <param name="answer"></param> | ||
61 | public void addAnswer(object[] answer) | ||
62 | { | ||
63 | // Store a copy of the answer array. | ||
64 | object[] answerCopy = new object[answer.Length]; | ||
65 | Variable.CopyStore copyStore = new Variable.CopyStore(); | ||
66 | for (int i = 0; i < answer.Length; ++i) | ||
67 | answerCopy[i] = YP.makeCopy(answer[i], copyStore); | ||
68 | if (copyStore.getNUniqueVariables() > 0) | ||
69 | throw new InvalidOperationException | ||
70 | ("Elements of answer must be ground, but found " + copyStore.getNUniqueVariables() + | ||
71 | " unbound variables"); | ||
72 | _allAnswers.Add(answerCopy); | ||
73 | |||
74 | // If match has already indexed answers for a signature, we need to add | ||
75 | // this to the existing indexed answers. | ||
76 | foreach(int signature in _gotAnswersForSignature.Keys) | ||
77 | indexAnswerForSignature(answerCopy, signature); | ||
78 | } | ||
79 | |||
80 | private void indexAnswerForSignature(object[] answer, int signature) | ||
81 | { | ||
82 | // First find out which of the answer values can be used as an index. | ||
83 | object[] indexValues = new object[answer.Length]; | ||
84 | for (int i = 0; i < answer.Length; ++i) | ||
85 | { | ||
86 | // We limit the number of indexed args in a 32-bit signature. | ||
87 | if (i >= MAX_INDEX_ARGS) | ||
88 | indexValues[i] = null; | ||
89 | else | ||
90 | indexValues[i] = getIndexValue(YP.getValue(answer[i])); | ||
91 | } | ||
92 | |||
93 | // We need an entry in indexArgs from indexValues for each 1 bit in signature. | ||
94 | HashedList indexArgs = new HashedList(indexValues.Length); | ||
95 | for (int i = 0; i < indexValues.Length; ++i) | ||
96 | { | ||
97 | if ((signature & (1 << i)) == 0) | ||
98 | indexArgs.Add(null); | ||
99 | else | ||
100 | { | ||
101 | if (indexValues[i] == null) | ||
102 | // The signature wants an index value here, but we don't have one so | ||
103 | // we can't add it as an answer for this signature. | ||
104 | return; | ||
105 | else | ||
106 | indexArgs.Add(indexValues[i]); | ||
107 | } | ||
108 | } | ||
109 | |||
110 | // Add the answer to the answers list for indexArgs, creating the entry if needed. | ||
111 | List<object[]> answers; | ||
112 | if (!_indexedAnswers.TryGetValue(indexArgs, out answers)) | ||
113 | { | ||
114 | answers = new List<object[]>(); | ||
115 | _indexedAnswers[indexArgs] = answers; | ||
116 | } | ||
117 | answers.Add(answer); | ||
118 | } | ||
119 | |||
120 | public IEnumerable<bool> match(object[] arguments) | ||
121 | { | ||
122 | // Set up indexArgs, up to arg position MAX_INDEX_ARGS. The signature has a 1 bit for | ||
123 | // each non-null index arg. | ||
124 | HashedList indexArgs = new HashedList(arguments.Length); | ||
125 | bool gotAllIndexArgs = true; | ||
126 | int signature = 0; | ||
127 | for (int i = 0; i < arguments.Length; ++i) | ||
128 | { | ||
129 | object indexValue = null; | ||
130 | if (i < MAX_INDEX_ARGS) | ||
131 | { | ||
132 | // We limit the number of args in a 32-bit signature. | ||
133 | indexValue = getIndexValue(YP.getValue(arguments[i])); | ||
134 | if (indexValue != null) | ||
135 | signature += (1 << i); | ||
136 | } | ||
137 | if (indexValue == null) | ||
138 | gotAllIndexArgs = false; | ||
139 | indexArgs.Add(indexValue); | ||
140 | } | ||
141 | |||
142 | List<object[]> answers; | ||
143 | if (signature == 0) | ||
144 | // No index args, so we have to match from _allAnswers. | ||
145 | answers = _allAnswers; | ||
146 | else | ||
147 | { | ||
148 | if (!_gotAnswersForSignature.ContainsKey(signature)) | ||
149 | { | ||
150 | // We need to create the entry in _indexedAnswers. | ||
151 | foreach (object[] answer in _allAnswers) | ||
152 | indexAnswerForSignature(answer, signature); | ||
153 | // Mark that we did this signature. | ||
154 | _gotAnswersForSignature[signature] = null; | ||
155 | } | ||
156 | if (!_indexedAnswers.TryGetValue(indexArgs, out answers)) | ||
157 | yield break; | ||
158 | } | ||
159 | |||
160 | if (gotAllIndexArgs) | ||
161 | { | ||
162 | // All the arguments were already bound, so we don't need to do bindings. | ||
163 | yield return false; | ||
164 | yield break; | ||
165 | } | ||
166 | |||
167 | // Find matches in answers. | ||
168 | IEnumerator<bool>[] iterators = new IEnumerator<bool>[arguments.Length]; | ||
169 | foreach (object[] answer in answers) | ||
170 | { | ||
171 | bool gotMatch = true; | ||
172 | int nIterators = 0; | ||
173 | // Try to bind all the arguments. | ||
174 | for (int i = 0; i < arguments.Length; ++i) | ||
175 | { | ||
176 | if (indexArgs[i] != null) | ||
177 | // We already matched this argument by looking up _indexedAnswers. | ||
178 | continue; | ||
179 | |||
180 | IEnumerator<bool> iterator = YP.unify(arguments[i], answer[i]).GetEnumerator(); | ||
181 | iterators[nIterators++] = iterator; | ||
182 | // MoveNext() is true if YP.unify succeeds. | ||
183 | if (!iterator.MoveNext()) | ||
184 | { | ||
185 | gotMatch = false; | ||
186 | break; | ||
187 | } | ||
188 | } | ||
189 | |||
190 | try | ||
191 | { | ||
192 | if (gotMatch) | ||
193 | yield return false; | ||
194 | } | ||
195 | finally | ||
196 | { | ||
197 | // Manually finalize all the iterators. | ||
198 | for (int i = 0; i < nIterators; ++i) | ||
199 | iterators[i].Dispose(); | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | |||
204 | /// <summary> | ||
205 | /// A HashedList extends an ArrayList with methods to get a hash and to check equality | ||
206 | /// based on the elements of the list. | ||
207 | /// </summary> | ||
208 | public class HashedList : ArrayList | ||
209 | { | ||
210 | private bool _gotHashCode = false; | ||
211 | private int _hashCode; | ||
212 | |||
213 | public HashedList() | ||
214 | : base() | ||
215 | { | ||
216 | } | ||
217 | |||
218 | public HashedList(int capacity) | ||
219 | : base(capacity) | ||
220 | { | ||
221 | } | ||
222 | |||
223 | public HashedList(ICollection c) | ||
224 | : base(c) | ||
225 | { | ||
226 | } | ||
227 | |||
228 | // Debug: Should override all the other methods that change this. | ||
229 | public override int Add(object value) | ||
230 | { | ||
231 | _gotHashCode = false; | ||
232 | return base.Add(value); | ||
233 | } | ||
234 | |||
235 | public override int GetHashCode() | ||
236 | { | ||
237 | if (!_gotHashCode) | ||
238 | { | ||
239 | int hashCode = 1; | ||
240 | foreach (object obj in this) | ||
241 | hashCode = 31 * hashCode + (obj == null ? 0 : obj.GetHashCode()); | ||
242 | _hashCode = hashCode; | ||
243 | _gotHashCode = true; | ||
244 | } | ||
245 | return _hashCode; | ||
246 | } | ||
247 | |||
248 | public override bool Equals(object obj) | ||
249 | { | ||
250 | if (!(obj is ArrayList)) | ||
251 | return false; | ||
252 | |||
253 | ArrayList objList = (ArrayList)obj; | ||
254 | if (objList.Count != Count) | ||
255 | return false; | ||
256 | |||
257 | for (int i = 0; i < Count; ++i) | ||
258 | { | ||
259 | object value = objList[i]; | ||
260 | if (value == null) | ||
261 | { | ||
262 | if (this[i] != null) | ||
263 | return false; | ||
264 | } | ||
265 | else | ||
266 | { | ||
267 | if (!value.Equals(this[i])) | ||
268 | return false; | ||
269 | } | ||
270 | } | ||
271 | return true; | ||
272 | } | ||
273 | } | ||
274 | |||
275 | /// <summary> | ||
276 | /// If we keep an index on value, return the value, or null if we don't index it. | ||
277 | /// </summary> | ||
278 | /// <param name="value">the term to examine. Assume you already called YP.getValue(value)</param> | ||
279 | /// <returns></returns> | ||
280 | public static object getIndexValue(object value) | ||
281 | { | ||
282 | if (value is Atom || value is string || value is Int32 || value is DateTime) | ||
283 | return value; | ||
284 | else | ||
285 | return null; | ||
286 | } | ||
287 | } | ||
288 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/ListPair.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/ListPair.cs new file mode 100644 index 0000000..b16e8a4 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/ListPair.cs | |||
@@ -0,0 +1,156 @@ | |||
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.DotNetEngine.Compiler.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 | /// This does not call YP.getValue on each element. | ||
136 | /// </summary> | ||
137 | /// <param name="list"></param> | ||
138 | /// <returns></returns> | ||
139 | public static object[] toArray(object list) | ||
140 | { | ||
141 | list = YP.getValue(list); | ||
142 | if (list.Equals(Atom.NIL)) | ||
143 | return new object[0]; | ||
144 | |||
145 | List<object> result = new List<object>(); | ||
146 | for (object element = list; | ||
147 | element is Functor2 && ((Functor2)element)._name == Atom.DOT; | ||
148 | element = YP.getValue(((Functor2)element)._arg2)) | ||
149 | result.Add(((Functor2)element)._arg1); | ||
150 | |||
151 | if (result.Count <= 0) | ||
152 | return null; | ||
153 | return result.ToArray(); | ||
154 | } | ||
155 | } | ||
156 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Parser.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Parser.cs new file mode 100644 index 0000000..7ef5c51 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Parser.cs | |||
@@ -0,0 +1,4457 @@ | |||
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.DotNetEngine.Compiler.YieldProlog | ||
35 | { | ||
36 | public class Parser | ||
37 | { | ||
38 | public static IEnumerable<bool> formatError(object Output, object Format, object Arguments) | ||
39 | { | ||
40 | // Debug: Simple implementation for now. | ||
41 | YP.write(Format); | ||
42 | YP.write(Arguments); | ||
43 | YP.nl(); | ||
44 | yield return false; | ||
45 | } | ||
46 | |||
47 | // Debug: Hand-modify this central predicate to do tail recursion. | ||
48 | public static IEnumerable<bool> read_tokens(object arg1, object arg2, object arg3) | ||
49 | { | ||
50 | bool repeat = true; | ||
51 | while (repeat) | ||
52 | { | ||
53 | repeat = false; | ||
54 | { | ||
55 | object C1 = arg1; | ||
56 | object Dict = arg2; | ||
57 | object Tokens = arg3; | ||
58 | Variable C2 = new Variable(); | ||
59 | if (YP.lessThanOrEqual(C1, new ListPair(32, Atom.NIL))) | ||
60 | { | ||
61 | if (YP.greaterThanOrEqual(C1, 0)) | ||
62 | { | ||
63 | foreach (bool l4 in YP.get_code(C2)) | ||
64 | { | ||
65 | #if false | ||
66 | foreach (bool l5 in read_tokens(C2, Dict, Tokens)) | ||
67 | { | ||
68 | yield return false; | ||
69 | } | ||
70 | #endif | ||
71 | arg1 = YP.getValue(C2); | ||
72 | arg2 = YP.getValue(Dict); | ||
73 | arg3 = YP.getValue(Tokens); | ||
74 | repeat = true; | ||
75 | } | ||
76 | } | ||
77 | goto cutIf1; | ||
78 | } | ||
79 | if (YP.greaterThanOrEqual(C1, new ListPair(97, Atom.NIL))) | ||
80 | { | ||
81 | if (YP.lessThanOrEqual(C1, new ListPair(122, Atom.NIL))) | ||
82 | { | ||
83 | foreach (bool l4 in read_identifier(C1, Dict, Tokens)) | ||
84 | { | ||
85 | yield return false; | ||
86 | } | ||
87 | goto cutIf2; | ||
88 | } | ||
89 | } | ||
90 | if (YP.greaterThanOrEqual(C1, new ListPair(65, Atom.NIL))) | ||
91 | { | ||
92 | if (YP.lessThanOrEqual(C1, new ListPair(90, Atom.NIL))) | ||
93 | { | ||
94 | foreach (bool l4 in read_variable(C1, Dict, Tokens)) | ||
95 | { | ||
96 | yield return false; | ||
97 | } | ||
98 | goto cutIf3; | ||
99 | } | ||
100 | } | ||
101 | if (YP.greaterThanOrEqual(C1, new ListPair(48, Atom.NIL))) | ||
102 | { | ||
103 | if (YP.lessThanOrEqual(C1, new ListPair(57, Atom.NIL))) | ||
104 | { | ||
105 | foreach (bool l4 in read_number(C1, Dict, Tokens)) | ||
106 | { | ||
107 | yield return false; | ||
108 | } | ||
109 | goto cutIf4; | ||
110 | } | ||
111 | } | ||
112 | if (YP.lessThan(C1, 127)) | ||
113 | { | ||
114 | foreach (bool l3 in read_special(C1, Dict, Tokens)) | ||
115 | { | ||
116 | yield return false; | ||
117 | } | ||
118 | goto cutIf5; | ||
119 | } | ||
120 | if (YP.lessThanOrEqual(C1, 160)) | ||
121 | { | ||
122 | foreach (bool l3 in YP.get_code(C2)) | ||
123 | { | ||
124 | #if false | ||
125 | foreach (bool l4 in read_tokens(C2, Dict, Tokens)) | ||
126 | { | ||
127 | yield return false; | ||
128 | } | ||
129 | #endif | ||
130 | arg1 = YP.getValue(C2); | ||
131 | arg2 = YP.getValue(Dict); | ||
132 | arg3 = YP.getValue(Tokens); | ||
133 | repeat = true; | ||
134 | } | ||
135 | goto cutIf6; | ||
136 | } | ||
137 | if (YP.greaterThanOrEqual(C1, 223)) | ||
138 | { | ||
139 | if (YP.notEqual(C1, 247)) | ||
140 | { | ||
141 | foreach (bool l4 in read_identifier(C1, Dict, Tokens)) | ||
142 | { | ||
143 | yield return false; | ||
144 | } | ||
145 | goto cutIf7; | ||
146 | } | ||
147 | } | ||
148 | if (YP.greaterThanOrEqual(C1, 192)) | ||
149 | { | ||
150 | if (YP.notEqual(C1, 215)) | ||
151 | { | ||
152 | foreach (bool l4 in read_variable(C1, Dict, Tokens)) | ||
153 | { | ||
154 | yield return false; | ||
155 | } | ||
156 | goto cutIf8; | ||
157 | } | ||
158 | } | ||
159 | if (YP.notEqual(C1, 170)) | ||
160 | { | ||
161 | if (YP.notEqual(C1, 186)) | ||
162 | { | ||
163 | foreach (bool l4 in read_symbol(C1, Dict, Tokens)) | ||
164 | { | ||
165 | yield return false; | ||
166 | } | ||
167 | goto cutIf9; | ||
168 | } | ||
169 | } | ||
170 | foreach (bool l2 in read_identifier(C1, Dict, Tokens)) | ||
171 | { | ||
172 | yield return false; | ||
173 | } | ||
174 | cutIf9: | ||
175 | cutIf8: | ||
176 | cutIf7: | ||
177 | cutIf6: | ||
178 | cutIf5: | ||
179 | cutIf4: | ||
180 | cutIf3: | ||
181 | cutIf2: | ||
182 | cutIf1: | ||
183 | { } | ||
184 | } | ||
185 | } | ||
186 | } | ||
187 | |||
188 | // Compiler output follows. | ||
189 | |||
190 | class YPInnerClass { } | ||
191 | static Type getDeclaringClass() { return typeof(YPInnerClass).DeclaringType; } | ||
192 | |||
193 | public static IEnumerable<bool> parseInput(object TermList) | ||
194 | { | ||
195 | { | ||
196 | Variable TermAndVariables = new Variable(); | ||
197 | FindallAnswers findallAnswers1 = new FindallAnswers(TermAndVariables); | ||
198 | foreach (bool l2 in parseInputHelper(TermAndVariables)) | ||
199 | { | ||
200 | findallAnswers1.add(); | ||
201 | } | ||
202 | foreach (bool l2 in findallAnswers1.result(TermList)) | ||
203 | { | ||
204 | yield return false; | ||
205 | } | ||
206 | } | ||
207 | } | ||
208 | |||
209 | public static IEnumerable<bool> parseInputHelper(object arg1) | ||
210 | { | ||
211 | { | ||
212 | Variable Term = new Variable(); | ||
213 | Variable Variables = new Variable(); | ||
214 | Variable Answer = new Variable(); | ||
215 | Variable x4 = new Variable(); | ||
216 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"f", Term, Variables))) | ||
217 | { | ||
218 | foreach (bool l3 in YP.repeat()) | ||
219 | { | ||
220 | foreach (bool l4 in portable_read3(Answer, Variables, x4)) | ||
221 | { | ||
222 | foreach (bool l5 in remove_pos(Answer, Term)) | ||
223 | { | ||
224 | if (YP.termEqual(Term, Atom.a(@"end_of_file"))) | ||
225 | { | ||
226 | yield break; | ||
227 | goto cutIf1; | ||
228 | } | ||
229 | yield return false; | ||
230 | cutIf1: | ||
231 | { } | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | } | ||
236 | } | ||
237 | } | ||
238 | |||
239 | public static IEnumerable<bool> clear_errors() | ||
240 | { | ||
241 | { | ||
242 | yield return false; | ||
243 | } | ||
244 | } | ||
245 | |||
246 | public static IEnumerable<bool> remove_pos(object arg1, object arg2) | ||
247 | { | ||
248 | { | ||
249 | Variable X = new Variable(); | ||
250 | foreach (bool l2 in YP.unify(arg1, X)) | ||
251 | { | ||
252 | foreach (bool l3 in YP.unify(arg2, X)) | ||
253 | { | ||
254 | if (YP.var(X)) | ||
255 | { | ||
256 | yield return true; | ||
257 | yield break; | ||
258 | } | ||
259 | } | ||
260 | } | ||
261 | } | ||
262 | { | ||
263 | object X = arg2; | ||
264 | Variable _Pos = new Variable(); | ||
265 | Variable _Name = new Variable(); | ||
266 | foreach (bool l2 in YP.unify(arg1, new Functor3(@"$VAR", _Pos, _Name, X))) | ||
267 | { | ||
268 | if (YP.var(X)) | ||
269 | { | ||
270 | yield return true; | ||
271 | yield break; | ||
272 | } | ||
273 | } | ||
274 | } | ||
275 | { | ||
276 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
277 | { | ||
278 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
279 | { | ||
280 | yield return true; | ||
281 | yield break; | ||
282 | } | ||
283 | } | ||
284 | } | ||
285 | { | ||
286 | Variable H = new Variable(); | ||
287 | Variable T = new Variable(); | ||
288 | Variable NH = new Variable(); | ||
289 | Variable NT = new Variable(); | ||
290 | foreach (bool l2 in YP.unify(arg1, new ListPair(H, T))) | ||
291 | { | ||
292 | foreach (bool l3 in YP.unify(arg2, new ListPair(NH, NT))) | ||
293 | { | ||
294 | foreach (bool l4 in remove_pos(H, NH)) | ||
295 | { | ||
296 | foreach (bool l5 in remove_pos(T, NT)) | ||
297 | { | ||
298 | yield return false; | ||
299 | } | ||
300 | } | ||
301 | yield break; | ||
302 | } | ||
303 | } | ||
304 | } | ||
305 | { | ||
306 | Variable A = new Variable(); | ||
307 | Variable B = new Variable(); | ||
308 | Variable NA = new Variable(); | ||
309 | Variable NB = new Variable(); | ||
310 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", A, B))) | ||
311 | { | ||
312 | foreach (bool l3 in YP.unify(arg2, new Functor2(@",", NA, NB))) | ||
313 | { | ||
314 | foreach (bool l4 in remove_pos(A, NA)) | ||
315 | { | ||
316 | foreach (bool l5 in remove_pos(B, NB)) | ||
317 | { | ||
318 | yield return false; | ||
319 | } | ||
320 | } | ||
321 | yield break; | ||
322 | } | ||
323 | } | ||
324 | } | ||
325 | { | ||
326 | Variable Atom_1 = new Variable(); | ||
327 | Variable _F = new Variable(); | ||
328 | foreach (bool l2 in YP.unify(arg1, Atom_1)) | ||
329 | { | ||
330 | foreach (bool l3 in YP.unify(arg2, Atom_1)) | ||
331 | { | ||
332 | foreach (bool l4 in YP.functor(Atom_1, _F, 0)) | ||
333 | { | ||
334 | yield return false; | ||
335 | } | ||
336 | } | ||
337 | } | ||
338 | } | ||
339 | { | ||
340 | object Term = arg1; | ||
341 | object NewTerm = arg2; | ||
342 | Variable Func = new Variable(); | ||
343 | Variable _Pos = new Variable(); | ||
344 | Variable Args = new Variable(); | ||
345 | Variable NArgs = new Variable(); | ||
346 | if (YP.nonvar(Term)) | ||
347 | { | ||
348 | foreach (bool l3 in YP.univ(Term, new ListPair(Func, new ListPair(_Pos, Args)))) | ||
349 | { | ||
350 | foreach (bool l4 in remove_pos(Args, NArgs)) | ||
351 | { | ||
352 | foreach (bool l5 in YP.univ(NewTerm, new ListPair(Func, NArgs))) | ||
353 | { | ||
354 | yield return false; | ||
355 | } | ||
356 | } | ||
357 | } | ||
358 | } | ||
359 | } | ||
360 | } | ||
361 | |||
362 | public static IEnumerable<bool> portable_read_position(object Term, object PosTerm, object Syntax) | ||
363 | { | ||
364 | { | ||
365 | foreach (bool l2 in portable_read(PosTerm, Syntax)) | ||
366 | { | ||
367 | foreach (bool l3 in remove_pos(PosTerm, Term)) | ||
368 | { | ||
369 | yield return false; | ||
370 | } | ||
371 | } | ||
372 | } | ||
373 | } | ||
374 | |||
375 | public static IEnumerable<bool> portable_read(object Answer, object Syntax) | ||
376 | { | ||
377 | { | ||
378 | Variable Tokens = new Variable(); | ||
379 | Variable ParseTokens = new Variable(); | ||
380 | foreach (bool l2 in read_tokens1(Tokens)) | ||
381 | { | ||
382 | foreach (bool l3 in remove_comments(Tokens, ParseTokens, Syntax)) | ||
383 | { | ||
384 | foreach (bool l4 in parse2(ParseTokens, Answer)) | ||
385 | { | ||
386 | yield return false; | ||
387 | } | ||
388 | } | ||
389 | } | ||
390 | } | ||
391 | } | ||
392 | |||
393 | public static IEnumerable<bool> portable_read3(object Answer, object Variables, object Syntax) | ||
394 | { | ||
395 | { | ||
396 | Variable Tokens = new Variable(); | ||
397 | Variable ParseTokens = new Variable(); | ||
398 | foreach (bool l2 in read_tokens2(Tokens, Variables)) | ||
399 | { | ||
400 | foreach (bool l3 in remove_comments(Tokens, ParseTokens, Syntax)) | ||
401 | { | ||
402 | foreach (bool l4 in parse2(ParseTokens, Answer)) | ||
403 | { | ||
404 | yield return false; | ||
405 | } | ||
406 | } | ||
407 | } | ||
408 | } | ||
409 | } | ||
410 | |||
411 | public static IEnumerable<bool> remove_comments(object arg1, object arg2, object arg3) | ||
412 | { | ||
413 | { | ||
414 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
415 | { | ||
416 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
417 | { | ||
418 | foreach (bool l4 in YP.unify(arg3, Atom.NIL)) | ||
419 | { | ||
420 | yield return false; | ||
421 | } | ||
422 | } | ||
423 | } | ||
424 | } | ||
425 | { | ||
426 | object Ys = arg2; | ||
427 | Variable S = new Variable(); | ||
428 | Variable E = new Variable(); | ||
429 | Variable Xs = new Variable(); | ||
430 | Variable Zs = new Variable(); | ||
431 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"comment", S, E), Xs))) | ||
432 | { | ||
433 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2(@"comment", S, E), Zs))) | ||
434 | { | ||
435 | foreach (bool l4 in remove_comments(Xs, Ys, Zs)) | ||
436 | { | ||
437 | yield return false; | ||
438 | } | ||
439 | yield break; | ||
440 | } | ||
441 | } | ||
442 | } | ||
443 | { | ||
444 | Variable Pos = new Variable(); | ||
445 | Variable Xs = new Variable(); | ||
446 | Variable Ys = new Variable(); | ||
447 | Variable Pos2 = new Variable(); | ||
448 | Variable Zs = new Variable(); | ||
449 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"/", Atom.a(@"["), Pos), Xs))) | ||
450 | { | ||
451 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a(@"["), Ys))) | ||
452 | { | ||
453 | foreach (bool l4 in YP.unify(arg3, new ListPair(new Functor2(@"list", Pos, Pos2), Zs))) | ||
454 | { | ||
455 | foreach (bool l5 in YP.unify(Pos2, YP.add(Pos, 1))) | ||
456 | { | ||
457 | foreach (bool l6 in remove_comments(Xs, Ys, Zs)) | ||
458 | { | ||
459 | yield return false; | ||
460 | } | ||
461 | } | ||
462 | yield break; | ||
463 | } | ||
464 | } | ||
465 | } | ||
466 | } | ||
467 | { | ||
468 | Variable Pos = new Variable(); | ||
469 | Variable Xs = new Variable(); | ||
470 | Variable Ys = new Variable(); | ||
471 | Variable Pos2 = new Variable(); | ||
472 | Variable Zs = new Variable(); | ||
473 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"/", Atom.a(@"]"), Pos), Xs))) | ||
474 | { | ||
475 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a(@"]"), Ys))) | ||
476 | { | ||
477 | foreach (bool l4 in YP.unify(arg3, new ListPair(new Functor2(@"list", Pos, Pos2), Zs))) | ||
478 | { | ||
479 | foreach (bool l5 in YP.unify(Pos2, YP.add(Pos, 1))) | ||
480 | { | ||
481 | foreach (bool l6 in remove_comments(Xs, Ys, Zs)) | ||
482 | { | ||
483 | yield return false; | ||
484 | } | ||
485 | } | ||
486 | yield break; | ||
487 | } | ||
488 | } | ||
489 | } | ||
490 | } | ||
491 | { | ||
492 | object Zs = arg3; | ||
493 | Variable Token = new Variable(); | ||
494 | Variable Xs = new Variable(); | ||
495 | Variable Ys = new Variable(); | ||
496 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, Xs))) | ||
497 | { | ||
498 | foreach (bool l3 in YP.unify(arg2, new ListPair(Token, Ys))) | ||
499 | { | ||
500 | foreach (bool l4 in remove_comments(Xs, Ys, Zs)) | ||
501 | { | ||
502 | yield return false; | ||
503 | } | ||
504 | } | ||
505 | } | ||
506 | } | ||
507 | } | ||
508 | |||
509 | public static IEnumerable<bool> expect(object Token, object arg2, object arg3) | ||
510 | { | ||
511 | { | ||
512 | object Rest = arg3; | ||
513 | foreach (bool l2 in YP.unify(arg2, new ListPair(Token, Rest))) | ||
514 | { | ||
515 | yield return true; | ||
516 | yield break; | ||
517 | } | ||
518 | } | ||
519 | { | ||
520 | object S0 = arg2; | ||
521 | object x3 = arg3; | ||
522 | foreach (bool l2 in syntax_error(new ListPair(Token, new ListPair(Atom.a(@"or"), new ListPair(Atom.a(@"operator"), new ListPair(Atom.a(@"expected"), Atom.NIL)))), S0)) | ||
523 | { | ||
524 | yield return false; | ||
525 | } | ||
526 | } | ||
527 | } | ||
528 | |||
529 | public static IEnumerable<bool> parse2(object Tokens, object Answer) | ||
530 | { | ||
531 | { | ||
532 | Variable Term = new Variable(); | ||
533 | Variable LeftOver = new Variable(); | ||
534 | foreach (bool l2 in clear_errors()) | ||
535 | { | ||
536 | foreach (bool l3 in parse(Tokens, 1200, Term, LeftOver)) | ||
537 | { | ||
538 | foreach (bool l4 in all_read(LeftOver)) | ||
539 | { | ||
540 | foreach (bool l5 in YP.unify(Answer, Term)) | ||
541 | { | ||
542 | yield return false; | ||
543 | } | ||
544 | yield break; | ||
545 | } | ||
546 | } | ||
547 | foreach (bool l3 in syntax_error(Tokens)) | ||
548 | { | ||
549 | yield return false; | ||
550 | } | ||
551 | } | ||
552 | } | ||
553 | } | ||
554 | |||
555 | public static IEnumerable<bool> all_read(object arg1) | ||
556 | { | ||
557 | { | ||
558 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
559 | { | ||
560 | yield return false; | ||
561 | } | ||
562 | } | ||
563 | { | ||
564 | Variable Token = new Variable(); | ||
565 | Variable S = new Variable(); | ||
566 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, S))) | ||
567 | { | ||
568 | foreach (bool l3 in syntax_error(new ListPair(Atom.a(@"operator"), new ListPair(Atom.a(@"expected"), new ListPair(Atom.a(@"after"), new ListPair(Atom.a(@"expression"), Atom.NIL)))), new ListPair(Token, S))) | ||
569 | { | ||
570 | yield return false; | ||
571 | } | ||
572 | } | ||
573 | } | ||
574 | } | ||
575 | |||
576 | public static IEnumerable<bool> parse(object arg1, object arg2, object arg3, object arg4) | ||
577 | { | ||
578 | { | ||
579 | object x1 = arg2; | ||
580 | object x2 = arg3; | ||
581 | object x3 = arg4; | ||
582 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
583 | { | ||
584 | foreach (bool l3 in syntax_error(new ListPair(Atom.a(@"expression"), new ListPair(Atom.a(@"expected"), Atom.NIL)), Atom.NIL)) | ||
585 | { | ||
586 | yield return false; | ||
587 | } | ||
588 | } | ||
589 | } | ||
590 | { | ||
591 | object Precedence = arg2; | ||
592 | object Term = arg3; | ||
593 | object LeftOver = arg4; | ||
594 | Variable Token = new Variable(); | ||
595 | Variable RestTokens = new Variable(); | ||
596 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, RestTokens))) | ||
597 | { | ||
598 | foreach (bool l3 in parse5(Token, RestTokens, Precedence, Term, LeftOver)) | ||
599 | { | ||
600 | yield return false; | ||
601 | } | ||
602 | } | ||
603 | } | ||
604 | } | ||
605 | |||
606 | public static IEnumerable<bool> parse5(object arg1, object arg2, object arg3, object arg4, object arg5) | ||
607 | { | ||
608 | { | ||
609 | object S0 = arg2; | ||
610 | object x2 = arg3; | ||
611 | object x3 = arg4; | ||
612 | object x4 = arg5; | ||
613 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"}"))) | ||
614 | { | ||
615 | foreach (bool l3 in cannot_start(Atom.a(@"}"), S0)) | ||
616 | { | ||
617 | yield return false; | ||
618 | } | ||
619 | } | ||
620 | } | ||
621 | { | ||
622 | object S0 = arg2; | ||
623 | object x2 = arg3; | ||
624 | object x3 = arg4; | ||
625 | object x4 = arg5; | ||
626 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"]"))) | ||
627 | { | ||
628 | foreach (bool l3 in cannot_start(Atom.a(@"]"), S0)) | ||
629 | { | ||
630 | yield return false; | ||
631 | } | ||
632 | } | ||
633 | } | ||
634 | { | ||
635 | object S0 = arg2; | ||
636 | object x2 = arg3; | ||
637 | object x3 = arg4; | ||
638 | object x4 = arg5; | ||
639 | foreach (bool l2 in YP.unify(arg1, Atom.a(@")"))) | ||
640 | { | ||
641 | foreach (bool l3 in cannot_start(Atom.a(@")"), S0)) | ||
642 | { | ||
643 | yield return false; | ||
644 | } | ||
645 | } | ||
646 | } | ||
647 | { | ||
648 | object S0 = arg2; | ||
649 | object x2 = arg3; | ||
650 | object x3 = arg4; | ||
651 | object x4 = arg5; | ||
652 | foreach (bool l2 in YP.unify(arg1, Atom.a(@","))) | ||
653 | { | ||
654 | foreach (bool l3 in cannot_start(Atom.a(@","), S0)) | ||
655 | { | ||
656 | yield return false; | ||
657 | } | ||
658 | } | ||
659 | } | ||
660 | { | ||
661 | object S0 = arg2; | ||
662 | object x2 = arg3; | ||
663 | object x3 = arg4; | ||
664 | object x4 = arg5; | ||
665 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"|"))) | ||
666 | { | ||
667 | foreach (bool l3 in cannot_start(Atom.a(@"|"), S0)) | ||
668 | { | ||
669 | yield return false; | ||
670 | } | ||
671 | } | ||
672 | } | ||
673 | { | ||
674 | object S0 = arg2; | ||
675 | object Precedence = arg3; | ||
676 | object Answer = arg4; | ||
677 | object S = arg5; | ||
678 | Variable Chars = new Variable(); | ||
679 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"string", Chars))) | ||
680 | { | ||
681 | foreach (bool l3 in exprtl0(S0, Chars, Precedence, Answer, S)) | ||
682 | { | ||
683 | yield return false; | ||
684 | } | ||
685 | } | ||
686 | } | ||
687 | { | ||
688 | object S0 = arg2; | ||
689 | object Precedence = arg3; | ||
690 | object Answer = arg4; | ||
691 | object S = arg5; | ||
692 | Variable Number = new Variable(); | ||
693 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"number", Number))) | ||
694 | { | ||
695 | foreach (bool l3 in exprtl0(S0, Number, Precedence, Answer, S)) | ||
696 | { | ||
697 | yield return false; | ||
698 | } | ||
699 | } | ||
700 | } | ||
701 | { | ||
702 | object Precedence = arg3; | ||
703 | object Answer = arg4; | ||
704 | object S = arg5; | ||
705 | Variable S1 = new Variable(); | ||
706 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"["))) | ||
707 | { | ||
708 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a(@"]"), S1))) | ||
709 | { | ||
710 | foreach (bool l4 in read_atom(new Functor2(@"/", Atom.NIL, 0), S1, Precedence, Answer, S)) | ||
711 | { | ||
712 | yield return false; | ||
713 | } | ||
714 | yield break; | ||
715 | } | ||
716 | } | ||
717 | } | ||
718 | { | ||
719 | object S1 = arg2; | ||
720 | object Precedence = arg3; | ||
721 | object Answer = arg4; | ||
722 | object S = arg5; | ||
723 | Variable Arg1 = new Variable(); | ||
724 | Variable S2 = new Variable(); | ||
725 | Variable RestArgs = new Variable(); | ||
726 | Variable S3 = new Variable(); | ||
727 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"["))) | ||
728 | { | ||
729 | foreach (bool l3 in parse(S1, 999, Arg1, S2)) | ||
730 | { | ||
731 | foreach (bool l4 in read_list(S2, RestArgs, S3)) | ||
732 | { | ||
733 | foreach (bool l5 in exprtl0(S3, new ListPair(Arg1, RestArgs), Precedence, Answer, S)) | ||
734 | { | ||
735 | yield return false; | ||
736 | } | ||
737 | yield break; | ||
738 | } | ||
739 | } | ||
740 | } | ||
741 | } | ||
742 | { | ||
743 | object S1 = arg2; | ||
744 | object Precedence = arg3; | ||
745 | object Answer = arg4; | ||
746 | object S = arg5; | ||
747 | Variable Term = new Variable(); | ||
748 | Variable S2 = new Variable(); | ||
749 | Variable S3 = new Variable(); | ||
750 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"("))) | ||
751 | { | ||
752 | foreach (bool l3 in parse(S1, 1200, Term, S2)) | ||
753 | { | ||
754 | foreach (bool l4 in expect(Atom.a(@")"), S2, S3)) | ||
755 | { | ||
756 | foreach (bool l5 in exprtl0(S3, Term, Precedence, Answer, S)) | ||
757 | { | ||
758 | yield return false; | ||
759 | } | ||
760 | yield break; | ||
761 | } | ||
762 | } | ||
763 | } | ||
764 | } | ||
765 | { | ||
766 | object S1 = arg2; | ||
767 | object Precedence = arg3; | ||
768 | object Answer = arg4; | ||
769 | object S = arg5; | ||
770 | Variable Term = new Variable(); | ||
771 | Variable S2 = new Variable(); | ||
772 | Variable S3 = new Variable(); | ||
773 | foreach (bool l2 in YP.unify(arg1, Atom.a(@" ("))) | ||
774 | { | ||
775 | foreach (bool l3 in parse(S1, 1200, Term, S2)) | ||
776 | { | ||
777 | foreach (bool l4 in expect(Atom.a(@")"), S2, S3)) | ||
778 | { | ||
779 | foreach (bool l5 in exprtl0(S3, Term, Precedence, Answer, S)) | ||
780 | { | ||
781 | yield return false; | ||
782 | } | ||
783 | yield break; | ||
784 | } | ||
785 | } | ||
786 | } | ||
787 | } | ||
788 | { | ||
789 | object Precedence = arg3; | ||
790 | object Answer = arg4; | ||
791 | object S = arg5; | ||
792 | Variable _Pos = new Variable(); | ||
793 | Variable S1 = new Variable(); | ||
794 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"/", Atom.a(@"{"), _Pos))) | ||
795 | { | ||
796 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a(@"}"), S1))) | ||
797 | { | ||
798 | foreach (bool l4 in read_atom(Atom.a(@"{}"), S1, Precedence, Answer, S)) | ||
799 | { | ||
800 | yield return false; | ||
801 | } | ||
802 | yield break; | ||
803 | } | ||
804 | } | ||
805 | } | ||
806 | { | ||
807 | object S1 = arg2; | ||
808 | object Precedence = arg3; | ||
809 | object Answer = arg4; | ||
810 | object S = arg5; | ||
811 | Variable Pos = new Variable(); | ||
812 | Variable Term = new Variable(); | ||
813 | Variable S2 = new Variable(); | ||
814 | Variable S3 = new Variable(); | ||
815 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"/", Atom.a(@"{"), Pos))) | ||
816 | { | ||
817 | foreach (bool l3 in parse(S1, 1200, Term, S2)) | ||
818 | { | ||
819 | foreach (bool l4 in expect(Atom.a(@"}"), S2, S3)) | ||
820 | { | ||
821 | foreach (bool l5 in exprtl0(S3, new Functor2(@"{}", Pos, Term), Precedence, Answer, S)) | ||
822 | { | ||
823 | yield return false; | ||
824 | } | ||
825 | yield break; | ||
826 | } | ||
827 | } | ||
828 | } | ||
829 | } | ||
830 | { | ||
831 | object Precedence = arg3; | ||
832 | object Answer = arg4; | ||
833 | object S = arg5; | ||
834 | Variable Variable_1 = new Variable(); | ||
835 | Variable Name = new Variable(); | ||
836 | Variable Pos = new Variable(); | ||
837 | Variable S1 = new Variable(); | ||
838 | Variable Arg1 = new Variable(); | ||
839 | Variable S2 = new Variable(); | ||
840 | Variable RestArgs = new Variable(); | ||
841 | Variable S3 = new Variable(); | ||
842 | Variable Term = new Variable(); | ||
843 | foreach (bool l2 in YP.unify(arg1, new Functor3(@"var", Variable_1, Name, Pos))) | ||
844 | { | ||
845 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a(@"("), S1))) | ||
846 | { | ||
847 | foreach (bool l4 in parse(S1, 999, Arg1, S2)) | ||
848 | { | ||
849 | foreach (bool l5 in read_args(S2, RestArgs, S3)) | ||
850 | { | ||
851 | 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))))) | ||
852 | { | ||
853 | foreach (bool l7 in exprtl0(S3, Term, Precedence, Answer, S)) | ||
854 | { | ||
855 | yield return false; | ||
856 | } | ||
857 | } | ||
858 | yield break; | ||
859 | } | ||
860 | } | ||
861 | yield break; | ||
862 | } | ||
863 | } | ||
864 | } | ||
865 | { | ||
866 | object S0 = arg2; | ||
867 | object Precedence = arg3; | ||
868 | object Answer = arg4; | ||
869 | object S = arg5; | ||
870 | Variable Variable_1 = new Variable(); | ||
871 | Variable Name = new Variable(); | ||
872 | Variable Pos = new Variable(); | ||
873 | foreach (bool l2 in YP.unify(arg1, new Functor3(@"var", Variable_1, Name, Pos))) | ||
874 | { | ||
875 | foreach (bool l3 in exprtl0(S0, new Functor3(@"$VAR", Pos, Name, Variable_1), Precedence, Answer, S)) | ||
876 | { | ||
877 | yield return false; | ||
878 | } | ||
879 | } | ||
880 | } | ||
881 | { | ||
882 | object S0 = arg2; | ||
883 | object Precedence = arg3; | ||
884 | object Answer = arg4; | ||
885 | object S = arg5; | ||
886 | Variable Atom_1 = new Variable(); | ||
887 | Variable P = new Variable(); | ||
888 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"atom", Atom_1, P))) | ||
889 | { | ||
890 | foreach (bool l3 in read_atom(new Functor2(@"/", Atom_1, P), S0, Precedence, Answer, S)) | ||
891 | { | ||
892 | yield return false; | ||
893 | } | ||
894 | } | ||
895 | } | ||
896 | } | ||
897 | |||
898 | public static IEnumerable<bool> read_atom(object arg1, object arg2, object Precedence, object Answer, object S) | ||
899 | { | ||
900 | { | ||
901 | Variable _Pos = new Variable(); | ||
902 | Variable Number = new Variable(); | ||
903 | Variable S1 = new Variable(); | ||
904 | Variable Negative = new Variable(); | ||
905 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"/", Atom.a(@"-"), _Pos))) | ||
906 | { | ||
907 | foreach (bool l3 in YP.unify(arg2, new ListPair(new Functor1(@"number", Number), S1))) | ||
908 | { | ||
909 | foreach (bool l4 in YP.unify(Negative, YP.negate(Number))) | ||
910 | { | ||
911 | foreach (bool l5 in exprtl0(S1, Negative, Precedence, Answer, S)) | ||
912 | { | ||
913 | yield return false; | ||
914 | } | ||
915 | } | ||
916 | yield break; | ||
917 | } | ||
918 | } | ||
919 | } | ||
920 | { | ||
921 | Variable Functor_1 = new Variable(); | ||
922 | Variable Pos = new Variable(); | ||
923 | Variable S1 = new Variable(); | ||
924 | Variable Arg1 = new Variable(); | ||
925 | Variable S2 = new Variable(); | ||
926 | Variable RestArgs = new Variable(); | ||
927 | Variable S3 = new Variable(); | ||
928 | Variable Term = new Variable(); | ||
929 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"/", Functor_1, Pos))) | ||
930 | { | ||
931 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a(@"("), S1))) | ||
932 | { | ||
933 | foreach (bool l4 in parse(S1, 999, Arg1, S2)) | ||
934 | { | ||
935 | foreach (bool l5 in read_args(S2, RestArgs, S3)) | ||
936 | { | ||
937 | foreach (bool l6 in YP.univ(Term, new ListPair(Functor_1, new ListPair(Pos, new ListPair(Arg1, RestArgs))))) | ||
938 | { | ||
939 | foreach (bool l7 in exprtl0(S3, Term, Precedence, Answer, S)) | ||
940 | { | ||
941 | yield return false; | ||
942 | } | ||
943 | } | ||
944 | yield break; | ||
945 | } | ||
946 | } | ||
947 | yield break; | ||
948 | } | ||
949 | } | ||
950 | } | ||
951 | { | ||
952 | object S0 = arg2; | ||
953 | Variable Op = new Variable(); | ||
954 | Variable Pos = new Variable(); | ||
955 | Variable Oprec = new Variable(); | ||
956 | Variable Aprec = new Variable(); | ||
957 | Variable Flag = new Variable(); | ||
958 | Variable Term = new Variable(); | ||
959 | Variable Arg = new Variable(); | ||
960 | Variable S1 = new Variable(); | ||
961 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"/", Op, Pos))) | ||
962 | { | ||
963 | foreach (bool l3 in prefixop(Op, Oprec, Aprec)) | ||
964 | { | ||
965 | foreach (bool l4 in possible_right_operand(S0, Flag)) | ||
966 | { | ||
967 | if (YP.lessThan(Flag, 0)) | ||
968 | { | ||
969 | foreach (bool l6 in YP.univ(Term, new ListPair(Op, new ListPair(Pos, Atom.NIL)))) | ||
970 | { | ||
971 | foreach (bool l7 in exprtl0(S0, Term, Precedence, Answer, S)) | ||
972 | { | ||
973 | yield return false; | ||
974 | } | ||
975 | } | ||
976 | goto cutIf1; | ||
977 | } | ||
978 | if (YP.greaterThan(Oprec, Precedence)) | ||
979 | { | ||
980 | foreach (bool l6 in syntax_error(new ListPair(Atom.a(@"prefix"), new ListPair(Atom.a(@"operator"), new ListPair(Op, new ListPair(Atom.a(@"in"), new ListPair(Atom.a(@"context"), new ListPair(Atom.a(@"with"), new ListPair(Atom.a(@"precedence"), new ListPair(Precedence, Atom.NIL)))))))), S0)) | ||
981 | { | ||
982 | yield return false; | ||
983 | } | ||
984 | goto cutIf2; | ||
985 | } | ||
986 | if (YP.greaterThan(Flag, 0)) | ||
987 | { | ||
988 | foreach (bool l6 in parse(S0, Aprec, Arg, S1)) | ||
989 | { | ||
990 | foreach (bool l7 in YP.univ(Term, new ListPair(Op, new ListPair(Pos, new ListPair(Arg, Atom.NIL))))) | ||
991 | { | ||
992 | foreach (bool l8 in exprtl(S1, Oprec, Term, Precedence, Answer, S)) | ||
993 | { | ||
994 | yield return false; | ||
995 | } | ||
996 | } | ||
997 | yield break; | ||
998 | } | ||
999 | goto cutIf3; | ||
1000 | } | ||
1001 | foreach (bool l5 in peepop(S0, S1)) | ||
1002 | { | ||
1003 | foreach (bool l6 in prefix_is_atom(S1, Oprec)) | ||
1004 | { | ||
1005 | foreach (bool l7 in exprtl(S1, Oprec, new Functor2(@"/", Op, Pos), Precedence, Answer, S)) | ||
1006 | { | ||
1007 | yield return false; | ||
1008 | } | ||
1009 | } | ||
1010 | } | ||
1011 | foreach (bool l5 in parse(S0, Aprec, Arg, S1)) | ||
1012 | { | ||
1013 | foreach (bool l6 in YP.univ(Term, new ListPair(Op, new ListPair(Pos, new ListPair(Arg, Atom.NIL))))) | ||
1014 | { | ||
1015 | foreach (bool l7 in exprtl(S1, Oprec, Term, Precedence, Answer, S)) | ||
1016 | { | ||
1017 | yield return false; | ||
1018 | } | ||
1019 | } | ||
1020 | yield break; | ||
1021 | } | ||
1022 | cutIf3: | ||
1023 | cutIf2: | ||
1024 | cutIf1: | ||
1025 | { } | ||
1026 | } | ||
1027 | yield break; | ||
1028 | } | ||
1029 | } | ||
1030 | } | ||
1031 | { | ||
1032 | object S0 = arg2; | ||
1033 | Variable Atom_1 = new Variable(); | ||
1034 | Variable Pos = new Variable(); | ||
1035 | Variable Term = new Variable(); | ||
1036 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"/", Atom_1, Pos))) | ||
1037 | { | ||
1038 | foreach (bool l3 in YP.univ(Term, new ListPair(Atom_1, new ListPair(Pos, Atom.NIL)))) | ||
1039 | { | ||
1040 | foreach (bool l4 in exprtl0(S0, Term, Precedence, Answer, S)) | ||
1041 | { | ||
1042 | yield return false; | ||
1043 | } | ||
1044 | } | ||
1045 | } | ||
1046 | } | ||
1047 | } | ||
1048 | |||
1049 | public static IEnumerable<bool> cannot_start(object Token, object S0) | ||
1050 | { | ||
1051 | { | ||
1052 | foreach (bool l2 in syntax_error(new ListPair(Token, new ListPair(Atom.a(@"cannot"), new ListPair(Atom.a(@"start"), new ListPair(Atom.a(@"an"), new ListPair(Atom.a(@"expression"), Atom.NIL))))), S0)) | ||
1053 | { | ||
1054 | yield return false; | ||
1055 | } | ||
1056 | } | ||
1057 | } | ||
1058 | |||
1059 | public static IEnumerable<bool> read_args(object arg1, object arg2, object arg3) | ||
1060 | { | ||
1061 | { | ||
1062 | object S = arg3; | ||
1063 | Variable S1 = new Variable(); | ||
1064 | Variable Term = new Variable(); | ||
1065 | Variable Rest = new Variable(); | ||
1066 | Variable S2 = new Variable(); | ||
1067 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@","), S1))) | ||
1068 | { | ||
1069 | foreach (bool l3 in YP.unify(arg2, new ListPair(Term, Rest))) | ||
1070 | { | ||
1071 | foreach (bool l4 in parse(S1, 999, Term, S2)) | ||
1072 | { | ||
1073 | foreach (bool l5 in read_args(S2, Rest, S)) | ||
1074 | { | ||
1075 | yield return false; | ||
1076 | } | ||
1077 | yield break; | ||
1078 | } | ||
1079 | yield break; | ||
1080 | } | ||
1081 | } | ||
1082 | } | ||
1083 | { | ||
1084 | object S = arg3; | ||
1085 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@")"), S))) | ||
1086 | { | ||
1087 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
1088 | { | ||
1089 | yield return true; | ||
1090 | yield break; | ||
1091 | } | ||
1092 | } | ||
1093 | } | ||
1094 | { | ||
1095 | object S = arg1; | ||
1096 | object x2 = arg2; | ||
1097 | object x3 = arg3; | ||
1098 | foreach (bool l2 in syntax_error(new ListPair(Atom.a(@", or )"), new ListPair(Atom.a(@"expected"), new ListPair(Atom.a(@"in"), new ListPair(Atom.a(@"arguments"), Atom.NIL)))), S)) | ||
1099 | { | ||
1100 | yield return false; | ||
1101 | } | ||
1102 | } | ||
1103 | } | ||
1104 | |||
1105 | public static IEnumerable<bool> read_list(object arg1, object arg2, object arg3) | ||
1106 | { | ||
1107 | { | ||
1108 | object x1 = arg2; | ||
1109 | object x2 = arg3; | ||
1110 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1111 | { | ||
1112 | foreach (bool l3 in syntax_error(new ListPair(Atom.a(@", | or ]"), new ListPair(Atom.a(@"expected"), new ListPair(Atom.a(@"in"), new ListPair(Atom.a(@"list"), Atom.NIL)))), Atom.NIL)) | ||
1113 | { | ||
1114 | yield return false; | ||
1115 | } | ||
1116 | } | ||
1117 | } | ||
1118 | { | ||
1119 | object Rest = arg2; | ||
1120 | object S = arg3; | ||
1121 | Variable Token = new Variable(); | ||
1122 | Variable S1 = new Variable(); | ||
1123 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, S1))) | ||
1124 | { | ||
1125 | foreach (bool l3 in read_list4(Token, S1, Rest, S)) | ||
1126 | { | ||
1127 | yield return false; | ||
1128 | } | ||
1129 | } | ||
1130 | } | ||
1131 | } | ||
1132 | |||
1133 | public static IEnumerable<bool> read_list4(object arg1, object arg2, object arg3, object arg4) | ||
1134 | { | ||
1135 | { | ||
1136 | object S1 = arg2; | ||
1137 | object S = arg4; | ||
1138 | Variable Term = new Variable(); | ||
1139 | Variable Rest = new Variable(); | ||
1140 | Variable S2 = new Variable(); | ||
1141 | foreach (bool l2 in YP.unify(arg1, Atom.a(@","))) | ||
1142 | { | ||
1143 | foreach (bool l3 in YP.unify(arg3, new ListPair(Term, Rest))) | ||
1144 | { | ||
1145 | foreach (bool l4 in parse(S1, 999, Term, S2)) | ||
1146 | { | ||
1147 | foreach (bool l5 in read_list(S2, Rest, S)) | ||
1148 | { | ||
1149 | yield return false; | ||
1150 | } | ||
1151 | yield break; | ||
1152 | } | ||
1153 | yield break; | ||
1154 | } | ||
1155 | } | ||
1156 | } | ||
1157 | { | ||
1158 | object S1 = arg2; | ||
1159 | object Rest = arg3; | ||
1160 | object S = arg4; | ||
1161 | Variable S2 = new Variable(); | ||
1162 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"|"))) | ||
1163 | { | ||
1164 | foreach (bool l3 in parse(S1, 999, Rest, S2)) | ||
1165 | { | ||
1166 | foreach (bool l4 in expect(Atom.a(@"]"), S2, S)) | ||
1167 | { | ||
1168 | yield return false; | ||
1169 | } | ||
1170 | yield break; | ||
1171 | } | ||
1172 | yield break; | ||
1173 | } | ||
1174 | } | ||
1175 | { | ||
1176 | Variable S1 = new Variable(); | ||
1177 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"]"))) | ||
1178 | { | ||
1179 | foreach (bool l3 in YP.unify(arg2, S1)) | ||
1180 | { | ||
1181 | foreach (bool l4 in YP.unify(arg3, Atom.NIL)) | ||
1182 | { | ||
1183 | foreach (bool l5 in YP.unify(arg4, S1)) | ||
1184 | { | ||
1185 | yield return true; | ||
1186 | yield break; | ||
1187 | } | ||
1188 | } | ||
1189 | } | ||
1190 | } | ||
1191 | } | ||
1192 | { | ||
1193 | object Token = arg1; | ||
1194 | object S1 = arg2; | ||
1195 | object x3 = arg3; | ||
1196 | object x4 = arg4; | ||
1197 | foreach (bool l2 in syntax_error(new ListPair(Atom.a(@", | or ]"), new ListPair(Atom.a(@"expected"), new ListPair(Atom.a(@"in"), new ListPair(Atom.a(@"list"), Atom.NIL)))), new ListPair(Token, S1))) | ||
1198 | { | ||
1199 | yield return false; | ||
1200 | } | ||
1201 | } | ||
1202 | } | ||
1203 | |||
1204 | public static IEnumerable<bool> possible_right_operand(object arg1, object arg2) | ||
1205 | { | ||
1206 | { | ||
1207 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1208 | { | ||
1209 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1210 | { | ||
1211 | yield return false; | ||
1212 | } | ||
1213 | } | ||
1214 | } | ||
1215 | { | ||
1216 | object Flag = arg2; | ||
1217 | Variable H = new Variable(); | ||
1218 | Variable T = new Variable(); | ||
1219 | foreach (bool l2 in YP.unify(arg1, new ListPair(H, T))) | ||
1220 | { | ||
1221 | foreach (bool l3 in possible_right_operand3(H, Flag, T)) | ||
1222 | { | ||
1223 | yield return false; | ||
1224 | } | ||
1225 | } | ||
1226 | } | ||
1227 | } | ||
1228 | |||
1229 | public static IEnumerable<bool> possible_right_operand3(object arg1, object arg2, object arg3) | ||
1230 | { | ||
1231 | { | ||
1232 | object x4 = arg3; | ||
1233 | Variable x1 = new Variable(); | ||
1234 | Variable x2 = new Variable(); | ||
1235 | Variable x3 = new Variable(); | ||
1236 | foreach (bool l2 in YP.unify(arg1, new Functor3(@"var", x1, x2, x3))) | ||
1237 | { | ||
1238 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1239 | { | ||
1240 | yield return false; | ||
1241 | } | ||
1242 | } | ||
1243 | } | ||
1244 | { | ||
1245 | object x2 = arg3; | ||
1246 | Variable x1 = new Variable(); | ||
1247 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"number", x1))) | ||
1248 | { | ||
1249 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1250 | { | ||
1251 | yield return false; | ||
1252 | } | ||
1253 | } | ||
1254 | } | ||
1255 | { | ||
1256 | object x2 = arg3; | ||
1257 | Variable x1 = new Variable(); | ||
1258 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"string", x1))) | ||
1259 | { | ||
1260 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1261 | { | ||
1262 | yield return false; | ||
1263 | } | ||
1264 | } | ||
1265 | } | ||
1266 | { | ||
1267 | object x1 = arg3; | ||
1268 | foreach (bool l2 in YP.unify(arg1, Atom.a(@" ("))) | ||
1269 | { | ||
1270 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1271 | { | ||
1272 | yield return false; | ||
1273 | } | ||
1274 | } | ||
1275 | } | ||
1276 | { | ||
1277 | object x1 = arg3; | ||
1278 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"("))) | ||
1279 | { | ||
1280 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
1281 | { | ||
1282 | yield return false; | ||
1283 | } | ||
1284 | } | ||
1285 | } | ||
1286 | { | ||
1287 | object x1 = arg3; | ||
1288 | foreach (bool l2 in YP.unify(arg1, Atom.a(@")"))) | ||
1289 | { | ||
1290 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1291 | { | ||
1292 | yield return false; | ||
1293 | } | ||
1294 | } | ||
1295 | } | ||
1296 | { | ||
1297 | Variable x1 = new Variable(); | ||
1298 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"["))) | ||
1299 | { | ||
1300 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
1301 | { | ||
1302 | foreach (bool l4 in YP.unify(arg3, new ListPair(Atom.a(@"]"), x1))) | ||
1303 | { | ||
1304 | yield return true; | ||
1305 | yield break; | ||
1306 | } | ||
1307 | } | ||
1308 | } | ||
1309 | } | ||
1310 | { | ||
1311 | object x1 = arg3; | ||
1312 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"["))) | ||
1313 | { | ||
1314 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1315 | { | ||
1316 | yield return false; | ||
1317 | } | ||
1318 | } | ||
1319 | } | ||
1320 | { | ||
1321 | object x1 = arg3; | ||
1322 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"]"))) | ||
1323 | { | ||
1324 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1325 | { | ||
1326 | yield return false; | ||
1327 | } | ||
1328 | } | ||
1329 | } | ||
1330 | { | ||
1331 | Variable x1 = new Variable(); | ||
1332 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"{"))) | ||
1333 | { | ||
1334 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
1335 | { | ||
1336 | foreach (bool l4 in YP.unify(arg3, new ListPair(Atom.a(@"}"), x1))) | ||
1337 | { | ||
1338 | yield return true; | ||
1339 | yield break; | ||
1340 | } | ||
1341 | } | ||
1342 | } | ||
1343 | } | ||
1344 | { | ||
1345 | object x1 = arg3; | ||
1346 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"{"))) | ||
1347 | { | ||
1348 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1349 | { | ||
1350 | yield return false; | ||
1351 | } | ||
1352 | } | ||
1353 | } | ||
1354 | { | ||
1355 | object x1 = arg3; | ||
1356 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"}"))) | ||
1357 | { | ||
1358 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1359 | { | ||
1360 | yield return false; | ||
1361 | } | ||
1362 | } | ||
1363 | } | ||
1364 | { | ||
1365 | object x1 = arg3; | ||
1366 | foreach (bool l2 in YP.unify(arg1, Atom.a(@","))) | ||
1367 | { | ||
1368 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1369 | { | ||
1370 | yield return false; | ||
1371 | } | ||
1372 | } | ||
1373 | } | ||
1374 | { | ||
1375 | object x1 = arg3; | ||
1376 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"|"))) | ||
1377 | { | ||
1378 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1379 | { | ||
1380 | yield return false; | ||
1381 | } | ||
1382 | } | ||
1383 | } | ||
1384 | { | ||
1385 | object x3 = arg3; | ||
1386 | Variable x1 = new Variable(); | ||
1387 | Variable x2 = new Variable(); | ||
1388 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"atom", x1, x2))) | ||
1389 | { | ||
1390 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
1391 | { | ||
1392 | yield return false; | ||
1393 | } | ||
1394 | } | ||
1395 | } | ||
1396 | } | ||
1397 | |||
1398 | public static IEnumerable<bool> peepop(object arg1, object arg2) | ||
1399 | { | ||
1400 | { | ||
1401 | Variable F = new Variable(); | ||
1402 | Variable Pos = new Variable(); | ||
1403 | Variable S1 = new Variable(); | ||
1404 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"atom", F, Pos), new ListPair(Atom.a(@"("), S1)))) | ||
1405 | { | ||
1406 | foreach (bool l3 in YP.unify(arg2, new ListPair(new Functor2(@"atom", F, Pos), new ListPair(Atom.a(@"("), S1)))) | ||
1407 | { | ||
1408 | yield return true; | ||
1409 | yield break; | ||
1410 | } | ||
1411 | } | ||
1412 | } | ||
1413 | { | ||
1414 | Variable F = new Variable(); | ||
1415 | Variable Pos = new Variable(); | ||
1416 | Variable S1 = new Variable(); | ||
1417 | Variable L = new Variable(); | ||
1418 | Variable P = new Variable(); | ||
1419 | Variable R = new Variable(); | ||
1420 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"atom", F, Pos), S1))) | ||
1421 | { | ||
1422 | 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))) | ||
1423 | { | ||
1424 | foreach (bool l4 in infixop(F, L, P, R)) | ||
1425 | { | ||
1426 | yield return false; | ||
1427 | } | ||
1428 | } | ||
1429 | } | ||
1430 | } | ||
1431 | { | ||
1432 | Variable F = new Variable(); | ||
1433 | Variable Pos = new Variable(); | ||
1434 | Variable S1 = new Variable(); | ||
1435 | Variable L = new Variable(); | ||
1436 | Variable P = new Variable(); | ||
1437 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"atom", F, Pos), S1))) | ||
1438 | { | ||
1439 | foreach (bool l3 in YP.unify(arg2, new ListPair(new Functor3(Atom.a(@"postfixop", Atom.a(@"")), new Functor2(@"/", F, Pos), L, P), S1))) | ||
1440 | { | ||
1441 | foreach (bool l4 in postfixop(F, L, P)) | ||
1442 | { | ||
1443 | yield return false; | ||
1444 | } | ||
1445 | } | ||
1446 | } | ||
1447 | } | ||
1448 | { | ||
1449 | Variable S0 = new Variable(); | ||
1450 | foreach (bool l2 in YP.unify(arg1, S0)) | ||
1451 | { | ||
1452 | foreach (bool l3 in YP.unify(arg2, S0)) | ||
1453 | { | ||
1454 | yield return false; | ||
1455 | } | ||
1456 | } | ||
1457 | } | ||
1458 | } | ||
1459 | |||
1460 | public static IEnumerable<bool> prefix_is_atom(object arg1, object arg2) | ||
1461 | { | ||
1462 | { | ||
1463 | object Precedence = arg2; | ||
1464 | Variable Token = new Variable(); | ||
1465 | Variable x2 = new Variable(); | ||
1466 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, x2))) | ||
1467 | { | ||
1468 | foreach (bool l3 in prefix_is_atom(Token, Precedence)) | ||
1469 | { | ||
1470 | yield return false; | ||
1471 | } | ||
1472 | } | ||
1473 | } | ||
1474 | { | ||
1475 | object P = arg2; | ||
1476 | Variable x1 = new Variable(); | ||
1477 | Variable L = new Variable(); | ||
1478 | Variable x3 = new Variable(); | ||
1479 | Variable x4 = new Variable(); | ||
1480 | foreach (bool l2 in YP.unify(arg1, new Functor(Atom.a(@"infixop", Atom.a(@"")), new object[] { x1, L, x3, x4 }))) | ||
1481 | { | ||
1482 | if (YP.greaterThanOrEqual(L, P)) | ||
1483 | { | ||
1484 | yield return false; | ||
1485 | } | ||
1486 | } | ||
1487 | } | ||
1488 | { | ||
1489 | object P = arg2; | ||
1490 | Variable x1 = new Variable(); | ||
1491 | Variable L = new Variable(); | ||
1492 | Variable x3 = new Variable(); | ||
1493 | foreach (bool l2 in YP.unify(arg1, new Functor3(Atom.a(@"postfixop", Atom.a(@"")), x1, L, x3))) | ||
1494 | { | ||
1495 | if (YP.greaterThanOrEqual(L, P)) | ||
1496 | { | ||
1497 | yield return false; | ||
1498 | } | ||
1499 | } | ||
1500 | } | ||
1501 | { | ||
1502 | object x1 = arg2; | ||
1503 | foreach (bool l2 in YP.unify(arg1, Atom.a(@")"))) | ||
1504 | { | ||
1505 | yield return false; | ||
1506 | } | ||
1507 | } | ||
1508 | { | ||
1509 | object x1 = arg2; | ||
1510 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"]"))) | ||
1511 | { | ||
1512 | yield return false; | ||
1513 | } | ||
1514 | } | ||
1515 | { | ||
1516 | object x1 = arg2; | ||
1517 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"}"))) | ||
1518 | { | ||
1519 | yield return false; | ||
1520 | } | ||
1521 | } | ||
1522 | { | ||
1523 | object P = arg2; | ||
1524 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"|"))) | ||
1525 | { | ||
1526 | if (YP.greaterThanOrEqual(1100, P)) | ||
1527 | { | ||
1528 | yield return false; | ||
1529 | } | ||
1530 | } | ||
1531 | } | ||
1532 | { | ||
1533 | object P = arg2; | ||
1534 | foreach (bool l2 in YP.unify(arg1, Atom.a(@","))) | ||
1535 | { | ||
1536 | if (YP.greaterThanOrEqual(1000, P)) | ||
1537 | { | ||
1538 | yield return false; | ||
1539 | } | ||
1540 | } | ||
1541 | } | ||
1542 | { | ||
1543 | object x1 = arg2; | ||
1544 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1545 | { | ||
1546 | yield return false; | ||
1547 | } | ||
1548 | } | ||
1549 | } | ||
1550 | |||
1551 | public static IEnumerable<bool> exprtl0(object arg1, object arg2, object arg3, object arg4, object arg5) | ||
1552 | { | ||
1553 | { | ||
1554 | object x2 = arg3; | ||
1555 | Variable Term = new Variable(); | ||
1556 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1557 | { | ||
1558 | foreach (bool l3 in YP.unify(arg2, Term)) | ||
1559 | { | ||
1560 | foreach (bool l4 in YP.unify(arg4, Term)) | ||
1561 | { | ||
1562 | foreach (bool l5 in YP.unify(arg5, Atom.NIL)) | ||
1563 | { | ||
1564 | yield return false; | ||
1565 | } | ||
1566 | } | ||
1567 | } | ||
1568 | } | ||
1569 | } | ||
1570 | { | ||
1571 | object Term = arg2; | ||
1572 | object Precedence = arg3; | ||
1573 | object Answer = arg4; | ||
1574 | object S = arg5; | ||
1575 | Variable Token = new Variable(); | ||
1576 | Variable S1 = new Variable(); | ||
1577 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, S1))) | ||
1578 | { | ||
1579 | foreach (bool l3 in exprtl0_6(Token, Term, Precedence, Answer, S, S1)) | ||
1580 | { | ||
1581 | yield return false; | ||
1582 | } | ||
1583 | } | ||
1584 | } | ||
1585 | } | ||
1586 | |||
1587 | public static IEnumerable<bool> exprtl0_6(object arg1, object arg2, object arg3, object arg4, object arg5, object arg6) | ||
1588 | { | ||
1589 | { | ||
1590 | object x2 = arg3; | ||
1591 | object S1 = arg6; | ||
1592 | Variable Term = new Variable(); | ||
1593 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"}"))) | ||
1594 | { | ||
1595 | foreach (bool l3 in YP.unify(arg2, Term)) | ||
1596 | { | ||
1597 | foreach (bool l4 in YP.unify(arg4, Term)) | ||
1598 | { | ||
1599 | foreach (bool l5 in YP.unify(arg5, new ListPair(Atom.a(@"}"), S1))) | ||
1600 | { | ||
1601 | yield return false; | ||
1602 | } | ||
1603 | } | ||
1604 | } | ||
1605 | } | ||
1606 | } | ||
1607 | { | ||
1608 | object x2 = arg3; | ||
1609 | object S1 = arg6; | ||
1610 | Variable Term = new Variable(); | ||
1611 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"]"))) | ||
1612 | { | ||
1613 | foreach (bool l3 in YP.unify(arg2, Term)) | ||
1614 | { | ||
1615 | foreach (bool l4 in YP.unify(arg4, Term)) | ||
1616 | { | ||
1617 | foreach (bool l5 in YP.unify(arg5, new ListPair(Atom.a(@"]"), S1))) | ||
1618 | { | ||
1619 | yield return false; | ||
1620 | } | ||
1621 | } | ||
1622 | } | ||
1623 | } | ||
1624 | } | ||
1625 | { | ||
1626 | object x2 = arg3; | ||
1627 | object S1 = arg6; | ||
1628 | Variable Term = new Variable(); | ||
1629 | foreach (bool l2 in YP.unify(arg1, Atom.a(@")"))) | ||
1630 | { | ||
1631 | foreach (bool l3 in YP.unify(arg2, Term)) | ||
1632 | { | ||
1633 | foreach (bool l4 in YP.unify(arg4, Term)) | ||
1634 | { | ||
1635 | foreach (bool l5 in YP.unify(arg5, new ListPair(Atom.a(@")"), S1))) | ||
1636 | { | ||
1637 | yield return false; | ||
1638 | } | ||
1639 | } | ||
1640 | } | ||
1641 | } | ||
1642 | } | ||
1643 | { | ||
1644 | object Term = arg2; | ||
1645 | object Precedence = arg3; | ||
1646 | object Answer = arg4; | ||
1647 | object S = arg5; | ||
1648 | object S1 = arg6; | ||
1649 | Variable Next = new Variable(); | ||
1650 | Variable S2 = new Variable(); | ||
1651 | foreach (bool l2 in YP.unify(arg1, Atom.a(@","))) | ||
1652 | { | ||
1653 | if (YP.greaterThanOrEqual(Precedence, 1000)) | ||
1654 | { | ||
1655 | foreach (bool l4 in parse(S1, 1000, Next, S2)) | ||
1656 | { | ||
1657 | foreach (bool l5 in exprtl(S2, 1000, new Functor2(@",", Term, Next), Precedence, Answer, S)) | ||
1658 | { | ||
1659 | yield return false; | ||
1660 | } | ||
1661 | yield break; | ||
1662 | } | ||
1663 | goto cutIf1; | ||
1664 | } | ||
1665 | foreach (bool l3 in YP.unify(Answer, Term)) | ||
1666 | { | ||
1667 | foreach (bool l4 in YP.unify(S, new ListPair(Atom.a(@","), S1))) | ||
1668 | { | ||
1669 | yield return false; | ||
1670 | } | ||
1671 | } | ||
1672 | cutIf1: | ||
1673 | { } | ||
1674 | } | ||
1675 | } | ||
1676 | { | ||
1677 | object Term = arg2; | ||
1678 | object Precedence = arg3; | ||
1679 | object Answer = arg4; | ||
1680 | object S = arg5; | ||
1681 | object S1 = arg6; | ||
1682 | Variable Next = new Variable(); | ||
1683 | Variable S2 = new Variable(); | ||
1684 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"|"))) | ||
1685 | { | ||
1686 | if (YP.greaterThanOrEqual(Precedence, 1100)) | ||
1687 | { | ||
1688 | foreach (bool l4 in parse(S1, 1100, Next, S2)) | ||
1689 | { | ||
1690 | foreach (bool l5 in exprtl(S2, 1100, new Functor2(@";", Term, Next), Precedence, Answer, S)) | ||
1691 | { | ||
1692 | yield return false; | ||
1693 | } | ||
1694 | yield break; | ||
1695 | } | ||
1696 | goto cutIf2; | ||
1697 | } | ||
1698 | foreach (bool l3 in YP.unify(Answer, Term)) | ||
1699 | { | ||
1700 | foreach (bool l4 in YP.unify(S, new ListPair(Atom.a(@"|"), S1))) | ||
1701 | { | ||
1702 | yield return false; | ||
1703 | } | ||
1704 | } | ||
1705 | cutIf2: | ||
1706 | { } | ||
1707 | } | ||
1708 | } | ||
1709 | { | ||
1710 | object x2 = arg2; | ||
1711 | object x3 = arg3; | ||
1712 | object x4 = arg4; | ||
1713 | object x5 = arg5; | ||
1714 | object S1 = arg6; | ||
1715 | Variable S = new Variable(); | ||
1716 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"string", S))) | ||
1717 | { | ||
1718 | foreach (bool l3 in cannot_follow(Atom.a(@"chars"), new Functor1(@"string", S), S1)) | ||
1719 | { | ||
1720 | yield return false; | ||
1721 | } | ||
1722 | } | ||
1723 | } | ||
1724 | { | ||
1725 | object x2 = arg2; | ||
1726 | object x3 = arg3; | ||
1727 | object x4 = arg4; | ||
1728 | object x5 = arg5; | ||
1729 | object S1 = arg6; | ||
1730 | Variable N = new Variable(); | ||
1731 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"number", N))) | ||
1732 | { | ||
1733 | foreach (bool l3 in cannot_follow(Atom.a(@"number"), new Functor1(@"number", N), S1)) | ||
1734 | { | ||
1735 | yield return false; | ||
1736 | } | ||
1737 | } | ||
1738 | } | ||
1739 | { | ||
1740 | object Term = arg2; | ||
1741 | object Precedence = arg3; | ||
1742 | object Answer = arg4; | ||
1743 | object S = arg5; | ||
1744 | Variable S1 = new Variable(); | ||
1745 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"{"))) | ||
1746 | { | ||
1747 | foreach (bool l3 in YP.unify(arg6, new ListPair(Atom.a(@"}"), S1))) | ||
1748 | { | ||
1749 | foreach (bool l4 in exprtl0_atom(Atom.a(@"{}"), Term, Precedence, Answer, S, S1)) | ||
1750 | { | ||
1751 | yield return false; | ||
1752 | } | ||
1753 | yield break; | ||
1754 | } | ||
1755 | } | ||
1756 | } | ||
1757 | { | ||
1758 | object x1 = arg2; | ||
1759 | object x2 = arg3; | ||
1760 | object x3 = arg4; | ||
1761 | object x4 = arg5; | ||
1762 | object S1 = arg6; | ||
1763 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"{"))) | ||
1764 | { | ||
1765 | foreach (bool l3 in cannot_follow(Atom.a(@"brace"), Atom.a(@"{"), S1)) | ||
1766 | { | ||
1767 | yield return false; | ||
1768 | } | ||
1769 | } | ||
1770 | } | ||
1771 | { | ||
1772 | object Term = arg2; | ||
1773 | object Precedence = arg3; | ||
1774 | object Answer = arg4; | ||
1775 | object S = arg5; | ||
1776 | Variable S1 = new Variable(); | ||
1777 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"["))) | ||
1778 | { | ||
1779 | foreach (bool l3 in YP.unify(arg6, new ListPair(Atom.a(@"]"), S1))) | ||
1780 | { | ||
1781 | foreach (bool l4 in exprtl0_atom(Atom.NIL, Term, Precedence, Answer, S, S1)) | ||
1782 | { | ||
1783 | yield return false; | ||
1784 | } | ||
1785 | yield break; | ||
1786 | } | ||
1787 | } | ||
1788 | } | ||
1789 | { | ||
1790 | object x1 = arg2; | ||
1791 | object x2 = arg3; | ||
1792 | object x3 = arg4; | ||
1793 | object x4 = arg5; | ||
1794 | object S1 = arg6; | ||
1795 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"["))) | ||
1796 | { | ||
1797 | foreach (bool l3 in cannot_follow(Atom.a(@"bracket"), Atom.a(@"["), S1)) | ||
1798 | { | ||
1799 | yield return false; | ||
1800 | } | ||
1801 | } | ||
1802 | } | ||
1803 | { | ||
1804 | object x1 = arg2; | ||
1805 | object x2 = arg3; | ||
1806 | object x3 = arg4; | ||
1807 | object x4 = arg5; | ||
1808 | object S1 = arg6; | ||
1809 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"("))) | ||
1810 | { | ||
1811 | foreach (bool l3 in cannot_follow(Atom.a(@"parenthesis"), Atom.a(@"("), S1)) | ||
1812 | { | ||
1813 | yield return false; | ||
1814 | } | ||
1815 | } | ||
1816 | } | ||
1817 | { | ||
1818 | object x1 = arg2; | ||
1819 | object x2 = arg3; | ||
1820 | object x3 = arg4; | ||
1821 | object x4 = arg5; | ||
1822 | object S1 = arg6; | ||
1823 | foreach (bool l2 in YP.unify(arg1, Atom.a(@" ("))) | ||
1824 | { | ||
1825 | foreach (bool l3 in cannot_follow(Atom.a(@"parenthesis"), Atom.a(@"("), S1)) | ||
1826 | { | ||
1827 | yield return false; | ||
1828 | } | ||
1829 | } | ||
1830 | } | ||
1831 | { | ||
1832 | object x4 = arg2; | ||
1833 | object x5 = arg3; | ||
1834 | object x6 = arg4; | ||
1835 | object x7 = arg5; | ||
1836 | object S1 = arg6; | ||
1837 | Variable A = new Variable(); | ||
1838 | Variable B = new Variable(); | ||
1839 | Variable P = new Variable(); | ||
1840 | foreach (bool l2 in YP.unify(arg1, new Functor3(@"var", A, B, P))) | ||
1841 | { | ||
1842 | foreach (bool l3 in cannot_follow(Atom.a(@"variable"), new Functor3(@"var", A, B, P), S1)) | ||
1843 | { | ||
1844 | yield return false; | ||
1845 | } | ||
1846 | } | ||
1847 | } | ||
1848 | { | ||
1849 | object Term = arg2; | ||
1850 | object Precedence = arg3; | ||
1851 | object Answer = arg4; | ||
1852 | object S = arg5; | ||
1853 | object S1 = arg6; | ||
1854 | Variable F = new Variable(); | ||
1855 | Variable P = new Variable(); | ||
1856 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"atom", F, P))) | ||
1857 | { | ||
1858 | foreach (bool l3 in exprtl0_atom(new Functor2(@"/", F, P), Term, Precedence, Answer, S, S1)) | ||
1859 | { | ||
1860 | yield return false; | ||
1861 | } | ||
1862 | } | ||
1863 | } | ||
1864 | } | ||
1865 | |||
1866 | public static IEnumerable<bool> exprtl0_atom(object arg1, object arg2, object arg3, object arg4, object arg5, object S1) | ||
1867 | { | ||
1868 | { | ||
1869 | object Term = arg2; | ||
1870 | object Precedence = arg3; | ||
1871 | object Answer = arg4; | ||
1872 | object S = arg5; | ||
1873 | Variable F = new Variable(); | ||
1874 | Variable Pos = new Variable(); | ||
1875 | Variable L1 = new Variable(); | ||
1876 | Variable O1 = new Variable(); | ||
1877 | Variable R1 = new Variable(); | ||
1878 | Variable L2 = new Variable(); | ||
1879 | Variable O2 = new Variable(); | ||
1880 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"/", F, Pos))) | ||
1881 | { | ||
1882 | foreach (bool l3 in ambigop(F, Precedence, L1, O1, R1, L2, O2)) | ||
1883 | { | ||
1884 | foreach (bool l4 in prefix_is_atom(S1, Precedence)) | ||
1885 | { | ||
1886 | 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)) | ||
1887 | { | ||
1888 | yield return false; | ||
1889 | } | ||
1890 | yield break; | ||
1891 | } | ||
1892 | 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)) | ||
1893 | { | ||
1894 | yield return false; | ||
1895 | } | ||
1896 | 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)) | ||
1897 | { | ||
1898 | yield return false; | ||
1899 | } | ||
1900 | yield break; | ||
1901 | } | ||
1902 | } | ||
1903 | } | ||
1904 | { | ||
1905 | object Term = arg2; | ||
1906 | object Precedence = arg3; | ||
1907 | object Answer = arg4; | ||
1908 | object S = arg5; | ||
1909 | Variable F = new Variable(); | ||
1910 | Variable Pos = new Variable(); | ||
1911 | Variable L1 = new Variable(); | ||
1912 | Variable O1 = new Variable(); | ||
1913 | Variable R1 = new Variable(); | ||
1914 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"/", F, Pos))) | ||
1915 | { | ||
1916 | foreach (bool l3 in infixop(F, L1, O1, R1)) | ||
1917 | { | ||
1918 | 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)) | ||
1919 | { | ||
1920 | yield return false; | ||
1921 | } | ||
1922 | yield break; | ||
1923 | } | ||
1924 | } | ||
1925 | } | ||
1926 | { | ||
1927 | object Term = arg2; | ||
1928 | object Precedence = arg3; | ||
1929 | object Answer = arg4; | ||
1930 | object S = arg5; | ||
1931 | Variable F = new Variable(); | ||
1932 | Variable Pos = new Variable(); | ||
1933 | Variable L2 = new Variable(); | ||
1934 | Variable O2 = new Variable(); | ||
1935 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"/", F, Pos))) | ||
1936 | { | ||
1937 | foreach (bool l3 in postfixop(F, L2, O2)) | ||
1938 | { | ||
1939 | 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)) | ||
1940 | { | ||
1941 | yield return false; | ||
1942 | } | ||
1943 | yield break; | ||
1944 | } | ||
1945 | } | ||
1946 | } | ||
1947 | { | ||
1948 | object X = arg1; | ||
1949 | object x2 = arg2; | ||
1950 | object x3 = arg3; | ||
1951 | object x4 = arg4; | ||
1952 | object x5 = arg5; | ||
1953 | Variable x7 = new Variable(); | ||
1954 | foreach (bool l2 in syntax_error(new ListPair(new Functor2(@"-", Atom.a(@"non"), Atom.a(@"operator")), new ListPair(X, new ListPair(Atom.a(@"follows"), new ListPair(Atom.a(@"expression"), Atom.NIL)))), new ListPair(new Functor2(@"atom", X, x7), S1))) | ||
1955 | { | ||
1956 | yield return false; | ||
1957 | } | ||
1958 | yield break; | ||
1959 | } | ||
1960 | } | ||
1961 | |||
1962 | public static IEnumerable<bool> cannot_follow(object Type, object Token, object Tokens) | ||
1963 | { | ||
1964 | { | ||
1965 | foreach (bool l2 in syntax_error(new ListPair(Type, new ListPair(Atom.a(@"follows"), new ListPair(Atom.a(@"expression"), Atom.NIL))), new ListPair(Token, Tokens))) | ||
1966 | { | ||
1967 | yield return false; | ||
1968 | } | ||
1969 | } | ||
1970 | } | ||
1971 | |||
1972 | public static IEnumerable<bool> exprtl(object arg1, object arg2, object arg3, object arg4, object arg5, object arg6) | ||
1973 | { | ||
1974 | { | ||
1975 | object x1 = arg2; | ||
1976 | object x3 = arg4; | ||
1977 | Variable Term = new Variable(); | ||
1978 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1979 | { | ||
1980 | foreach (bool l3 in YP.unify(arg3, Term)) | ||
1981 | { | ||
1982 | foreach (bool l4 in YP.unify(arg5, Term)) | ||
1983 | { | ||
1984 | foreach (bool l5 in YP.unify(arg6, Atom.NIL)) | ||
1985 | { | ||
1986 | yield return false; | ||
1987 | } | ||
1988 | } | ||
1989 | } | ||
1990 | } | ||
1991 | } | ||
1992 | { | ||
1993 | object C = arg2; | ||
1994 | object Term = arg3; | ||
1995 | object Precedence = arg4; | ||
1996 | object Answer = arg5; | ||
1997 | object S = arg6; | ||
1998 | Variable Token = new Variable(); | ||
1999 | Variable Tokens = new Variable(); | ||
2000 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, Tokens))) | ||
2001 | { | ||
2002 | foreach (bool l3 in exprtl_7(Token, C, Term, Precedence, Answer, S, Tokens)) | ||
2003 | { | ||
2004 | yield return false; | ||
2005 | } | ||
2006 | } | ||
2007 | } | ||
2008 | } | ||
2009 | |||
2010 | public static IEnumerable<bool> exprtl_7(object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7) | ||
2011 | { | ||
2012 | { | ||
2013 | object C = arg2; | ||
2014 | object Term = arg3; | ||
2015 | object Precedence = arg4; | ||
2016 | object Answer = arg5; | ||
2017 | object S = arg6; | ||
2018 | object S1 = arg7; | ||
2019 | Variable F = new Variable(); | ||
2020 | Variable Pos = new Variable(); | ||
2021 | Variable L = new Variable(); | ||
2022 | Variable O = new Variable(); | ||
2023 | Variable R = new Variable(); | ||
2024 | Variable Other = new Variable(); | ||
2025 | Variable S2 = new Variable(); | ||
2026 | Variable Expr = new Variable(); | ||
2027 | foreach (bool l2 in YP.unify(arg1, new Functor(Atom.a(@"infixop", Atom.a(@"")), new object[] { new Functor2(@"/", F, Pos), L, O, R }))) | ||
2028 | { | ||
2029 | if (YP.greaterThanOrEqual(Precedence, O)) | ||
2030 | { | ||
2031 | if (YP.lessThanOrEqual(C, L)) | ||
2032 | { | ||
2033 | foreach (bool l5 in parse(S1, R, Other, S2)) | ||
2034 | { | ||
2035 | foreach (bool l6 in YP.univ(Expr, new ListPair(F, new ListPair(Pos, new ListPair(Term, new ListPair(Other, Atom.NIL)))))) | ||
2036 | { | ||
2037 | foreach (bool l7 in exprtl(S2, O, Expr, Precedence, Answer, S)) | ||
2038 | { | ||
2039 | yield return false; | ||
2040 | } | ||
2041 | } | ||
2042 | } | ||
2043 | yield break; | ||
2044 | } | ||
2045 | } | ||
2046 | } | ||
2047 | } | ||
2048 | { | ||
2049 | object C = arg2; | ||
2050 | object Term = arg3; | ||
2051 | object Precedence = arg4; | ||
2052 | object Answer = arg5; | ||
2053 | object S = arg6; | ||
2054 | object S1 = arg7; | ||
2055 | Variable F = new Variable(); | ||
2056 | Variable Pos = new Variable(); | ||
2057 | Variable L = new Variable(); | ||
2058 | Variable O = new Variable(); | ||
2059 | Variable Expr = new Variable(); | ||
2060 | Variable S2 = new Variable(); | ||
2061 | foreach (bool l2 in YP.unify(arg1, new Functor3(Atom.a(@"postfixop", Atom.a(@"")), new Functor2(@"/", F, Pos), L, O))) | ||
2062 | { | ||
2063 | if (YP.greaterThanOrEqual(Precedence, O)) | ||
2064 | { | ||
2065 | if (YP.lessThanOrEqual(C, L)) | ||
2066 | { | ||
2067 | foreach (bool l5 in YP.univ(Expr, new ListPair(F, new ListPair(Pos, new ListPair(Term, Atom.NIL))))) | ||
2068 | { | ||
2069 | foreach (bool l6 in peepop(S1, S2)) | ||
2070 | { | ||
2071 | foreach (bool l7 in exprtl(S2, O, Expr, Precedence, Answer, S)) | ||
2072 | { | ||
2073 | yield return false; | ||
2074 | } | ||
2075 | } | ||
2076 | } | ||
2077 | yield break; | ||
2078 | } | ||
2079 | } | ||
2080 | } | ||
2081 | } | ||
2082 | { | ||
2083 | object C = arg2; | ||
2084 | object Term = arg3; | ||
2085 | object Precedence = arg4; | ||
2086 | object Answer = arg5; | ||
2087 | object S = arg6; | ||
2088 | object S1 = arg7; | ||
2089 | Variable Next = new Variable(); | ||
2090 | Variable S2 = new Variable(); | ||
2091 | foreach (bool l2 in YP.unify(arg1, Atom.a(@","))) | ||
2092 | { | ||
2093 | if (YP.greaterThanOrEqual(Precedence, 1000)) | ||
2094 | { | ||
2095 | if (YP.lessThan(C, 1000)) | ||
2096 | { | ||
2097 | foreach (bool l5 in parse(S1, 1000, Next, S2)) | ||
2098 | { | ||
2099 | foreach (bool l6 in exprtl(S2, 1000, new Functor2(@",", Term, Next), Precedence, Answer, S)) | ||
2100 | { | ||
2101 | yield return false; | ||
2102 | } | ||
2103 | } | ||
2104 | yield break; | ||
2105 | } | ||
2106 | } | ||
2107 | } | ||
2108 | } | ||
2109 | { | ||
2110 | object C = arg2; | ||
2111 | object Term = arg3; | ||
2112 | object Precedence = arg4; | ||
2113 | object Answer = arg5; | ||
2114 | object S = arg6; | ||
2115 | object S1 = arg7; | ||
2116 | Variable Next = new Variable(); | ||
2117 | Variable S2 = new Variable(); | ||
2118 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"|"))) | ||
2119 | { | ||
2120 | if (YP.greaterThanOrEqual(Precedence, 1100)) | ||
2121 | { | ||
2122 | if (YP.lessThan(C, 1100)) | ||
2123 | { | ||
2124 | foreach (bool l5 in parse(S1, 1100, Next, S2)) | ||
2125 | { | ||
2126 | foreach (bool l6 in exprtl(S2, 1100, new Functor2(@";", Term, Next), Precedence, Answer, S)) | ||
2127 | { | ||
2128 | yield return false; | ||
2129 | } | ||
2130 | } | ||
2131 | yield break; | ||
2132 | } | ||
2133 | } | ||
2134 | } | ||
2135 | } | ||
2136 | { | ||
2137 | object Token = arg1; | ||
2138 | object x2 = arg2; | ||
2139 | object x4 = arg4; | ||
2140 | object Tokens = arg7; | ||
2141 | Variable Term = new Variable(); | ||
2142 | foreach (bool l2 in YP.unify(arg3, Term)) | ||
2143 | { | ||
2144 | foreach (bool l3 in YP.unify(arg5, Term)) | ||
2145 | { | ||
2146 | foreach (bool l4 in YP.unify(arg6, new ListPair(Token, Tokens))) | ||
2147 | { | ||
2148 | yield return false; | ||
2149 | } | ||
2150 | } | ||
2151 | } | ||
2152 | } | ||
2153 | } | ||
2154 | |||
2155 | public static IEnumerable<bool> syntax_error(object _Message, object _List) | ||
2156 | { | ||
2157 | { | ||
2158 | yield break; | ||
2159 | } | ||
2160 | } | ||
2161 | |||
2162 | public static IEnumerable<bool> syntax_error(object _List) | ||
2163 | { | ||
2164 | { | ||
2165 | yield break; | ||
2166 | } | ||
2167 | } | ||
2168 | |||
2169 | public static IEnumerable<bool> prefixop(object F, object O, object Q) | ||
2170 | { | ||
2171 | { | ||
2172 | foreach (bool l2 in YP.current_op(O, Atom.a(@"fx"), F)) | ||
2173 | { | ||
2174 | foreach (bool l3 in YP.unify(Q, YP.subtract(O, 1))) | ||
2175 | { | ||
2176 | yield return false; | ||
2177 | } | ||
2178 | goto cutIf1; | ||
2179 | } | ||
2180 | foreach (bool l2 in YP.current_op(O, Atom.a(@"fy"), F)) | ||
2181 | { | ||
2182 | foreach (bool l3 in YP.unify(Q, O)) | ||
2183 | { | ||
2184 | yield return false; | ||
2185 | } | ||
2186 | goto cutIf2; | ||
2187 | } | ||
2188 | cutIf2: | ||
2189 | cutIf1: | ||
2190 | { } | ||
2191 | } | ||
2192 | } | ||
2193 | |||
2194 | public static IEnumerable<bool> postfixop(object F, object P, object O) | ||
2195 | { | ||
2196 | { | ||
2197 | foreach (bool l2 in YP.current_op(O, Atom.a(@"xf"), F)) | ||
2198 | { | ||
2199 | foreach (bool l3 in YP.unify(P, YP.subtract(O, 1))) | ||
2200 | { | ||
2201 | yield return false; | ||
2202 | } | ||
2203 | goto cutIf1; | ||
2204 | } | ||
2205 | foreach (bool l2 in YP.current_op(O, Atom.a(@"yf"), F)) | ||
2206 | { | ||
2207 | foreach (bool l3 in YP.unify(P, O)) | ||
2208 | { | ||
2209 | yield return false; | ||
2210 | } | ||
2211 | goto cutIf2; | ||
2212 | } | ||
2213 | cutIf2: | ||
2214 | cutIf1: | ||
2215 | { } | ||
2216 | } | ||
2217 | } | ||
2218 | |||
2219 | public static IEnumerable<bool> infixop(object F, object P, object O, object Q) | ||
2220 | { | ||
2221 | { | ||
2222 | foreach (bool l2 in YP.current_op(O, Atom.a(@"xfy"), F)) | ||
2223 | { | ||
2224 | foreach (bool l3 in YP.unify(P, YP.subtract(O, 1))) | ||
2225 | { | ||
2226 | foreach (bool l4 in YP.unify(Q, O)) | ||
2227 | { | ||
2228 | yield return false; | ||
2229 | } | ||
2230 | } | ||
2231 | goto cutIf1; | ||
2232 | } | ||
2233 | foreach (bool l2 in YP.current_op(O, Atom.a(@"xfx"), F)) | ||
2234 | { | ||
2235 | foreach (bool l3 in YP.unify(P, YP.subtract(O, 1))) | ||
2236 | { | ||
2237 | foreach (bool l4 in YP.unify(Q, P)) | ||
2238 | { | ||
2239 | yield return false; | ||
2240 | } | ||
2241 | } | ||
2242 | goto cutIf2; | ||
2243 | } | ||
2244 | foreach (bool l2 in YP.current_op(O, Atom.a(@"yfx"), F)) | ||
2245 | { | ||
2246 | foreach (bool l3 in YP.unify(Q, YP.subtract(O, 1))) | ||
2247 | { | ||
2248 | foreach (bool l4 in YP.unify(P, O)) | ||
2249 | { | ||
2250 | yield return false; | ||
2251 | } | ||
2252 | } | ||
2253 | goto cutIf3; | ||
2254 | } | ||
2255 | cutIf3: | ||
2256 | cutIf2: | ||
2257 | cutIf1: | ||
2258 | { } | ||
2259 | } | ||
2260 | } | ||
2261 | |||
2262 | public static IEnumerable<bool> ambigop(object F, object Precedence, object L1, object O1, object R1, object L2, object O2) | ||
2263 | { | ||
2264 | { | ||
2265 | foreach (bool l2 in postfixop(F, L2, O2)) | ||
2266 | { | ||
2267 | if (YP.lessThanOrEqual(O2, Precedence)) | ||
2268 | { | ||
2269 | foreach (bool l4 in infixop(F, L1, O1, R1)) | ||
2270 | { | ||
2271 | if (YP.lessThanOrEqual(O1, Precedence)) | ||
2272 | { | ||
2273 | yield return false; | ||
2274 | } | ||
2275 | } | ||
2276 | } | ||
2277 | } | ||
2278 | } | ||
2279 | } | ||
2280 | |||
2281 | public static IEnumerable<bool> read_tokens1(object arg1) | ||
2282 | { | ||
2283 | { | ||
2284 | object TokenList = arg1; | ||
2285 | Variable C1 = new Variable(); | ||
2286 | Variable _X = new Variable(); | ||
2287 | Variable ListOfTokens = new Variable(); | ||
2288 | foreach (bool l2 in YP.get_code(C1)) | ||
2289 | { | ||
2290 | foreach (bool l3 in read_tokens(C1, _X, ListOfTokens)) | ||
2291 | { | ||
2292 | foreach (bool l4 in YP.unify(TokenList, ListOfTokens)) | ||
2293 | { | ||
2294 | yield return false; | ||
2295 | } | ||
2296 | yield break; | ||
2297 | } | ||
2298 | } | ||
2299 | } | ||
2300 | { | ||
2301 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"atom", Atom.a(@"end_of_file"), 0), Atom.NIL))) | ||
2302 | { | ||
2303 | yield return false; | ||
2304 | } | ||
2305 | } | ||
2306 | } | ||
2307 | |||
2308 | public static IEnumerable<bool> read_tokens2(object arg1, object arg2) | ||
2309 | { | ||
2310 | { | ||
2311 | object TokenList = arg1; | ||
2312 | object Dictionary = arg2; | ||
2313 | Variable C1 = new Variable(); | ||
2314 | Variable Dict = new Variable(); | ||
2315 | Variable ListOfTokens = new Variable(); | ||
2316 | foreach (bool l2 in YP.get_code(C1)) | ||
2317 | { | ||
2318 | foreach (bool l3 in read_tokens(C1, Dict, ListOfTokens)) | ||
2319 | { | ||
2320 | foreach (bool l4 in terminate_list(Dict)) | ||
2321 | { | ||
2322 | foreach (bool l5 in YP.unify(Dictionary, Dict)) | ||
2323 | { | ||
2324 | foreach (bool l6 in YP.unify(TokenList, ListOfTokens)) | ||
2325 | { | ||
2326 | yield return false; | ||
2327 | } | ||
2328 | } | ||
2329 | yield break; | ||
2330 | } | ||
2331 | } | ||
2332 | } | ||
2333 | } | ||
2334 | { | ||
2335 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"atom", Atom.a(@"end_of_file"), 0), Atom.NIL))) | ||
2336 | { | ||
2337 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
2338 | { | ||
2339 | yield return false; | ||
2340 | } | ||
2341 | } | ||
2342 | } | ||
2343 | } | ||
2344 | |||
2345 | public static IEnumerable<bool> terminate_list(object arg1) | ||
2346 | { | ||
2347 | { | ||
2348 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
2349 | { | ||
2350 | yield return false; | ||
2351 | } | ||
2352 | } | ||
2353 | { | ||
2354 | Variable x1 = new Variable(); | ||
2355 | Variable Tail = new Variable(); | ||
2356 | foreach (bool l2 in YP.unify(arg1, new ListPair(x1, Tail))) | ||
2357 | { | ||
2358 | foreach (bool l3 in terminate_list(Tail)) | ||
2359 | { | ||
2360 | yield return false; | ||
2361 | } | ||
2362 | } | ||
2363 | } | ||
2364 | } | ||
2365 | |||
2366 | public static IEnumerable<bool> read_special(object arg1, object Dict, object arg3) | ||
2367 | { | ||
2368 | { | ||
2369 | object Tokens = arg3; | ||
2370 | foreach (bool l2 in YP.unify(arg1, 95)) | ||
2371 | { | ||
2372 | foreach (bool l3 in read_variable(95, Dict, Tokens)) | ||
2373 | { | ||
2374 | yield return false; | ||
2375 | } | ||
2376 | } | ||
2377 | } | ||
2378 | { | ||
2379 | object Tokens = arg3; | ||
2380 | foreach (bool l2 in YP.unify(arg1, 247)) | ||
2381 | { | ||
2382 | foreach (bool l3 in read_symbol(247, Dict, Tokens)) | ||
2383 | { | ||
2384 | yield return false; | ||
2385 | } | ||
2386 | } | ||
2387 | } | ||
2388 | { | ||
2389 | object Tokens = arg3; | ||
2390 | foreach (bool l2 in YP.unify(arg1, 215)) | ||
2391 | { | ||
2392 | foreach (bool l3 in read_symbol(215, Dict, Tokens)) | ||
2393 | { | ||
2394 | yield return false; | ||
2395 | } | ||
2396 | } | ||
2397 | } | ||
2398 | { | ||
2399 | Variable StartPos = new Variable(); | ||
2400 | Variable EndPos = new Variable(); | ||
2401 | Variable Tokens = new Variable(); | ||
2402 | Variable Ch = new Variable(); | ||
2403 | Variable NextCh = new Variable(); | ||
2404 | foreach (bool l2 in YP.unify(arg1, 37)) | ||
2405 | { | ||
2406 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2(@"comment", StartPos, EndPos), Tokens))) | ||
2407 | { | ||
2408 | foreach (bool l4 in get_current_position(StartPos)) | ||
2409 | { | ||
2410 | foreach (bool l5 in YP.repeat()) | ||
2411 | { | ||
2412 | foreach (bool l6 in YP.get_code(Ch)) | ||
2413 | { | ||
2414 | if (YP.lessThan(Ch, new ListPair(32, Atom.NIL))) | ||
2415 | { | ||
2416 | if (YP.notEqual(Ch, 9)) | ||
2417 | { | ||
2418 | if (YP.termNotEqual(Ch, -1)) | ||
2419 | { | ||
2420 | foreach (bool l10 in get_current_position(EndPos)) | ||
2421 | { | ||
2422 | foreach (bool l11 in YP.get_code(NextCh)) | ||
2423 | { | ||
2424 | foreach (bool l12 in read_tokens(NextCh, Dict, Tokens)) | ||
2425 | { | ||
2426 | yield return false; | ||
2427 | } | ||
2428 | } | ||
2429 | } | ||
2430 | } | ||
2431 | yield break; | ||
2432 | } | ||
2433 | } | ||
2434 | } | ||
2435 | } | ||
2436 | } | ||
2437 | } | ||
2438 | } | ||
2439 | } | ||
2440 | { | ||
2441 | object T = arg3; | ||
2442 | Variable C2 = new Variable(); | ||
2443 | Variable StartPos = new Variable(); | ||
2444 | Variable EndPos = new Variable(); | ||
2445 | Variable Tokens = new Variable(); | ||
2446 | Variable StartPos1 = new Variable(); | ||
2447 | Variable NextCh = new Variable(); | ||
2448 | Variable Chars = new Variable(); | ||
2449 | foreach (bool l2 in YP.unify(arg1, 47)) | ||
2450 | { | ||
2451 | foreach (bool l3 in YP.get_code(C2)) | ||
2452 | { | ||
2453 | if (YP.equal(C2, new ListPair(42, Atom.NIL))) | ||
2454 | { | ||
2455 | foreach (bool l5 in YP.unify(T, new ListPair(new Functor2(@"comment", StartPos, EndPos), Tokens))) | ||
2456 | { | ||
2457 | foreach (bool l6 in get_current_position(StartPos1)) | ||
2458 | { | ||
2459 | foreach (bool l7 in YP.unify(StartPos, YP.subtract(StartPos1, 1))) | ||
2460 | { | ||
2461 | foreach (bool l8 in read_solidus(32, NextCh)) | ||
2462 | { | ||
2463 | foreach (bool l9 in get_current_position(EndPos)) | ||
2464 | { | ||
2465 | foreach (bool l10 in read_tokens(NextCh, Dict, Tokens)) | ||
2466 | { | ||
2467 | yield return false; | ||
2468 | } | ||
2469 | } | ||
2470 | } | ||
2471 | } | ||
2472 | } | ||
2473 | } | ||
2474 | goto cutIf1; | ||
2475 | } | ||
2476 | foreach (bool l4 in YP.unify(T, Tokens)) | ||
2477 | { | ||
2478 | foreach (bool l5 in rest_symbol(C2, Chars, NextCh)) | ||
2479 | { | ||
2480 | foreach (bool l6 in read_after_atom4(NextCh, Dict, Tokens, new ListPair(47, Chars))) | ||
2481 | { | ||
2482 | yield return false; | ||
2483 | } | ||
2484 | } | ||
2485 | } | ||
2486 | cutIf1: | ||
2487 | { } | ||
2488 | } | ||
2489 | } | ||
2490 | } | ||
2491 | { | ||
2492 | Variable Pos = new Variable(); | ||
2493 | Variable Tokens = new Variable(); | ||
2494 | Variable NextCh = new Variable(); | ||
2495 | foreach (bool l2 in YP.unify(arg1, 33)) | ||
2496 | { | ||
2497 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2(@"atom", Atom.a(@"!"), Pos), Tokens))) | ||
2498 | { | ||
2499 | foreach (bool l4 in get_current_position(Pos)) | ||
2500 | { | ||
2501 | foreach (bool l5 in YP.get_code(NextCh)) | ||
2502 | { | ||
2503 | foreach (bool l6 in read_after_atom(NextCh, Dict, Tokens)) | ||
2504 | { | ||
2505 | yield return false; | ||
2506 | } | ||
2507 | } | ||
2508 | } | ||
2509 | } | ||
2510 | } | ||
2511 | } | ||
2512 | { | ||
2513 | Variable Tokens = new Variable(); | ||
2514 | Variable NextCh = new Variable(); | ||
2515 | foreach (bool l2 in YP.unify(arg1, 40)) | ||
2516 | { | ||
2517 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(@" ("), Tokens))) | ||
2518 | { | ||
2519 | foreach (bool l4 in YP.get_code(NextCh)) | ||
2520 | { | ||
2521 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
2522 | { | ||
2523 | yield return false; | ||
2524 | } | ||
2525 | } | ||
2526 | } | ||
2527 | } | ||
2528 | } | ||
2529 | { | ||
2530 | Variable Tokens = new Variable(); | ||
2531 | Variable NextCh = new Variable(); | ||
2532 | foreach (bool l2 in YP.unify(arg1, 41)) | ||
2533 | { | ||
2534 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(@")"), Tokens))) | ||
2535 | { | ||
2536 | foreach (bool l4 in YP.get_code(NextCh)) | ||
2537 | { | ||
2538 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
2539 | { | ||
2540 | yield return false; | ||
2541 | } | ||
2542 | } | ||
2543 | } | ||
2544 | } | ||
2545 | } | ||
2546 | { | ||
2547 | Variable Tokens = new Variable(); | ||
2548 | Variable NextCh = new Variable(); | ||
2549 | foreach (bool l2 in YP.unify(arg1, 44)) | ||
2550 | { | ||
2551 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(@","), Tokens))) | ||
2552 | { | ||
2553 | foreach (bool l4 in YP.get_code(NextCh)) | ||
2554 | { | ||
2555 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
2556 | { | ||
2557 | yield return false; | ||
2558 | } | ||
2559 | } | ||
2560 | } | ||
2561 | } | ||
2562 | } | ||
2563 | { | ||
2564 | Variable Pos = new Variable(); | ||
2565 | Variable Tokens = new Variable(); | ||
2566 | Variable NextCh = new Variable(); | ||
2567 | foreach (bool l2 in YP.unify(arg1, 59)) | ||
2568 | { | ||
2569 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2(@"atom", Atom.a(@";"), Pos), Tokens))) | ||
2570 | { | ||
2571 | foreach (bool l4 in get_current_position(Pos)) | ||
2572 | { | ||
2573 | foreach (bool l5 in YP.get_code(NextCh)) | ||
2574 | { | ||
2575 | foreach (bool l6 in read_after_atom(NextCh, Dict, Tokens)) | ||
2576 | { | ||
2577 | yield return false; | ||
2578 | } | ||
2579 | } | ||
2580 | } | ||
2581 | } | ||
2582 | } | ||
2583 | } | ||
2584 | { | ||
2585 | Variable Pos = new Variable(); | ||
2586 | Variable Tokens = new Variable(); | ||
2587 | Variable NextCh = new Variable(); | ||
2588 | foreach (bool l2 in YP.unify(arg1, 91)) | ||
2589 | { | ||
2590 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2(@"/", Atom.a(@"["), Pos), Tokens))) | ||
2591 | { | ||
2592 | foreach (bool l4 in get_current_position(Pos)) | ||
2593 | { | ||
2594 | foreach (bool l5 in YP.get_code(NextCh)) | ||
2595 | { | ||
2596 | foreach (bool l6 in read_tokens(NextCh, Dict, Tokens)) | ||
2597 | { | ||
2598 | yield return false; | ||
2599 | } | ||
2600 | } | ||
2601 | } | ||
2602 | } | ||
2603 | } | ||
2604 | } | ||
2605 | { | ||
2606 | Variable Pos = new Variable(); | ||
2607 | Variable Tokens = new Variable(); | ||
2608 | Variable NextCh = new Variable(); | ||
2609 | foreach (bool l2 in YP.unify(arg1, 93)) | ||
2610 | { | ||
2611 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2(@"/", Atom.a(@"]"), Pos), Tokens))) | ||
2612 | { | ||
2613 | foreach (bool l4 in get_current_position(Pos)) | ||
2614 | { | ||
2615 | foreach (bool l5 in YP.get_code(NextCh)) | ||
2616 | { | ||
2617 | foreach (bool l6 in read_after_atom(NextCh, Dict, Tokens)) | ||
2618 | { | ||
2619 | yield return false; | ||
2620 | } | ||
2621 | } | ||
2622 | } | ||
2623 | } | ||
2624 | } | ||
2625 | } | ||
2626 | { | ||
2627 | Variable Pos = new Variable(); | ||
2628 | Variable Tokens = new Variable(); | ||
2629 | Variable NextCh = new Variable(); | ||
2630 | foreach (bool l2 in YP.unify(arg1, 123)) | ||
2631 | { | ||
2632 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2(@"/", Atom.a(@"{"), Pos), Tokens))) | ||
2633 | { | ||
2634 | foreach (bool l4 in get_current_position(Pos)) | ||
2635 | { | ||
2636 | foreach (bool l5 in YP.get_code(NextCh)) | ||
2637 | { | ||
2638 | foreach (bool l6 in read_tokens(NextCh, Dict, Tokens)) | ||
2639 | { | ||
2640 | yield return false; | ||
2641 | } | ||
2642 | } | ||
2643 | } | ||
2644 | } | ||
2645 | } | ||
2646 | } | ||
2647 | { | ||
2648 | Variable Tokens = new Variable(); | ||
2649 | Variable NextCh = new Variable(); | ||
2650 | foreach (bool l2 in YP.unify(arg1, 124)) | ||
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, 125)) | ||
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_after_atom(NextCh, Dict, Tokens)) | ||
2674 | { | ||
2675 | yield return false; | ||
2676 | } | ||
2677 | } | ||
2678 | } | ||
2679 | } | ||
2680 | } | ||
2681 | { | ||
2682 | object Tokens = arg3; | ||
2683 | Variable NextCh = new Variable(); | ||
2684 | foreach (bool l2 in YP.unify(arg1, 46)) | ||
2685 | { | ||
2686 | foreach (bool l3 in YP.get_code(NextCh)) | ||
2687 | { | ||
2688 | foreach (bool l4 in read_fullstop(NextCh, Dict, Tokens)) | ||
2689 | { | ||
2690 | yield return false; | ||
2691 | } | ||
2692 | } | ||
2693 | } | ||
2694 | } | ||
2695 | { | ||
2696 | Variable Chars = new Variable(); | ||
2697 | Variable Tokens = new Variable(); | ||
2698 | Variable NextCh = new Variable(); | ||
2699 | foreach (bool l2 in YP.unify(arg1, 34)) | ||
2700 | { | ||
2701 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor1(@"string", Chars), Tokens))) | ||
2702 | { | ||
2703 | foreach (bool l4 in read_string(Chars, 34, NextCh)) | ||
2704 | { | ||
2705 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
2706 | { | ||
2707 | yield return false; | ||
2708 | } | ||
2709 | } | ||
2710 | } | ||
2711 | } | ||
2712 | } | ||
2713 | { | ||
2714 | object Tokens = arg3; | ||
2715 | Variable Chars = new Variable(); | ||
2716 | Variable NextCh = new Variable(); | ||
2717 | foreach (bool l2 in YP.unify(arg1, 39)) | ||
2718 | { | ||
2719 | foreach (bool l3 in read_string(Chars, 39, NextCh)) | ||
2720 | { | ||
2721 | foreach (bool l4 in read_after_atom4(NextCh, Dict, Tokens, Chars)) | ||
2722 | { | ||
2723 | yield return false; | ||
2724 | } | ||
2725 | } | ||
2726 | } | ||
2727 | } | ||
2728 | { | ||
2729 | object Tokens = arg3; | ||
2730 | foreach (bool l2 in YP.unify(arg1, 35)) | ||
2731 | { | ||
2732 | foreach (bool l3 in read_symbol(35, Dict, Tokens)) | ||
2733 | { | ||
2734 | yield return false; | ||
2735 | } | ||
2736 | } | ||
2737 | } | ||
2738 | { | ||
2739 | object Tokens = arg3; | ||
2740 | foreach (bool l2 in YP.unify(arg1, 36)) | ||
2741 | { | ||
2742 | foreach (bool l3 in read_symbol(36, Dict, Tokens)) | ||
2743 | { | ||
2744 | yield return false; | ||
2745 | } | ||
2746 | } | ||
2747 | } | ||
2748 | { | ||
2749 | object Tokens = arg3; | ||
2750 | foreach (bool l2 in YP.unify(arg1, 38)) | ||
2751 | { | ||
2752 | foreach (bool l3 in read_symbol(38, Dict, Tokens)) | ||
2753 | { | ||
2754 | yield return false; | ||
2755 | } | ||
2756 | } | ||
2757 | } | ||
2758 | { | ||
2759 | object Tokens = arg3; | ||
2760 | foreach (bool l2 in YP.unify(arg1, 42)) | ||
2761 | { | ||
2762 | foreach (bool l3 in read_symbol(42, Dict, Tokens)) | ||
2763 | { | ||
2764 | yield return false; | ||
2765 | } | ||
2766 | } | ||
2767 | } | ||
2768 | { | ||
2769 | object Tokens = arg3; | ||
2770 | foreach (bool l2 in YP.unify(arg1, 43)) | ||
2771 | { | ||
2772 | foreach (bool l3 in read_symbol(43, Dict, Tokens)) | ||
2773 | { | ||
2774 | yield return false; | ||
2775 | } | ||
2776 | } | ||
2777 | } | ||
2778 | { | ||
2779 | object Tokens = arg3; | ||
2780 | foreach (bool l2 in YP.unify(arg1, 45)) | ||
2781 | { | ||
2782 | foreach (bool l3 in read_symbol(45, Dict, Tokens)) | ||
2783 | { | ||
2784 | yield return false; | ||
2785 | } | ||
2786 | } | ||
2787 | } | ||
2788 | { | ||
2789 | object Tokens = arg3; | ||
2790 | foreach (bool l2 in YP.unify(arg1, 58)) | ||
2791 | { | ||
2792 | foreach (bool l3 in read_symbol(58, Dict, Tokens)) | ||
2793 | { | ||
2794 | yield return false; | ||
2795 | } | ||
2796 | } | ||
2797 | } | ||
2798 | { | ||
2799 | object Tokens = arg3; | ||
2800 | foreach (bool l2 in YP.unify(arg1, 60)) | ||
2801 | { | ||
2802 | foreach (bool l3 in read_symbol(60, Dict, Tokens)) | ||
2803 | { | ||
2804 | yield return false; | ||
2805 | } | ||
2806 | } | ||
2807 | } | ||
2808 | { | ||
2809 | object Tokens = arg3; | ||
2810 | foreach (bool l2 in YP.unify(arg1, 61)) | ||
2811 | { | ||
2812 | foreach (bool l3 in read_symbol(61, Dict, Tokens)) | ||
2813 | { | ||
2814 | yield return false; | ||
2815 | } | ||
2816 | } | ||
2817 | } | ||
2818 | { | ||
2819 | object Tokens = arg3; | ||
2820 | foreach (bool l2 in YP.unify(arg1, 62)) | ||
2821 | { | ||
2822 | foreach (bool l3 in read_symbol(62, Dict, Tokens)) | ||
2823 | { | ||
2824 | yield return false; | ||
2825 | } | ||
2826 | } | ||
2827 | } | ||
2828 | { | ||
2829 | object Tokens = arg3; | ||
2830 | foreach (bool l2 in YP.unify(arg1, 63)) | ||
2831 | { | ||
2832 | foreach (bool l3 in read_symbol(63, Dict, Tokens)) | ||
2833 | { | ||
2834 | yield return false; | ||
2835 | } | ||
2836 | } | ||
2837 | } | ||
2838 | { | ||
2839 | object Tokens = arg3; | ||
2840 | foreach (bool l2 in YP.unify(arg1, 64)) | ||
2841 | { | ||
2842 | foreach (bool l3 in read_symbol(64, Dict, Tokens)) | ||
2843 | { | ||
2844 | yield return false; | ||
2845 | } | ||
2846 | } | ||
2847 | } | ||
2848 | { | ||
2849 | object Tokens = arg3; | ||
2850 | foreach (bool l2 in YP.unify(arg1, 92)) | ||
2851 | { | ||
2852 | foreach (bool l3 in read_symbol(92, Dict, Tokens)) | ||
2853 | { | ||
2854 | yield return false; | ||
2855 | } | ||
2856 | } | ||
2857 | } | ||
2858 | { | ||
2859 | object Tokens = arg3; | ||
2860 | foreach (bool l2 in YP.unify(arg1, 94)) | ||
2861 | { | ||
2862 | foreach (bool l3 in read_symbol(94, Dict, Tokens)) | ||
2863 | { | ||
2864 | yield return false; | ||
2865 | } | ||
2866 | } | ||
2867 | } | ||
2868 | { | ||
2869 | object Tokens = arg3; | ||
2870 | foreach (bool l2 in YP.unify(arg1, 96)) | ||
2871 | { | ||
2872 | foreach (bool l3 in read_symbol(96, Dict, Tokens)) | ||
2873 | { | ||
2874 | yield return false; | ||
2875 | } | ||
2876 | } | ||
2877 | } | ||
2878 | { | ||
2879 | object Tokens = arg3; | ||
2880 | foreach (bool l2 in YP.unify(arg1, 126)) | ||
2881 | { | ||
2882 | foreach (bool l3 in read_symbol(126, Dict, Tokens)) | ||
2883 | { | ||
2884 | yield return false; | ||
2885 | } | ||
2886 | } | ||
2887 | } | ||
2888 | } | ||
2889 | |||
2890 | public static IEnumerable<bool> read_symbol(object C1, object Dict, object Tokens) | ||
2891 | { | ||
2892 | { | ||
2893 | Variable C2 = new Variable(); | ||
2894 | Variable Chars = new Variable(); | ||
2895 | Variable NextCh = new Variable(); | ||
2896 | foreach (bool l2 in YP.get_code(C2)) | ||
2897 | { | ||
2898 | foreach (bool l3 in rest_symbol(C2, Chars, NextCh)) | ||
2899 | { | ||
2900 | foreach (bool l4 in read_after_atom4(NextCh, Dict, Tokens, new ListPair(C1, Chars))) | ||
2901 | { | ||
2902 | yield return false; | ||
2903 | } | ||
2904 | } | ||
2905 | } | ||
2906 | } | ||
2907 | } | ||
2908 | |||
2909 | public static IEnumerable<bool> rest_symbol(object arg1, object arg2, object arg3) | ||
2910 | { | ||
2911 | { | ||
2912 | object C2 = arg1; | ||
2913 | object LastCh = arg3; | ||
2914 | Variable Chars = new Variable(); | ||
2915 | Variable NextCh = new Variable(); | ||
2916 | foreach (bool l2 in YP.unify(arg2, new ListPair(C2, Chars))) | ||
2917 | { | ||
2918 | if (YP.greaterThan(C2, 160)) | ||
2919 | { | ||
2920 | if (YP.lessThan(C2, 192)) | ||
2921 | { | ||
2922 | if (YP.notEqual(C2, 186)) | ||
2923 | { | ||
2924 | if (YP.notEqual(C2, 170)) | ||
2925 | { | ||
2926 | foreach (bool l7 in YP.get_code(NextCh)) | ||
2927 | { | ||
2928 | foreach (bool l8 in rest_symbol(NextCh, Chars, LastCh)) | ||
2929 | { | ||
2930 | yield return false; | ||
2931 | } | ||
2932 | } | ||
2933 | yield break; | ||
2934 | } | ||
2935 | } | ||
2936 | } | ||
2937 | goto cutIf1; | ||
2938 | } | ||
2939 | foreach (bool l3 in symbol_char(C2)) | ||
2940 | { | ||
2941 | foreach (bool l4 in YP.get_code(NextCh)) | ||
2942 | { | ||
2943 | foreach (bool l5 in rest_symbol(NextCh, Chars, LastCh)) | ||
2944 | { | ||
2945 | yield return false; | ||
2946 | } | ||
2947 | } | ||
2948 | yield break; | ||
2949 | } | ||
2950 | cutIf1: | ||
2951 | { } | ||
2952 | } | ||
2953 | } | ||
2954 | { | ||
2955 | Variable C2 = new Variable(); | ||
2956 | foreach (bool l2 in YP.unify(arg1, C2)) | ||
2957 | { | ||
2958 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
2959 | { | ||
2960 | foreach (bool l4 in YP.unify(arg3, C2)) | ||
2961 | { | ||
2962 | yield return false; | ||
2963 | } | ||
2964 | } | ||
2965 | } | ||
2966 | } | ||
2967 | } | ||
2968 | |||
2969 | public static IEnumerable<bool> symbol_char(object arg1) | ||
2970 | { | ||
2971 | { | ||
2972 | foreach (bool l2 in YP.unify(arg1, 35)) | ||
2973 | { | ||
2974 | yield return false; | ||
2975 | } | ||
2976 | } | ||
2977 | { | ||
2978 | foreach (bool l2 in YP.unify(arg1, 36)) | ||
2979 | { | ||
2980 | yield return false; | ||
2981 | } | ||
2982 | } | ||
2983 | { | ||
2984 | foreach (bool l2 in YP.unify(arg1, 38)) | ||
2985 | { | ||
2986 | yield return false; | ||
2987 | } | ||
2988 | } | ||
2989 | { | ||
2990 | foreach (bool l2 in YP.unify(arg1, 42)) | ||
2991 | { | ||
2992 | yield return false; | ||
2993 | } | ||
2994 | } | ||
2995 | { | ||
2996 | foreach (bool l2 in YP.unify(arg1, 43)) | ||
2997 | { | ||
2998 | yield return false; | ||
2999 | } | ||
3000 | } | ||
3001 | { | ||
3002 | foreach (bool l2 in YP.unify(arg1, 45)) | ||
3003 | { | ||
3004 | yield return false; | ||
3005 | } | ||
3006 | } | ||
3007 | { | ||
3008 | foreach (bool l2 in YP.unify(arg1, 46)) | ||
3009 | { | ||
3010 | yield return false; | ||
3011 | } | ||
3012 | } | ||
3013 | { | ||
3014 | foreach (bool l2 in YP.unify(arg1, 47)) | ||
3015 | { | ||
3016 | yield return false; | ||
3017 | } | ||
3018 | } | ||
3019 | { | ||
3020 | foreach (bool l2 in YP.unify(arg1, 58)) | ||
3021 | { | ||
3022 | yield return false; | ||
3023 | } | ||
3024 | } | ||
3025 | { | ||
3026 | foreach (bool l2 in YP.unify(arg1, 60)) | ||
3027 | { | ||
3028 | yield return false; | ||
3029 | } | ||
3030 | } | ||
3031 | { | ||
3032 | foreach (bool l2 in YP.unify(arg1, 61)) | ||
3033 | { | ||
3034 | yield return false; | ||
3035 | } | ||
3036 | } | ||
3037 | { | ||
3038 | foreach (bool l2 in YP.unify(arg1, 62)) | ||
3039 | { | ||
3040 | yield return false; | ||
3041 | } | ||
3042 | } | ||
3043 | { | ||
3044 | foreach (bool l2 in YP.unify(arg1, 63)) | ||
3045 | { | ||
3046 | yield return false; | ||
3047 | } | ||
3048 | } | ||
3049 | { | ||
3050 | foreach (bool l2 in YP.unify(arg1, 64)) | ||
3051 | { | ||
3052 | yield return false; | ||
3053 | } | ||
3054 | } | ||
3055 | { | ||
3056 | foreach (bool l2 in YP.unify(arg1, 92)) | ||
3057 | { | ||
3058 | yield return false; | ||
3059 | } | ||
3060 | } | ||
3061 | { | ||
3062 | foreach (bool l2 in YP.unify(arg1, 94)) | ||
3063 | { | ||
3064 | yield return false; | ||
3065 | } | ||
3066 | } | ||
3067 | { | ||
3068 | foreach (bool l2 in YP.unify(arg1, 96)) | ||
3069 | { | ||
3070 | yield return false; | ||
3071 | } | ||
3072 | } | ||
3073 | { | ||
3074 | foreach (bool l2 in YP.unify(arg1, 126)) | ||
3075 | { | ||
3076 | yield return false; | ||
3077 | } | ||
3078 | } | ||
3079 | } | ||
3080 | |||
3081 | public static IEnumerable<bool> get_current_position(object Pos) | ||
3082 | { | ||
3083 | { | ||
3084 | foreach (bool l2 in YP.unify(Pos, 0)) | ||
3085 | { | ||
3086 | yield return false; | ||
3087 | } | ||
3088 | } | ||
3089 | } | ||
3090 | |||
3091 | public static IEnumerable<bool> read_after_atom4(object Ch, object Dict, object arg3, object Chars) | ||
3092 | { | ||
3093 | { | ||
3094 | Variable Atom_1 = new Variable(); | ||
3095 | Variable Pos = new Variable(); | ||
3096 | Variable Tokens = new Variable(); | ||
3097 | foreach (bool l2 in YP.unify(arg3, new ListPair(new Functor2(@"atom", Atom_1, Pos), Tokens))) | ||
3098 | { | ||
3099 | foreach (bool l3 in YP.unify(Pos, 0)) | ||
3100 | { | ||
3101 | foreach (bool l4 in YP.atom_codes(Atom_1, Chars)) | ||
3102 | { | ||
3103 | foreach (bool l5 in read_after_atom(Ch, Dict, Tokens)) | ||
3104 | { | ||
3105 | yield return false; | ||
3106 | } | ||
3107 | } | ||
3108 | } | ||
3109 | } | ||
3110 | } | ||
3111 | } | ||
3112 | |||
3113 | public static IEnumerable<bool> read_after_atom(object arg1, object Dict, object arg3) | ||
3114 | { | ||
3115 | { | ||
3116 | Variable Tokens = new Variable(); | ||
3117 | Variable NextCh = new Variable(); | ||
3118 | foreach (bool l2 in YP.unify(arg1, 40)) | ||
3119 | { | ||
3120 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(@"("), Tokens))) | ||
3121 | { | ||
3122 | foreach (bool l4 in YP.get_code(NextCh)) | ||
3123 | { | ||
3124 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
3125 | { | ||
3126 | yield return false; | ||
3127 | } | ||
3128 | } | ||
3129 | yield break; | ||
3130 | } | ||
3131 | } | ||
3132 | } | ||
3133 | { | ||
3134 | object Ch = arg1; | ||
3135 | object Tokens = arg3; | ||
3136 | foreach (bool l2 in read_tokens(Ch, Dict, Tokens)) | ||
3137 | { | ||
3138 | yield return false; | ||
3139 | } | ||
3140 | } | ||
3141 | } | ||
3142 | |||
3143 | public static IEnumerable<bool> read_string(object Chars, object Quote, object NextCh) | ||
3144 | { | ||
3145 | { | ||
3146 | Variable Ch = new Variable(); | ||
3147 | Variable Char = new Variable(); | ||
3148 | Variable Next = new Variable(); | ||
3149 | foreach (bool l2 in YP.get_code(Ch)) | ||
3150 | { | ||
3151 | foreach (bool l3 in read_char(Ch, Quote, Char, Next)) | ||
3152 | { | ||
3153 | foreach (bool l4 in rest_string5(Char, Next, Chars, Quote, NextCh)) | ||
3154 | { | ||
3155 | yield return false; | ||
3156 | } | ||
3157 | } | ||
3158 | } | ||
3159 | } | ||
3160 | } | ||
3161 | |||
3162 | public static IEnumerable<bool> rest_string5(object arg1, object arg2, object arg3, object arg4, object arg5) | ||
3163 | { | ||
3164 | { | ||
3165 | object _X = arg4; | ||
3166 | Variable NextCh = new Variable(); | ||
3167 | foreach (bool l2 in YP.unify(arg1, -1)) | ||
3168 | { | ||
3169 | foreach (bool l3 in YP.unify(arg2, NextCh)) | ||
3170 | { | ||
3171 | foreach (bool l4 in YP.unify(arg3, Atom.NIL)) | ||
3172 | { | ||
3173 | foreach (bool l5 in YP.unify(arg5, NextCh)) | ||
3174 | { | ||
3175 | yield return true; | ||
3176 | yield break; | ||
3177 | } | ||
3178 | } | ||
3179 | } | ||
3180 | } | ||
3181 | } | ||
3182 | { | ||
3183 | object Char = arg1; | ||
3184 | object Next = arg2; | ||
3185 | object Quote = arg4; | ||
3186 | object NextCh = arg5; | ||
3187 | Variable Chars = new Variable(); | ||
3188 | Variable Char2 = new Variable(); | ||
3189 | Variable Next2 = new Variable(); | ||
3190 | foreach (bool l2 in YP.unify(arg3, new ListPair(Char, Chars))) | ||
3191 | { | ||
3192 | foreach (bool l3 in read_char(Next, Quote, Char2, Next2)) | ||
3193 | { | ||
3194 | foreach (bool l4 in rest_string5(Char2, Next2, Chars, Quote, NextCh)) | ||
3195 | { | ||
3196 | yield return false; | ||
3197 | } | ||
3198 | } | ||
3199 | } | ||
3200 | } | ||
3201 | } | ||
3202 | |||
3203 | public static IEnumerable<bool> escape_char(object arg1, object arg2) | ||
3204 | { | ||
3205 | { | ||
3206 | foreach (bool l2 in YP.unify(arg1, 110)) | ||
3207 | { | ||
3208 | foreach (bool l3 in YP.unify(arg2, 10)) | ||
3209 | { | ||
3210 | yield return false; | ||
3211 | } | ||
3212 | } | ||
3213 | } | ||
3214 | { | ||
3215 | foreach (bool l2 in YP.unify(arg1, 78)) | ||
3216 | { | ||
3217 | foreach (bool l3 in YP.unify(arg2, 10)) | ||
3218 | { | ||
3219 | yield return false; | ||
3220 | } | ||
3221 | } | ||
3222 | } | ||
3223 | { | ||
3224 | foreach (bool l2 in YP.unify(arg1, 116)) | ||
3225 | { | ||
3226 | foreach (bool l3 in YP.unify(arg2, 9)) | ||
3227 | { | ||
3228 | yield return false; | ||
3229 | } | ||
3230 | } | ||
3231 | } | ||
3232 | { | ||
3233 | foreach (bool l2 in YP.unify(arg1, 84)) | ||
3234 | { | ||
3235 | foreach (bool l3 in YP.unify(arg2, 9)) | ||
3236 | { | ||
3237 | yield return false; | ||
3238 | } | ||
3239 | } | ||
3240 | } | ||
3241 | { | ||
3242 | foreach (bool l2 in YP.unify(arg1, 114)) | ||
3243 | { | ||
3244 | foreach (bool l3 in YP.unify(arg2, 13)) | ||
3245 | { | ||
3246 | yield return false; | ||
3247 | } | ||
3248 | } | ||
3249 | } | ||
3250 | { | ||
3251 | foreach (bool l2 in YP.unify(arg1, 82)) | ||
3252 | { | ||
3253 | foreach (bool l3 in YP.unify(arg2, 13)) | ||
3254 | { | ||
3255 | yield return false; | ||
3256 | } | ||
3257 | } | ||
3258 | } | ||
3259 | { | ||
3260 | foreach (bool l2 in YP.unify(arg1, 118)) | ||
3261 | { | ||
3262 | foreach (bool l3 in YP.unify(arg2, 11)) | ||
3263 | { | ||
3264 | yield return false; | ||
3265 | } | ||
3266 | } | ||
3267 | } | ||
3268 | { | ||
3269 | foreach (bool l2 in YP.unify(arg1, 86)) | ||
3270 | { | ||
3271 | foreach (bool l3 in YP.unify(arg2, 11)) | ||
3272 | { | ||
3273 | yield return false; | ||
3274 | } | ||
3275 | } | ||
3276 | } | ||
3277 | { | ||
3278 | foreach (bool l2 in YP.unify(arg1, 98)) | ||
3279 | { | ||
3280 | foreach (bool l3 in YP.unify(arg2, 8)) | ||
3281 | { | ||
3282 | yield return false; | ||
3283 | } | ||
3284 | } | ||
3285 | } | ||
3286 | { | ||
3287 | foreach (bool l2 in YP.unify(arg1, 66)) | ||
3288 | { | ||
3289 | foreach (bool l3 in YP.unify(arg2, 8)) | ||
3290 | { | ||
3291 | yield return false; | ||
3292 | } | ||
3293 | } | ||
3294 | } | ||
3295 | { | ||
3296 | foreach (bool l2 in YP.unify(arg1, 102)) | ||
3297 | { | ||
3298 | foreach (bool l3 in YP.unify(arg2, 12)) | ||
3299 | { | ||
3300 | yield return false; | ||
3301 | } | ||
3302 | } | ||
3303 | } | ||
3304 | { | ||
3305 | foreach (bool l2 in YP.unify(arg1, 70)) | ||
3306 | { | ||
3307 | foreach (bool l3 in YP.unify(arg2, 12)) | ||
3308 | { | ||
3309 | yield return false; | ||
3310 | } | ||
3311 | } | ||
3312 | } | ||
3313 | { | ||
3314 | foreach (bool l2 in YP.unify(arg1, 101)) | ||
3315 | { | ||
3316 | foreach (bool l3 in YP.unify(arg2, 27)) | ||
3317 | { | ||
3318 | yield return false; | ||
3319 | } | ||
3320 | } | ||
3321 | } | ||
3322 | { | ||
3323 | foreach (bool l2 in YP.unify(arg1, 69)) | ||
3324 | { | ||
3325 | foreach (bool l3 in YP.unify(arg2, 27)) | ||
3326 | { | ||
3327 | yield return false; | ||
3328 | } | ||
3329 | } | ||
3330 | } | ||
3331 | { | ||
3332 | foreach (bool l2 in YP.unify(arg1, 100)) | ||
3333 | { | ||
3334 | foreach (bool l3 in YP.unify(arg2, 127)) | ||
3335 | { | ||
3336 | yield return false; | ||
3337 | } | ||
3338 | } | ||
3339 | } | ||
3340 | { | ||
3341 | foreach (bool l2 in YP.unify(arg1, 68)) | ||
3342 | { | ||
3343 | foreach (bool l3 in YP.unify(arg2, 127)) | ||
3344 | { | ||
3345 | yield return false; | ||
3346 | } | ||
3347 | } | ||
3348 | } | ||
3349 | { | ||
3350 | foreach (bool l2 in YP.unify(arg1, 115)) | ||
3351 | { | ||
3352 | foreach (bool l3 in YP.unify(arg2, 32)) | ||
3353 | { | ||
3354 | yield return false; | ||
3355 | } | ||
3356 | } | ||
3357 | } | ||
3358 | { | ||
3359 | foreach (bool l2 in YP.unify(arg1, 83)) | ||
3360 | { | ||
3361 | foreach (bool l3 in YP.unify(arg2, 32)) | ||
3362 | { | ||
3363 | yield return false; | ||
3364 | } | ||
3365 | } | ||
3366 | } | ||
3367 | { | ||
3368 | foreach (bool l2 in YP.unify(arg1, 122)) | ||
3369 | { | ||
3370 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
3371 | { | ||
3372 | yield return false; | ||
3373 | } | ||
3374 | } | ||
3375 | } | ||
3376 | { | ||
3377 | foreach (bool l2 in YP.unify(arg1, 90)) | ||
3378 | { | ||
3379 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
3380 | { | ||
3381 | yield return false; | ||
3382 | } | ||
3383 | } | ||
3384 | } | ||
3385 | } | ||
3386 | |||
3387 | public static IEnumerable<bool> read_variable(object C1, object Dict, object arg3) | ||
3388 | { | ||
3389 | { | ||
3390 | Variable Var = new Variable(); | ||
3391 | Variable Name = new Variable(); | ||
3392 | Variable StartPos = new Variable(); | ||
3393 | Variable Tokens = new Variable(); | ||
3394 | Variable Chars = new Variable(); | ||
3395 | Variable NextCh = new Variable(); | ||
3396 | foreach (bool l2 in YP.unify(arg3, new ListPair(new Functor3(@"var", Var, Name, StartPos), Tokens))) | ||
3397 | { | ||
3398 | foreach (bool l3 in get_current_position(StartPos)) | ||
3399 | { | ||
3400 | foreach (bool l4 in read_name(C1, Chars, NextCh)) | ||
3401 | { | ||
3402 | foreach (bool l5 in YP.atom_codes(Name, Chars)) | ||
3403 | { | ||
3404 | if (YP.termEqual(Name, Atom.a(@"_"))) | ||
3405 | { | ||
3406 | foreach (bool l7 in read_after_atom(NextCh, Dict, Tokens)) | ||
3407 | { | ||
3408 | yield return false; | ||
3409 | } | ||
3410 | goto cutIf1; | ||
3411 | } | ||
3412 | foreach (bool l6 in read_lookup(Dict, Name, Var)) | ||
3413 | { | ||
3414 | foreach (bool l7 in read_after_atom(NextCh, Dict, Tokens)) | ||
3415 | { | ||
3416 | yield return false; | ||
3417 | } | ||
3418 | } | ||
3419 | cutIf1: | ||
3420 | { } | ||
3421 | } | ||
3422 | } | ||
3423 | } | ||
3424 | } | ||
3425 | } | ||
3426 | } | ||
3427 | |||
3428 | public static IEnumerable<bool> read_lookup(object arg1, object Name, object Var) | ||
3429 | { | ||
3430 | { | ||
3431 | Variable N = new Variable(); | ||
3432 | Variable V = new Variable(); | ||
3433 | Variable L = new Variable(); | ||
3434 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"=", N, V), L))) | ||
3435 | { | ||
3436 | foreach (bool l3 in YP.unify(N, Name)) | ||
3437 | { | ||
3438 | foreach (bool l4 in YP.unify(V, Var)) | ||
3439 | { | ||
3440 | yield return false; | ||
3441 | } | ||
3442 | goto cutIf1; | ||
3443 | } | ||
3444 | foreach (bool l3 in read_lookup(L, Name, Var)) | ||
3445 | { | ||
3446 | yield return false; | ||
3447 | } | ||
3448 | cutIf1: | ||
3449 | { } | ||
3450 | } | ||
3451 | } | ||
3452 | } | ||
3453 | |||
3454 | public static IEnumerable<bool> read_solidus(object Ch, object LastCh) | ||
3455 | { | ||
3456 | { | ||
3457 | Variable NextCh = new Variable(); | ||
3458 | if (YP.equal(Ch, 42)) | ||
3459 | { | ||
3460 | foreach (bool l3 in YP.get_code(NextCh)) | ||
3461 | { | ||
3462 | if (YP.equal(NextCh, 47)) | ||
3463 | { | ||
3464 | foreach (bool l5 in YP.get_code(LastCh)) | ||
3465 | { | ||
3466 | yield return false; | ||
3467 | } | ||
3468 | goto cutIf2; | ||
3469 | } | ||
3470 | foreach (bool l4 in read_solidus(NextCh, LastCh)) | ||
3471 | { | ||
3472 | yield return false; | ||
3473 | } | ||
3474 | cutIf2: | ||
3475 | { } | ||
3476 | } | ||
3477 | goto cutIf1; | ||
3478 | } | ||
3479 | if (YP.notEqual(Ch, -1)) | ||
3480 | { | ||
3481 | foreach (bool l3 in YP.get_code(NextCh)) | ||
3482 | { | ||
3483 | foreach (bool l4 in read_solidus(NextCh, LastCh)) | ||
3484 | { | ||
3485 | yield return false; | ||
3486 | } | ||
3487 | } | ||
3488 | goto cutIf3; | ||
3489 | } | ||
3490 | foreach (bool l2 in YP.unify(LastCh, Ch)) | ||
3491 | { | ||
3492 | foreach (bool l3 in formatError(Atom.a(@"user_error"), Atom.a(@"~N** end of file in /*comment~n"), Atom.NIL)) | ||
3493 | { | ||
3494 | yield return false; | ||
3495 | } | ||
3496 | } | ||
3497 | cutIf3: | ||
3498 | cutIf1: | ||
3499 | { } | ||
3500 | } | ||
3501 | } | ||
3502 | |||
3503 | public static IEnumerable<bool> read_identifier(object C1, object Dict, object Tokens) | ||
3504 | { | ||
3505 | { | ||
3506 | Variable Chars = new Variable(); | ||
3507 | Variable NextCh = new Variable(); | ||
3508 | foreach (bool l2 in read_name(C1, Chars, NextCh)) | ||
3509 | { | ||
3510 | foreach (bool l3 in read_after_atom4(NextCh, Dict, Tokens, Chars)) | ||
3511 | { | ||
3512 | yield return false; | ||
3513 | } | ||
3514 | } | ||
3515 | } | ||
3516 | } | ||
3517 | |||
3518 | public static IEnumerable<bool> read_name(object C1, object arg2, object LastCh) | ||
3519 | { | ||
3520 | { | ||
3521 | Variable Chars = new Variable(); | ||
3522 | Variable C2 = new Variable(); | ||
3523 | foreach (bool l2 in YP.unify(arg2, new ListPair(C1, Chars))) | ||
3524 | { | ||
3525 | foreach (bool l3 in YP.get_code(C2)) | ||
3526 | { | ||
3527 | if (YP.greaterThanOrEqual(C2, new ListPair(97, Atom.NIL))) | ||
3528 | { | ||
3529 | if (YP.lessThanOrEqual(C2, new ListPair(122, Atom.NIL))) | ||
3530 | { | ||
3531 | foreach (bool l6 in read_name(C2, Chars, LastCh)) | ||
3532 | { | ||
3533 | yield return false; | ||
3534 | } | ||
3535 | goto cutIf2; | ||
3536 | } | ||
3537 | if (YP.lessThan(C2, 192)) | ||
3538 | { | ||
3539 | if (YP.notEqual(YP.bitwiseOr(C2, 16), 186)) | ||
3540 | { | ||
3541 | foreach (bool l7 in YP.unify(Chars, Atom.NIL)) | ||
3542 | { | ||
3543 | foreach (bool l8 in YP.unify(LastCh, C2)) | ||
3544 | { | ||
3545 | yield return false; | ||
3546 | } | ||
3547 | } | ||
3548 | goto cutIf3; | ||
3549 | } | ||
3550 | } | ||
3551 | if (YP.equal(YP.bitwiseOr(C2, 32), 247)) | ||
3552 | { | ||
3553 | foreach (bool l6 in YP.unify(Chars, Atom.NIL)) | ||
3554 | { | ||
3555 | foreach (bool l7 in YP.unify(LastCh, C2)) | ||
3556 | { | ||
3557 | yield return false; | ||
3558 | } | ||
3559 | } | ||
3560 | goto cutIf4; | ||
3561 | } | ||
3562 | foreach (bool l5 in read_name(C2, Chars, LastCh)) | ||
3563 | { | ||
3564 | yield return false; | ||
3565 | } | ||
3566 | cutIf4: | ||
3567 | cutIf3: | ||
3568 | cutIf2: | ||
3569 | goto cutIf1; | ||
3570 | } | ||
3571 | if (YP.greaterThanOrEqual(C2, new ListPair(65, Atom.NIL))) | ||
3572 | { | ||
3573 | if (YP.greaterThan(C2, new ListPair(90, Atom.NIL))) | ||
3574 | { | ||
3575 | if (YP.notEqual(C2, new ListPair(95, Atom.NIL))) | ||
3576 | { | ||
3577 | foreach (bool l7 in YP.unify(Chars, Atom.NIL)) | ||
3578 | { | ||
3579 | foreach (bool l8 in YP.unify(LastCh, C2)) | ||
3580 | { | ||
3581 | yield return false; | ||
3582 | } | ||
3583 | } | ||
3584 | goto cutIf6; | ||
3585 | } | ||
3586 | } | ||
3587 | foreach (bool l5 in read_name(C2, Chars, LastCh)) | ||
3588 | { | ||
3589 | yield return false; | ||
3590 | } | ||
3591 | cutIf6: | ||
3592 | goto cutIf5; | ||
3593 | } | ||
3594 | if (YP.greaterThanOrEqual(C2, new ListPair(48, Atom.NIL))) | ||
3595 | { | ||
3596 | if (YP.lessThanOrEqual(C2, new ListPair(57, Atom.NIL))) | ||
3597 | { | ||
3598 | foreach (bool l6 in read_name(C2, Chars, LastCh)) | ||
3599 | { | ||
3600 | yield return false; | ||
3601 | } | ||
3602 | goto cutIf7; | ||
3603 | } | ||
3604 | } | ||
3605 | foreach (bool l4 in YP.unify(Chars, Atom.NIL)) | ||
3606 | { | ||
3607 | foreach (bool l5 in YP.unify(LastCh, C2)) | ||
3608 | { | ||
3609 | yield return false; | ||
3610 | } | ||
3611 | } | ||
3612 | cutIf7: | ||
3613 | cutIf5: | ||
3614 | cutIf1: | ||
3615 | { } | ||
3616 | } | ||
3617 | } | ||
3618 | } | ||
3619 | } | ||
3620 | |||
3621 | public static IEnumerable<bool> read_fullstop(object Ch, object Dict, object Tokens) | ||
3622 | { | ||
3623 | { | ||
3624 | Variable Number = new Variable(); | ||
3625 | Variable Tokens1 = new Variable(); | ||
3626 | Variable Chars = new Variable(); | ||
3627 | Variable NextCh = new Variable(); | ||
3628 | if (YP.lessThanOrEqual(Ch, new ListPair(57, Atom.NIL))) | ||
3629 | { | ||
3630 | if (YP.greaterThanOrEqual(Ch, new ListPair(48, Atom.NIL))) | ||
3631 | { | ||
3632 | foreach (bool l4 in YP.unify(Tokens, new ListPair(new Functor1(@"number", Number), Tokens1))) | ||
3633 | { | ||
3634 | foreach (bool l5 in read_float(Number, Dict, Tokens1, new ListPair(48, Atom.NIL), Ch)) | ||
3635 | { | ||
3636 | yield return false; | ||
3637 | } | ||
3638 | } | ||
3639 | goto cutIf1; | ||
3640 | } | ||
3641 | } | ||
3642 | if (YP.greaterThan(Ch, new ListPair(32, Atom.NIL))) | ||
3643 | { | ||
3644 | foreach (bool l3 in rest_symbol(Ch, Chars, NextCh)) | ||
3645 | { | ||
3646 | foreach (bool l4 in read_after_atom4(NextCh, Dict, Tokens, new ListPair(46, Chars))) | ||
3647 | { | ||
3648 | yield return false; | ||
3649 | } | ||
3650 | } | ||
3651 | goto cutIf2; | ||
3652 | } | ||
3653 | if (YP.greaterThanOrEqual(Ch, 0)) | ||
3654 | { | ||
3655 | foreach (bool l3 in YP.unify(Tokens, Atom.NIL)) | ||
3656 | { | ||
3657 | yield return false; | ||
3658 | } | ||
3659 | goto cutIf3; | ||
3660 | } | ||
3661 | foreach (bool l2 in formatError(Atom.a(@"user_error"), Atom.a(@"~N** end of file just after full stop~n"), Atom.NIL)) | ||
3662 | { | ||
3663 | } | ||
3664 | cutIf3: | ||
3665 | cutIf2: | ||
3666 | cutIf1: | ||
3667 | { } | ||
3668 | } | ||
3669 | } | ||
3670 | |||
3671 | public static IEnumerable<bool> read_float(object Number, object Dict, object Tokens, object Digits, object Digit) | ||
3672 | { | ||
3673 | { | ||
3674 | Variable Chars = new Variable(); | ||
3675 | Variable Rest = new Variable(); | ||
3676 | Variable NextCh = new Variable(); | ||
3677 | foreach (bool l2 in prepend(Digits, Chars, Rest)) | ||
3678 | { | ||
3679 | foreach (bool l3 in read_float(Digit, Rest, NextCh, Chars)) | ||
3680 | { | ||
3681 | foreach (bool l4 in YP.number_codes(Number, Chars)) | ||
3682 | { | ||
3683 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
3684 | { | ||
3685 | yield return false; | ||
3686 | } | ||
3687 | } | ||
3688 | } | ||
3689 | } | ||
3690 | } | ||
3691 | } | ||
3692 | |||
3693 | public static IEnumerable<bool> prepend(object arg1, object arg2, object arg3) | ||
3694 | { | ||
3695 | { | ||
3696 | object X = arg3; | ||
3697 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
3698 | { | ||
3699 | foreach (bool l3 in YP.unify(arg2, new ListPair(46, X))) | ||
3700 | { | ||
3701 | yield return false; | ||
3702 | } | ||
3703 | } | ||
3704 | } | ||
3705 | { | ||
3706 | object Y = arg3; | ||
3707 | Variable C = new Variable(); | ||
3708 | Variable Cs = new Variable(); | ||
3709 | Variable X = new Variable(); | ||
3710 | foreach (bool l2 in YP.unify(arg1, new ListPair(C, Cs))) | ||
3711 | { | ||
3712 | foreach (bool l3 in YP.unify(arg2, new ListPair(C, X))) | ||
3713 | { | ||
3714 | foreach (bool l4 in prepend(Cs, X, Y)) | ||
3715 | { | ||
3716 | yield return false; | ||
3717 | } | ||
3718 | } | ||
3719 | } | ||
3720 | } | ||
3721 | } | ||
3722 | |||
3723 | public static IEnumerable<bool> read_float(object C1, object arg2, object NextCh, object Total) | ||
3724 | { | ||
3725 | { | ||
3726 | Variable Chars = new Variable(); | ||
3727 | Variable C2 = new Variable(); | ||
3728 | Variable C3 = new Variable(); | ||
3729 | Variable C4 = new Variable(); | ||
3730 | Variable More = new Variable(); | ||
3731 | foreach (bool l2 in YP.unify(arg2, new ListPair(C1, Chars))) | ||
3732 | { | ||
3733 | foreach (bool l3 in YP.get_code(C2)) | ||
3734 | { | ||
3735 | if (YP.greaterThanOrEqual(C2, new ListPair(48, Atom.NIL))) | ||
3736 | { | ||
3737 | if (YP.lessThanOrEqual(C2, new ListPair(57, Atom.NIL))) | ||
3738 | { | ||
3739 | foreach (bool l6 in read_float(C2, Chars, NextCh, Total)) | ||
3740 | { | ||
3741 | yield return false; | ||
3742 | } | ||
3743 | goto cutIf1; | ||
3744 | } | ||
3745 | } | ||
3746 | if (YP.equal(YP.bitwiseOr(C2, 32), new ListPair(101, Atom.NIL))) | ||
3747 | { | ||
3748 | foreach (bool l5 in YP.get_code(C3)) | ||
3749 | { | ||
3750 | if (YP.equal(C3, new ListPair(45, Atom.NIL))) | ||
3751 | { | ||
3752 | foreach (bool l7 in YP.get_code(C4)) | ||
3753 | { | ||
3754 | foreach (bool l8 in YP.unify(Chars, new ListPair(C2, new ListPair(45, More)))) | ||
3755 | { | ||
3756 | if (YP.greaterThanOrEqual(C4, new ListPair(48, Atom.NIL))) | ||
3757 | { | ||
3758 | if (YP.lessThanOrEqual(C4, new ListPair(57, Atom.NIL))) | ||
3759 | { | ||
3760 | foreach (bool l11 in read_exponent(C4, More, NextCh)) | ||
3761 | { | ||
3762 | yield return false; | ||
3763 | } | ||
3764 | goto cutIf4; | ||
3765 | } | ||
3766 | } | ||
3767 | foreach (bool l9 in YP.unify(More, Atom.NIL)) | ||
3768 | { | ||
3769 | foreach (bool l10 in formatError(Atom.a(@"user_error"), Atom.a(@"~N** Missing exponent in ~s~n"), new ListPair(Total, Atom.NIL))) | ||
3770 | { | ||
3771 | } | ||
3772 | } | ||
3773 | foreach (bool l9 in YP.unify(More, new ListPair(48, Atom.NIL))) | ||
3774 | { | ||
3775 | foreach (bool l10 in YP.unify(NextCh, C4)) | ||
3776 | { | ||
3777 | yield return false; | ||
3778 | } | ||
3779 | } | ||
3780 | cutIf4: | ||
3781 | { } | ||
3782 | } | ||
3783 | } | ||
3784 | goto cutIf3; | ||
3785 | } | ||
3786 | if (YP.equal(C3, new ListPair(43, Atom.NIL))) | ||
3787 | { | ||
3788 | foreach (bool l7 in YP.get_code(C4)) | ||
3789 | { | ||
3790 | foreach (bool l8 in YP.unify(Chars, new ListPair(C2, More))) | ||
3791 | { | ||
3792 | if (YP.greaterThanOrEqual(C4, new ListPair(48, Atom.NIL))) | ||
3793 | { | ||
3794 | if (YP.lessThanOrEqual(C4, new ListPair(57, Atom.NIL))) | ||
3795 | { | ||
3796 | foreach (bool l11 in read_exponent(C4, More, NextCh)) | ||
3797 | { | ||
3798 | yield return false; | ||
3799 | } | ||
3800 | goto cutIf6; | ||
3801 | } | ||
3802 | } | ||
3803 | foreach (bool l9 in YP.unify(More, Atom.NIL)) | ||
3804 | { | ||
3805 | foreach (bool l10 in formatError(Atom.a(@"user_error"), Atom.a(@"~N** Missing exponent in ~s~n"), new ListPair(Total, Atom.NIL))) | ||
3806 | { | ||
3807 | } | ||
3808 | } | ||
3809 | foreach (bool l9 in YP.unify(More, new ListPair(48, Atom.NIL))) | ||
3810 | { | ||
3811 | foreach (bool l10 in YP.unify(NextCh, C4)) | ||
3812 | { | ||
3813 | yield return false; | ||
3814 | } | ||
3815 | } | ||
3816 | cutIf6: | ||
3817 | { } | ||
3818 | } | ||
3819 | } | ||
3820 | goto cutIf5; | ||
3821 | } | ||
3822 | foreach (bool l6 in YP.unify(C4, C3)) | ||
3823 | { | ||
3824 | foreach (bool l7 in YP.unify(Chars, new ListPair(C2, More))) | ||
3825 | { | ||
3826 | if (YP.greaterThanOrEqual(C4, new ListPair(48, Atom.NIL))) | ||
3827 | { | ||
3828 | if (YP.lessThanOrEqual(C4, new ListPair(57, Atom.NIL))) | ||
3829 | { | ||
3830 | foreach (bool l10 in read_exponent(C4, More, NextCh)) | ||
3831 | { | ||
3832 | yield return false; | ||
3833 | } | ||
3834 | goto cutIf7; | ||
3835 | } | ||
3836 | } | ||
3837 | foreach (bool l8 in YP.unify(More, Atom.NIL)) | ||
3838 | { | ||
3839 | foreach (bool l9 in formatError(Atom.a(@"user_error"), Atom.a(@"~N** Missing exponent in ~s~n"), new ListPair(Total, Atom.NIL))) | ||
3840 | { | ||
3841 | } | ||
3842 | } | ||
3843 | foreach (bool l8 in YP.unify(More, new ListPair(48, Atom.NIL))) | ||
3844 | { | ||
3845 | foreach (bool l9 in YP.unify(NextCh, C4)) | ||
3846 | { | ||
3847 | yield return false; | ||
3848 | } | ||
3849 | } | ||
3850 | cutIf7: | ||
3851 | { } | ||
3852 | } | ||
3853 | } | ||
3854 | cutIf5: | ||
3855 | cutIf3: | ||
3856 | { } | ||
3857 | } | ||
3858 | goto cutIf2; | ||
3859 | } | ||
3860 | foreach (bool l4 in YP.unify(Chars, Atom.NIL)) | ||
3861 | { | ||
3862 | foreach (bool l5 in YP.unify(NextCh, C2)) | ||
3863 | { | ||
3864 | yield return false; | ||
3865 | } | ||
3866 | } | ||
3867 | cutIf2: | ||
3868 | cutIf1: | ||
3869 | { } | ||
3870 | } | ||
3871 | } | ||
3872 | } | ||
3873 | } | ||
3874 | |||
3875 | public static IEnumerable<bool> read_exponent(object C1, object arg2, object NextCh) | ||
3876 | { | ||
3877 | { | ||
3878 | Variable Chars = new Variable(); | ||
3879 | Variable C2 = new Variable(); | ||
3880 | foreach (bool l2 in YP.unify(arg2, new ListPair(C1, Chars))) | ||
3881 | { | ||
3882 | foreach (bool l3 in YP.get_code(C2)) | ||
3883 | { | ||
3884 | if (YP.greaterThanOrEqual(C2, new ListPair(48, Atom.NIL))) | ||
3885 | { | ||
3886 | if (YP.lessThanOrEqual(C2, new ListPair(57, Atom.NIL))) | ||
3887 | { | ||
3888 | foreach (bool l6 in read_exponent(C2, Chars, NextCh)) | ||
3889 | { | ||
3890 | yield return false; | ||
3891 | } | ||
3892 | goto cutIf1; | ||
3893 | } | ||
3894 | } | ||
3895 | foreach (bool l4 in YP.unify(Chars, Atom.NIL)) | ||
3896 | { | ||
3897 | foreach (bool l5 in YP.unify(NextCh, C2)) | ||
3898 | { | ||
3899 | yield return false; | ||
3900 | } | ||
3901 | } | ||
3902 | cutIf1: | ||
3903 | { } | ||
3904 | } | ||
3905 | } | ||
3906 | } | ||
3907 | } | ||
3908 | |||
3909 | public static IEnumerable<bool> read_number(object C1, object Dict, object arg3) | ||
3910 | { | ||
3911 | { | ||
3912 | Variable Number = new Variable(); | ||
3913 | Variable Tokens = new Variable(); | ||
3914 | Variable C2 = new Variable(); | ||
3915 | Variable N = new Variable(); | ||
3916 | Variable C = new Variable(); | ||
3917 | Variable C3 = new Variable(); | ||
3918 | Variable Digits = new Variable(); | ||
3919 | foreach (bool l2 in YP.unify(arg3, new ListPair(new Functor1(@"number", Number), Tokens))) | ||
3920 | { | ||
3921 | foreach (bool l3 in read_number4(C1, C2, 0, N)) | ||
3922 | { | ||
3923 | if (YP.equal(C2, 39)) | ||
3924 | { | ||
3925 | if (YP.greaterThanOrEqual(N, 2)) | ||
3926 | { | ||
3927 | if (YP.lessThanOrEqual(N, 36)) | ||
3928 | { | ||
3929 | foreach (bool l7 in read_based(N, 0, Number, C)) | ||
3930 | { | ||
3931 | foreach (bool l8 in read_tokens(C, Dict, Tokens)) | ||
3932 | { | ||
3933 | yield return false; | ||
3934 | } | ||
3935 | } | ||
3936 | goto cutIf2; | ||
3937 | } | ||
3938 | } | ||
3939 | if (YP.equal(N, 0)) | ||
3940 | { | ||
3941 | foreach (bool l6 in YP.get_code(C3)) | ||
3942 | { | ||
3943 | foreach (bool l7 in read_char(C3, -1, Number, C)) | ||
3944 | { | ||
3945 | foreach (bool l8 in read_tokens(C, Dict, Tokens)) | ||
3946 | { | ||
3947 | yield return false; | ||
3948 | } | ||
3949 | } | ||
3950 | } | ||
3951 | goto cutIf3; | ||
3952 | } | ||
3953 | 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)))) | ||
3954 | { | ||
3955 | foreach (bool l6 in YP.unify(Number, N)) | ||
3956 | { | ||
3957 | foreach (bool l7 in YP.unify(C, C2)) | ||
3958 | { | ||
3959 | foreach (bool l8 in read_tokens(C, Dict, Tokens)) | ||
3960 | { | ||
3961 | yield return false; | ||
3962 | } | ||
3963 | } | ||
3964 | } | ||
3965 | } | ||
3966 | cutIf3: | ||
3967 | cutIf2: | ||
3968 | goto cutIf1; | ||
3969 | } | ||
3970 | if (YP.equal(C2, 46)) | ||
3971 | { | ||
3972 | foreach (bool l5 in YP.get_code(C3)) | ||
3973 | { | ||
3974 | if (YP.greaterThanOrEqual(C3, new ListPair(48, Atom.NIL))) | ||
3975 | { | ||
3976 | if (YP.lessThanOrEqual(C3, new ListPair(57, Atom.NIL))) | ||
3977 | { | ||
3978 | foreach (bool l8 in YP.number_codes(N, Digits)) | ||
3979 | { | ||
3980 | foreach (bool l9 in read_float(Number, Dict, Tokens, Digits, C3)) | ||
3981 | { | ||
3982 | yield return false; | ||
3983 | } | ||
3984 | } | ||
3985 | goto cutIf5; | ||
3986 | } | ||
3987 | } | ||
3988 | foreach (bool l6 in YP.unify(Number, N)) | ||
3989 | { | ||
3990 | foreach (bool l7 in read_fullstop(C3, Dict, Tokens)) | ||
3991 | { | ||
3992 | yield return false; | ||
3993 | } | ||
3994 | } | ||
3995 | cutIf5: | ||
3996 | { } | ||
3997 | } | ||
3998 | goto cutIf4; | ||
3999 | } | ||
4000 | foreach (bool l4 in YP.unify(Number, N)) | ||
4001 | { | ||
4002 | foreach (bool l5 in read_tokens(C2, Dict, Tokens)) | ||
4003 | { | ||
4004 | yield return false; | ||
4005 | } | ||
4006 | } | ||
4007 | cutIf4: | ||
4008 | cutIf1: | ||
4009 | { } | ||
4010 | } | ||
4011 | } | ||
4012 | } | ||
4013 | } | ||
4014 | |||
4015 | public static IEnumerable<bool> read_number4(object C0, object C, object N0, object N) | ||
4016 | { | ||
4017 | { | ||
4018 | Variable N1 = new Variable(); | ||
4019 | Variable C1 = new Variable(); | ||
4020 | if (YP.greaterThanOrEqual(C0, new ListPair(48, Atom.NIL))) | ||
4021 | { | ||
4022 | if (YP.lessThanOrEqual(C0, new ListPair(57, Atom.NIL))) | ||
4023 | { | ||
4024 | foreach (bool l4 in YP.unify(N1, YP.add(YP.subtract(YP.multiply(N0, 10), new ListPair(48, Atom.NIL)), C0))) | ||
4025 | { | ||
4026 | foreach (bool l5 in YP.get_code(C1)) | ||
4027 | { | ||
4028 | foreach (bool l6 in read_number4(C1, C, N1, N)) | ||
4029 | { | ||
4030 | yield return false; | ||
4031 | } | ||
4032 | } | ||
4033 | } | ||
4034 | goto cutIf1; | ||
4035 | } | ||
4036 | } | ||
4037 | if (YP.equal(C0, 95)) | ||
4038 | { | ||
4039 | foreach (bool l3 in YP.get_code(C1)) | ||
4040 | { | ||
4041 | foreach (bool l4 in read_number4(C1, C, N0, N)) | ||
4042 | { | ||
4043 | yield return false; | ||
4044 | } | ||
4045 | } | ||
4046 | goto cutIf2; | ||
4047 | } | ||
4048 | foreach (bool l2 in YP.unify(C, C0)) | ||
4049 | { | ||
4050 | foreach (bool l3 in YP.unify(N, N0)) | ||
4051 | { | ||
4052 | yield return false; | ||
4053 | } | ||
4054 | } | ||
4055 | cutIf2: | ||
4056 | cutIf1: | ||
4057 | { } | ||
4058 | } | ||
4059 | } | ||
4060 | |||
4061 | public static IEnumerable<bool> read_based(object Base, object N0, object N, object C) | ||
4062 | { | ||
4063 | { | ||
4064 | Variable C1 = new Variable(); | ||
4065 | Variable Digit = new Variable(); | ||
4066 | Variable N1 = new Variable(); | ||
4067 | foreach (bool l2 in YP.get_code(C1)) | ||
4068 | { | ||
4069 | if (YP.greaterThanOrEqual(C1, new ListPair(48, Atom.NIL))) | ||
4070 | { | ||
4071 | if (YP.lessThanOrEqual(C1, new ListPair(57, Atom.NIL))) | ||
4072 | { | ||
4073 | foreach (bool l5 in YP.unify(Digit, YP.subtract(C1, new ListPair(48, Atom.NIL)))) | ||
4074 | { | ||
4075 | if (YP.lessThan(Digit, Base)) | ||
4076 | { | ||
4077 | foreach (bool l7 in YP.unify(N1, YP.add(YP.multiply(N0, Base), Digit))) | ||
4078 | { | ||
4079 | foreach (bool l8 in read_based(Base, N1, N, C)) | ||
4080 | { | ||
4081 | yield return false; | ||
4082 | } | ||
4083 | } | ||
4084 | goto cutIf2; | ||
4085 | } | ||
4086 | if (YP.equal(C1, new ListPair(95, Atom.NIL))) | ||
4087 | { | ||
4088 | foreach (bool l7 in read_based(Base, N0, N, C)) | ||
4089 | { | ||
4090 | yield return false; | ||
4091 | } | ||
4092 | goto cutIf3; | ||
4093 | } | ||
4094 | foreach (bool l6 in YP.unify(N, N0)) | ||
4095 | { | ||
4096 | foreach (bool l7 in YP.unify(C, C1)) | ||
4097 | { | ||
4098 | yield return false; | ||
4099 | } | ||
4100 | } | ||
4101 | cutIf3: | ||
4102 | cutIf2: | ||
4103 | { } | ||
4104 | } | ||
4105 | goto cutIf1; | ||
4106 | } | ||
4107 | } | ||
4108 | if (YP.greaterThanOrEqual(C1, new ListPair(65, Atom.NIL))) | ||
4109 | { | ||
4110 | if (YP.lessThanOrEqual(C1, new ListPair(90, Atom.NIL))) | ||
4111 | { | ||
4112 | foreach (bool l5 in YP.unify(Digit, YP.subtract(C1, YP.subtract(new ListPair(65, Atom.NIL), 10)))) | ||
4113 | { | ||
4114 | if (YP.lessThan(Digit, Base)) | ||
4115 | { | ||
4116 | foreach (bool l7 in YP.unify(N1, YP.add(YP.multiply(N0, Base), Digit))) | ||
4117 | { | ||
4118 | foreach (bool l8 in read_based(Base, N1, N, C)) | ||
4119 | { | ||
4120 | yield return false; | ||
4121 | } | ||
4122 | } | ||
4123 | goto cutIf5; | ||
4124 | } | ||
4125 | if (YP.equal(C1, new ListPair(95, Atom.NIL))) | ||
4126 | { | ||
4127 | foreach (bool l7 in read_based(Base, N0, N, C)) | ||
4128 | { | ||
4129 | yield return false; | ||
4130 | } | ||
4131 | goto cutIf6; | ||
4132 | } | ||
4133 | foreach (bool l6 in YP.unify(N, N0)) | ||
4134 | { | ||
4135 | foreach (bool l7 in YP.unify(C, C1)) | ||
4136 | { | ||
4137 | yield return false; | ||
4138 | } | ||
4139 | } | ||
4140 | cutIf6: | ||
4141 | cutIf5: | ||
4142 | { } | ||
4143 | } | ||
4144 | goto cutIf4; | ||
4145 | } | ||
4146 | } | ||
4147 | if (YP.greaterThanOrEqual(C1, new ListPair(97, Atom.NIL))) | ||
4148 | { | ||
4149 | if (YP.lessThanOrEqual(C1, new ListPair(122, Atom.NIL))) | ||
4150 | { | ||
4151 | foreach (bool l5 in YP.unify(Digit, YP.subtract(C1, YP.subtract(new ListPair(97, Atom.NIL), 10)))) | ||
4152 | { | ||
4153 | if (YP.lessThan(Digit, Base)) | ||
4154 | { | ||
4155 | foreach (bool l7 in YP.unify(N1, YP.add(YP.multiply(N0, Base), Digit))) | ||
4156 | { | ||
4157 | foreach (bool l8 in read_based(Base, N1, N, C)) | ||
4158 | { | ||
4159 | yield return false; | ||
4160 | } | ||
4161 | } | ||
4162 | goto cutIf8; | ||
4163 | } | ||
4164 | if (YP.equal(C1, new ListPair(95, Atom.NIL))) | ||
4165 | { | ||
4166 | foreach (bool l7 in read_based(Base, N0, N, C)) | ||
4167 | { | ||
4168 | yield return false; | ||
4169 | } | ||
4170 | goto cutIf9; | ||
4171 | } | ||
4172 | foreach (bool l6 in YP.unify(N, N0)) | ||
4173 | { | ||
4174 | foreach (bool l7 in YP.unify(C, C1)) | ||
4175 | { | ||
4176 | yield return false; | ||
4177 | } | ||
4178 | } | ||
4179 | cutIf9: | ||
4180 | cutIf8: | ||
4181 | { } | ||
4182 | } | ||
4183 | goto cutIf7; | ||
4184 | } | ||
4185 | } | ||
4186 | foreach (bool l3 in YP.unify(Digit, 99)) | ||
4187 | { | ||
4188 | if (YP.lessThan(Digit, Base)) | ||
4189 | { | ||
4190 | foreach (bool l5 in YP.unify(N1, YP.add(YP.multiply(N0, Base), Digit))) | ||
4191 | { | ||
4192 | foreach (bool l6 in read_based(Base, N1, N, C)) | ||
4193 | { | ||
4194 | yield return false; | ||
4195 | } | ||
4196 | } | ||
4197 | goto cutIf10; | ||
4198 | } | ||
4199 | if (YP.equal(C1, new ListPair(95, Atom.NIL))) | ||
4200 | { | ||
4201 | foreach (bool l5 in read_based(Base, N0, N, C)) | ||
4202 | { | ||
4203 | yield return false; | ||
4204 | } | ||
4205 | goto cutIf11; | ||
4206 | } | ||
4207 | foreach (bool l4 in YP.unify(N, N0)) | ||
4208 | { | ||
4209 | foreach (bool l5 in YP.unify(C, C1)) | ||
4210 | { | ||
4211 | yield return false; | ||
4212 | } | ||
4213 | } | ||
4214 | cutIf11: | ||
4215 | cutIf10: | ||
4216 | { } | ||
4217 | } | ||
4218 | cutIf7: | ||
4219 | cutIf4: | ||
4220 | cutIf1: | ||
4221 | { } | ||
4222 | } | ||
4223 | } | ||
4224 | } | ||
4225 | |||
4226 | public static IEnumerable<bool> read_char(object Char, object Quote, object Result, object Next) | ||
4227 | { | ||
4228 | { | ||
4229 | Variable C1 = new Variable(); | ||
4230 | Variable C2 = new Variable(); | ||
4231 | Variable C3 = new Variable(); | ||
4232 | Variable Ch = new Variable(); | ||
4233 | if (YP.equal(Char, 92)) | ||
4234 | { | ||
4235 | foreach (bool l3 in YP.get_code(C1)) | ||
4236 | { | ||
4237 | if (YP.lessThan(C1, 0)) | ||
4238 | { | ||
4239 | 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)))) | ||
4240 | { | ||
4241 | foreach (bool l6 in YP.unify(Result, -1)) | ||
4242 | { | ||
4243 | foreach (bool l7 in YP.unify(Next, C1)) | ||
4244 | { | ||
4245 | yield return false; | ||
4246 | } | ||
4247 | } | ||
4248 | } | ||
4249 | goto cutIf2; | ||
4250 | } | ||
4251 | if (YP.lessThanOrEqual(C1, new ListPair(32, Atom.NIL))) | ||
4252 | { | ||
4253 | foreach (bool l5 in YP.get_code(C2)) | ||
4254 | { | ||
4255 | foreach (bool l6 in read_char(C2, Quote, Result, Next)) | ||
4256 | { | ||
4257 | yield return false; | ||
4258 | } | ||
4259 | } | ||
4260 | goto cutIf3; | ||
4261 | } | ||
4262 | if (YP.equal(YP.bitwiseOr(C1, 32), new ListPair(99, Atom.NIL))) | ||
4263 | { | ||
4264 | foreach (bool l5 in YP.get_code(C2)) | ||
4265 | { | ||
4266 | foreach (bool l6 in read_char(C2, Quote, Result, Next)) | ||
4267 | { | ||
4268 | yield return false; | ||
4269 | } | ||
4270 | } | ||
4271 | goto cutIf4; | ||
4272 | } | ||
4273 | if (YP.lessThanOrEqual(C1, new ListPair(55, Atom.NIL))) | ||
4274 | { | ||
4275 | if (YP.greaterThanOrEqual(C1, new ListPair(48, Atom.NIL))) | ||
4276 | { | ||
4277 | foreach (bool l6 in YP.get_code(C2)) | ||
4278 | { | ||
4279 | if (YP.lessThanOrEqual(C2, new ListPair(55, Atom.NIL))) | ||
4280 | { | ||
4281 | if (YP.greaterThanOrEqual(C2, new ListPair(48, Atom.NIL))) | ||
4282 | { | ||
4283 | foreach (bool l9 in YP.get_code(C3)) | ||
4284 | { | ||
4285 | if (YP.lessThanOrEqual(C3, new ListPair(55, Atom.NIL))) | ||
4286 | { | ||
4287 | if (YP.greaterThanOrEqual(C3, new ListPair(48, Atom.NIL))) | ||
4288 | { | ||
4289 | foreach (bool l12 in YP.get_code(Next)) | ||
4290 | { | ||
4291 | 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))))) | ||
4292 | { | ||
4293 | yield return false; | ||
4294 | } | ||
4295 | } | ||
4296 | goto cutIf7; | ||
4297 | } | ||
4298 | } | ||
4299 | foreach (bool l10 in YP.unify(Next, C3)) | ||
4300 | { | ||
4301 | foreach (bool l11 in YP.unify(Result, YP.subtract(YP.add(YP.multiply(C1, 8), C2), YP.multiply(9, new ListPair(48, Atom.NIL))))) | ||
4302 | { | ||
4303 | yield return false; | ||
4304 | } | ||
4305 | } | ||
4306 | cutIf7: | ||
4307 | { } | ||
4308 | } | ||
4309 | goto cutIf6; | ||
4310 | } | ||
4311 | } | ||
4312 | foreach (bool l7 in YP.unify(Next, C2)) | ||
4313 | { | ||
4314 | foreach (bool l8 in YP.unify(Result, YP.subtract(C1, new ListPair(48, Atom.NIL)))) | ||
4315 | { | ||
4316 | yield return false; | ||
4317 | } | ||
4318 | } | ||
4319 | cutIf6: | ||
4320 | { } | ||
4321 | } | ||
4322 | goto cutIf5; | ||
4323 | } | ||
4324 | } | ||
4325 | if (YP.equal(C1, new ListPair(94, Atom.NIL))) | ||
4326 | { | ||
4327 | foreach (bool l5 in YP.get_code(C2)) | ||
4328 | { | ||
4329 | if (YP.lessThan(C2, 0)) | ||
4330 | { | ||
4331 | foreach (bool l7 in formatError(Atom.a(@"user_error"), Atom.a(@"~N** end of file in ~c..~c^..~c~n"), new ListPair(Quote, new ListPair(92, new ListPair(Quote, Atom.NIL))))) | ||
4332 | { | ||
4333 | foreach (bool l8 in YP.unify(Result, -1)) | ||
4334 | { | ||
4335 | foreach (bool l9 in YP.unify(Next, C2)) | ||
4336 | { | ||
4337 | yield return false; | ||
4338 | } | ||
4339 | } | ||
4340 | } | ||
4341 | goto cutIf9; | ||
4342 | } | ||
4343 | if (YP.equal(C2, new ListPair(63, Atom.NIL))) | ||
4344 | { | ||
4345 | foreach (bool l7 in YP.unify(Result, 127)) | ||
4346 | { | ||
4347 | foreach (bool l8 in YP.get_code(Next)) | ||
4348 | { | ||
4349 | yield return false; | ||
4350 | } | ||
4351 | } | ||
4352 | goto cutIf10; | ||
4353 | } | ||
4354 | foreach (bool l6 in YP.unify(Result, YP.bitwiseAnd(C2, 31))) | ||
4355 | { | ||
4356 | foreach (bool l7 in YP.get_code(Next)) | ||
4357 | { | ||
4358 | yield return false; | ||
4359 | } | ||
4360 | } | ||
4361 | cutIf10: | ||
4362 | cutIf9: | ||
4363 | { } | ||
4364 | } | ||
4365 | goto cutIf8; | ||
4366 | } | ||
4367 | foreach (bool l4 in escape_char(C1, Result)) | ||
4368 | { | ||
4369 | foreach (bool l5 in YP.get_code(Next)) | ||
4370 | { | ||
4371 | yield return false; | ||
4372 | } | ||
4373 | goto cutIf11; | ||
4374 | } | ||
4375 | foreach (bool l4 in YP.unify(Result, C1)) | ||
4376 | { | ||
4377 | foreach (bool l5 in YP.get_code(Next)) | ||
4378 | { | ||
4379 | yield return false; | ||
4380 | } | ||
4381 | } | ||
4382 | cutIf11: | ||
4383 | cutIf8: | ||
4384 | cutIf5: | ||
4385 | cutIf4: | ||
4386 | cutIf3: | ||
4387 | cutIf2: | ||
4388 | { } | ||
4389 | } | ||
4390 | goto cutIf1; | ||
4391 | } | ||
4392 | if (YP.equal(Char, Quote)) | ||
4393 | { | ||
4394 | foreach (bool l3 in YP.get_code(Ch)) | ||
4395 | { | ||
4396 | if (YP.equal(Ch, Quote)) | ||
4397 | { | ||
4398 | foreach (bool l5 in YP.unify(Result, Quote)) | ||
4399 | { | ||
4400 | foreach (bool l6 in YP.get_code(Next)) | ||
4401 | { | ||
4402 | yield return false; | ||
4403 | } | ||
4404 | } | ||
4405 | goto cutIf13; | ||
4406 | } | ||
4407 | foreach (bool l4 in YP.unify(Result, -1)) | ||
4408 | { | ||
4409 | foreach (bool l5 in YP.unify(Next, Ch)) | ||
4410 | { | ||
4411 | yield return false; | ||
4412 | } | ||
4413 | } | ||
4414 | cutIf13: | ||
4415 | { } | ||
4416 | } | ||
4417 | goto cutIf12; | ||
4418 | } | ||
4419 | if (YP.lessThan(Char, new ListPair(32, Atom.NIL))) | ||
4420 | { | ||
4421 | if (YP.notEqual(Char, 9)) | ||
4422 | { | ||
4423 | if (YP.notEqual(Char, 10)) | ||
4424 | { | ||
4425 | if (YP.notEqual(Char, 13)) | ||
4426 | { | ||
4427 | foreach (bool l6 in YP.unify(Result, -1)) | ||
4428 | { | ||
4429 | foreach (bool l7 in YP.unify(Next, Char)) | ||
4430 | { | ||
4431 | foreach (bool l8 in formatError(Atom.a(@"user_error"), Atom.a(@"~N** Strange character ~d ends ~ctoken~c~n"), new ListPair(Char, new ListPair(Quote, new ListPair(Quote, Atom.NIL))))) | ||
4432 | { | ||
4433 | yield return false; | ||
4434 | } | ||
4435 | } | ||
4436 | } | ||
4437 | goto cutIf14; | ||
4438 | } | ||
4439 | } | ||
4440 | } | ||
4441 | } | ||
4442 | foreach (bool l2 in YP.unify(Result, Char)) | ||
4443 | { | ||
4444 | foreach (bool l3 in YP.get_code(Next)) | ||
4445 | { | ||
4446 | yield return false; | ||
4447 | } | ||
4448 | } | ||
4449 | cutIf14: | ||
4450 | cutIf12: | ||
4451 | cutIf1: | ||
4452 | { } | ||
4453 | } | ||
4454 | } | ||
4455 | |||
4456 | } | ||
4457 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/PrologException.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/PrologException.cs new file mode 100644 index 0000000..ffb8ddc --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/PrologException.cs | |||
@@ -0,0 +1,71 @@ | |||
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.DotNetEngine.Compiler.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 | /// </param> | ||
47 | public PrologException(object Term) | ||
48 | : base(YP.getValue(Term).ToString()) | ||
49 | { | ||
50 | _term = YP.makeCopy(Term, new Variable.CopyStore()); | ||
51 | } | ||
52 | |||
53 | /// <summary> | ||
54 | /// Create a PrologException where the Term is error(ErrorTerm, Message). | ||
55 | /// This uses YP.makeCopy to copy the ErrorTerm and Message so that they are valid after unbinding. | ||
56 | /// </summary> | ||
57 | /// <param name="ErrorTerm">the term of the exception</param> | ||
58 | /// <param name="Messsage">the message, converted to a string, to use as the printable exception message | ||
59 | /// </param> | ||
60 | public PrologException(object ErrorTerm, object Message) | ||
61 | : base(YP.getValue(Message).ToString()) | ||
62 | { | ||
63 | _term = YP.makeCopy(new Functor2(Atom.a("error"), ErrorTerm, Message), new Variable.CopyStore()); | ||
64 | } | ||
65 | |||
66 | public object Term | ||
67 | { | ||
68 | get { return _term; } | ||
69 | } | ||
70 | } | ||
71 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/README.TXT b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/README.TXT new file mode 100644 index 0000000..05186f1 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/README.TXT | |||
@@ -0,0 +1,405 @@ | |||
1 | YPOS: YieldProlog for OpenSim | ||
2 | |||
3 | a compiler from Prolog to OpenSim compatible C# scripts | ||
4 | |||
5 | Ported by Kino Coursey and Douglas Miles at Daxtron Labs. | ||
6 | Based on Jeff Thompson Yield Prolog, http://yieldprolog.sourceforge.net/ | ||
7 | For Prolog see http://en.wikipedia.org/wiki/Prolog | ||
8 | |||
9 | |||
10 | INTRODUCTION | ||
11 | |||
12 | This folder contains code to implement a Prolog compiler using the "Yield Statement" found in C#, Javascript, and Python. | ||
13 | The original Yield Prolog system can transform Prolog programs into C# code. | ||
14 | In this system we detect and extract YieldProlog code (with "//YP" as the first four characters in the script) and seperate it from any c# code ("marked by "//CS"). | ||
15 | The YP code is transformed to C# and prepended to the "//CS" section, and passed as a bundel to the existing C# compiler. | ||
16 | The end result is Prolog can interface to OpenSim using the existing "//CS" functionality, and C# can call the compiled Prolog. | ||
17 | As such YP allows both declaritive and procedural programming in a 3D script enabled environment. | ||
18 | |||
19 | FEATURES | ||
20 | * Allows implementation of logic programming for objects and agents. | ||
21 | * C#/Javascript/Python as intermediate language | ||
22 | * Yield Prolog has relatively high speed of execution which is important in OpenSim. http://yieldprolog.sourceforge.net/benchmarks.html | ||
23 | * It is compatable with the existing C#/Mono based system. | ||
24 | * Yield Prolog is BSD license | ||
25 | * Calling Prolog from C# scripts | ||
26 | * Calling C# functions (with LSL and OS functions) from Prolog | ||
27 | * Prolog dynamic database | ||
28 | * Edinburgh, Cocksin & Mellish style syntax. | ||
29 | * Compiler is generated by compiling the Prolog descrition of itself into C# | ||
30 | * Same script entry interface as LSL | ||
31 | |||
32 | |||
33 | TODO | ||
34 | * Utilize ability to generate Javascript and Python code | ||
35 | * Integrate Prolog database with Sim | ||
36 | * Translation error reporting back to the editor | ||
37 | * Communications via message passing | ||
38 | * Interface to external inference engines | ||
39 | |||
40 | POSSIBILITIES | ||
41 | * Inworld expert systems | ||
42 | * Parallel logic programming and expert systems | ||
43 | * Ontology based processing | ||
44 | * Knowledge based alerting, accessing and business rules | ||
45 | For instance, listen on channel x, filter the events and broadcast alerts on channel y | ||
46 | or send IM, emails etc. | ||
47 | |||
48 | |||
49 | USAGE: | ||
50 | |||
51 | Add "yp" as an allowed compiler | ||
52 | |||
53 | OpenSim.ini | ||
54 | [ScriptEngine.DotNetEngine] | ||
55 | AllowedCompilers=lsl,cs,js,vb,yp | ||
56 | |||
57 | Enter scripts using the inworld editing process. Scripts have the following format. | ||
58 | The first line of a file must have "//yp". | ||
59 | |||
60 | //yp | ||
61 | <PROLOG CODE> | ||
62 | //CS | ||
63 | <CS CODE> | ||
64 | |||
65 | |||
66 | |||
67 | |||
68 | |||
69 | |||
70 | C# code calling a Prolog Predicate: | ||
71 | ----------------------------------- | ||
72 | The Prolog predicate is transformed into a C# boolean function. So the general calling format is: | ||
73 | foreach( bool var in prolog_predicate(ARGS)) {}; | ||
74 | |||
75 | I/O is via using a string reader and writer in conjunction with YP.See() and YP.Tell() | ||
76 | |||
77 | StringWriter PrologOutuput= new StringWriter(); | ||
78 | StringReader PrologInput= new StringReader(myInputString); | ||
79 | YP.see(PrologInput); | ||
80 | YP.tell(PrologOutuput); | ||
81 | <CALL PROLOG CODE HERE> | ||
82 | YP.seen(); | ||
83 | YP.told(); | ||
84 | StringBuilder builder = PrologOutput.GetStringBuilder(); | ||
85 | string finaloutput = builder.ToString(); | ||
86 | |||
87 | Any prolog reads and writes will be to the passed StringReader and StringWriter. In fact any TextReader/TextWriter class can be used. | ||
88 | |||
89 | Strings in Prolog are stored as Atom's and you need to use an Atom object to match. | ||
90 | |||
91 | \\yp | ||
92 | wanted('bob'). | ||
93 | \\cs | ||
94 | string Who="bob"; | ||
95 | foreach( bool ans in wanted(Atom.a(Who) )){}; | ||
96 | |||
97 | |||
98 | Prolog code calling a C# function: | ||
99 | ----------------------------------- | ||
100 | The prolog code uses the script_event('name_of_function',ARGS) builtin, which is transformed into the function call. | ||
101 | The C# function called uses "PrologCallback" and returns a boolean. | ||
102 | |||
103 | |||
104 | |||
105 | Dynamic database assertions: | ||
106 | ----------------------------------- | ||
107 | |||
108 | void assertdb2(string predicate, string arg1, string arg2) | ||
109 | { | ||
110 | name = Atom.a(predicate); | ||
111 | YP.assertFact(name, new object[] { arg1, arg2 }); | ||
112 | } | ||
113 | |||
114 | void retractdb2(string predicate, string arg1, string arg2) | ||
115 | { | ||
116 | name = Atom.a(predicate); | ||
117 | YP.retractFact(name, new object[] { arg1, arg2 }); | ||
118 | } | ||
119 | |||
120 | |||
121 | ========================= APPENDIX A: touch test ================================ | ||
122 | |||
123 | |||
124 | =================================== | ||
125 | Input YP Code | ||
126 | =================================== | ||
127 | //yp | ||
128 | mydb('field2','field1'). | ||
129 | mydb('andy','jane'). | ||
130 | mydb('carl','dan'). | ||
131 | mydb('andy','bill'). | ||
132 | mydb('andy','betty'). | ||
133 | |||
134 | call_me(X):-mydb(X,Y) , respond(Y). | ||
135 | respond(X):- script_event('sayit',X). | ||
136 | |||
137 | //cs | ||
138 | public void default_event_touch_start(int N ) | ||
139 | { | ||
140 | llSay(0,"pstart1"); | ||
141 | foreach( bool ans in call_me(Atom.a(@"andy") )){}; | ||
142 | llSay(0,"pstop2"); | ||
143 | } | ||
144 | |||
145 | public void default_event_state_entry() | ||
146 | { | ||
147 | llSay(0,"prolog tester active."); | ||
148 | } | ||
149 | |||
150 | PrologCallback sayit(object ans) | ||
151 | { | ||
152 | llSay(0,"sayit1"); | ||
153 | string msg = "one answer is :"+((Variable)ans).getValue(); | ||
154 | llSay(0,msg); | ||
155 | yield return false; | ||
156 | } | ||
157 | |||
158 | |||
159 | =================================== | ||
160 | Generated CS Code | ||
161 | =================================== | ||
162 | using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog;using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic; | ||
163 | namespace SecondLife { public class Script : OpenSim.Region.ScriptEngine.Common.BuiltIn_Commands_BaseClass { | ||
164 | static OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog.YP YP=null;public Script() { YP= new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog.YP(); } | ||
165 | //cs | ||
166 | public void default_event_touch_start(int N ) | ||
167 | { | ||
168 | llSay(0,"pstart1"); | ||
169 | foreach( bool ans in call_me(Atom.a(@"carl") )){}; | ||
170 | llSay(0,"pstop2"); | ||
171 | } | ||
172 | |||
173 | public void default_event_state_entry() | ||
174 | { | ||
175 | llSay(0,"prolog tester active."); | ||
176 | } | ||
177 | |||
178 | public IEnumerable<bool> sayit(object ans) | ||
179 | { | ||
180 | llSay(0,"sayit1"); | ||
181 | string msg = "one answer is :"+((Variable)ans).getValue(); | ||
182 | llSay(0,msg); | ||
183 | yield return false; | ||
184 | } | ||
185 | |||
186 | |||
187 | //YPEncoded | ||
188 | public IEnumerable<bool> mydb(object arg1, object arg2) { | ||
189 | { | ||
190 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"carl"))) { | ||
191 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"dan"))) { | ||
192 | yield return false; | ||
193 | } | ||
194 | } | ||
195 | } | ||
196 | { | ||
197 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"andy"))) { | ||
198 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"bill"))) { | ||
199 | yield return false; | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | { | ||
204 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"andy"))) { | ||
205 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"betty"))) { | ||
206 | yield return false; | ||
207 | } | ||
208 | } | ||
209 | } | ||
210 | } | ||
211 | |||
212 | public IEnumerable<bool> call_me(object X) { | ||
213 | { | ||
214 | Variable Y = new Variable(); | ||
215 | foreach (bool l2 in mydb(X, Y)) { | ||
216 | foreach (bool l3 in respond(Y)) { | ||
217 | yield return false; | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | |||
223 | public IEnumerable<bool> respond(object X) { | ||
224 | { | ||
225 | foreach (bool l2 in this.sayit( X)) { | ||
226 | yield return false; | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | |||
231 | } } | ||
232 | |||
233 | |||
234 | |||
235 | ========================= APPENDIX B:SENSOR INFORMED SCRIPT ===================== | ||
236 | |||
237 | |||
238 | =================================== | ||
239 | Input YP Code | ||
240 | =================================== | ||
241 | //yp | ||
242 | |||
243 | nop. | ||
244 | |||
245 | good('Daxxon Kinoc'). | ||
246 | good('Fluffy Kitty'). | ||
247 | |||
248 | bad('Eric Evil'). | ||
249 | bad('Spikey Plant'). | ||
250 | |||
251 | prolog_notify(X) :- good(X) , script_event('accept',X). | ||
252 | prolog_notify(X) :- bad(X) , script_event('reject',X). | ||
253 | |||
254 | |||
255 | //cs | ||
256 | |||
257 | public void default_event_state_entry() | ||
258 | { | ||
259 | llSay(0,"prolog sensor tester active."); | ||
260 | |||
261 | // Start a sensor looking for Agents | ||
262 | llSensorRepeat("","",AGENT, 10, PI,20); | ||
263 | |||
264 | } | ||
265 | |||
266 | public void default_event_sensor(int number_detected ) | ||
267 | { | ||
268 | int i; | ||
269 | for(i=0;i< number_detected ;i++) | ||
270 | { | ||
271 | string dName = llDetectedName(i); | ||
272 | string dOwner = llDetectedName(i); | ||
273 | foreach(bool response in prolog_notify(Atom.a(dName)) ){}; | ||
274 | foreach(bool response in prolog_notify(dOwner) ){}; | ||
275 | llSay(0,"Saw "+dName); | ||
276 | } | ||
277 | } | ||
278 | |||
279 | string decodeToString(object obj) | ||
280 | { | ||
281 | if (obj is Variable) { return (string) ((Variable)obj).getValue();} | ||
282 | if (obj is Atom) { return (string) ((Atom)obj)._name;} | ||
283 | return "unknown type"; | ||
284 | } | ||
285 | |||
286 | PrologCallback accept(object ans) | ||
287 | { | ||
288 | string msg = "Welcoming :"+decodeToString(ans); | ||
289 | llSay(0,msg); | ||
290 | yield return false; | ||
291 | } | ||
292 | |||
293 | PrologCallback reject(object ans) | ||
294 | { | ||
295 | string msg = "Watching :"+decodeToString(ans); | ||
296 | llSay(0,msg); | ||
297 | yield return false; | ||
298 | } | ||
299 | |||
300 | |||
301 | =================================== | ||
302 | Generated CS Code | ||
303 | =================================== | ||
304 | |||
305 | using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog; using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic; | ||
306 | namespace SecondLife { public class Script : OpenSim.Region.ScriptEngine.Common.BuiltIn_Commands_BaseClass { | ||
307 | static OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog.YP YP=null; public Script() { YP= new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog.YP(); } | ||
308 | //cs | ||
309 | |||
310 | public void default_event_state_entry() | ||
311 | { | ||
312 | llSay(0,"prolog sensor tester active."); | ||
313 | |||
314 | // Start a sensor looking for Agents | ||
315 | llSensorRepeat("","",AGENT, 10, PI,20); | ||
316 | |||
317 | } | ||
318 | |||
319 | public void default_event_sensor(int number_detected ) | ||
320 | { | ||
321 | int i; | ||
322 | for(i=0;i< number_detected ;i++) | ||
323 | { | ||
324 | string dName = llDetectedName(i); | ||
325 | string dOwner = llDetectedName(i); | ||
326 | foreach(bool response in prolog_notify(Atom.a(dName)) ){}; | ||
327 | foreach(bool response in prolog_notify(dOwner) ){}; | ||
328 | llSay(0,"Saw "+dName); | ||
329 | } | ||
330 | } | ||
331 | |||
332 | string decodeToString(object obj) | ||
333 | { | ||
334 | if (obj is Variable) { return (string) ((Variable)obj).getValue();} | ||
335 | if (obj is Atom) { return (string) ((Atom)obj)._name;} | ||
336 | return "unknown type"; | ||
337 | } | ||
338 | |||
339 | public IEnumerable<bool> accept(object ans) | ||
340 | { | ||
341 | string msg = "Welcoming :"+decodeToString(ans); | ||
342 | llSay(0,msg); | ||
343 | yield return false; | ||
344 | } | ||
345 | |||
346 | public IEnumerable<bool> reject(object ans) | ||
347 | { | ||
348 | string msg = "Watching :"+decodeToString(ans); | ||
349 | llSay(0,msg); | ||
350 | yield return false; | ||
351 | } | ||
352 | |||
353 | |||
354 | //YPEncoded | ||
355 | public IEnumerable<bool> yp_nop_header_nop() { | ||
356 | { | ||
357 | yield return false; | ||
358 | } | ||
359 | } | ||
360 | |||
361 | public IEnumerable<bool> good(object arg1) { | ||
362 | { | ||
363 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"Daxxon Kinoc"))) { | ||
364 | yield return false; | ||
365 | } | ||
366 | } | ||
367 | { | ||
368 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"Fluffy Kitty"))) { | ||
369 | yield return false; | ||
370 | } | ||
371 | } | ||
372 | } | ||
373 | |||
374 | public IEnumerable<bool> bad(object arg1) { | ||
375 | { | ||
376 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"Eric Evil"))) { | ||
377 | yield return false; | ||
378 | } | ||
379 | } | ||
380 | { | ||
381 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"Spikey Plant"))) { | ||
382 | yield return false; | ||
383 | } | ||
384 | } | ||
385 | } | ||
386 | |||
387 | public IEnumerable<bool> prolog_notify(object X) { | ||
388 | { | ||
389 | foreach (bool l2 in good(X)) { | ||
390 | foreach (bool l3 in this.accept( X)) { | ||
391 | yield return false; | ||
392 | } | ||
393 | } | ||
394 | } | ||
395 | { | ||
396 | foreach (bool l2 in bad(X)) { | ||
397 | foreach (bool l3 in this.reject( X)) { | ||
398 | yield return false; | ||
399 | } | ||
400 | } | ||
401 | } | ||
402 | } | ||
403 | |||
404 | } } | ||
405 | |||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/UndefinedPredicateException.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/UndefinedPredicateException.cs new file mode 100644 index 0000000..035b79c --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/UndefinedPredicateException.cs | |||
@@ -0,0 +1,62 @@ | |||
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.DotNetEngine.Compiler.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/DotNetEngine/Compiler/YieldProlog/Variable.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Variable.cs new file mode 100644 index 0000000..d5ee21c --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Variable.cs | |||
@@ -0,0 +1,196 @@ | |||
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.DotNetEngine.Compiler.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 | public class Variable : IUnifiable | ||
47 | { | ||
48 | // Use _isBound separate from _value so that it can be bound to any value, | ||
49 | // including null. | ||
50 | private bool _isBound = false; | ||
51 | private object _value; | ||
52 | |||
53 | public object getValue() | ||
54 | { | ||
55 | if (!_isBound) | ||
56 | return this; | ||
57 | |||
58 | object result = _value; | ||
59 | while (result is Variable) | ||
60 | { | ||
61 | if (!((Variable)result)._isBound) | ||
62 | return result; | ||
63 | |||
64 | // Keep following the Variable chain. | ||
65 | result = ((Variable)result)._value; | ||
66 | } | ||
67 | |||
68 | return result; | ||
69 | } | ||
70 | |||
71 | public IEnumerable<bool> unify(object arg) | ||
72 | { | ||
73 | if (!_isBound) | ||
74 | { | ||
75 | _value = YP.getValue(arg); | ||
76 | if (_value == this) | ||
77 | // We are unifying this unbound variable with itself, so leave it unbound. | ||
78 | yield return false; | ||
79 | else | ||
80 | { | ||
81 | _isBound = true; | ||
82 | try | ||
83 | { | ||
84 | yield return false; | ||
85 | } | ||
86 | finally | ||
87 | { | ||
88 | // Remove the binding. | ||
89 | _isBound = false; | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | foreach (bool l1 in YP.unify(this, arg)) | ||
96 | yield return false; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | public override string ToString() | ||
101 | { | ||
102 | object value = getValue(); | ||
103 | if (value == this) | ||
104 | return "Variable"; | ||
105 | else | ||
106 | return getValue().ToString(); | ||
107 | } | ||
108 | |||
109 | /// <summary> | ||
110 | /// If bound, call YP.addUniqueVariables on the value. Otherwise, if this unbound | ||
111 | /// variable is not already in variableSet, add it. | ||
112 | /// </summary> | ||
113 | /// <param name="variableSet"></param> | ||
114 | public void addUniqueVariables(List<Variable> variableSet) | ||
115 | { | ||
116 | if (_isBound) | ||
117 | YP.addUniqueVariables(getValue(), variableSet); | ||
118 | else | ||
119 | { | ||
120 | if (variableSet.IndexOf(this) < 0) | ||
121 | variableSet.Add(this); | ||
122 | } | ||
123 | } | ||
124 | |||
125 | /// <summary> | ||
126 | /// If bound, return YP.makeCopy for the value, else return copyStore.getCopy(this). | ||
127 | /// However, if copyStore is null, just return this. | ||
128 | /// </summary> | ||
129 | /// <param name="copyStore"></param> | ||
130 | /// <returns></returns> | ||
131 | public object makeCopy(Variable.CopyStore copyStore) | ||
132 | { | ||
133 | if (_isBound) | ||
134 | return YP.makeCopy(getValue(), copyStore); | ||
135 | else | ||
136 | return copyStore == null ? this : copyStore.getCopy(this); | ||
137 | } | ||
138 | |||
139 | public bool termEqual(object term) | ||
140 | { | ||
141 | if (_isBound) | ||
142 | return YP.termEqual(getValue(), term); | ||
143 | else | ||
144 | return this == YP.getValue(term); | ||
145 | } | ||
146 | |||
147 | public bool ground() | ||
148 | { | ||
149 | if (_isBound) | ||
150 | // This is usually called by YP.ground which already did getValue, so this | ||
151 | // should never be reached, but check anyway. | ||
152 | return YP.ground(getValue()); | ||
153 | else | ||
154 | return false; | ||
155 | } | ||
156 | |||
157 | /// <summary> | ||
158 | /// A CopyStore is used by makeCopy to track which Variable objects have | ||
159 | /// been copied. | ||
160 | /// </summary> | ||
161 | public class CopyStore | ||
162 | { | ||
163 | private List<Variable> _inVariableSet = new List<Variable>(); | ||
164 | private List<Variable> _outVariableSet = new List<Variable>(); | ||
165 | |||
166 | /// <summary> | ||
167 | /// If inVariable has already been copied, return its copy. Otherwise, | ||
168 | /// return a fresh Variable associated with inVariable. | ||
169 | /// </summary> | ||
170 | /// <param name="inVariable"></param> | ||
171 | /// <returns></returns> | ||
172 | public Variable getCopy(Variable inVariable) | ||
173 | { | ||
174 | int index = _inVariableSet.IndexOf(inVariable); | ||
175 | if (index >= 0) | ||
176 | return _outVariableSet[index]; | ||
177 | else | ||
178 | { | ||
179 | Variable outVariable = new Variable(); | ||
180 | _inVariableSet.Add(inVariable); | ||
181 | _outVariableSet.Add(outVariable); | ||
182 | return outVariable; | ||
183 | } | ||
184 | } | ||
185 | |||
186 | /// <summary> | ||
187 | /// Return the number of unique variables that have been copied. | ||
188 | /// </summary> | ||
189 | /// <returns></returns> | ||
190 | public int getNUniqueVariables() | ||
191 | { | ||
192 | return _inVariableSet.Count; | ||
193 | } | ||
194 | } | ||
195 | } | ||
196 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YP.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YP.cs new file mode 100644 index 0000000..3c0e4e0 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YP.cs | |||
@@ -0,0 +1,1440 @@ | |||
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 | |||
37 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// YP has static methods for general functions in Yield Prolog such as <see cref="getValue"/> | ||
41 | /// and <see cref="unify"/>. | ||
42 | /// </summary> | ||
43 | public class YP | ||
44 | { | ||
45 | private static Fail _fail = new Fail(); | ||
46 | private static Repeat _repeat = new Repeat(); | ||
47 | private static Dictionary<NameArity, List<IClause>> _predicatesStore = | ||
48 | new Dictionary<NameArity, List<IClause>>(); | ||
49 | private static TextWriter _outputStream = System.Console.Out; | ||
50 | private static TextReader _inputStream = System.Console.In; | ||
51 | private static List<object[]> _operatorTable = null; | ||
52 | |||
53 | /// <summary> | ||
54 | /// An IClause is used so that dynamic predicates can call match. | ||
55 | /// </summary> | ||
56 | public interface IClause | ||
57 | { | ||
58 | IEnumerable<bool> match(object[] args); | ||
59 | } | ||
60 | |||
61 | public static object getValue(object value) | ||
62 | { | ||
63 | if (value is Variable) | ||
64 | return ((Variable)value).getValue(); | ||
65 | else | ||
66 | return value; | ||
67 | } | ||
68 | |||
69 | public static IEnumerable<bool> unify(object arg1, object arg2) | ||
70 | { | ||
71 | arg1 = getValue(arg1); | ||
72 | arg2 = getValue(arg2); | ||
73 | if (arg1 is IUnifiable) | ||
74 | return ((IUnifiable)arg1).unify(arg2); | ||
75 | else if (arg2 is IUnifiable) | ||
76 | return ((IUnifiable)arg2).unify(arg1); | ||
77 | else | ||
78 | { | ||
79 | // Arguments are "normal" types. | ||
80 | if (arg1.Equals(arg2)) | ||
81 | return new Succeed(); | ||
82 | else | ||
83 | return _fail; | ||
84 | } | ||
85 | } | ||
86 | |||
87 | /// <summary> | ||
88 | /// This is used for the lookup key in _factStore. | ||
89 | /// </summary> | ||
90 | public struct NameArity | ||
91 | { | ||
92 | public readonly Atom _name; | ||
93 | public readonly int _arity; | ||
94 | |||
95 | public NameArity(Atom name, int arity) | ||
96 | { | ||
97 | _name = name; | ||
98 | _arity = arity; | ||
99 | } | ||
100 | |||
101 | public override bool Equals(object obj) | ||
102 | { | ||
103 | if (obj is NameArity) | ||
104 | { | ||
105 | NameArity nameArity = (NameArity)obj; | ||
106 | return nameArity._name.Equals(_name) && nameArity._arity.Equals(_arity); | ||
107 | } | ||
108 | else | ||
109 | { | ||
110 | return false; | ||
111 | } | ||
112 | } | ||
113 | |||
114 | public override int GetHashCode() | ||
115 | { | ||
116 | return _name.GetHashCode() ^ _arity.GetHashCode(); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | /// <summary> | ||
121 | /// Convert term to an int. | ||
122 | /// If term is a single-element List, use its first element | ||
123 | /// (to handle the char types like "a"). If can't convert, throw an exception. | ||
124 | /// </summary> | ||
125 | /// <param name="term"></param> | ||
126 | /// <returns></returns> | ||
127 | public static int convertInt(object term) | ||
128 | { | ||
129 | term = YP.getValue(term); | ||
130 | if (term is Functor2 && ((Functor2)term)._name == Atom.DOT && | ||
131 | YP.getValue(((Functor2)term)._arg2) == Atom.NIL) | ||
132 | // Assume it is a char type like "a". | ||
133 | term = YP.getValue(((Functor2)term)._arg1); | ||
134 | |||
135 | return (int)term; | ||
136 | } | ||
137 | |||
138 | /// <summary> | ||
139 | /// Convert term to a double. This may convert an int to a double, etc. | ||
140 | /// If term is a single-element List, use its first element | ||
141 | /// (to handle the char types like "a"). If can't convert, throw an exception. | ||
142 | /// </summary> | ||
143 | /// <param name="term"></param> | ||
144 | /// <returns></returns> | ||
145 | public static double convertDouble(object term) | ||
146 | { | ||
147 | term = YP.getValue(term); | ||
148 | if (term is Functor2 && ((Functor2)term)._name == Atom.DOT && | ||
149 | YP.getValue(((Functor2)term)._arg2) == Atom.NIL) | ||
150 | // Assume it is a char type like "a". | ||
151 | term = YP.getValue(((Functor2)term)._arg1); | ||
152 | |||
153 | return Convert.ToDouble(term); | ||
154 | } | ||
155 | |||
156 | /// <summary> | ||
157 | /// If term is an integer, set intTerm. | ||
158 | /// If term is a single-element List, use its first element | ||
159 | /// (to handle the char types like "a"). Return true for success, false if can't convert. | ||
160 | /// We use a success return value because throwing an exception is inefficient. | ||
161 | /// </summary> | ||
162 | /// <param name="term"></param> | ||
163 | /// <returns></returns> | ||
164 | public static bool getInt(object term, out int intTerm) | ||
165 | { | ||
166 | term = YP.getValue(term); | ||
167 | if (term is Functor2 && ((Functor2)term)._name == Atom.DOT && | ||
168 | YP.getValue(((Functor2)term)._arg2) == Atom.NIL) | ||
169 | // Assume it is a char type like "a". | ||
170 | term = YP.getValue(((Functor2)term)._arg1); | ||
171 | |||
172 | if (term is int) | ||
173 | { | ||
174 | intTerm = (int)term; | ||
175 | return true; | ||
176 | } | ||
177 | |||
178 | intTerm = 0; | ||
179 | return false; | ||
180 | } | ||
181 | |||
182 | public static bool equal(object x, object y) | ||
183 | { | ||
184 | x = YP.getValue(x); | ||
185 | if (x is DateTime) | ||
186 | return (DateTime)x == (DateTime)YP.getValue(y); | ||
187 | // Assume convertDouble converts an int to a double perfectly. | ||
188 | return YP.convertDouble(x) == YP.convertDouble(y); | ||
189 | } | ||
190 | |||
191 | public static bool notEqual(object x, object y) | ||
192 | { | ||
193 | x = YP.getValue(x); | ||
194 | if (x is DateTime) | ||
195 | return (DateTime)x != (DateTime)YP.getValue(y); | ||
196 | // Assume convertDouble converts an int to a double perfectly. | ||
197 | return YP.convertDouble(x) != YP.convertDouble(y); | ||
198 | } | ||
199 | |||
200 | public static bool greaterThan(object x, object y) | ||
201 | { | ||
202 | x = YP.getValue(x); | ||
203 | if (x is DateTime) | ||
204 | return (DateTime)x > (DateTime)YP.getValue(y); | ||
205 | // Assume convertDouble converts an int to a double perfectly. | ||
206 | return YP.convertDouble(x) > YP.convertDouble(y); | ||
207 | } | ||
208 | |||
209 | public static bool lessThan(object x, object y) | ||
210 | { | ||
211 | x = YP.getValue(x); | ||
212 | if (x is DateTime) | ||
213 | return (DateTime)x < (DateTime)YP.getValue(y); | ||
214 | // Assume convertDouble converts an int to a double perfectly. | ||
215 | return YP.convertDouble(x) < YP.convertDouble(y); | ||
216 | } | ||
217 | |||
218 | public static bool greaterThanOrEqual(object x, object y) | ||
219 | { | ||
220 | x = YP.getValue(x); | ||
221 | if (x is DateTime) | ||
222 | return (DateTime)x >= (DateTime)YP.getValue(y); | ||
223 | // Assume convertDouble converts an int to a double perfectly. | ||
224 | return YP.convertDouble(x) >= YP.convertDouble(y); | ||
225 | } | ||
226 | |||
227 | public static bool lessThanOrEqual(object x, object y) | ||
228 | { | ||
229 | x = YP.getValue(x); | ||
230 | if (x is DateTime) | ||
231 | return (DateTime)x <= (DateTime)YP.getValue(y); | ||
232 | // Assume convertDouble converts an int to a double perfectly. | ||
233 | return YP.convertDouble(x) <= YP.convertDouble(y); | ||
234 | } | ||
235 | |||
236 | public static object negate(object x) | ||
237 | { | ||
238 | int intX; | ||
239 | if (getInt(x, out intX)) | ||
240 | return -intX; | ||
241 | return -convertDouble(x); | ||
242 | } | ||
243 | |||
244 | public static object abs(object x) | ||
245 | { | ||
246 | int intX; | ||
247 | if (getInt(x, out intX)) | ||
248 | return Math.Abs(intX); | ||
249 | return Math.Abs(convertDouble(x)); | ||
250 | } | ||
251 | |||
252 | public static object sign(object x) | ||
253 | { | ||
254 | int intX; | ||
255 | if (getInt(x, out intX)) | ||
256 | return Math.Sign(intX); | ||
257 | return Math.Sign(convertDouble(x)); | ||
258 | } | ||
259 | |||
260 | /// <summary> | ||
261 | /// The ISO standard returns an int. | ||
262 | /// </summary> | ||
263 | /// <param name="x"></param> | ||
264 | /// <returns></returns> | ||
265 | public static object floor(object x) | ||
266 | { | ||
267 | return (int)Math.Floor(convertDouble(x)); | ||
268 | } | ||
269 | |||
270 | /// <summary> | ||
271 | /// The ISO standard returns an int. | ||
272 | /// </summary> | ||
273 | /// <param name="x"></param> | ||
274 | /// <returns></returns> | ||
275 | public static object truncate(object x) | ||
276 | { | ||
277 | return (int)Math.Truncate(convertDouble(x)); | ||
278 | } | ||
279 | |||
280 | /// <summary> | ||
281 | /// The ISO standard returns an int. | ||
282 | /// </summary> | ||
283 | /// <param name="x"></param> | ||
284 | /// <returns></returns> | ||
285 | public static object round(object x) | ||
286 | { | ||
287 | return (int)Math.Round(convertDouble(x)); | ||
288 | } | ||
289 | |||
290 | /// <summary> | ||
291 | /// The ISO standard returns an int. | ||
292 | /// </summary> | ||
293 | /// <param name="x"></param> | ||
294 | /// <returns></returns> | ||
295 | public static object ceiling(object x) | ||
296 | { | ||
297 | return (int)Math.Ceiling(convertDouble(x)); | ||
298 | } | ||
299 | |||
300 | public static object sin(object x) | ||
301 | { | ||
302 | return Math.Sin(YP.convertDouble(x)); | ||
303 | } | ||
304 | |||
305 | public static object cos(object x) | ||
306 | { | ||
307 | return Math.Cos(YP.convertDouble(x)); | ||
308 | } | ||
309 | |||
310 | public static object atan(object x) | ||
311 | { | ||
312 | return Math.Atan(YP.convertDouble(x)); | ||
313 | } | ||
314 | |||
315 | public static object exp(object x) | ||
316 | { | ||
317 | return Math.Exp(YP.convertDouble(x)); | ||
318 | } | ||
319 | |||
320 | public static object log(object x) | ||
321 | { | ||
322 | return Math.Log(YP.convertDouble(x)); | ||
323 | } | ||
324 | |||
325 | public static object sqrt(object x) | ||
326 | { | ||
327 | return Math.Sqrt(convertDouble(x)); | ||
328 | } | ||
329 | |||
330 | public static object bitwiseComplement(object x) | ||
331 | { | ||
332 | return ~YP.convertInt(x); | ||
333 | } | ||
334 | |||
335 | public static object add(object x, object y) | ||
336 | { | ||
337 | int intX, intY; | ||
338 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
339 | return intX + intY; | ||
340 | return convertDouble(x) + convertDouble(y); | ||
341 | } | ||
342 | |||
343 | public static object subtract(object x, object y) | ||
344 | { | ||
345 | int intX, intY; | ||
346 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
347 | return intX - intY; | ||
348 | return convertDouble(x) - convertDouble(y); | ||
349 | } | ||
350 | |||
351 | public static object multiply(object x, object y) | ||
352 | { | ||
353 | int intX, intY; | ||
354 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
355 | return intX * intY; | ||
356 | return convertDouble(x) * convertDouble(y); | ||
357 | } | ||
358 | |||
359 | /// <summary> | ||
360 | /// Return floating point, even if both arguments are integer. | ||
361 | /// </summary> | ||
362 | /// <param name="x"></param> | ||
363 | /// <param name="y"></param> | ||
364 | /// <returns></returns> | ||
365 | public static object divide(object x, object y) | ||
366 | { | ||
367 | return convertDouble(x) / convertDouble(y); | ||
368 | } | ||
369 | |||
370 | public static object intDivide(object x, object y) | ||
371 | { | ||
372 | int intX, intY; | ||
373 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
374 | return intX / intY; | ||
375 | // Still allow passing a double, but treat as an int. | ||
376 | return (int)convertDouble(x) / (int)convertDouble(y); | ||
377 | } | ||
378 | |||
379 | public static object mod(object x, object y) | ||
380 | { | ||
381 | int intX, intY; | ||
382 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
383 | return intX % intY; | ||
384 | // Still allow passing a double, but treat as an int. | ||
385 | return (int)convertDouble(x) % (int)convertDouble(y); | ||
386 | } | ||
387 | |||
388 | public static object pow(object x, object y) | ||
389 | { | ||
390 | return Math.Pow(YP.convertDouble(x), YP.convertDouble(y)); | ||
391 | } | ||
392 | |||
393 | public static object bitwiseShiftRight(object x, object y) | ||
394 | { | ||
395 | return YP.convertInt(x) >> YP.convertInt(y); | ||
396 | } | ||
397 | |||
398 | public static object bitwiseShiftLeft(object x, object y) | ||
399 | { | ||
400 | return YP.convertInt(x) << YP.convertInt(y); | ||
401 | } | ||
402 | |||
403 | public static object bitwiseAnd(object x, object y) | ||
404 | { | ||
405 | return YP.convertInt(x) & YP.convertInt(y); | ||
406 | } | ||
407 | |||
408 | public static object bitwiseOr(object x, object y) | ||
409 | { | ||
410 | return YP.convertInt(x) | YP.convertInt(y); | ||
411 | } | ||
412 | |||
413 | public static object min(object x, object y) | ||
414 | { | ||
415 | int intX, intY; | ||
416 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
417 | return Math.Min(intX, intY); | ||
418 | return Math.Min(convertDouble(x), convertDouble(y)); | ||
419 | } | ||
420 | |||
421 | public static object max(object x, object y) | ||
422 | { | ||
423 | int intX, intY; | ||
424 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
425 | return Math.Max(intX, intY); | ||
426 | return Math.Max(convertDouble(x), convertDouble(y)); | ||
427 | } | ||
428 | |||
429 | public static IEnumerable<bool> copy_term(object inTerm, object outTerm) | ||
430 | { | ||
431 | return YP.unify(outTerm, YP.makeCopy(inTerm, new Variable.CopyStore())); | ||
432 | } | ||
433 | |||
434 | public static void addUniqueVariables(object term, List<Variable> variableSet) | ||
435 | { | ||
436 | term = YP.getValue(term); | ||
437 | if (term is IUnifiable) | ||
438 | ((IUnifiable)term).addUniqueVariables(variableSet); | ||
439 | } | ||
440 | |||
441 | public static object makeCopy(object term, Variable.CopyStore copyStore) | ||
442 | { | ||
443 | term = YP.getValue(term); | ||
444 | if (term is IUnifiable) | ||
445 | return ((IUnifiable)term).makeCopy(copyStore); | ||
446 | else | ||
447 | // term is a "normal" type. Assume it is ground. | ||
448 | return term; | ||
449 | } | ||
450 | |||
451 | /// <summary> | ||
452 | /// Sort the array in place according to termLessThan. This does not remove duplicates | ||
453 | /// </summary> | ||
454 | /// <param name="array"></param> | ||
455 | public static void sortArray(object[] array) | ||
456 | { | ||
457 | Array.Sort(array, YP.compareTerms); | ||
458 | } | ||
459 | |||
460 | /// <summary> | ||
461 | /// Sort the array in place according to termLessThan. This does not remove duplicates | ||
462 | /// </summary> | ||
463 | /// <param name="array"></param> | ||
464 | public static void sortArray(List<object> array) | ||
465 | { | ||
466 | array.Sort(YP.compareTerms); | ||
467 | } | ||
468 | |||
469 | /// <summary> | ||
470 | /// Sort List according to termLessThan, remove duplicates and unify with Sorted. | ||
471 | /// </summary> | ||
472 | /// <param name="List"></param> | ||
473 | /// <param name="Sorted"></param> | ||
474 | /// <returns></returns> | ||
475 | public static IEnumerable<bool> sort(object List, object Sorted) | ||
476 | { | ||
477 | object[] array = ListPair.toArray(List); | ||
478 | if (array == null) | ||
479 | return YP.fail(); | ||
480 | if (array.Length > 1) | ||
481 | sortArray(array); | ||
482 | return YP.unify(Sorted, ListPair.makeWithoutRepeatedTerms(array)); | ||
483 | } | ||
484 | |||
485 | |||
486 | |||
487 | /// <summary> | ||
488 | /// Use YP.unify to unify each of the elements of the two arrays, and yield | ||
489 | /// once if they all unify. | ||
490 | /// </summary> | ||
491 | /// <param name="array1"></param> | ||
492 | /// <param name="array2"></param> | ||
493 | /// <returns></returns> | ||
494 | public static IEnumerable<bool> unifyArrays(object[] array1, object[] array2) | ||
495 | { | ||
496 | if (array1.Length != array2.Length) | ||
497 | yield break; | ||
498 | |||
499 | IEnumerator<bool>[] iterators = new IEnumerator<bool>[array1.Length]; | ||
500 | bool gotMatch = true; | ||
501 | int nIterators = 0; | ||
502 | // Try to bind all the arguments. | ||
503 | for (int i = 0; i < array1.Length; ++i) | ||
504 | { | ||
505 | IEnumerator<bool> iterator = YP.unify(array1[i], array2[i]).GetEnumerator(); | ||
506 | iterators[nIterators++] = iterator; | ||
507 | // MoveNext() is true if YP.unify succeeds. | ||
508 | if (!iterator.MoveNext()) | ||
509 | { | ||
510 | gotMatch = false; | ||
511 | break; | ||
512 | } | ||
513 | } | ||
514 | |||
515 | try | ||
516 | { | ||
517 | if (gotMatch) | ||
518 | yield return false; | ||
519 | } | ||
520 | finally | ||
521 | { | ||
522 | // Manually finalize all the iterators. | ||
523 | for (int i = 0; i < nIterators; ++i) | ||
524 | iterators[i].Dispose(); | ||
525 | } | ||
526 | } | ||
527 | |||
528 | /// <summary> | ||
529 | /// Return an iterator (which you can use in a for-in loop) which does | ||
530 | /// zero iterations. This returns a pre-existing iterator which is | ||
531 | /// more efficient than letting the compiler generate a new one. | ||
532 | /// </summary> | ||
533 | /// <returns></returns> | ||
534 | public static IEnumerable<bool> fail() | ||
535 | { | ||
536 | return _fail; | ||
537 | } | ||
538 | |||
539 | /// <summary> | ||
540 | /// Return an iterator (which you can use in a for-in loop) which does | ||
541 | /// one iteration. This returns a pre-existing iterator which is | ||
542 | /// more efficient than letting the compiler generate a new one. | ||
543 | /// </summary> | ||
544 | /// <returns></returns> | ||
545 | public static IEnumerable<bool> succeed() | ||
546 | { | ||
547 | return new Succeed(); | ||
548 | } | ||
549 | |||
550 | /// <summary> | ||
551 | /// Return an iterator (which you can use in a for-in loop) which repeats | ||
552 | /// indefinitely. This returns a pre-existing iterator which is | ||
553 | /// more efficient than letting the compiler generate a new one. | ||
554 | /// </summary> | ||
555 | /// <returns></returns> | ||
556 | public static IEnumerable<bool> repeat() | ||
557 | { | ||
558 | return _repeat; | ||
559 | } | ||
560 | |||
561 | public static IEnumerable<bool> univ(object Term, object List) | ||
562 | { | ||
563 | Term = YP.getValue(Term); | ||
564 | List = YP.getValue(List); | ||
565 | |||
566 | if (nonvar(Term)) | ||
567 | return YP.unify(new ListPair | ||
568 | (getFunctorName(Term), ListPair.make(getFunctorArgs(Term))), List); | ||
569 | |||
570 | Variable Name = new Variable(); | ||
571 | Variable ArgList = new Variable(); | ||
572 | foreach (bool l1 in new ListPair(Name, ArgList).unify(List)) | ||
573 | { | ||
574 | object[] args = ListPair.toArray(ArgList); | ||
575 | if (args == null) | ||
576 | throw new Exception("Expected a list. Got: " + ArgList.getValue()); | ||
577 | if (args.Length == 0) | ||
578 | // Return the Name, even if it is not an Atom. | ||
579 | return YP.unify(Term, Name); | ||
580 | if (!atom(Name)) | ||
581 | throw new Exception("Expected an atom. Got: " + Name.getValue()); | ||
582 | |||
583 | return YP.unify(Term, Functor.make((Atom)YP.getValue(Name), args)); | ||
584 | } | ||
585 | |||
586 | return YP.fail(); | ||
587 | } | ||
588 | |||
589 | public static IEnumerable<bool> functor(object Term, object FunctorName, object Arity) | ||
590 | { | ||
591 | Term = YP.getValue(Term); | ||
592 | FunctorName = YP.getValue(FunctorName); | ||
593 | Arity = YP.getValue(Arity); | ||
594 | |||
595 | if (!(Term is Variable)) | ||
596 | { | ||
597 | foreach (bool l1 in YP.unify(FunctorName, getFunctorName(Term))) | ||
598 | { | ||
599 | foreach (bool l2 in YP.unify(Arity, getFunctorArgs(Term).Length)) | ||
600 | yield return false; | ||
601 | } | ||
602 | } | ||
603 | else | ||
604 | throw new NotImplementedException("Debug: must finish functor/3"); | ||
605 | } | ||
606 | |||
607 | public static IEnumerable<bool> arg(object ArgNumber, object Term, object Value) | ||
608 | { | ||
609 | if (YP.var(ArgNumber)) | ||
610 | throw new NotImplementedException("Debug: must finish arg/3"); | ||
611 | else | ||
612 | { | ||
613 | int argNumberInt = convertInt(ArgNumber); | ||
614 | if (argNumberInt < 0) | ||
615 | throw new Exception("ArgNumber must be non-negative"); | ||
616 | object[] termArgs = YP.getFunctorArgs(Term); | ||
617 | // Silently fail if argNumberInt is out of range. | ||
618 | if (argNumberInt >= 1 && argNumberInt <= termArgs.Length) | ||
619 | { | ||
620 | // The first ArgNumber is at 1, not 0. | ||
621 | foreach (bool l1 in YP.unify(Value, termArgs[argNumberInt - 1])) | ||
622 | yield return false; | ||
623 | } | ||
624 | } | ||
625 | } | ||
626 | |||
627 | public static bool termEqual(object Term1, object Term2) | ||
628 | { | ||
629 | Term1 = YP.getValue(Term1); | ||
630 | if (Term1 is IUnifiable) | ||
631 | return ((IUnifiable)Term1).termEqual(Term2); | ||
632 | return Term1.Equals(YP.getValue(Term2)); | ||
633 | } | ||
634 | |||
635 | public static bool termNotEqual(object Term1, object Term2) | ||
636 | { | ||
637 | return !termEqual(Term1, Term2); | ||
638 | } | ||
639 | |||
640 | public static bool termLessThan(object Term1, object Term2) | ||
641 | { | ||
642 | Term1 = YP.getValue(Term1); | ||
643 | Term2 = YP.getValue(Term2); | ||
644 | int term1TypeCode = getTypeCode(Term1); | ||
645 | int term2TypeCode = getTypeCode(Term2); | ||
646 | if (term1TypeCode != term2TypeCode) | ||
647 | return term1TypeCode < term2TypeCode; | ||
648 | |||
649 | // The terms are the same type code. | ||
650 | if (term1TypeCode == -2) | ||
651 | { | ||
652 | // Variable. | ||
653 | // We always check for equality first because we want to be sure | ||
654 | // that less than returns false if the terms are equal, in | ||
655 | // case that the less than check really behaves like less than or equal. | ||
656 | if ((Variable)Term1 != (Variable)Term2) | ||
657 | // The hash code should be unique to a Variable object. | ||
658 | return Term1.GetHashCode() < Term2.GetHashCode(); | ||
659 | return false; | ||
660 | } | ||
661 | if (term1TypeCode == 0) | ||
662 | return ((Atom)Term1)._name.CompareTo(((Atom)Term2)._name) < 0; | ||
663 | if (term1TypeCode == 1) | ||
664 | return ((Functor1)Term1).lessThan((Functor1)Term2); | ||
665 | if (term1TypeCode == 2) | ||
666 | return ((Functor2)Term1).lessThan((Functor2)Term2); | ||
667 | if (term1TypeCode == 3) | ||
668 | return ((Functor3)Term1).lessThan((Functor3)Term2); | ||
669 | if (term1TypeCode == 4) | ||
670 | return ((Functor)Term1).lessThan((Functor)Term2); | ||
671 | |||
672 | // Type code is -1 for general objects. First compare their type names. | ||
673 | // Note that this puts Double before Int32 as required by ISO Prolog. | ||
674 | string term1TypeName = Term1.GetType().ToString(); | ||
675 | string term2TypeName = Term2.GetType().ToString(); | ||
676 | if (term1TypeName != term2TypeName) | ||
677 | return term1TypeName.CompareTo(term2TypeName) < 0; | ||
678 | |||
679 | // The terms are the same type name. | ||
680 | if (Term1 is int) | ||
681 | return (int)Term1 < (int)Term2; | ||
682 | else if (Term1 is double) | ||
683 | return (double)Term1 < (double)Term2; | ||
684 | else if (Term1 is DateTime) | ||
685 | return (DateTime)Term1 < (DateTime)Term2; | ||
686 | else if (Term1 is String) | ||
687 | return ((String)Term1).CompareTo((String)Term2) < 0; | ||
688 | // Debug: Should we try arrays, etc.? | ||
689 | |||
690 | if (!Term1.Equals(Term2)) | ||
691 | // Could be equal or greater than. | ||
692 | return Term1.GetHashCode() < Term2.GetHashCode(); | ||
693 | return false; | ||
694 | } | ||
695 | |||
696 | /// <summary> | ||
697 | /// Type code is -2 if term is a Variable, 0 if it is an Atom, | ||
698 | /// 1 if it is a Functor1, 2 if it is a Functor2, 3 if it is a Functor3, | ||
699 | /// 4 if it is Functor. | ||
700 | /// Otherwise, type code is -1. | ||
701 | /// This does not call YP.getValue(term). | ||
702 | /// </summary> | ||
703 | /// <param name="term"></param> | ||
704 | /// <returns></returns> | ||
705 | private static int getTypeCode(object term) | ||
706 | { | ||
707 | if (term is Variable) | ||
708 | return -2; | ||
709 | else if (term is Atom) | ||
710 | return 0; | ||
711 | else if (term is Functor1) | ||
712 | return 1; | ||
713 | else if (term is Functor2) | ||
714 | return 2; | ||
715 | else if (term is Functor3) | ||
716 | return 3; | ||
717 | else if (term is Functor) | ||
718 | return 4; | ||
719 | else | ||
720 | return -1; | ||
721 | } | ||
722 | |||
723 | public static bool termLessThanOrEqual(object Term1, object Term2) | ||
724 | { | ||
725 | if (YP.termEqual(Term1, Term2)) | ||
726 | return true; | ||
727 | return YP.termLessThan(Term1, Term2); | ||
728 | } | ||
729 | |||
730 | public static bool termGreaterThan(object Term1, object Term2) | ||
731 | { | ||
732 | return !YP.termLessThanOrEqual(Term1, Term2); | ||
733 | } | ||
734 | |||
735 | public static bool termGreaterThanOrEqual(object Term1, object Term2) | ||
736 | { | ||
737 | // termLessThan should ensure that it returns false if terms are equal, | ||
738 | // so that this would return true. | ||
739 | return !YP.termLessThan(Term1, Term2); | ||
740 | } | ||
741 | |||
742 | public static int compareTerms(object Term1, object Term2) | ||
743 | { | ||
744 | if (YP.termEqual(Term1, Term2)) | ||
745 | return 0; | ||
746 | else if (YP.termLessThan(Term1, Term2)) | ||
747 | return -1; | ||
748 | else | ||
749 | return 1; | ||
750 | } | ||
751 | |||
752 | public static bool ground(object Term) | ||
753 | { | ||
754 | Term = YP.getValue(Term); | ||
755 | if (Term is IUnifiable) | ||
756 | return ((IUnifiable)Term).ground(); | ||
757 | return true; | ||
758 | } | ||
759 | |||
760 | public static IEnumerable<bool> current_op | ||
761 | (object Priority, object Specifier, object Operator) | ||
762 | { | ||
763 | if (_operatorTable == null) | ||
764 | { | ||
765 | // Initialize. | ||
766 | _operatorTable = new List<object[]>(); | ||
767 | _operatorTable.Add(new object[] { 1200, Atom.a("xfx"), Atom.a(":-") }); | ||
768 | _operatorTable.Add(new object[] { 1200, Atom.a("xfx"), Atom.a("-->") }); | ||
769 | _operatorTable.Add(new object[] { 1200, Atom.a("fx"), Atom.a(":-") }); | ||
770 | _operatorTable.Add(new object[] { 1200, Atom.a("fx"), Atom.a("?-") }); | ||
771 | _operatorTable.Add(new object[] { 1100, Atom.a("xfy"), Atom.a(";") }); | ||
772 | _operatorTable.Add(new object[] { 1050, Atom.a("xfy"), Atom.a("->") }); | ||
773 | _operatorTable.Add(new object[] { 1000, Atom.a("xfy"), Atom.a(",") }); | ||
774 | _operatorTable.Add(new object[] { 900, Atom.a("fy"), Atom.a("\\+") }); | ||
775 | _operatorTable.Add(new object[] { 700, Atom.a("xfx"), Atom.a("=") }); | ||
776 | _operatorTable.Add(new object[] { 700, Atom.a("xfx"), Atom.a("\\=") }); | ||
777 | _operatorTable.Add(new object[] { 700, Atom.a("xfx"), Atom.a("==") }); | ||
778 | _operatorTable.Add(new object[] { 700, Atom.a("xfx"), Atom.a("\\==") }); | ||
779 | _operatorTable.Add(new object[] { 700, Atom.a("xfx"), Atom.a("@<") }); | ||
780 | _operatorTable.Add(new object[] { 700, Atom.a("xfx"), Atom.a("@=<") }); | ||
781 | _operatorTable.Add(new object[] { 700, Atom.a("xfx"), Atom.a("@>") }); | ||
782 | _operatorTable.Add(new object[] { 700, Atom.a("xfx"), Atom.a("@>=") }); | ||
783 | _operatorTable.Add(new object[] { 700, Atom.a("xfx"), Atom.a("=..") }); | ||
784 | _operatorTable.Add(new object[] { 700, Atom.a("xfx"), Atom.a("is") }); | ||
785 | _operatorTable.Add(new object[] { 700, Atom.a("xfx"), Atom.a("=:=") }); | ||
786 | _operatorTable.Add(new object[] { 700, Atom.a("xfx"), Atom.a("=\\=") }); | ||
787 | _operatorTable.Add(new object[] { 700, Atom.a("xfx"), Atom.a("<") }); | ||
788 | _operatorTable.Add(new object[] { 700, Atom.a("xfx"), Atom.a("=<") }); | ||
789 | _operatorTable.Add(new object[] { 700, Atom.a("xfx"), Atom.a(">") }); | ||
790 | _operatorTable.Add(new object[] { 700, Atom.a("xfx"), Atom.a(">=") }); | ||
791 | _operatorTable.Add(new object[] { 600, Atom.a("xfy"), Atom.a(":") }); | ||
792 | _operatorTable.Add(new object[] { 500, Atom.a("yfx"), Atom.a("+") }); | ||
793 | _operatorTable.Add(new object[] { 500, Atom.a("yfx"), Atom.a("-") }); | ||
794 | _operatorTable.Add(new object[] { 500, Atom.a("yfx"), Atom.a("/\\") }); | ||
795 | _operatorTable.Add(new object[] { 500, Atom.a("yfx"), Atom.a("\\/") }); | ||
796 | _operatorTable.Add(new object[] { 400, Atom.a("yfx"), Atom.a("*") }); | ||
797 | _operatorTable.Add(new object[] { 400, Atom.a("yfx"), Atom.a("/") }); | ||
798 | _operatorTable.Add(new object[] { 400, Atom.a("yfx"), Atom.a("//") }); | ||
799 | _operatorTable.Add(new object[] { 400, Atom.a("yfx"), Atom.a("rem") }); | ||
800 | _operatorTable.Add(new object[] { 400, Atom.a("yfx"), Atom.a("mod") }); | ||
801 | _operatorTable.Add(new object[] { 400, Atom.a("yfx"), Atom.a("<<") }); | ||
802 | _operatorTable.Add(new object[] { 400, Atom.a("yfx"), Atom.a(">>") }); | ||
803 | _operatorTable.Add(new object[] { 200, Atom.a("xfx"), Atom.a("**") }); | ||
804 | _operatorTable.Add(new object[] { 200, Atom.a("xfy"), Atom.a("^") }); | ||
805 | _operatorTable.Add(new object[] { 200, Atom.a("fy"), Atom.a("-") }); | ||
806 | _operatorTable.Add(new object[] { 200, Atom.a("fy"), Atom.a("\\") }); | ||
807 | // Debug: This is hacked in to run the Prolog test suite until we implement op/3. | ||
808 | _operatorTable.Add(new object[] { 20, Atom.a("xfx"), Atom.a("<--") }); | ||
809 | } | ||
810 | |||
811 | object[] args = new object[] { Priority, Specifier, Operator }; | ||
812 | foreach (object[] answer in _operatorTable) | ||
813 | { | ||
814 | foreach (bool l1 in YP.unifyArrays(args, answer)) | ||
815 | yield return false; | ||
816 | } | ||
817 | } | ||
818 | |||
819 | public static IEnumerable<bool> atom_length(object atom, object Length) | ||
820 | { | ||
821 | return YP.unify(Length, ((Atom)YP.getValue(atom))._name.Length); | ||
822 | } | ||
823 | |||
824 | public static IEnumerable<bool> atom_concat(object Start, object End, object Whole) | ||
825 | { | ||
826 | // Debug: Should implement for var(Start) which is a kind of search. | ||
827 | // Debug: Should we try to preserve the _declaringClass? | ||
828 | return YP.unify(Whole, Atom.a(((Atom)YP.getValue(Start))._name + | ||
829 | ((Atom)YP.getValue(End))._name)); | ||
830 | } | ||
831 | |||
832 | public static IEnumerable<bool> sub_atom | ||
833 | (object atom, object Before, object Length, object After, object Sub_atom) | ||
834 | { | ||
835 | // Debug: Should implement for var(atom) which is a kind of search. | ||
836 | // Debug: Should we try to preserve the _declaringClass? | ||
837 | Atom atomAtom = (Atom)YP.getValue(atom); | ||
838 | int beforeInt = YP.convertInt(Before); | ||
839 | int lengthInt = YP.convertInt(Length); | ||
840 | if (beforeInt < 0) | ||
841 | throw new Exception("Before must be non-negative"); | ||
842 | if (lengthInt < 0) | ||
843 | throw new Exception("Length must be non-negative"); | ||
844 | int afterInt = atomAtom._name.Length - (beforeInt + lengthInt); | ||
845 | if (afterInt >= 0) | ||
846 | { | ||
847 | foreach (bool l1 in YP.unify(After, afterInt)) | ||
848 | { | ||
849 | foreach (bool l2 in YP.unify | ||
850 | (Sub_atom, Atom.a(atomAtom._name.Substring(beforeInt, lengthInt)))) | ||
851 | yield return false; | ||
852 | } | ||
853 | } | ||
854 | } | ||
855 | |||
856 | public static IEnumerable<bool> atom_codes(object atom, object List) | ||
857 | { | ||
858 | atom = YP.getValue(atom); | ||
859 | List = YP.getValue(List); | ||
860 | |||
861 | if (nonvar(atom)) | ||
862 | { | ||
863 | string name = ((Atom)atom)._name; | ||
864 | object codeList = Atom.NIL; | ||
865 | // Start from the back to make the list. | ||
866 | for (int i = name.Length - 1; i >= 0; --i) | ||
867 | codeList = new ListPair((int)name[i], codeList); | ||
868 | return YP.unify(List, codeList); | ||
869 | } | ||
870 | { | ||
871 | object[] codeArray = ListPair.toArray(List); | ||
872 | char[] charArray = new char[codeArray.Length]; | ||
873 | for (int i = 0; i < codeArray.Length; ++i) | ||
874 | charArray[i] = (char)YP.convertInt(codeArray[i]); | ||
875 | return YP.unify(atom, Atom.a(new String(charArray))); | ||
876 | } | ||
877 | } | ||
878 | |||
879 | public static IEnumerable<bool> number_codes(object number, object List) | ||
880 | { | ||
881 | number = YP.getValue(number); | ||
882 | List = YP.getValue(List); | ||
883 | |||
884 | if (nonvar(number)) | ||
885 | { | ||
886 | string numberString = null; | ||
887 | // Try converting to an int first. | ||
888 | int intNumber; | ||
889 | if (YP.getInt(number, out intNumber)) | ||
890 | numberString = intNumber.ToString(); | ||
891 | else | ||
892 | numberString = YP.doubleToString(YP.convertDouble(number)); | ||
893 | |||
894 | object codeList = Atom.NIL; | ||
895 | // Start from the back to make the list. | ||
896 | for (int i = numberString.Length - 1; i >= 0; --i) | ||
897 | codeList = new ListPair((int)numberString[i], codeList); | ||
898 | return YP.unify(List, codeList); | ||
899 | } | ||
900 | { | ||
901 | object[] codeArray = ListPair.toArray(List); | ||
902 | char[] charArray = new char[codeArray.Length]; | ||
903 | for (int i = 0; i < codeArray.Length; ++i) | ||
904 | charArray[i] = (char)YP.convertInt(codeArray[i]); | ||
905 | String numberString = new String(charArray); | ||
906 | // Debug: Is there a way in C# to ask if a string parses as int without throwing an exception? | ||
907 | try | ||
908 | { | ||
909 | // Try an int first. | ||
910 | return YP.unify(number, Convert.ToInt32(numberString)); | ||
911 | } | ||
912 | catch (FormatException) { } | ||
913 | return YP.unify(number, Convert.ToDouble(numberString)); | ||
914 | } | ||
915 | } | ||
916 | |||
917 | /// <summary> | ||
918 | /// If term is an Atom or functor type, return its name. | ||
919 | /// Otherwise, return term. | ||
920 | /// </summary> | ||
921 | /// <param name="term"></param> | ||
922 | /// <returns></returns> | ||
923 | public static object getFunctorName(object term) | ||
924 | { | ||
925 | term = YP.getValue(term); | ||
926 | if (term is Functor1) | ||
927 | return ((Functor1)term)._name; | ||
928 | else if (term is Functor2) | ||
929 | return ((Functor2)term)._name; | ||
930 | else if (term is Functor3) | ||
931 | return ((Functor3)term)._name; | ||
932 | else if (term is Functor) | ||
933 | return ((Functor)term)._name; | ||
934 | else | ||
935 | return term; | ||
936 | } | ||
937 | |||
938 | /// <summary> | ||
939 | /// If term is an Atom or functor type, return an array of its args. | ||
940 | /// Otherwise, return an empty array. | ||
941 | /// </summary> | ||
942 | /// <param name="term"></param> | ||
943 | /// <returns></returns> | ||
944 | public static object[] getFunctorArgs(object term) | ||
945 | { | ||
946 | term = YP.getValue(term); | ||
947 | if (term is Functor1) | ||
948 | { | ||
949 | Functor1 functor = (Functor1)term; | ||
950 | return new object[] { functor._arg1 }; | ||
951 | } | ||
952 | else if (term is Functor2) | ||
953 | { | ||
954 | Functor2 functor = (Functor2)term; | ||
955 | return new object[] { functor._arg1, functor._arg2 }; | ||
956 | } | ||
957 | else if (term is Functor3) | ||
958 | { | ||
959 | Functor3 functor = (Functor3)term; | ||
960 | return new object[] { functor._arg1, functor._arg2, functor._arg3 }; | ||
961 | } | ||
962 | else if (term is Functor) { | ||
963 | Functor functor = (Functor)term; | ||
964 | return functor._args; | ||
965 | } | ||
966 | else | ||
967 | return new object[0]; | ||
968 | } | ||
969 | |||
970 | public static bool var(object Term) | ||
971 | { | ||
972 | return YP.getValue(Term) is Variable; | ||
973 | } | ||
974 | |||
975 | public static bool nonvar(object Term) | ||
976 | { | ||
977 | return !YP.var(Term); | ||
978 | } | ||
979 | |||
980 | public static bool atom(object Term) | ||
981 | { | ||
982 | return YP.getValue(Term) is Atom; | ||
983 | } | ||
984 | |||
985 | public static bool number(object Term) | ||
986 | { | ||
987 | Term = getValue(Term); | ||
988 | // Debug: Should exhaustively check for all number types. | ||
989 | return Term is int || Term is double; | ||
990 | } | ||
991 | |||
992 | public static bool atomic(object Term) | ||
993 | { | ||
994 | return YP.atom(Term) || YP.number(Term); | ||
995 | } | ||
996 | |||
997 | public static bool compound(object Term) | ||
998 | { | ||
999 | Term = getValue(Term); | ||
1000 | return Term is Functor1 || Term is Functor2 || Term is Functor3 || Term is Functor; | ||
1001 | } | ||
1002 | |||
1003 | public static void see(object input) | ||
1004 | { | ||
1005 | input = YP.getValue(input); | ||
1006 | if (input is TextReader) | ||
1007 | { | ||
1008 | _inputStream = (TextReader)input; | ||
1009 | return; | ||
1010 | } | ||
1011 | else if (input is Atom) | ||
1012 | { | ||
1013 | _inputStream = new StreamReader(((Atom)input)._name); | ||
1014 | return; | ||
1015 | } | ||
1016 | else if (input is String) | ||
1017 | { | ||
1018 | _inputStream = new StreamReader((String)input); | ||
1019 | return; | ||
1020 | } | ||
1021 | else | ||
1022 | throw new InvalidOperationException("Can't open stream for " + input); | ||
1023 | } | ||
1024 | |||
1025 | public static void seen() | ||
1026 | { | ||
1027 | if (_inputStream == Console.In) | ||
1028 | return; | ||
1029 | _inputStream.Close(); | ||
1030 | _inputStream = Console.In; | ||
1031 | } | ||
1032 | |||
1033 | public static void tell(object output) | ||
1034 | { | ||
1035 | output = YP.getValue(output); | ||
1036 | if (output is TextWriter) | ||
1037 | { | ||
1038 | _outputStream = (TextWriter)output; | ||
1039 | return; | ||
1040 | } | ||
1041 | else if (output is Atom) | ||
1042 | { | ||
1043 | _outputStream = new StreamWriter(((Atom)output)._name); | ||
1044 | return; | ||
1045 | } | ||
1046 | else if (output is String) | ||
1047 | { | ||
1048 | _outputStream = new StreamWriter((String)output); | ||
1049 | return; | ||
1050 | } | ||
1051 | else | ||
1052 | throw new InvalidOperationException("Can't open stream for " + output); | ||
1053 | } | ||
1054 | |||
1055 | public static void told() | ||
1056 | { | ||
1057 | if (_outputStream == Console.Out) | ||
1058 | return; | ||
1059 | _outputStream.Close(); | ||
1060 | _outputStream = Console.Out; | ||
1061 | } | ||
1062 | |||
1063 | public static void write(object x) | ||
1064 | { | ||
1065 | x = YP.getValue(x); | ||
1066 | if (x is double) | ||
1067 | _outputStream.Write(doubleToString((double)x)); | ||
1068 | else | ||
1069 | _outputStream.Write(x.ToString()); | ||
1070 | } | ||
1071 | |||
1072 | /// <summary> | ||
1073 | /// Format x as a string, making sure that it will parse as an int later. I.e., for 1.0, don't just | ||
1074 | /// use "1" which will parse as an int. | ||
1075 | /// </summary> | ||
1076 | /// <param name="x"></param> | ||
1077 | /// <returns></returns> | ||
1078 | private static string doubleToString(double x) | ||
1079 | { | ||
1080 | string xString = x.ToString(); | ||
1081 | // Debug: Is there a way in C# to ask if a string parses as int without throwing an exception? | ||
1082 | try | ||
1083 | { | ||
1084 | Convert.ToInt32(xString); | ||
1085 | // The string will parse as an int, not a double, so re-format so that it does. | ||
1086 | // Use float if possible, else exponential if it would be too big. | ||
1087 | return x.ToString(x >= 100000.0 ? "E1" : "f1"); | ||
1088 | } | ||
1089 | catch (FormatException) | ||
1090 | { | ||
1091 | // Assume it will parse as a double. | ||
1092 | } | ||
1093 | return xString; | ||
1094 | } | ||
1095 | |||
1096 | public static void put_code(object x) | ||
1097 | { | ||
1098 | _outputStream.Write((char)YP.convertInt(x)); | ||
1099 | } | ||
1100 | |||
1101 | public static void nl() | ||
1102 | { | ||
1103 | _outputStream.WriteLine(); | ||
1104 | } | ||
1105 | |||
1106 | public static IEnumerable<bool> get_code(object code) | ||
1107 | { | ||
1108 | return YP.unify(code, _inputStream.Read()); | ||
1109 | } | ||
1110 | |||
1111 | public static void assertFact(Atom name, object[] values) | ||
1112 | { | ||
1113 | NameArity nameArity = new NameArity(name, values.Length); | ||
1114 | List<IClause> clauses; | ||
1115 | IndexedAnswers indexedAnswers; | ||
1116 | if (!_predicatesStore.TryGetValue(nameArity, out clauses)) | ||
1117 | { | ||
1118 | // Create an IndexedAnswers as the first clause of the predicate. | ||
1119 | _predicatesStore[nameArity] = (clauses = new List<IClause>()); | ||
1120 | clauses.Add(indexedAnswers = new IndexedAnswers()); | ||
1121 | } | ||
1122 | else | ||
1123 | { | ||
1124 | indexedAnswers = clauses[clauses.Count - 1] as IndexedAnswers; | ||
1125 | if (indexedAnswers == null) | ||
1126 | // The latest clause is not an IndexedAnswers, so add one. | ||
1127 | clauses.Add(indexedAnswers = new IndexedAnswers()); | ||
1128 | } | ||
1129 | |||
1130 | indexedAnswers.addAnswer(values); | ||
1131 | } | ||
1132 | |||
1133 | public static IEnumerable<bool> matchFact(Atom name, object[] arguments) | ||
1134 | { | ||
1135 | List<IClause> clauses; | ||
1136 | if (!_predicatesStore.TryGetValue(new NameArity(name, arguments.Length), out clauses)) | ||
1137 | throw new UndefinedPredicateException | ||
1138 | ("Undefined fact: " + name + "/" + arguments.Length, name, | ||
1139 | arguments.Length); | ||
1140 | |||
1141 | if (clauses.Count == 1) | ||
1142 | // Usually there is only one clause, so return it without needing to wrap it in an iterator. | ||
1143 | return clauses[0].match(arguments); | ||
1144 | else | ||
1145 | return matchAllClauses(clauses, arguments); | ||
1146 | } | ||
1147 | |||
1148 | /// <summary> | ||
1149 | /// Call match(arguments) for each IClause in clauses. We make this a separate | ||
1150 | /// function so that matchFact itself does not need to be an iterator object. | ||
1151 | /// </summary> | ||
1152 | /// <param name="clauses"></param> | ||
1153 | /// <param name="arguments"></param> | ||
1154 | /// <returns></returns> | ||
1155 | private static IEnumerable<bool> matchAllClauses(List<IClause> clauses, object[] arguments) | ||
1156 | { | ||
1157 | foreach (IClause clause in clauses) | ||
1158 | { | ||
1159 | foreach (bool lastCall in clause.match(arguments)) | ||
1160 | yield return false; | ||
1161 | } | ||
1162 | } | ||
1163 | |||
1164 | public static void retractFact(Atom name, object[] arguments) | ||
1165 | { | ||
1166 | NameArity nameArity = new NameArity(name, arguments.Length); | ||
1167 | List<IClause> clauses; | ||
1168 | if (!_predicatesStore.TryGetValue(nameArity, out clauses)) | ||
1169 | // Can't find, so ignore. | ||
1170 | return; | ||
1171 | |||
1172 | foreach (object arg in arguments) | ||
1173 | { | ||
1174 | if (!YP.var(arg)) | ||
1175 | throw new InvalidOperationException("All arguments must be unbound"); | ||
1176 | } | ||
1177 | // Set to a fresh empty IndexedAnswers. | ||
1178 | _predicatesStore[nameArity] = (clauses = new List<IClause>()); | ||
1179 | clauses.Add(new IndexedAnswers()); | ||
1180 | } | ||
1181 | |||
1182 | public static IEnumerable<bool> current_predicate(object NameSlashArity) | ||
1183 | { | ||
1184 | NameSlashArity = YP.getValue(NameSlashArity); | ||
1185 | // First check if Name and Arity are nonvar so we can do a direct lookup. | ||
1186 | if (YP.ground(NameSlashArity)) | ||
1187 | { | ||
1188 | if (NameSlashArity is Functor2) | ||
1189 | { | ||
1190 | Functor2 NameArityFunctor = (Functor2)NameSlashArity; | ||
1191 | if (NameArityFunctor._name == Atom.SLASH) | ||
1192 | { | ||
1193 | if (_predicatesStore.ContainsKey(new NameArity | ||
1194 | ((Atom)YP.getValue(NameArityFunctor._arg1), | ||
1195 | (int)YP.getValue(NameArityFunctor._arg2)))) | ||
1196 | // The predicate is defined. | ||
1197 | yield return false; | ||
1198 | } | ||
1199 | } | ||
1200 | yield break; | ||
1201 | } | ||
1202 | |||
1203 | foreach (NameArity key in _predicatesStore.Keys) | ||
1204 | { | ||
1205 | foreach (bool l1 in YP.unify | ||
1206 | (new Functor2(Atom.SLASH, key._name, key._arity), NameSlashArity)) | ||
1207 | yield return false; | ||
1208 | } | ||
1209 | } | ||
1210 | |||
1211 | /// <summary> | ||
1212 | /// Use YP.getFunctorName(Goal) and invoke the static method of this name in the | ||
1213 | /// declaringClass, using arguments from YP.getFunctorArgs(Goal). | ||
1214 | /// Note that Goal must be a simple functor, not a complex expression. | ||
1215 | /// If not found, this throws UndefinedPredicateException. | ||
1216 | /// </summary> | ||
1217 | /// <param name="Goal"></param> | ||
1218 | /// <param name="contextClass">the class for looking up default function references</param> | ||
1219 | /// <returns></returns> | ||
1220 | public static IEnumerable<bool> getIterator(object Goal, Type declaringClass) | ||
1221 | { | ||
1222 | #if true | ||
1223 | List<Variable> variableSetList = new List<Variable>(); | ||
1224 | addUniqueVariables(Goal, variableSetList); | ||
1225 | Variable[] variableSet = variableSetList.ToArray(); | ||
1226 | object Head = Functor.make("function", variableSet); | ||
1227 | |||
1228 | object Rule = new Functor2(Atom.RULE, Head, Goal); | ||
1229 | object RuleList = ListPair.make(new Functor2(Atom.F, Rule, Atom.NIL)); | ||
1230 | StringWriter functionCode = new StringWriter(); | ||
1231 | TextWriter saveOutputStream = _outputStream; | ||
1232 | try | ||
1233 | { | ||
1234 | tell(functionCode); | ||
1235 | Variable FunctionCode = new Variable(); | ||
1236 | foreach (bool l1 in YPCompiler.makeFunctionPseudoCode(RuleList, FunctionCode)) | ||
1237 | { | ||
1238 | if (YP.termEqual(FunctionCode, Atom.a("getDeclaringClass"))) | ||
1239 | // Ignore getDeclaringClass since we have access to the one passed in. | ||
1240 | continue; | ||
1241 | |||
1242 | // Debug: should check if FunctionCode is a single call. | ||
1243 | YPCompiler.convertFunctionCSharp(FunctionCode); | ||
1244 | } | ||
1245 | told(); | ||
1246 | } | ||
1247 | finally | ||
1248 | { | ||
1249 | // Restore after calling tell. | ||
1250 | _outputStream = saveOutputStream; | ||
1251 | } | ||
1252 | return YPCompiler.compileAnonymousFunction | ||
1253 | (functionCode.ToString(), variableSet.Length, declaringClass).match(variableSet); | ||
1254 | #else | ||
1255 | Goal = YP.getValue(Goal); | ||
1256 | Atom name; | ||
1257 | object[] args; | ||
1258 | while (true) | ||
1259 | { | ||
1260 | name = (Atom)YP.getFunctorName(Goal); | ||
1261 | args = YP.getFunctorArgs(Goal); | ||
1262 | if (name == Atom.HAT && args.Length == 2) | ||
1263 | // Assume this is called from a bagof operation. Skip the leading qualifiers. | ||
1264 | Goal = YP.getValue(((Functor2)Goal)._arg2); | ||
1265 | else | ||
1266 | break; | ||
1267 | } | ||
1268 | try | ||
1269 | { | ||
1270 | return (IEnumerable<bool>)declaringClass.InvokeMember | ||
1271 | (name._name, BindingFlags.InvokeMethod, null, null, args); | ||
1272 | } | ||
1273 | catch (TargetInvocationException exception) | ||
1274 | { | ||
1275 | throw exception.InnerException; | ||
1276 | } | ||
1277 | catch (MissingMethodException) | ||
1278 | { | ||
1279 | throw new UndefinedPredicateException | ||
1280 | ("Cannot find predicate function: " + name + "/" + args.Length + " in " + | ||
1281 | declaringClass.FullName, name, args.Length); | ||
1282 | } | ||
1283 | #endif | ||
1284 | } | ||
1285 | |||
1286 | public static void throwException(object Term) | ||
1287 | { | ||
1288 | throw new PrologException(Term); | ||
1289 | } | ||
1290 | |||
1291 | /// <summary> | ||
1292 | /// script_event calls hosting script with events as a callback method. | ||
1293 | /// </summary> | ||
1294 | /// <param name="script_event"></param> | ||
1295 | /// <param name="script_params"></param> | ||
1296 | /// <returns></returns> | ||
1297 | public static void script_event(object script_event, object script_params) | ||
1298 | { | ||
1299 | string function = ((Atom)YP.getValue(script_event))._name; | ||
1300 | object[] array = ListPair.toArray(script_params); | ||
1301 | if (array == null) | ||
1302 | return; // YP.fail(); | ||
1303 | if (array.Length > 1) | ||
1304 | { | ||
1305 | //m_CmdManager.m_ScriptEngine.m_EventQueManager.AddToScriptQueue | ||
1306 | //(localID, itemID, function, array); | ||
1307 | // sortArray(array); | ||
1308 | } | ||
1309 | //return YP.unify(Sorted, ListPair.makeWithoutRepeatedTerms(array)); | ||
1310 | } | ||
1311 | |||
1312 | /// <summary> | ||
1313 | /// An enumerator that does zero loops. | ||
1314 | /// </summary> | ||
1315 | private class Fail : IEnumerator<bool>, IEnumerable<bool> | ||
1316 | { | ||
1317 | public bool MoveNext() | ||
1318 | { | ||
1319 | return false; | ||
1320 | } | ||
1321 | |||
1322 | public IEnumerator<bool> GetEnumerator() | ||
1323 | { | ||
1324 | return (IEnumerator<bool>)this; | ||
1325 | } | ||
1326 | |||
1327 | IEnumerator IEnumerable.GetEnumerator() | ||
1328 | { | ||
1329 | return GetEnumerator(); | ||
1330 | } | ||
1331 | |||
1332 | public bool Current | ||
1333 | { | ||
1334 | get { return true; } | ||
1335 | } | ||
1336 | |||
1337 | object IEnumerator.Current | ||
1338 | { | ||
1339 | get { return true; } | ||
1340 | } | ||
1341 | |||
1342 | public void Dispose() | ||
1343 | { | ||
1344 | } | ||
1345 | |||
1346 | public void Reset() | ||
1347 | { | ||
1348 | throw new NotImplementedException(); | ||
1349 | } | ||
1350 | } | ||
1351 | |||
1352 | /// <summary> | ||
1353 | /// An enumerator that does one iteration. | ||
1354 | /// </summary> | ||
1355 | private class Succeed : IEnumerator<bool>, IEnumerable<bool> | ||
1356 | { | ||
1357 | private bool _didIteration = false; | ||
1358 | |||
1359 | public bool MoveNext() | ||
1360 | { | ||
1361 | if (!_didIteration) | ||
1362 | { | ||
1363 | _didIteration = true; | ||
1364 | return true; | ||
1365 | } | ||
1366 | else | ||
1367 | return false; | ||
1368 | } | ||
1369 | |||
1370 | public IEnumerator<bool> GetEnumerator() | ||
1371 | { | ||
1372 | return (IEnumerator<bool>)this; | ||
1373 | } | ||
1374 | |||
1375 | IEnumerator IEnumerable.GetEnumerator() | ||
1376 | { | ||
1377 | return GetEnumerator(); | ||
1378 | } | ||
1379 | |||
1380 | public bool Current | ||
1381 | { | ||
1382 | get { return false; } | ||
1383 | } | ||
1384 | |||
1385 | object IEnumerator.Current | ||
1386 | { | ||
1387 | get { return false; } | ||
1388 | } | ||
1389 | |||
1390 | public void Dispose() | ||
1391 | { | ||
1392 | } | ||
1393 | |||
1394 | public void Reset() | ||
1395 | { | ||
1396 | throw new NotImplementedException(); | ||
1397 | } | ||
1398 | } | ||
1399 | |||
1400 | /// <summary> | ||
1401 | /// An enumerator that repeats forever. | ||
1402 | /// </summary> | ||
1403 | private class Repeat : IEnumerator<bool>, IEnumerable<bool> | ||
1404 | { | ||
1405 | public bool MoveNext() | ||
1406 | { | ||
1407 | return true; | ||
1408 | } | ||
1409 | |||
1410 | public IEnumerator<bool> GetEnumerator() | ||
1411 | { | ||
1412 | return (IEnumerator<bool>)this; | ||
1413 | } | ||
1414 | |||
1415 | IEnumerator IEnumerable.GetEnumerator() | ||
1416 | { | ||
1417 | return GetEnumerator(); | ||
1418 | } | ||
1419 | |||
1420 | public bool Current | ||
1421 | { | ||
1422 | get { return false; } | ||
1423 | } | ||
1424 | |||
1425 | object IEnumerator.Current | ||
1426 | { | ||
1427 | get { return false; } | ||
1428 | } | ||
1429 | |||
1430 | public void Dispose() | ||
1431 | { | ||
1432 | } | ||
1433 | |||
1434 | public void Reset() | ||
1435 | { | ||
1436 | throw new NotImplementedException(); | ||
1437 | } | ||
1438 | } | ||
1439 | } | ||
1440 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YPCompiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YPCompiler.cs new file mode 100644 index 0000000..923906b --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YPCompiler.cs | |||
@@ -0,0 +1,5247 @@ | |||
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 | |||
38 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog | ||
39 | { | ||
40 | public class YPCompiler | ||
41 | { | ||
42 | private class CompilerState | ||
43 | { | ||
44 | public IndexedAnswers _pred = new IndexedAnswers(); | ||
45 | public Dictionary<YP.NameArity, Atom> _moduleForNameArity = new Dictionary<YP.NameArity, Atom>(); | ||
46 | public int _gensymCounter; | ||
47 | public bool _useFinalCutCode; | ||
48 | public Variable _finalCutCode; | ||
49 | public bool _codeUsesYield; | ||
50 | public Atom _determinism; | ||
51 | // a list of '='(Name, Variable) | ||
52 | public List<object> _variableNames; | ||
53 | |||
54 | // Make these static functions that explicitly take the State so Prolog can call it. | ||
55 | |||
56 | /// <summary> | ||
57 | /// Make a new CompilerState and bind it to State. | ||
58 | /// </summary> | ||
59 | /// <param name="State"></param> | ||
60 | /// <returns></returns> | ||
61 | public static IEnumerable<bool> make(object State) | ||
62 | { | ||
63 | return YP.unify(State, new CompilerState()); | ||
64 | } | ||
65 | |||
66 | public static void assertPred(object State, object Pred, object Determinism) | ||
67 | { | ||
68 | State = YP.getValue(State); | ||
69 | object functorName = YP.getFunctorName(Pred); | ||
70 | object[] functorArgs = YP.getFunctorArgs(Pred); | ||
71 | // Debug: Should check if it's already asserted and is the same. | ||
72 | ((CompilerState)State)._pred.addAnswer | ||
73 | (new object[] { functorName, functorArgs.Length, Pred, YP.getValue(Determinism) }); | ||
74 | } | ||
75 | |||
76 | public static void assertModuleForNameArity(object State, object Name, object Arity, object Module) | ||
77 | { | ||
78 | State = YP.getValue(State); | ||
79 | Name = YP.getValue(Name); | ||
80 | Arity = YP.getValue(Arity); | ||
81 | Module = YP.getValue(Module); | ||
82 | // If the Module Atom comes from the parser, it always has null _declaringClass. | ||
83 | if (Module is Atom && ((Atom)Module)._module == null && Name is Atom && Arity is int) | ||
84 | { | ||
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 | |||
91 | public static void startFunction(object State, object Head) | ||
92 | { | ||
93 | State = YP.getValue(State); | ||
94 | ((CompilerState)State)._gensymCounter = 0; | ||
95 | ((CompilerState)State)._useFinalCutCode = false; | ||
96 | ((CompilerState)State)._finalCutCode = new Variable(); | ||
97 | ((CompilerState)State)._codeUsesYield = false; | ||
98 | if (CompilerState.isDetNoneOut(State, Head)) | ||
99 | ((CompilerState)State)._determinism = Atom.a("detNoneOut"); | ||
100 | else if (CompilerState.isSemidetNoneOut(State, Head)) | ||
101 | ((CompilerState)State)._determinism = Atom.a("semidetNoneOut"); | ||
102 | else | ||
103 | ((CompilerState)State)._determinism = Atom.a("nondet"); | ||
104 | } | ||
105 | |||
106 | public static void setCodeUsesYield(object State) | ||
107 | { | ||
108 | State = YP.getValue(State); | ||
109 | ((CompilerState)State)._codeUsesYield = true; | ||
110 | } | ||
111 | |||
112 | public static bool codeUsesYield(object State) | ||
113 | { | ||
114 | State = YP.getValue(State); | ||
115 | return ((CompilerState)State)._codeUsesYield; | ||
116 | } | ||
117 | |||
118 | public static bool determinismEquals(object State, object Term) | ||
119 | { | ||
120 | State = YP.getValue(State); | ||
121 | return YP.termEqual(((CompilerState)State)._determinism, Term); | ||
122 | } | ||
123 | |||
124 | /// <summary> | ||
125 | /// Set _variableNames to a new list of (Name = Variable) for each unique variable in rule. | ||
126 | /// If the variable is in variableNameSuggestions, use it, otherwise use x1, x2, etc. | ||
127 | /// </summary> | ||
128 | /// <param name="State"></param> | ||
129 | /// <param name="rule"></param> | ||
130 | /// <param name="variableNameSuggestions"></param> | ||
131 | public static void newVariableNames(object State, object Rule, object VariableNameSuggestions) | ||
132 | { | ||
133 | State = YP.getValue(State); | ||
134 | List<Variable> variablesSet = new List<Variable>(); | ||
135 | YP.addUniqueVariables(Rule, variablesSet); | ||
136 | |||
137 | ((CompilerState)State)._variableNames = new List<object>(); | ||
138 | int xCounter = 0; | ||
139 | foreach (Variable variable in variablesSet) | ||
140 | ((CompilerState)State)._variableNames.Add | ||
141 | (new Functor2(Atom.a("="), makeVariableName(variable, VariableNameSuggestions, ++xCounter), | ||
142 | variable)); | ||
143 | } | ||
144 | |||
145 | private static object makeVariableName(object variable, object variableNameSuggestions, int xCounter) | ||
146 | { | ||
147 | // Debug: should require named variables to start with _ or capital. Should | ||
148 | // check for duplicates and clashes with keywords. | ||
149 | for (object element = YP.getValue(variableNameSuggestions); | ||
150 | element is Functor2 && ((Functor2)element)._name == Atom.DOT; | ||
151 | element = YP.getValue(((Functor2)element)._arg2)) | ||
152 | { | ||
153 | object suggestionPair = YP.getValue(((Functor2)element)._arg1); | ||
154 | if (sameVariable(variable, ((Functor2)suggestionPair)._arg2)) | ||
155 | { | ||
156 | Atom suggestion = (Atom)YP.getValue(((Functor2)suggestionPair)._arg1); | ||
157 | if (suggestion.Equals(Atom.a("Atom"))) | ||
158 | suggestion = Atom.a("Atom_1"); | ||
159 | if (suggestion.Equals(Atom.a("Variable"))) | ||
160 | suggestion = Atom.a("Variable_1"); | ||
161 | if (suggestion.Equals(Atom.a("Functor"))) | ||
162 | suggestion = Atom.a("Functor_1"); | ||
163 | return suggestion; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | return Atom.a("x" + xCounter); | ||
168 | } | ||
169 | |||
170 | /// <summary> | ||
171 | /// Unify Result with the name assigned by CompilerState.newVariableNames in State._variableNames | ||
172 | /// for variable. | ||
173 | /// </summary> | ||
174 | /// <param name="variable">a Variable</param> | ||
175 | /// <param name="State"></param> | ||
176 | /// <param name="Result">the assigned Name</param> | ||
177 | public static IEnumerable<bool> getVariableName(object State, object variable, object Result) | ||
178 | { | ||
179 | State = YP.getValue(State); | ||
180 | foreach (object variableInfo in ((CompilerState)State)._variableNames) | ||
181 | { | ||
182 | if (variableInfo is Functor2 && ((Functor2)variableInfo)._name.Equals(Atom.a("="))) | ||
183 | { | ||
184 | if (sameVariable(variable, ((Functor2)variableInfo)._arg2)) | ||
185 | return YP.unify(Result, ((Functor2)variableInfo)._arg1); | ||
186 | } | ||
187 | } | ||
188 | |||
189 | // We set up names for all unique variables, so this should never happen. | ||
190 | throw new PrologException(Atom.a("Can't find entry in _variableNames")); | ||
191 | } | ||
192 | |||
193 | public static IEnumerable<bool> variableNamesList(object State, object VariableNamesList) | ||
194 | { | ||
195 | State = YP.getValue(State); | ||
196 | return YP.unify(VariableNamesList, ListPair.make(((CompilerState)State)._variableNames)); | ||
197 | } | ||
198 | |||
199 | public static IEnumerable<bool> gensym(object State, object Base, object Symbol) | ||
200 | { | ||
201 | State = YP.getValue(State); | ||
202 | return YP.unify(Symbol, Atom.a(Base.ToString() + ++((CompilerState)State)._gensymCounter)); | ||
203 | } | ||
204 | |||
205 | public static bool isDetNoneOut(object State, object Term) | ||
206 | { | ||
207 | State = YP.getValue(State); | ||
208 | object functorName = YP.getFunctorName(Term); | ||
209 | object[] functorArgs = YP.getFunctorArgs(Term); | ||
210 | |||
211 | Variable pred = new Variable(); | ||
212 | foreach (bool l1 in ((CompilerState)State)._pred.match | ||
213 | (new object[] { functorName, functorArgs.Length, pred, Atom.a("det") })) | ||
214 | { | ||
215 | if (CompilerState.isNoneOut(YP.getFunctorArgs(pred.getValue()))) | ||
216 | { | ||
217 | return true; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | return false; | ||
222 | } | ||
223 | |||
224 | public static bool isSemidetNoneOut(object State, object Term) | ||
225 | { | ||
226 | State = YP.getValue(State); | ||
227 | object functorName = YP.getFunctorName(Term); | ||
228 | object[] functorArgs = YP.getFunctorArgs(Term); | ||
229 | |||
230 | Variable pred = new Variable(); | ||
231 | foreach (bool l1 in ((CompilerState)State)._pred.match | ||
232 | (new object[] { functorName, functorArgs.Length, pred, Atom.a("semidet") })) | ||
233 | { | ||
234 | if (CompilerState.isNoneOut(YP.getFunctorArgs(pred.getValue()))) | ||
235 | { | ||
236 | return true; | ||
237 | } | ||
238 | } | ||
239 | |||
240 | return false; | ||
241 | } | ||
242 | |||
243 | /// <summary> | ||
244 | /// Return false if any of args is out, otherwise true. | ||
245 | /// args is an array of ::(Type,Mode) where Mode is in or out. | ||
246 | /// </summary> | ||
247 | /// <param name="args"></param> | ||
248 | /// <returns></returns> | ||
249 | private static bool isNoneOut(object[] args) | ||
250 | { | ||
251 | foreach (object arg in args) | ||
252 | { | ||
253 | if (arg is Functor2 && ((Functor2)arg)._name == Atom.a("::") && | ||
254 | ((Functor2)arg)._arg2 == Atom.a("out")) | ||
255 | return false; | ||
256 | } | ||
257 | return true; | ||
258 | } | ||
259 | |||
260 | public static bool nameArityHasModule(object State, object Name, object Arity, object Module) | ||
261 | { | ||
262 | State = YP.getValue(State); | ||
263 | Name = YP.getValue(Name); | ||
264 | Arity = YP.getValue(Arity); | ||
265 | Module = YP.getValue(Module); | ||
266 | if (Name is Atom && Arity is int) | ||
267 | { | ||
268 | Atom FoundModule; | ||
269 | if (!((CompilerState)State)._moduleForNameArity.TryGetValue | ||
270 | (new YP.NameArity((Atom)Name, (int)Arity), out FoundModule)) | ||
271 | return false; | ||
272 | return FoundModule == Module; | ||
273 | } | ||
274 | return false; | ||
275 | } | ||
276 | } | ||
277 | |||
278 | /// <summary> | ||
279 | /// Use CodeDomProvider to compile the functionCode and return a YP.IClause. | ||
280 | /// The function name must be "function" and have nArgs arguments. | ||
281 | /// </summary> | ||
282 | /// <param name="functionCode">the code for the iterator, such as | ||
283 | /// "public static IEnumerable<bool> function() { yield return false; }" | ||
284 | /// </param> | ||
285 | /// <param name="nArgs">the number of args in the function</param> | ||
286 | /// <param name="declaringClass">if not null, then use the functionCode inside a class which | ||
287 | /// inherits from contextClass, so that references in functionCode to methods in declaringClass don't | ||
288 | /// have to be qualified</param> | ||
289 | /// <returns>a new YP.IClause object on which you can call match(object[] args) where | ||
290 | /// args length is nArgs</returns> | ||
291 | public static YP.IClause compileAnonymousFunction(string functionCode, int nArgs, Type declaringClass) | ||
292 | { | ||
293 | CompilerParameters parameters = new CompilerParameters(); | ||
294 | // This gets the location of the System assembly. | ||
295 | parameters.ReferencedAssemblies.Add(typeof(System.Int32).Assembly.Location); | ||
296 | // This gets the location of this assembly which also has YieldProlog.YP, etc. | ||
297 | parameters.ReferencedAssemblies.Add(typeof(YPCompiler).Assembly.Location); | ||
298 | if (declaringClass != null) | ||
299 | parameters.ReferencedAssemblies.Add(declaringClass.Assembly.Location); | ||
300 | parameters.GenerateInMemory = true; | ||
301 | |||
302 | StringBuilder sourceCode = new StringBuilder(); | ||
303 | sourceCode.Append(@" | ||
304 | using System; | ||
305 | using System.Collections.Generic; | ||
306 | using YieldProlog; | ||
307 | |||
308 | namespace Temporary { | ||
309 | public class Temporary : YP.IClause { | ||
310 | public class Inner" + (declaringClass == null ? "" : " : " + declaringClass.FullName) + @" { | ||
311 | "); | ||
312 | sourceCode.Append(functionCode); | ||
313 | // Basically, match applies the args to function. | ||
314 | sourceCode.Append(@" | ||
315 | } | ||
316 | public IEnumerable<bool> match(object[] args) { | ||
317 | return Inner.function("); | ||
318 | if (nArgs >= 1) | ||
319 | sourceCode.Append("args[0]"); | ||
320 | for (int i = 1; i < nArgs; ++i) | ||
321 | sourceCode.Append(", args[" + i + "]"); | ||
322 | sourceCode.Append(@"); | ||
323 | } | ||
324 | } | ||
325 | } | ||
326 | "); | ||
327 | |||
328 | CompilerResults results = CodeDomProvider.CreateProvider | ||
329 | ("CSharp").CompileAssemblyFromSource(parameters, sourceCode.ToString()); | ||
330 | if (results.Errors.Count > 0) | ||
331 | throw new Exception("Error evaluating code: " + results.Errors[0]); | ||
332 | |||
333 | // Return a new Temporary.Temporary object. | ||
334 | return (YP.IClause)results.CompiledAssembly.GetType | ||
335 | ("Temporary.Temporary").GetConstructor(Type.EmptyTypes).Invoke(null); | ||
336 | } | ||
337 | |||
338 | // Compiler output follows. | ||
339 | |||
340 | class YPInnerClass { } | ||
341 | static Type getDeclaringClass() { return typeof(YPInnerClass).DeclaringType; } | ||
342 | |||
343 | public static void repeatWrite(object arg1, object N) | ||
344 | { | ||
345 | { | ||
346 | object _Value = arg1; | ||
347 | if (YP.termEqual(N, 0)) | ||
348 | { | ||
349 | return; | ||
350 | } | ||
351 | } | ||
352 | { | ||
353 | object Value = arg1; | ||
354 | Variable NextN = new Variable(); | ||
355 | YP.write(Value); | ||
356 | foreach (bool l2 in YP.unify(NextN, YP.subtract(N, 1))) | ||
357 | { | ||
358 | repeatWrite(Value, NextN); | ||
359 | return; | ||
360 | } | ||
361 | } | ||
362 | } | ||
363 | |||
364 | public static bool sameVariable(object Variable1, object Variable2) | ||
365 | { | ||
366 | { | ||
367 | if (YP.var(Variable1)) | ||
368 | { | ||
369 | if (YP.var(Variable2)) | ||
370 | { | ||
371 | if (YP.termEqual(Variable1, Variable2)) | ||
372 | { | ||
373 | return true; | ||
374 | } | ||
375 | } | ||
376 | } | ||
377 | } | ||
378 | return false; | ||
379 | } | ||
380 | |||
381 | public static IEnumerable<bool> makeFunctionPseudoCode(object RuleList, object FunctionCode) | ||
382 | { | ||
383 | { | ||
384 | Variable State = new Variable(); | ||
385 | foreach (bool l2 in CompilerState.make(State)) | ||
386 | { | ||
387 | CompilerState.assertPred(State, Atom.a(@"nl"), Atom.a(@"det")); | ||
388 | CompilerState.assertPred(State, new Functor1(@"write", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"det")); | ||
389 | CompilerState.assertPred(State, new Functor1(@"put_code", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"det")); | ||
390 | CompilerState.assertPred(State, new Functor1(@"throw", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"det")); | ||
391 | CompilerState.assertPred(State, new Functor1(@"var", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); | ||
392 | CompilerState.assertPred(State, new Functor1(@"nonvar", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); | ||
393 | CompilerState.assertPred(State, new Functor1(@"atom", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); | ||
394 | CompilerState.assertPred(State, new Functor1(@"number", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); | ||
395 | CompilerState.assertPred(State, new Functor2(@"==", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in")), new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); | ||
396 | CompilerState.assertPred(State, new Functor2(@"\==", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in")), new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); | ||
397 | CompilerState.assertPred(State, new Functor2(@"@<", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in")), new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); | ||
398 | CompilerState.assertPred(State, new Functor2(@"@=<", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in")), new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); | ||
399 | CompilerState.assertPred(State, new Functor2(@"@>", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in")), new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); | ||
400 | CompilerState.assertPred(State, new Functor2(@"@>=", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in")), new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); | ||
401 | processCompilerDirectives(RuleList, State); | ||
402 | foreach (bool l3 in YP.unify(FunctionCode, Atom.a(@"getDeclaringClass"))) | ||
403 | { | ||
404 | yield return false; | ||
405 | } | ||
406 | foreach (bool l3 in makeFunctionPseudoCode3(RuleList, State, FunctionCode)) | ||
407 | { | ||
408 | yield return false; | ||
409 | } | ||
410 | } | ||
411 | } | ||
412 | } | ||
413 | |||
414 | public static void processCompilerDirectives(object arg1, object arg2) | ||
415 | { | ||
416 | { | ||
417 | object _State = arg2; | ||
418 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
419 | { | ||
420 | return; | ||
421 | } | ||
422 | } | ||
423 | { | ||
424 | object State = arg2; | ||
425 | Variable Pred = new Variable(); | ||
426 | Variable Determinism = new Variable(); | ||
427 | Variable x3 = new Variable(); | ||
428 | Variable RestRules = new Variable(); | ||
429 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"f", new Functor1(@":-", new Functor1(@"pred", new Functor2(@"is", Pred, Determinism))), x3), RestRules))) | ||
430 | { | ||
431 | CompilerState.assertPred(State, Pred, Determinism); | ||
432 | processCompilerDirectives(RestRules, State); | ||
433 | return; | ||
434 | } | ||
435 | } | ||
436 | { | ||
437 | object State = arg2; | ||
438 | Variable Module = new Variable(); | ||
439 | Variable PredicateList = new Variable(); | ||
440 | Variable x3 = new Variable(); | ||
441 | Variable RestRules = new Variable(); | ||
442 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"f", new Functor1(@":-", new Functor2(@"import", Module, PredicateList)), x3), RestRules))) | ||
443 | { | ||
444 | foreach (bool l3 in importPredicateList(State, Module, PredicateList)) | ||
445 | { | ||
446 | processCompilerDirectives(RestRules, State); | ||
447 | return; | ||
448 | } | ||
449 | } | ||
450 | } | ||
451 | { | ||
452 | object State = arg2; | ||
453 | Variable x1 = new Variable(); | ||
454 | Variable x2 = new Variable(); | ||
455 | Variable RestRules = new Variable(); | ||
456 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"f", new Functor1(@":-", x1), x2), RestRules))) | ||
457 | { | ||
458 | processCompilerDirectives(RestRules, State); | ||
459 | return; | ||
460 | } | ||
461 | } | ||
462 | { | ||
463 | object State = arg2; | ||
464 | Variable Head = new Variable(); | ||
465 | Variable _Body = new Variable(); | ||
466 | Variable x3 = new Variable(); | ||
467 | Variable RestRules = new Variable(); | ||
468 | Variable Name = new Variable(); | ||
469 | Variable Arity = new Variable(); | ||
470 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"f", new Functor2(@":-", Head, _Body), x3), RestRules))) | ||
471 | { | ||
472 | foreach (bool l3 in YP.functor(Head, Name, Arity)) | ||
473 | { | ||
474 | CompilerState.assertModuleForNameArity(State, Name, Arity, Atom.a(@"")); | ||
475 | processCompilerDirectives(RestRules, State); | ||
476 | return; | ||
477 | } | ||
478 | } | ||
479 | } | ||
480 | { | ||
481 | object State = arg2; | ||
482 | Variable Fact = new Variable(); | ||
483 | Variable x2 = new Variable(); | ||
484 | Variable RestRules = new Variable(); | ||
485 | Variable Name = new Variable(); | ||
486 | Variable Arity = new Variable(); | ||
487 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"f", Fact, x2), RestRules))) | ||
488 | { | ||
489 | foreach (bool l3 in YP.functor(Fact, Name, Arity)) | ||
490 | { | ||
491 | CompilerState.assertModuleForNameArity(State, Name, Arity, Atom.a(@"")); | ||
492 | processCompilerDirectives(RestRules, State); | ||
493 | return; | ||
494 | } | ||
495 | } | ||
496 | } | ||
497 | { | ||
498 | object State = arg2; | ||
499 | Variable x1 = new Variable(); | ||
500 | Variable RestRules = new Variable(); | ||
501 | foreach (bool l2 in YP.unify(arg1, new ListPair(x1, RestRules))) | ||
502 | { | ||
503 | processCompilerDirectives(RestRules, State); | ||
504 | return; | ||
505 | } | ||
506 | } | ||
507 | } | ||
508 | |||
509 | public static IEnumerable<bool> importPredicateList(object arg1, object arg2, object arg3) | ||
510 | { | ||
511 | { | ||
512 | object _State = arg1; | ||
513 | object _Module = arg2; | ||
514 | foreach (bool l2 in YP.unify(arg3, Atom.NIL)) | ||
515 | { | ||
516 | yield return true; | ||
517 | yield break; | ||
518 | } | ||
519 | } | ||
520 | { | ||
521 | object State = arg1; | ||
522 | object Module = arg2; | ||
523 | Variable Name = new Variable(); | ||
524 | Variable Arity = new Variable(); | ||
525 | Variable Rest = new Variable(); | ||
526 | foreach (bool l2 in YP.unify(arg3, new ListPair(new Functor2(@"/", Name, Arity), Rest))) | ||
527 | { | ||
528 | CompilerState.assertModuleForNameArity(State, Name, Arity, Module); | ||
529 | foreach (bool l3 in importPredicateList(State, Module, Rest)) | ||
530 | { | ||
531 | yield return true; | ||
532 | yield break; | ||
533 | } | ||
534 | } | ||
535 | } | ||
536 | { | ||
537 | object State = arg1; | ||
538 | object Module = arg2; | ||
539 | Variable x3 = new Variable(); | ||
540 | Variable Rest = new Variable(); | ||
541 | foreach (bool l2 in YP.unify(arg3, new ListPair(x3, Rest))) | ||
542 | { | ||
543 | foreach (bool l3 in importPredicateList(State, Module, Rest)) | ||
544 | { | ||
545 | yield return true; | ||
546 | yield break; | ||
547 | } | ||
548 | } | ||
549 | } | ||
550 | } | ||
551 | |||
552 | public static IEnumerable<bool> makeFunctionPseudoCode3(object RuleList, object State, object FunctionCode) | ||
553 | { | ||
554 | { | ||
555 | Variable SamePredicateRuleList = new Variable(); | ||
556 | Variable RestRules = new Variable(); | ||
557 | foreach (bool l2 in samePredicateRuleList(RuleList, SamePredicateRuleList, RestRules)) | ||
558 | { | ||
559 | if (YP.termNotEqual(SamePredicateRuleList, Atom.NIL)) | ||
560 | { | ||
561 | foreach (bool l4 in compileSamePredicateFunction(SamePredicateRuleList, State, FunctionCode)) | ||
562 | { | ||
563 | yield return false; | ||
564 | } | ||
565 | foreach (bool l4 in makeFunctionPseudoCode3(RestRules, State, FunctionCode)) | ||
566 | { | ||
567 | yield return false; | ||
568 | } | ||
569 | } | ||
570 | } | ||
571 | } | ||
572 | } | ||
573 | |||
574 | public static IEnumerable<bool> compileSamePredicateFunction(object SamePredicateRuleList, object State, object FunctionCode) | ||
575 | { | ||
576 | { | ||
577 | Variable FirstRule = new Variable(); | ||
578 | Variable x5 = new Variable(); | ||
579 | Variable x6 = new Variable(); | ||
580 | Variable x7 = new Variable(); | ||
581 | Variable Head = new Variable(); | ||
582 | Variable x9 = new Variable(); | ||
583 | Variable ArgAssignments = new Variable(); | ||
584 | Variable Calls = new Variable(); | ||
585 | Variable Rule = new Variable(); | ||
586 | Variable VariableNameSuggestions = new Variable(); | ||
587 | Variable ClauseBag = new Variable(); | ||
588 | Variable Name = new Variable(); | ||
589 | Variable ArgsList = new Variable(); | ||
590 | Variable FunctionArgNames = new Variable(); | ||
591 | Variable MergedArgName = new Variable(); | ||
592 | Variable ArgName = new Variable(); | ||
593 | Variable MergedArgNames = new Variable(); | ||
594 | Variable FunctionArgs = new Variable(); | ||
595 | Variable BodyCode = new Variable(); | ||
596 | Variable ReturnType = new Variable(); | ||
597 | Variable BodyWithReturn = new Variable(); | ||
598 | foreach (bool l2 in YP.unify(new ListPair(new Functor2(@"f", FirstRule, x5), x6), SamePredicateRuleList)) | ||
599 | { | ||
600 | foreach (bool l3 in YP.unify(FirstRule, new Functor1(@":-", x7))) | ||
601 | { | ||
602 | goto cutIf1; | ||
603 | } | ||
604 | foreach (bool l3 in YP.unify(new Functor2(@":-", Head, x9), FirstRule)) | ||
605 | { | ||
606 | CompilerState.startFunction(State, Head); | ||
607 | FindallAnswers findallAnswers3 = new FindallAnswers(new Functor2(@"f", ArgAssignments, Calls)); | ||
608 | foreach (bool l4 in member(new Functor2(@"f", Rule, VariableNameSuggestions), SamePredicateRuleList)) | ||
609 | { | ||
610 | foreach (bool l5 in compileBodyWithHeadBindings(Rule, VariableNameSuggestions, State, ArgAssignments, Calls)) | ||
611 | { | ||
612 | findallAnswers3.add(); | ||
613 | } | ||
614 | } | ||
615 | foreach (bool l4 in findallAnswers3.result(ClauseBag)) | ||
616 | { | ||
617 | foreach (bool l5 in YP.univ(Head, new ListPair(Name, ArgsList))) | ||
618 | { | ||
619 | foreach (bool l6 in getFunctionArgNames(ArgsList, 1, FunctionArgNames)) | ||
620 | { | ||
621 | FindallAnswers findallAnswers4 = new FindallAnswers(MergedArgName); | ||
622 | foreach (bool l7 in member(ArgName, FunctionArgNames)) | ||
623 | { | ||
624 | foreach (bool l8 in argAssignedAll(ArgName, ClauseBag, MergedArgName)) | ||
625 | { | ||
626 | findallAnswers4.add(); | ||
627 | goto cutIf5; | ||
628 | } | ||
629 | foreach (bool l8 in YP.unify(MergedArgName, ArgName)) | ||
630 | { | ||
631 | findallAnswers4.add(); | ||
632 | } | ||
633 | cutIf5: | ||
634 | { } | ||
635 | } | ||
636 | foreach (bool l7 in findallAnswers4.result(MergedArgNames)) | ||
637 | { | ||
638 | foreach (bool l8 in maplist_arg(MergedArgNames, FunctionArgs)) | ||
639 | { | ||
640 | foreach (bool l9 in maplist_compileClause(ClauseBag, MergedArgNames, BodyCode)) | ||
641 | { | ||
642 | if (CompilerState.determinismEquals(State, Atom.a(@"detNoneOut"))) | ||
643 | { | ||
644 | foreach (bool l11 in YP.unify(ReturnType, Atom.a(@"void"))) | ||
645 | { | ||
646 | if (CompilerState.determinismEquals(State, Atom.a(@"semidetNoneOut"))) | ||
647 | { | ||
648 | foreach (bool l13 in append(BodyCode, new ListPair(Atom.a(@"returnfalse"), Atom.NIL), BodyWithReturn)) | ||
649 | { | ||
650 | foreach (bool l14 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
651 | { | ||
652 | yield return false; | ||
653 | } | ||
654 | } | ||
655 | goto cutIf7; | ||
656 | } | ||
657 | foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) | ||
658 | { | ||
659 | foreach (bool l13 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
660 | { | ||
661 | yield return false; | ||
662 | } | ||
663 | } | ||
664 | cutIf7: | ||
665 | { } | ||
666 | } | ||
667 | goto cutIf6; | ||
668 | } | ||
669 | if (CompilerState.determinismEquals(State, Atom.a(@"semidetNoneOut"))) | ||
670 | { | ||
671 | foreach (bool l11 in YP.unify(ReturnType, Atom.a(@"bool"))) | ||
672 | { | ||
673 | if (CompilerState.determinismEquals(State, Atom.a(@"semidetNoneOut"))) | ||
674 | { | ||
675 | foreach (bool l13 in append(BodyCode, new ListPair(Atom.a(@"returnfalse"), Atom.NIL), BodyWithReturn)) | ||
676 | { | ||
677 | foreach (bool l14 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
678 | { | ||
679 | yield return false; | ||
680 | } | ||
681 | } | ||
682 | goto cutIf9; | ||
683 | } | ||
684 | foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) | ||
685 | { | ||
686 | foreach (bool l13 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
687 | { | ||
688 | yield return false; | ||
689 | } | ||
690 | } | ||
691 | cutIf9: | ||
692 | { } | ||
693 | } | ||
694 | goto cutIf8; | ||
695 | } | ||
696 | foreach (bool l10 in YP.unify(ReturnType, Atom.a(@"IEnumerable<bool>"))) | ||
697 | { | ||
698 | if (CompilerState.determinismEquals(State, Atom.a(@"semidetNoneOut"))) | ||
699 | { | ||
700 | foreach (bool l12 in append(BodyCode, new ListPair(Atom.a(@"returnfalse"), Atom.NIL), BodyWithReturn)) | ||
701 | { | ||
702 | foreach (bool l13 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
703 | { | ||
704 | yield return false; | ||
705 | } | ||
706 | } | ||
707 | goto cutIf10; | ||
708 | } | ||
709 | foreach (bool l11 in YP.unify(BodyWithReturn, BodyCode)) | ||
710 | { | ||
711 | foreach (bool l12 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
712 | { | ||
713 | yield return false; | ||
714 | } | ||
715 | } | ||
716 | cutIf10: | ||
717 | { } | ||
718 | } | ||
719 | cutIf8: | ||
720 | cutIf6: | ||
721 | { } | ||
722 | } | ||
723 | } | ||
724 | } | ||
725 | } | ||
726 | } | ||
727 | } | ||
728 | goto cutIf2; | ||
729 | } | ||
730 | foreach (bool l3 in YP.unify(Head, FirstRule)) | ||
731 | { | ||
732 | CompilerState.startFunction(State, Head); | ||
733 | FindallAnswers findallAnswers11 = new FindallAnswers(new Functor2(@"f", ArgAssignments, Calls)); | ||
734 | foreach (bool l4 in member(new Functor2(@"f", Rule, VariableNameSuggestions), SamePredicateRuleList)) | ||
735 | { | ||
736 | foreach (bool l5 in compileBodyWithHeadBindings(Rule, VariableNameSuggestions, State, ArgAssignments, Calls)) | ||
737 | { | ||
738 | findallAnswers11.add(); | ||
739 | } | ||
740 | } | ||
741 | foreach (bool l4 in findallAnswers11.result(ClauseBag)) | ||
742 | { | ||
743 | foreach (bool l5 in YP.univ(Head, new ListPair(Name, ArgsList))) | ||
744 | { | ||
745 | foreach (bool l6 in getFunctionArgNames(ArgsList, 1, FunctionArgNames)) | ||
746 | { | ||
747 | FindallAnswers findallAnswers12 = new FindallAnswers(MergedArgName); | ||
748 | foreach (bool l7 in member(ArgName, FunctionArgNames)) | ||
749 | { | ||
750 | foreach (bool l8 in argAssignedAll(ArgName, ClauseBag, MergedArgName)) | ||
751 | { | ||
752 | findallAnswers12.add(); | ||
753 | goto cutIf13; | ||
754 | } | ||
755 | foreach (bool l8 in YP.unify(MergedArgName, ArgName)) | ||
756 | { | ||
757 | findallAnswers12.add(); | ||
758 | } | ||
759 | cutIf13: | ||
760 | { } | ||
761 | } | ||
762 | foreach (bool l7 in findallAnswers12.result(MergedArgNames)) | ||
763 | { | ||
764 | foreach (bool l8 in maplist_arg(MergedArgNames, FunctionArgs)) | ||
765 | { | ||
766 | foreach (bool l9 in maplist_compileClause(ClauseBag, MergedArgNames, BodyCode)) | ||
767 | { | ||
768 | if (CompilerState.determinismEquals(State, Atom.a(@"detNoneOut"))) | ||
769 | { | ||
770 | foreach (bool l11 in YP.unify(ReturnType, Atom.a(@"void"))) | ||
771 | { | ||
772 | if (CompilerState.determinismEquals(State, Atom.a(@"semidetNoneOut"))) | ||
773 | { | ||
774 | foreach (bool l13 in append(BodyCode, new ListPair(Atom.a(@"returnfalse"), Atom.NIL), BodyWithReturn)) | ||
775 | { | ||
776 | foreach (bool l14 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
777 | { | ||
778 | yield return false; | ||
779 | } | ||
780 | } | ||
781 | goto cutIf15; | ||
782 | } | ||
783 | foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) | ||
784 | { | ||
785 | foreach (bool l13 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
786 | { | ||
787 | yield return false; | ||
788 | } | ||
789 | } | ||
790 | cutIf15: | ||
791 | { } | ||
792 | } | ||
793 | goto cutIf14; | ||
794 | } | ||
795 | if (CompilerState.determinismEquals(State, Atom.a(@"semidetNoneOut"))) | ||
796 | { | ||
797 | foreach (bool l11 in YP.unify(ReturnType, Atom.a(@"bool"))) | ||
798 | { | ||
799 | if (CompilerState.determinismEquals(State, Atom.a(@"semidetNoneOut"))) | ||
800 | { | ||
801 | foreach (bool l13 in append(BodyCode, new ListPair(Atom.a(@"returnfalse"), Atom.NIL), BodyWithReturn)) | ||
802 | { | ||
803 | foreach (bool l14 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
804 | { | ||
805 | yield return false; | ||
806 | } | ||
807 | } | ||
808 | goto cutIf17; | ||
809 | } | ||
810 | foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) | ||
811 | { | ||
812 | foreach (bool l13 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
813 | { | ||
814 | yield return false; | ||
815 | } | ||
816 | } | ||
817 | cutIf17: | ||
818 | { } | ||
819 | } | ||
820 | goto cutIf16; | ||
821 | } | ||
822 | foreach (bool l10 in YP.unify(ReturnType, Atom.a(@"IEnumerable<bool>"))) | ||
823 | { | ||
824 | if (CompilerState.determinismEquals(State, Atom.a(@"semidetNoneOut"))) | ||
825 | { | ||
826 | foreach (bool l12 in append(BodyCode, new ListPair(Atom.a(@"returnfalse"), Atom.NIL), BodyWithReturn)) | ||
827 | { | ||
828 | foreach (bool l13 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
829 | { | ||
830 | yield return false; | ||
831 | } | ||
832 | } | ||
833 | goto cutIf18; | ||
834 | } | ||
835 | foreach (bool l11 in YP.unify(BodyWithReturn, BodyCode)) | ||
836 | { | ||
837 | foreach (bool l12 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
838 | { | ||
839 | yield return false; | ||
840 | } | ||
841 | } | ||
842 | cutIf18: | ||
843 | { } | ||
844 | } | ||
845 | cutIf16: | ||
846 | cutIf14: | ||
847 | { } | ||
848 | } | ||
849 | } | ||
850 | } | ||
851 | } | ||
852 | } | ||
853 | } | ||
854 | } | ||
855 | cutIf2: | ||
856 | cutIf1: | ||
857 | { } | ||
858 | } | ||
859 | } | ||
860 | } | ||
861 | |||
862 | public static IEnumerable<bool> samePredicateRuleList(object arg1, object arg2, object arg3) | ||
863 | { | ||
864 | { | ||
865 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
866 | { | ||
867 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
868 | { | ||
869 | foreach (bool l4 in YP.unify(arg3, Atom.NIL)) | ||
870 | { | ||
871 | yield return true; | ||
872 | yield break; | ||
873 | } | ||
874 | } | ||
875 | } | ||
876 | } | ||
877 | { | ||
878 | Variable First = new Variable(); | ||
879 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Atom.NIL))) | ||
880 | { | ||
881 | foreach (bool l3 in YP.unify(arg2, new ListPair(First, Atom.NIL))) | ||
882 | { | ||
883 | foreach (bool l4 in YP.unify(arg3, Atom.NIL)) | ||
884 | { | ||
885 | yield return true; | ||
886 | yield break; | ||
887 | } | ||
888 | } | ||
889 | } | ||
890 | } | ||
891 | { | ||
892 | object SamePredicateRuleList = arg2; | ||
893 | object RestRules = arg3; | ||
894 | Variable First = new Variable(); | ||
895 | Variable Rest = new Variable(); | ||
896 | Variable FirstRule = new Variable(); | ||
897 | Variable x6 = new Variable(); | ||
898 | Variable SecondRule = new Variable(); | ||
899 | Variable x8 = new Variable(); | ||
900 | Variable x9 = new Variable(); | ||
901 | Variable FirstHead = new Variable(); | ||
902 | Variable x11 = new Variable(); | ||
903 | Variable SecondHead = new Variable(); | ||
904 | Variable x13 = new Variable(); | ||
905 | Variable Name = new Variable(); | ||
906 | Variable Arity = new Variable(); | ||
907 | Variable RestSamePredicates = new Variable(); | ||
908 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) | ||
909 | { | ||
910 | foreach (bool l3 in YP.unify(new Functor2(@"f", FirstRule, x6), First)) | ||
911 | { | ||
912 | foreach (bool l4 in YP.unify(new ListPair(new Functor2(@"f", SecondRule, x8), x9), Rest)) | ||
913 | { | ||
914 | foreach (bool l5 in YP.unify(new Functor2(@":-", FirstHead, x11), FirstRule)) | ||
915 | { | ||
916 | foreach (bool l6 in YP.unify(new Functor2(@":-", SecondHead, x13), SecondRule)) | ||
917 | { | ||
918 | foreach (bool l7 in YP.functor(FirstHead, Name, Arity)) | ||
919 | { | ||
920 | foreach (bool l8 in YP.functor(SecondHead, Name, Arity)) | ||
921 | { | ||
922 | foreach (bool l9 in samePredicateRuleList(Rest, RestSamePredicates, RestRules)) | ||
923 | { | ||
924 | foreach (bool l10 in YP.unify(SamePredicateRuleList, new ListPair(First, RestSamePredicates))) | ||
925 | { | ||
926 | yield return true; | ||
927 | yield break; | ||
928 | } | ||
929 | } | ||
930 | goto cutIf3; | ||
931 | } | ||
932 | foreach (bool l8 in YP.unify(SamePredicateRuleList, new ListPair(First, Atom.NIL))) | ||
933 | { | ||
934 | foreach (bool l9 in YP.unify(RestRules, Rest)) | ||
935 | { | ||
936 | yield return true; | ||
937 | yield break; | ||
938 | } | ||
939 | } | ||
940 | cutIf3: | ||
941 | { } | ||
942 | } | ||
943 | goto cutIf2; | ||
944 | } | ||
945 | foreach (bool l6 in YP.unify(SecondHead, SecondRule)) | ||
946 | { | ||
947 | foreach (bool l7 in YP.functor(FirstHead, Name, Arity)) | ||
948 | { | ||
949 | foreach (bool l8 in YP.functor(SecondHead, Name, Arity)) | ||
950 | { | ||
951 | foreach (bool l9 in samePredicateRuleList(Rest, RestSamePredicates, RestRules)) | ||
952 | { | ||
953 | foreach (bool l10 in YP.unify(SamePredicateRuleList, new ListPair(First, RestSamePredicates))) | ||
954 | { | ||
955 | yield return true; | ||
956 | yield break; | ||
957 | } | ||
958 | } | ||
959 | goto cutIf4; | ||
960 | } | ||
961 | foreach (bool l8 in YP.unify(SamePredicateRuleList, new ListPair(First, Atom.NIL))) | ||
962 | { | ||
963 | foreach (bool l9 in YP.unify(RestRules, Rest)) | ||
964 | { | ||
965 | yield return true; | ||
966 | yield break; | ||
967 | } | ||
968 | } | ||
969 | cutIf4: | ||
970 | { } | ||
971 | } | ||
972 | } | ||
973 | cutIf2: | ||
974 | goto cutIf1; | ||
975 | } | ||
976 | foreach (bool l5 in YP.unify(FirstHead, FirstRule)) | ||
977 | { | ||
978 | foreach (bool l6 in YP.unify(new Functor2(@":-", SecondHead, x13), SecondRule)) | ||
979 | { | ||
980 | foreach (bool l7 in YP.functor(FirstHead, Name, Arity)) | ||
981 | { | ||
982 | foreach (bool l8 in YP.functor(SecondHead, Name, Arity)) | ||
983 | { | ||
984 | foreach (bool l9 in samePredicateRuleList(Rest, RestSamePredicates, RestRules)) | ||
985 | { | ||
986 | foreach (bool l10 in YP.unify(SamePredicateRuleList, new ListPair(First, RestSamePredicates))) | ||
987 | { | ||
988 | yield return true; | ||
989 | yield break; | ||
990 | } | ||
991 | } | ||
992 | goto cutIf6; | ||
993 | } | ||
994 | foreach (bool l8 in YP.unify(SamePredicateRuleList, new ListPair(First, Atom.NIL))) | ||
995 | { | ||
996 | foreach (bool l9 in YP.unify(RestRules, Rest)) | ||
997 | { | ||
998 | yield return true; | ||
999 | yield break; | ||
1000 | } | ||
1001 | } | ||
1002 | cutIf6: | ||
1003 | { } | ||
1004 | } | ||
1005 | goto cutIf5; | ||
1006 | } | ||
1007 | foreach (bool l6 in YP.unify(SecondHead, SecondRule)) | ||
1008 | { | ||
1009 | foreach (bool l7 in YP.functor(FirstHead, Name, Arity)) | ||
1010 | { | ||
1011 | foreach (bool l8 in YP.functor(SecondHead, Name, Arity)) | ||
1012 | { | ||
1013 | foreach (bool l9 in samePredicateRuleList(Rest, RestSamePredicates, RestRules)) | ||
1014 | { | ||
1015 | foreach (bool l10 in YP.unify(SamePredicateRuleList, new ListPair(First, RestSamePredicates))) | ||
1016 | { | ||
1017 | yield return true; | ||
1018 | yield break; | ||
1019 | } | ||
1020 | } | ||
1021 | goto cutIf7; | ||
1022 | } | ||
1023 | foreach (bool l8 in YP.unify(SamePredicateRuleList, new ListPair(First, Atom.NIL))) | ||
1024 | { | ||
1025 | foreach (bool l9 in YP.unify(RestRules, Rest)) | ||
1026 | { | ||
1027 | yield return true; | ||
1028 | yield break; | ||
1029 | } | ||
1030 | } | ||
1031 | cutIf7: | ||
1032 | { } | ||
1033 | } | ||
1034 | } | ||
1035 | cutIf5: | ||
1036 | { } | ||
1037 | } | ||
1038 | cutIf1: | ||
1039 | { } | ||
1040 | } | ||
1041 | } | ||
1042 | } | ||
1043 | } | ||
1044 | } | ||
1045 | |||
1046 | public static IEnumerable<bool> maplist_compileClause(object arg1, object arg2, object arg3) | ||
1047 | { | ||
1048 | { | ||
1049 | object _MergedArgNames = arg2; | ||
1050 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1051 | { | ||
1052 | foreach (bool l3 in YP.unify(arg3, Atom.NIL)) | ||
1053 | { | ||
1054 | yield return true; | ||
1055 | yield break; | ||
1056 | } | ||
1057 | } | ||
1058 | } | ||
1059 | { | ||
1060 | object MergedArgNames = arg2; | ||
1061 | Variable ArgAssignments = new Variable(); | ||
1062 | Variable Calls = new Variable(); | ||
1063 | Variable Rest = new Variable(); | ||
1064 | Variable ClauseCode = new Variable(); | ||
1065 | Variable RestResults = new Variable(); | ||
1066 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"f", ArgAssignments, Calls), Rest))) | ||
1067 | { | ||
1068 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor1(@"blockScope", ClauseCode), RestResults))) | ||
1069 | { | ||
1070 | foreach (bool l4 in prependArgAssignments(ArgAssignments, Calls, MergedArgNames, ClauseCode)) | ||
1071 | { | ||
1072 | foreach (bool l5 in maplist_compileClause(Rest, MergedArgNames, RestResults)) | ||
1073 | { | ||
1074 | yield return true; | ||
1075 | yield break; | ||
1076 | } | ||
1077 | } | ||
1078 | } | ||
1079 | } | ||
1080 | } | ||
1081 | } | ||
1082 | |||
1083 | public static IEnumerable<bool> prependArgAssignments(object arg1, object arg2, object arg3, object arg4) | ||
1084 | { | ||
1085 | { | ||
1086 | object _MergedArgNames = arg3; | ||
1087 | Variable In = new Variable(); | ||
1088 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1089 | { | ||
1090 | foreach (bool l3 in YP.unify(arg2, In)) | ||
1091 | { | ||
1092 | foreach (bool l4 in YP.unify(arg4, In)) | ||
1093 | { | ||
1094 | yield return true; | ||
1095 | yield break; | ||
1096 | } | ||
1097 | } | ||
1098 | } | ||
1099 | } | ||
1100 | { | ||
1101 | object In = arg2; | ||
1102 | object MergedArgNames = arg3; | ||
1103 | object ClauseCode = arg4; | ||
1104 | Variable VariableName = new Variable(); | ||
1105 | Variable ArgName = new Variable(); | ||
1106 | Variable RestArgAssignments = new Variable(); | ||
1107 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"f", VariableName, ArgName), RestArgAssignments))) | ||
1108 | { | ||
1109 | foreach (bool l3 in member(VariableName, MergedArgNames)) | ||
1110 | { | ||
1111 | foreach (bool l4 in prependArgAssignments(RestArgAssignments, In, MergedArgNames, ClauseCode)) | ||
1112 | { | ||
1113 | yield return true; | ||
1114 | yield break; | ||
1115 | } | ||
1116 | goto cutIf1; | ||
1117 | } | ||
1118 | foreach (bool l3 in prependArgAssignments(RestArgAssignments, new ListPair(new Functor3(@"declare", Atom.a(@"object"), VariableName, new Functor1(@"var", ArgName)), In), MergedArgNames, ClauseCode)) | ||
1119 | { | ||
1120 | yield return true; | ||
1121 | yield break; | ||
1122 | } | ||
1123 | cutIf1: | ||
1124 | { } | ||
1125 | } | ||
1126 | } | ||
1127 | } | ||
1128 | |||
1129 | public static IEnumerable<bool> argAssignedAll(object arg1, object arg2, object VariableName) | ||
1130 | { | ||
1131 | { | ||
1132 | object _ArgName = arg1; | ||
1133 | foreach (bool l2 in YP.unify(arg2, Atom.NIL)) | ||
1134 | { | ||
1135 | if (YP.nonvar(VariableName)) | ||
1136 | { | ||
1137 | yield return true; | ||
1138 | yield break; | ||
1139 | } | ||
1140 | } | ||
1141 | } | ||
1142 | { | ||
1143 | object ArgName = arg1; | ||
1144 | Variable ArgAssignments = new Variable(); | ||
1145 | Variable _Calls = new Variable(); | ||
1146 | Variable RestClauseBag = new Variable(); | ||
1147 | foreach (bool l2 in YP.unify(arg2, new ListPair(new Functor2(@"f", ArgAssignments, _Calls), RestClauseBag))) | ||
1148 | { | ||
1149 | foreach (bool l3 in member(new Functor2(@"f", VariableName, ArgName), ArgAssignments)) | ||
1150 | { | ||
1151 | foreach (bool l4 in argAssignedAll(ArgName, RestClauseBag, VariableName)) | ||
1152 | { | ||
1153 | yield return false; | ||
1154 | } | ||
1155 | } | ||
1156 | } | ||
1157 | } | ||
1158 | } | ||
1159 | |||
1160 | public static IEnumerable<bool> maplist_arg(object arg1, object arg2) | ||
1161 | { | ||
1162 | { | ||
1163 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1164 | { | ||
1165 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
1166 | { | ||
1167 | yield return true; | ||
1168 | yield break; | ||
1169 | } | ||
1170 | } | ||
1171 | } | ||
1172 | { | ||
1173 | Variable First = new Variable(); | ||
1174 | Variable Rest = new Variable(); | ||
1175 | Variable RestResults = new Variable(); | ||
1176 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) | ||
1177 | { | ||
1178 | foreach (bool l3 in YP.unify(arg2, new ListPair(new Functor1(@"arg", First), RestResults))) | ||
1179 | { | ||
1180 | foreach (bool l4 in maplist_arg(Rest, RestResults)) | ||
1181 | { | ||
1182 | yield return true; | ||
1183 | yield break; | ||
1184 | } | ||
1185 | } | ||
1186 | } | ||
1187 | } | ||
1188 | } | ||
1189 | |||
1190 | public static IEnumerable<bool> getFunctionArgNames(object arg1, object arg2, object arg3) | ||
1191 | { | ||
1192 | { | ||
1193 | object _StartArgNumber = arg2; | ||
1194 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1195 | { | ||
1196 | foreach (bool l3 in YP.unify(arg3, Atom.NIL)) | ||
1197 | { | ||
1198 | yield return true; | ||
1199 | yield break; | ||
1200 | } | ||
1201 | } | ||
1202 | } | ||
1203 | { | ||
1204 | object StartArgNumber = arg2; | ||
1205 | Variable x1 = new Variable(); | ||
1206 | Variable Rest = new Variable(); | ||
1207 | Variable ArgName = new Variable(); | ||
1208 | Variable RestFunctionArgs = new Variable(); | ||
1209 | Variable NumberCodes = new Variable(); | ||
1210 | Variable NumberAtom = new Variable(); | ||
1211 | Variable NextArgNumber = new Variable(); | ||
1212 | foreach (bool l2 in YP.unify(arg1, new ListPair(x1, Rest))) | ||
1213 | { | ||
1214 | foreach (bool l3 in YP.unify(arg3, new ListPair(ArgName, RestFunctionArgs))) | ||
1215 | { | ||
1216 | foreach (bool l4 in YP.number_codes(StartArgNumber, NumberCodes)) | ||
1217 | { | ||
1218 | foreach (bool l5 in YP.atom_codes(NumberAtom, NumberCodes)) | ||
1219 | { | ||
1220 | foreach (bool l6 in YP.atom_concat(Atom.a(@"arg"), NumberAtom, ArgName)) | ||
1221 | { | ||
1222 | foreach (bool l7 in YP.unify(NextArgNumber, YP.add(StartArgNumber, 1))) | ||
1223 | { | ||
1224 | foreach (bool l8 in getFunctionArgNames(Rest, NextArgNumber, RestFunctionArgs)) | ||
1225 | { | ||
1226 | yield return true; | ||
1227 | yield break; | ||
1228 | } | ||
1229 | } | ||
1230 | } | ||
1231 | } | ||
1232 | } | ||
1233 | } | ||
1234 | } | ||
1235 | } | ||
1236 | } | ||
1237 | |||
1238 | public static IEnumerable<bool> compileBodyWithHeadBindings(object Rule, object VariableNameSuggestions, object State, object ArgAssignments, object Calls) | ||
1239 | { | ||
1240 | { | ||
1241 | Variable Head = new Variable(); | ||
1242 | Variable Body = new Variable(); | ||
1243 | Variable x8 = new Variable(); | ||
1244 | Variable HeadArgs = new Variable(); | ||
1245 | Variable CompiledHeadArgs = new Variable(); | ||
1246 | Variable BodyCode = new Variable(); | ||
1247 | Variable VariableNamesList = new Variable(); | ||
1248 | Variable ArgUnifications = new Variable(); | ||
1249 | foreach (bool l2 in YP.unify(new Functor2(@":-", Head, Body), Rule)) | ||
1250 | { | ||
1251 | CompilerState.newVariableNames(State, Rule, VariableNameSuggestions); | ||
1252 | foreach (bool l3 in YP.univ(Head, new ListPair(x8, HeadArgs))) | ||
1253 | { | ||
1254 | foreach (bool l4 in maplist_compileTerm(HeadArgs, State, CompiledHeadArgs)) | ||
1255 | { | ||
1256 | foreach (bool l5 in compileRuleBody(Body, State, BodyCode)) | ||
1257 | { | ||
1258 | foreach (bool l6 in CompilerState.variableNamesList(State, VariableNamesList)) | ||
1259 | { | ||
1260 | foreach (bool l7 in compileArgUnifications(HeadArgs, CompiledHeadArgs, 1, HeadArgs, BodyCode, ArgUnifications)) | ||
1261 | { | ||
1262 | foreach (bool l8 in compileDeclarations(VariableNamesList, HeadArgs, Atom.NIL, ArgAssignments, ArgUnifications, Calls)) | ||
1263 | { | ||
1264 | yield return true; | ||
1265 | yield break; | ||
1266 | } | ||
1267 | } | ||
1268 | } | ||
1269 | } | ||
1270 | } | ||
1271 | } | ||
1272 | } | ||
1273 | } | ||
1274 | { | ||
1275 | foreach (bool l2 in compileBodyWithHeadBindings(new Functor2(@":-", Rule, Atom.a(@"true")), VariableNameSuggestions, State, ArgAssignments, Calls)) | ||
1276 | { | ||
1277 | yield return true; | ||
1278 | yield break; | ||
1279 | } | ||
1280 | } | ||
1281 | } | ||
1282 | |||
1283 | public static IEnumerable<bool> compileArgUnifications(object arg1, object arg2, object arg3, object arg4, object arg5, object arg6) | ||
1284 | { | ||
1285 | { | ||
1286 | object x1 = arg2; | ||
1287 | object x2 = arg3; | ||
1288 | object x3 = arg4; | ||
1289 | Variable BodyCode = new Variable(); | ||
1290 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1291 | { | ||
1292 | foreach (bool l3 in YP.unify(arg5, BodyCode)) | ||
1293 | { | ||
1294 | foreach (bool l4 in YP.unify(arg6, BodyCode)) | ||
1295 | { | ||
1296 | yield return true; | ||
1297 | yield break; | ||
1298 | } | ||
1299 | } | ||
1300 | } | ||
1301 | } | ||
1302 | { | ||
1303 | object Index = arg3; | ||
1304 | object AllHeadArgs = arg4; | ||
1305 | object BodyCode = arg5; | ||
1306 | object ArgUnifications = arg6; | ||
1307 | Variable HeadArg = new Variable(); | ||
1308 | Variable RestHeadArgs = new Variable(); | ||
1309 | Variable x3 = new Variable(); | ||
1310 | Variable RestCompiledHeadArgs = new Variable(); | ||
1311 | Variable _ArgIndex1 = new Variable(); | ||
1312 | Variable NextIndex = new Variable(); | ||
1313 | foreach (bool l2 in YP.unify(arg1, new ListPair(HeadArg, RestHeadArgs))) | ||
1314 | { | ||
1315 | foreach (bool l3 in YP.unify(arg2, new ListPair(x3, RestCompiledHeadArgs))) | ||
1316 | { | ||
1317 | foreach (bool l4 in getVariableArgIndex1(HeadArg, AllHeadArgs, _ArgIndex1)) | ||
1318 | { | ||
1319 | foreach (bool l5 in YP.unify(NextIndex, YP.add(Index, 1))) | ||
1320 | { | ||
1321 | foreach (bool l6 in compileArgUnifications(RestHeadArgs, RestCompiledHeadArgs, NextIndex, AllHeadArgs, BodyCode, ArgUnifications)) | ||
1322 | { | ||
1323 | yield return true; | ||
1324 | yield break; | ||
1325 | } | ||
1326 | } | ||
1327 | } | ||
1328 | } | ||
1329 | } | ||
1330 | } | ||
1331 | { | ||
1332 | object Index = arg3; | ||
1333 | object AllHeadArgs = arg4; | ||
1334 | object BodyCode = arg5; | ||
1335 | Variable _HeadArg = new Variable(); | ||
1336 | Variable RestHeadArgs = new Variable(); | ||
1337 | Variable CompiledHeadArg = new Variable(); | ||
1338 | Variable RestCompiledHeadArgs = new Variable(); | ||
1339 | Variable ArgName = new Variable(); | ||
1340 | Variable RestArgUnifications = new Variable(); | ||
1341 | Variable NumberCodes = new Variable(); | ||
1342 | Variable NumberAtom = new Variable(); | ||
1343 | Variable NextIndex = new Variable(); | ||
1344 | foreach (bool l2 in YP.unify(arg1, new ListPair(_HeadArg, RestHeadArgs))) | ||
1345 | { | ||
1346 | foreach (bool l3 in YP.unify(arg2, new ListPair(CompiledHeadArg, RestCompiledHeadArgs))) | ||
1347 | { | ||
1348 | 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))) | ||
1349 | { | ||
1350 | foreach (bool l5 in YP.number_codes(Index, NumberCodes)) | ||
1351 | { | ||
1352 | foreach (bool l6 in YP.atom_codes(NumberAtom, NumberCodes)) | ||
1353 | { | ||
1354 | foreach (bool l7 in YP.atom_concat(Atom.a(@"arg"), NumberAtom, ArgName)) | ||
1355 | { | ||
1356 | foreach (bool l8 in YP.unify(NextIndex, YP.add(Index, 1))) | ||
1357 | { | ||
1358 | foreach (bool l9 in compileArgUnifications(RestHeadArgs, RestCompiledHeadArgs, NextIndex, AllHeadArgs, BodyCode, RestArgUnifications)) | ||
1359 | { | ||
1360 | yield return true; | ||
1361 | yield break; | ||
1362 | } | ||
1363 | } | ||
1364 | } | ||
1365 | } | ||
1366 | } | ||
1367 | } | ||
1368 | } | ||
1369 | } | ||
1370 | } | ||
1371 | } | ||
1372 | |||
1373 | public static IEnumerable<bool> compileDeclarations(object arg1, object arg2, object arg3, object arg4, object arg5, object arg6) | ||
1374 | { | ||
1375 | { | ||
1376 | object _HeadArgs = arg2; | ||
1377 | Variable ArgAssignmentsIn = new Variable(); | ||
1378 | Variable DeclarationsIn = new Variable(); | ||
1379 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1380 | { | ||
1381 | foreach (bool l3 in YP.unify(arg3, ArgAssignmentsIn)) | ||
1382 | { | ||
1383 | foreach (bool l4 in YP.unify(arg4, ArgAssignmentsIn)) | ||
1384 | { | ||
1385 | foreach (bool l5 in YP.unify(arg5, DeclarationsIn)) | ||
1386 | { | ||
1387 | foreach (bool l6 in YP.unify(arg6, DeclarationsIn)) | ||
1388 | { | ||
1389 | yield return true; | ||
1390 | yield break; | ||
1391 | } | ||
1392 | } | ||
1393 | } | ||
1394 | } | ||
1395 | } | ||
1396 | } | ||
1397 | { | ||
1398 | object HeadArgs = arg2; | ||
1399 | object ArgAssignmentsIn = arg3; | ||
1400 | object ArgAssignmentsOut = arg4; | ||
1401 | object DeclarationsIn = arg5; | ||
1402 | object DeclarationsOut = arg6; | ||
1403 | Variable VariableName = new Variable(); | ||
1404 | Variable Var = new Variable(); | ||
1405 | Variable RestVariableNames = new Variable(); | ||
1406 | Variable ArgIndex1 = new Variable(); | ||
1407 | Variable NumberCodes = new Variable(); | ||
1408 | Variable NumberAtom = new Variable(); | ||
1409 | Variable ArgName = new Variable(); | ||
1410 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"=", VariableName, Var), RestVariableNames))) | ||
1411 | { | ||
1412 | foreach (bool l3 in getVariableArgIndex1(Var, HeadArgs, ArgIndex1)) | ||
1413 | { | ||
1414 | foreach (bool l4 in YP.number_codes(ArgIndex1, NumberCodes)) | ||
1415 | { | ||
1416 | foreach (bool l5 in YP.atom_codes(NumberAtom, NumberCodes)) | ||
1417 | { | ||
1418 | foreach (bool l6 in YP.atom_concat(Atom.a(@"arg"), NumberAtom, ArgName)) | ||
1419 | { | ||
1420 | foreach (bool l7 in compileDeclarations(RestVariableNames, HeadArgs, new ListPair(new Functor2(@"f", VariableName, ArgName), ArgAssignmentsIn), ArgAssignmentsOut, DeclarationsIn, DeclarationsOut)) | ||
1421 | { | ||
1422 | yield return true; | ||
1423 | yield break; | ||
1424 | } | ||
1425 | } | ||
1426 | } | ||
1427 | } | ||
1428 | } | ||
1429 | } | ||
1430 | } | ||
1431 | { | ||
1432 | object HeadArgs = arg2; | ||
1433 | object ArgAssignmentsIn = arg3; | ||
1434 | object ArgAssignmentsOut = arg4; | ||
1435 | object DeclarationsIn = arg5; | ||
1436 | Variable VariableName = new Variable(); | ||
1437 | Variable _Var = new Variable(); | ||
1438 | Variable RestVariableNames = new Variable(); | ||
1439 | Variable DeclarationsOut = new Variable(); | ||
1440 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"=", VariableName, _Var), RestVariableNames))) | ||
1441 | { | ||
1442 | 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))) | ||
1443 | { | ||
1444 | foreach (bool l4 in compileDeclarations(RestVariableNames, HeadArgs, ArgAssignmentsIn, ArgAssignmentsOut, DeclarationsIn, DeclarationsOut)) | ||
1445 | { | ||
1446 | yield return true; | ||
1447 | yield break; | ||
1448 | } | ||
1449 | } | ||
1450 | } | ||
1451 | } | ||
1452 | } | ||
1453 | |||
1454 | public static IEnumerable<bool> getVariableArgIndex1(object Var, object arg2, object arg3) | ||
1455 | { | ||
1456 | { | ||
1457 | Variable FirstHeadArgs = new Variable(); | ||
1458 | Variable RestHeadArgs = new Variable(); | ||
1459 | Variable x4 = new Variable(); | ||
1460 | foreach (bool l2 in YP.unify(arg2, new ListPair(FirstHeadArgs, RestHeadArgs))) | ||
1461 | { | ||
1462 | foreach (bool l3 in YP.unify(arg3, 1)) | ||
1463 | { | ||
1464 | if (sameVariable(Var, FirstHeadArgs)) | ||
1465 | { | ||
1466 | foreach (bool l5 in getVariableArgIndex1(Var, RestHeadArgs, x4)) | ||
1467 | { | ||
1468 | goto cutIf1; | ||
1469 | } | ||
1470 | yield return false; | ||
1471 | cutIf1: | ||
1472 | yield break; | ||
1473 | } | ||
1474 | } | ||
1475 | } | ||
1476 | } | ||
1477 | { | ||
1478 | object Index = arg3; | ||
1479 | Variable x2 = new Variable(); | ||
1480 | Variable RestHeadArgs = new Variable(); | ||
1481 | Variable RestIndex = new Variable(); | ||
1482 | foreach (bool l2 in YP.unify(arg2, new ListPair(x2, RestHeadArgs))) | ||
1483 | { | ||
1484 | foreach (bool l3 in getVariableArgIndex1(Var, RestHeadArgs, RestIndex)) | ||
1485 | { | ||
1486 | foreach (bool l4 in YP.unify(Index, YP.add(1, RestIndex))) | ||
1487 | { | ||
1488 | yield return true; | ||
1489 | yield break; | ||
1490 | } | ||
1491 | } | ||
1492 | } | ||
1493 | } | ||
1494 | } | ||
1495 | |||
1496 | public static IEnumerable<bool> compileRuleBody(object arg1, object arg2, object arg3) | ||
1497 | { | ||
1498 | { | ||
1499 | object A = arg1; | ||
1500 | object State = arg2; | ||
1501 | object PseudoCode = arg3; | ||
1502 | if (YP.var(A)) | ||
1503 | { | ||
1504 | foreach (bool l3 in compileRuleBody(new Functor2(@",", new Functor1(@"call", A), Atom.a(@"true")), State, PseudoCode)) | ||
1505 | { | ||
1506 | yield return true; | ||
1507 | yield break; | ||
1508 | } | ||
1509 | } | ||
1510 | } | ||
1511 | { | ||
1512 | object State = arg2; | ||
1513 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"!"))) | ||
1514 | { | ||
1515 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(@"return"), Atom.NIL))) | ||
1516 | { | ||
1517 | if (CompilerState.determinismEquals(State, Atom.a(@"detNoneOut"))) | ||
1518 | { | ||
1519 | yield return true; | ||
1520 | yield break; | ||
1521 | } | ||
1522 | } | ||
1523 | } | ||
1524 | } | ||
1525 | { | ||
1526 | object State = arg2; | ||
1527 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"!"))) | ||
1528 | { | ||
1529 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(@"returntrue"), Atom.NIL))) | ||
1530 | { | ||
1531 | if (CompilerState.determinismEquals(State, Atom.a(@"semidetNoneOut"))) | ||
1532 | { | ||
1533 | yield return true; | ||
1534 | yield break; | ||
1535 | } | ||
1536 | } | ||
1537 | } | ||
1538 | } | ||
1539 | { | ||
1540 | object _State = arg2; | ||
1541 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"!"))) | ||
1542 | { | ||
1543 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(@"yieldtrue"), new ListPair(Atom.a(@"yieldbreak"), Atom.NIL)))) | ||
1544 | { | ||
1545 | yield return true; | ||
1546 | yield break; | ||
1547 | } | ||
1548 | } | ||
1549 | } | ||
1550 | { | ||
1551 | object _State = arg2; | ||
1552 | Variable Name = new Variable(); | ||
1553 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"$CUTIF", Name))) | ||
1554 | { | ||
1555 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor1(@"breakBlock", Name), Atom.NIL))) | ||
1556 | { | ||
1557 | yield return true; | ||
1558 | yield break; | ||
1559 | } | ||
1560 | } | ||
1561 | } | ||
1562 | { | ||
1563 | object State = arg2; | ||
1564 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"true"))) | ||
1565 | { | ||
1566 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(@"return"), Atom.NIL))) | ||
1567 | { | ||
1568 | if (CompilerState.determinismEquals(State, Atom.a(@"detNoneOut"))) | ||
1569 | { | ||
1570 | yield return true; | ||
1571 | yield break; | ||
1572 | } | ||
1573 | } | ||
1574 | } | ||
1575 | } | ||
1576 | { | ||
1577 | object State = arg2; | ||
1578 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"true"))) | ||
1579 | { | ||
1580 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(@"returntrue"), Atom.NIL))) | ||
1581 | { | ||
1582 | if (CompilerState.determinismEquals(State, Atom.a(@"semidetNoneOut"))) | ||
1583 | { | ||
1584 | yield return true; | ||
1585 | yield break; | ||
1586 | } | ||
1587 | } | ||
1588 | } | ||
1589 | } | ||
1590 | { | ||
1591 | object _State = arg2; | ||
1592 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"true"))) | ||
1593 | { | ||
1594 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(@"yieldfalse"), Atom.NIL))) | ||
1595 | { | ||
1596 | yield return true; | ||
1597 | yield break; | ||
1598 | } | ||
1599 | } | ||
1600 | } | ||
1601 | { | ||
1602 | object State = arg2; | ||
1603 | object PseudoCode = arg3; | ||
1604 | Variable A = new Variable(); | ||
1605 | Variable B = new Variable(); | ||
1606 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", A, B))) | ||
1607 | { | ||
1608 | if (YP.var(A)) | ||
1609 | { | ||
1610 | foreach (bool l4 in compileRuleBody(new Functor2(@",", new Functor1(@"call", A), B), State, PseudoCode)) | ||
1611 | { | ||
1612 | yield return true; | ||
1613 | yield break; | ||
1614 | } | ||
1615 | } | ||
1616 | } | ||
1617 | } | ||
1618 | { | ||
1619 | object State = arg2; | ||
1620 | object PseudoCode = arg3; | ||
1621 | Variable A = new Variable(); | ||
1622 | Variable T = new Variable(); | ||
1623 | Variable B = new Variable(); | ||
1624 | Variable C = new Variable(); | ||
1625 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor2(@";", new Functor2(@"->", A, T), B), C))) | ||
1626 | { | ||
1627 | foreach (bool l3 in compileRuleBody(new Functor2(@";", new Functor2(@"->", A, new Functor2(@",", T, C)), new Functor2(@",", B, C)), State, PseudoCode)) | ||
1628 | { | ||
1629 | yield return true; | ||
1630 | yield break; | ||
1631 | } | ||
1632 | } | ||
1633 | } | ||
1634 | { | ||
1635 | object State = arg2; | ||
1636 | object PseudoCode = arg3; | ||
1637 | Variable A = new Variable(); | ||
1638 | Variable B = new Variable(); | ||
1639 | Variable C = new Variable(); | ||
1640 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor2(@";", A, B), C))) | ||
1641 | { | ||
1642 | foreach (bool l3 in compileRuleBody(new Functor2(@";", new Functor2(@",", A, C), new Functor2(@",", B, C)), State, PseudoCode)) | ||
1643 | { | ||
1644 | yield return true; | ||
1645 | yield break; | ||
1646 | } | ||
1647 | } | ||
1648 | } | ||
1649 | { | ||
1650 | object State = arg2; | ||
1651 | Variable A = new Variable(); | ||
1652 | Variable B = new Variable(); | ||
1653 | Variable ACode = new Variable(); | ||
1654 | Variable BCode = new Variable(); | ||
1655 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor1(@"\+", A), B))) | ||
1656 | { | ||
1657 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2(@"if", new Functor1(@"not", ACode), BCode), Atom.NIL))) | ||
1658 | { | ||
1659 | if (CompilerState.isSemidetNoneOut(State, A)) | ||
1660 | { | ||
1661 | foreach (bool l5 in compileFunctorCall(A, State, ACode)) | ||
1662 | { | ||
1663 | foreach (bool l6 in compileRuleBody(B, State, BCode)) | ||
1664 | { | ||
1665 | yield return true; | ||
1666 | yield break; | ||
1667 | } | ||
1668 | } | ||
1669 | } | ||
1670 | } | ||
1671 | } | ||
1672 | } | ||
1673 | { | ||
1674 | object State = arg2; | ||
1675 | object PseudoCode = arg3; | ||
1676 | Variable A = new Variable(); | ||
1677 | Variable B = new Variable(); | ||
1678 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor1(@"\+", A), B))) | ||
1679 | { | ||
1680 | foreach (bool l3 in compileRuleBody(new Functor2(@",", new Functor2(@";", new Functor2(@"->", A, Atom.a(@"fail")), Atom.a(@"true")), B), State, PseudoCode)) | ||
1681 | { | ||
1682 | yield return true; | ||
1683 | yield break; | ||
1684 | } | ||
1685 | } | ||
1686 | } | ||
1687 | { | ||
1688 | object State = arg2; | ||
1689 | object PseudoCode = arg3; | ||
1690 | Variable A = new Variable(); | ||
1691 | Variable B = new Variable(); | ||
1692 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor1(@"once", A), B))) | ||
1693 | { | ||
1694 | foreach (bool l3 in compileRuleBody(new Functor2(@",", new Functor2(@";", new Functor2(@"->", A, Atom.a(@"true")), Atom.a(@"fail")), B), State, PseudoCode)) | ||
1695 | { | ||
1696 | yield return true; | ||
1697 | yield break; | ||
1698 | } | ||
1699 | } | ||
1700 | } | ||
1701 | { | ||
1702 | object State = arg2; | ||
1703 | object PseudoCode = arg3; | ||
1704 | Variable A = new Variable(); | ||
1705 | Variable T = new Variable(); | ||
1706 | Variable B = new Variable(); | ||
1707 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor2(@"->", A, T), B))) | ||
1708 | { | ||
1709 | foreach (bool l3 in compileRuleBody(new Functor2(@",", new Functor2(@";", new Functor2(@"->", A, T), Atom.a(@"fail")), B), State, PseudoCode)) | ||
1710 | { | ||
1711 | yield return true; | ||
1712 | yield break; | ||
1713 | } | ||
1714 | } | ||
1715 | } | ||
1716 | { | ||
1717 | object State = arg2; | ||
1718 | object PseudoCode = arg3; | ||
1719 | Variable A = new Variable(); | ||
1720 | Variable B = new Variable(); | ||
1721 | Variable C = new Variable(); | ||
1722 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor2(@"\=", A, B), C))) | ||
1723 | { | ||
1724 | foreach (bool l3 in compileRuleBody(new Functor2(@",", new Functor1(@"\+", new Functor2(@"=", A, B)), C), State, PseudoCode)) | ||
1725 | { | ||
1726 | yield return true; | ||
1727 | yield break; | ||
1728 | } | ||
1729 | } | ||
1730 | } | ||
1731 | { | ||
1732 | object State = arg2; | ||
1733 | object PseudoCode = arg3; | ||
1734 | Variable A = new Variable(); | ||
1735 | Variable ACode = new Variable(); | ||
1736 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", Atom.a(@"!"), A))) | ||
1737 | { | ||
1738 | foreach (bool l3 in compileRuleBody(A, State, ACode)) | ||
1739 | { | ||
1740 | foreach (bool l4 in append(ACode, new ListPair(Atom.a(@"yieldbreak"), Atom.NIL), PseudoCode)) | ||
1741 | { | ||
1742 | yield return true; | ||
1743 | yield break; | ||
1744 | } | ||
1745 | } | ||
1746 | } | ||
1747 | } | ||
1748 | { | ||
1749 | object State = arg2; | ||
1750 | object PseudoCode = arg3; | ||
1751 | Variable Name = new Variable(); | ||
1752 | Variable A = new Variable(); | ||
1753 | Variable ACode = new Variable(); | ||
1754 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor1(@"$CUTIF", Name), A))) | ||
1755 | { | ||
1756 | foreach (bool l3 in compileRuleBody(A, State, ACode)) | ||
1757 | { | ||
1758 | foreach (bool l4 in append(ACode, new ListPair(new Functor1(@"breakBlock", Name), Atom.NIL), PseudoCode)) | ||
1759 | { | ||
1760 | yield return true; | ||
1761 | yield break; | ||
1762 | } | ||
1763 | } | ||
1764 | } | ||
1765 | } | ||
1766 | { | ||
1767 | object _State = arg2; | ||
1768 | Variable x1 = new Variable(); | ||
1769 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", Atom.a(@"fail"), x1))) | ||
1770 | { | ||
1771 | foreach (bool l3 in YP.unify(arg3, Atom.NIL)) | ||
1772 | { | ||
1773 | yield return true; | ||
1774 | yield break; | ||
1775 | } | ||
1776 | } | ||
1777 | } | ||
1778 | { | ||
1779 | object State = arg2; | ||
1780 | object PseudoCode = arg3; | ||
1781 | Variable A = new Variable(); | ||
1782 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", Atom.a(@"true"), A))) | ||
1783 | { | ||
1784 | foreach (bool l3 in compileRuleBody(A, State, PseudoCode)) | ||
1785 | { | ||
1786 | yield return true; | ||
1787 | yield break; | ||
1788 | } | ||
1789 | } | ||
1790 | } | ||
1791 | { | ||
1792 | object State = arg2; | ||
1793 | Variable A = new Variable(); | ||
1794 | Variable Term = new Variable(); | ||
1795 | Variable B = new Variable(); | ||
1796 | Variable ACode = new Variable(); | ||
1797 | Variable TermCode = new Variable(); | ||
1798 | Variable BCode = new Variable(); | ||
1799 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor2(@"is", A, Term), B))) | ||
1800 | { | ||
1801 | 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))) | ||
1802 | { | ||
1803 | foreach (bool l4 in compileTerm(A, State, ACode)) | ||
1804 | { | ||
1805 | foreach (bool l5 in compileExpression(Term, State, TermCode)) | ||
1806 | { | ||
1807 | foreach (bool l6 in compileRuleBody(B, State, BCode)) | ||
1808 | { | ||
1809 | yield return true; | ||
1810 | yield break; | ||
1811 | } | ||
1812 | } | ||
1813 | } | ||
1814 | } | ||
1815 | } | ||
1816 | } | ||
1817 | { | ||
1818 | object State = arg2; | ||
1819 | Variable A = new Variable(); | ||
1820 | Variable B = new Variable(); | ||
1821 | Variable ACode = new Variable(); | ||
1822 | Variable BCode = new Variable(); | ||
1823 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", A, B))) | ||
1824 | { | ||
1825 | foreach (bool l3 in YP.unify(arg3, new ListPair(ACode, BCode))) | ||
1826 | { | ||
1827 | if (CompilerState.isDetNoneOut(State, A)) | ||
1828 | { | ||
1829 | foreach (bool l5 in compileFunctorCall(A, State, ACode)) | ||
1830 | { | ||
1831 | foreach (bool l6 in compileRuleBody(B, State, BCode)) | ||
1832 | { | ||
1833 | yield return true; | ||
1834 | yield break; | ||
1835 | } | ||
1836 | } | ||
1837 | } | ||
1838 | } | ||
1839 | } | ||
1840 | } | ||
1841 | { | ||
1842 | object State = arg2; | ||
1843 | Variable A = new Variable(); | ||
1844 | Variable B = new Variable(); | ||
1845 | Variable ACode = new Variable(); | ||
1846 | Variable BCode = new Variable(); | ||
1847 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", A, B))) | ||
1848 | { | ||
1849 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2(@"if", ACode, BCode), Atom.NIL))) | ||
1850 | { | ||
1851 | if (CompilerState.isSemidetNoneOut(State, A)) | ||
1852 | { | ||
1853 | foreach (bool l5 in compileFunctorCall(A, State, ACode)) | ||
1854 | { | ||
1855 | foreach (bool l6 in compileRuleBody(B, State, BCode)) | ||
1856 | { | ||
1857 | yield return true; | ||
1858 | yield break; | ||
1859 | } | ||
1860 | } | ||
1861 | } | ||
1862 | } | ||
1863 | } | ||
1864 | } | ||
1865 | { | ||
1866 | object State = arg2; | ||
1867 | Variable ACode = new Variable(); | ||
1868 | Variable B = new Variable(); | ||
1869 | Variable BCode = new Variable(); | ||
1870 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor1(@"$DET_NONE_OUT", ACode), B))) | ||
1871 | { | ||
1872 | foreach (bool l3 in YP.unify(arg3, new ListPair(ACode, BCode))) | ||
1873 | { | ||
1874 | foreach (bool l4 in compileRuleBody(B, State, BCode)) | ||
1875 | { | ||
1876 | yield return true; | ||
1877 | yield break; | ||
1878 | } | ||
1879 | } | ||
1880 | } | ||
1881 | } | ||
1882 | { | ||
1883 | object State = arg2; | ||
1884 | Variable A = new Variable(); | ||
1885 | Variable B = new Variable(); | ||
1886 | Variable FunctionName = new Variable(); | ||
1887 | Variable X1Code = new Variable(); | ||
1888 | Variable X2Code = new Variable(); | ||
1889 | Variable BCode = new Variable(); | ||
1890 | Variable Name = new Variable(); | ||
1891 | Variable X1 = new Variable(); | ||
1892 | Variable X2 = new Variable(); | ||
1893 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", A, B))) | ||
1894 | { | ||
1895 | 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))) | ||
1896 | { | ||
1897 | foreach (bool l4 in YP.univ(A, new ListPair(Name, new ListPair(X1, new ListPair(X2, Atom.NIL))))) | ||
1898 | { | ||
1899 | foreach (bool l5 in binaryExpressionConditional(Name, FunctionName)) | ||
1900 | { | ||
1901 | foreach (bool l6 in compileExpression(X1, State, X1Code)) | ||
1902 | { | ||
1903 | foreach (bool l7 in compileExpression(X2, State, X2Code)) | ||
1904 | { | ||
1905 | foreach (bool l8 in compileRuleBody(B, State, BCode)) | ||
1906 | { | ||
1907 | yield return true; | ||
1908 | yield break; | ||
1909 | } | ||
1910 | } | ||
1911 | } | ||
1912 | } | ||
1913 | } | ||
1914 | } | ||
1915 | } | ||
1916 | } | ||
1917 | { | ||
1918 | object State = arg2; | ||
1919 | object PseudoCode = arg3; | ||
1920 | Variable A = new Variable(); | ||
1921 | Variable B = new Variable(); | ||
1922 | Variable C = new Variable(); | ||
1923 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor2(@",", A, B), C))) | ||
1924 | { | ||
1925 | foreach (bool l3 in compileRuleBody(new Functor2(@",", A, new Functor2(@",", B, C)), State, PseudoCode)) | ||
1926 | { | ||
1927 | yield return true; | ||
1928 | yield break; | ||
1929 | } | ||
1930 | } | ||
1931 | } | ||
1932 | { | ||
1933 | object State = arg2; | ||
1934 | object PseudoCode = arg3; | ||
1935 | Variable Template = new Variable(); | ||
1936 | Variable Goal = new Variable(); | ||
1937 | Variable Bag = new Variable(); | ||
1938 | Variable B = new Variable(); | ||
1939 | Variable TemplateCode = new Variable(); | ||
1940 | Variable FindallAnswers = new Variable(); | ||
1941 | Variable GoalAndAddCode = new Variable(); | ||
1942 | Variable BagCode = new Variable(); | ||
1943 | Variable BCode = new Variable(); | ||
1944 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor3(@"findall", Template, Goal, Bag), B))) | ||
1945 | { | ||
1946 | foreach (bool l3 in compileTerm(Template, State, TemplateCode)) | ||
1947 | { | ||
1948 | foreach (bool l4 in CompilerState.gensym(State, Atom.a(@"findallAnswers"), FindallAnswers)) | ||
1949 | { | ||
1950 | 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)) | ||
1951 | { | ||
1952 | foreach (bool l6 in compileTerm(Bag, State, BagCode)) | ||
1953 | { | ||
1954 | foreach (bool l7 in compileRuleBody(B, State, BCode)) | ||
1955 | { | ||
1956 | 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)) | ||
1957 | { | ||
1958 | yield return true; | ||
1959 | yield break; | ||
1960 | } | ||
1961 | } | ||
1962 | } | ||
1963 | } | ||
1964 | } | ||
1965 | } | ||
1966 | } | ||
1967 | } | ||
1968 | { | ||
1969 | object State = arg2; | ||
1970 | object PseudoCode = arg3; | ||
1971 | Variable Template = new Variable(); | ||
1972 | Variable Goal = new Variable(); | ||
1973 | Variable Bag = new Variable(); | ||
1974 | Variable B = new Variable(); | ||
1975 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor3(@"bagof", Template, Goal, Bag), B))) | ||
1976 | { | ||
1977 | foreach (bool l3 in compileBagof(Atom.a(@"result"), Template, Goal, Bag, B, State, PseudoCode)) | ||
1978 | { | ||
1979 | yield return true; | ||
1980 | yield break; | ||
1981 | } | ||
1982 | } | ||
1983 | } | ||
1984 | { | ||
1985 | object State = arg2; | ||
1986 | object PseudoCode = arg3; | ||
1987 | Variable Template = new Variable(); | ||
1988 | Variable Goal = new Variable(); | ||
1989 | Variable Bag = new Variable(); | ||
1990 | Variable B = new Variable(); | ||
1991 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor3(@"setof", Template, Goal, Bag), B))) | ||
1992 | { | ||
1993 | foreach (bool l3 in compileBagof(Atom.a(@"resultSet"), Template, Goal, Bag, B, State, PseudoCode)) | ||
1994 | { | ||
1995 | yield return true; | ||
1996 | yield break; | ||
1997 | } | ||
1998 | } | ||
1999 | } | ||
2000 | { | ||
2001 | object State = arg2; | ||
2002 | Variable A = new Variable(); | ||
2003 | Variable B = new Variable(); | ||
2004 | Variable ATermCode = new Variable(); | ||
2005 | Variable BCode = new Variable(); | ||
2006 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor1(@"call", A), B))) | ||
2007 | { | ||
2008 | 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))) | ||
2009 | { | ||
2010 | foreach (bool l4 in compileTerm(A, State, ATermCode)) | ||
2011 | { | ||
2012 | foreach (bool l5 in compileRuleBody(B, State, BCode)) | ||
2013 | { | ||
2014 | yield return true; | ||
2015 | yield break; | ||
2016 | } | ||
2017 | } | ||
2018 | } | ||
2019 | } | ||
2020 | } | ||
2021 | { | ||
2022 | object State = arg2; | ||
2023 | Variable A = new Variable(); | ||
2024 | Variable B = new Variable(); | ||
2025 | Variable ACode = new Variable(); | ||
2026 | Variable BCode = new Variable(); | ||
2027 | foreach (bool l2 in YP.unify(arg1, new Functor2(@",", A, B))) | ||
2028 | { | ||
2029 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2(@"foreach", ACode, BCode), Atom.NIL))) | ||
2030 | { | ||
2031 | foreach (bool l4 in compileFunctorCall(A, State, ACode)) | ||
2032 | { | ||
2033 | foreach (bool l5 in compileRuleBody(B, State, BCode)) | ||
2034 | { | ||
2035 | yield return true; | ||
2036 | yield break; | ||
2037 | } | ||
2038 | } | ||
2039 | } | ||
2040 | } | ||
2041 | } | ||
2042 | { | ||
2043 | object State = arg2; | ||
2044 | object PseudoCode = arg3; | ||
2045 | Variable A = new Variable(); | ||
2046 | Variable B = new Variable(); | ||
2047 | foreach (bool l2 in YP.unify(arg1, new Functor2(@";", A, B))) | ||
2048 | { | ||
2049 | if (YP.var(A)) | ||
2050 | { | ||
2051 | foreach (bool l4 in compileRuleBody(new Functor2(@";", new Functor1(@"call", A), B), State, PseudoCode)) | ||
2052 | { | ||
2053 | yield return true; | ||
2054 | yield break; | ||
2055 | } | ||
2056 | } | ||
2057 | } | ||
2058 | } | ||
2059 | { | ||
2060 | object State = arg2; | ||
2061 | Variable A = new Variable(); | ||
2062 | Variable T = new Variable(); | ||
2063 | Variable B = new Variable(); | ||
2064 | Variable CutIfLabel = new Variable(); | ||
2065 | Variable Code = new Variable(); | ||
2066 | foreach (bool l2 in YP.unify(arg1, new Functor2(@";", new Functor2(@"->", A, T), B))) | ||
2067 | { | ||
2068 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2(@"breakableBlock", CutIfLabel, Code), Atom.NIL))) | ||
2069 | { | ||
2070 | foreach (bool l4 in CompilerState.gensym(State, Atom.a(@"cutIf"), CutIfLabel)) | ||
2071 | { | ||
2072 | foreach (bool l5 in compileRuleBody(new Functor2(@";", new Functor2(@",", A, new Functor2(@",", new Functor1(@"$CUTIF", CutIfLabel), T)), B), State, Code)) | ||
2073 | { | ||
2074 | yield return true; | ||
2075 | yield break; | ||
2076 | } | ||
2077 | } | ||
2078 | } | ||
2079 | } | ||
2080 | } | ||
2081 | { | ||
2082 | object State = arg2; | ||
2083 | object PseudoCode = arg3; | ||
2084 | Variable A = new Variable(); | ||
2085 | Variable B = new Variable(); | ||
2086 | Variable ACode = new Variable(); | ||
2087 | Variable BCode = new Variable(); | ||
2088 | foreach (bool l2 in YP.unify(arg1, new Functor2(@";", A, B))) | ||
2089 | { | ||
2090 | foreach (bool l3 in compileRuleBody(A, State, ACode)) | ||
2091 | { | ||
2092 | foreach (bool l4 in compileRuleBody(B, State, BCode)) | ||
2093 | { | ||
2094 | foreach (bool l5 in append(ACode, BCode, PseudoCode)) | ||
2095 | { | ||
2096 | yield return true; | ||
2097 | yield break; | ||
2098 | } | ||
2099 | } | ||
2100 | } | ||
2101 | } | ||
2102 | } | ||
2103 | { | ||
2104 | object A = arg1; | ||
2105 | object State = arg2; | ||
2106 | object PseudoCode = arg3; | ||
2107 | foreach (bool l2 in compileRuleBody(new Functor2(@",", A, Atom.a(@"true")), State, PseudoCode)) | ||
2108 | { | ||
2109 | yield return true; | ||
2110 | yield break; | ||
2111 | } | ||
2112 | } | ||
2113 | } | ||
2114 | |||
2115 | public static IEnumerable<bool> compileBagof(object ResultMethod, object Template, object Goal, object Bag, object B, object State, object PseudoCode) | ||
2116 | { | ||
2117 | { | ||
2118 | Variable TemplateCode = new Variable(); | ||
2119 | Variable GoalTermCode = new Variable(); | ||
2120 | Variable UnqualifiedGoal = new Variable(); | ||
2121 | Variable BagofAnswers = new Variable(); | ||
2122 | Variable GoalAndAddCode = new Variable(); | ||
2123 | Variable BagCode = new Variable(); | ||
2124 | Variable BCode = new Variable(); | ||
2125 | foreach (bool l2 in compileTerm(Template, State, TemplateCode)) | ||
2126 | { | ||
2127 | foreach (bool l3 in compileTerm(Goal, State, GoalTermCode)) | ||
2128 | { | ||
2129 | foreach (bool l4 in unqualifiedGoal(Goal, UnqualifiedGoal)) | ||
2130 | { | ||
2131 | foreach (bool l5 in CompilerState.gensym(State, Atom.a(@"bagofAnswers"), BagofAnswers)) | ||
2132 | { | ||
2133 | 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)) | ||
2134 | { | ||
2135 | foreach (bool l7 in compileTerm(Bag, State, BagCode)) | ||
2136 | { | ||
2137 | foreach (bool l8 in compileRuleBody(B, State, BCode)) | ||
2138 | { | ||
2139 | 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)) | ||
2140 | { | ||
2141 | yield return true; | ||
2142 | yield break; | ||
2143 | } | ||
2144 | } | ||
2145 | } | ||
2146 | } | ||
2147 | } | ||
2148 | } | ||
2149 | } | ||
2150 | } | ||
2151 | } | ||
2152 | } | ||
2153 | |||
2154 | public static IEnumerable<bool> unqualifiedGoal(object arg1, object arg2) | ||
2155 | { | ||
2156 | { | ||
2157 | object Goal = arg1; | ||
2158 | foreach (bool l2 in YP.unify(arg2, new Functor1(@"call", Goal))) | ||
2159 | { | ||
2160 | if (YP.var(Goal)) | ||
2161 | { | ||
2162 | yield return true; | ||
2163 | yield break; | ||
2164 | } | ||
2165 | } | ||
2166 | } | ||
2167 | { | ||
2168 | object UnqualifiedGoal = arg2; | ||
2169 | Variable x1 = new Variable(); | ||
2170 | Variable Goal = new Variable(); | ||
2171 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"^", x1, Goal))) | ||
2172 | { | ||
2173 | foreach (bool l3 in unqualifiedGoal(Goal, UnqualifiedGoal)) | ||
2174 | { | ||
2175 | yield return true; | ||
2176 | yield break; | ||
2177 | } | ||
2178 | } | ||
2179 | } | ||
2180 | { | ||
2181 | Variable UnqualifiedGoal = new Variable(); | ||
2182 | foreach (bool l2 in YP.unify(arg1, UnqualifiedGoal)) | ||
2183 | { | ||
2184 | foreach (bool l3 in YP.unify(arg2, UnqualifiedGoal)) | ||
2185 | { | ||
2186 | yield return true; | ||
2187 | yield break; | ||
2188 | } | ||
2189 | } | ||
2190 | } | ||
2191 | } | ||
2192 | |||
2193 | public static IEnumerable<bool> binaryExpressionConditional(object arg1, object arg2) | ||
2194 | { | ||
2195 | { | ||
2196 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"=:="))) | ||
2197 | { | ||
2198 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.equal"))) | ||
2199 | { | ||
2200 | yield return true; | ||
2201 | yield break; | ||
2202 | } | ||
2203 | } | ||
2204 | } | ||
2205 | { | ||
2206 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"=\="))) | ||
2207 | { | ||
2208 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.notEqual"))) | ||
2209 | { | ||
2210 | yield return true; | ||
2211 | yield break; | ||
2212 | } | ||
2213 | } | ||
2214 | } | ||
2215 | { | ||
2216 | foreach (bool l2 in YP.unify(arg1, Atom.a(@">"))) | ||
2217 | { | ||
2218 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.greaterThan"))) | ||
2219 | { | ||
2220 | yield return true; | ||
2221 | yield break; | ||
2222 | } | ||
2223 | } | ||
2224 | } | ||
2225 | { | ||
2226 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"<"))) | ||
2227 | { | ||
2228 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.lessThan"))) | ||
2229 | { | ||
2230 | yield return true; | ||
2231 | yield break; | ||
2232 | } | ||
2233 | } | ||
2234 | } | ||
2235 | { | ||
2236 | foreach (bool l2 in YP.unify(arg1, Atom.a(@">="))) | ||
2237 | { | ||
2238 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.greaterThanOrEqual"))) | ||
2239 | { | ||
2240 | yield return true; | ||
2241 | yield break; | ||
2242 | } | ||
2243 | } | ||
2244 | } | ||
2245 | { | ||
2246 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"=<"))) | ||
2247 | { | ||
2248 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.lessThanOrEqual"))) | ||
2249 | { | ||
2250 | yield return true; | ||
2251 | yield break; | ||
2252 | } | ||
2253 | } | ||
2254 | } | ||
2255 | } | ||
2256 | |||
2257 | public static IEnumerable<bool> compileFunctorCall(object Functor_1, object State, object arg3) | ||
2258 | { | ||
2259 | { | ||
2260 | Variable FunctionName = new Variable(); | ||
2261 | Variable CompiledArgs = new Variable(); | ||
2262 | Variable FunctorName = new Variable(); | ||
2263 | Variable FunctorArgs = new Variable(); | ||
2264 | Variable x7 = new Variable(); | ||
2265 | Variable Arity = new Variable(); | ||
2266 | foreach (bool l2 in YP.unify(arg3, new Functor2(@"call", FunctionName, CompiledArgs))) | ||
2267 | { | ||
2268 | foreach (bool l3 in YP.univ(Functor_1, new ListPair(FunctorName, FunctorArgs))) | ||
2269 | { | ||
2270 | foreach (bool l4 in YP.functor(Functor_1, x7, Arity)) | ||
2271 | { | ||
2272 | foreach (bool l5 in functorCallFunctionName(State, FunctorName, Arity, FunctionName)) | ||
2273 | { | ||
2274 | foreach (bool l6 in maplist_compileTerm(FunctorArgs, State, CompiledArgs)) | ||
2275 | { | ||
2276 | yield return true; | ||
2277 | yield break; | ||
2278 | } | ||
2279 | } | ||
2280 | } | ||
2281 | } | ||
2282 | } | ||
2283 | } | ||
2284 | } | ||
2285 | |||
2286 | public static IEnumerable<bool> functorCallFunctionName(object arg1, object arg2, object arg3, object arg4) | ||
2287 | { | ||
2288 | { | ||
2289 | object x1 = arg1; | ||
2290 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"="))) | ||
2291 | { | ||
2292 | foreach (bool l3 in YP.unify(arg3, 2)) | ||
2293 | { | ||
2294 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.unify"))) | ||
2295 | { | ||
2296 | yield return true; | ||
2297 | yield break; | ||
2298 | } | ||
2299 | } | ||
2300 | } | ||
2301 | } | ||
2302 | { | ||
2303 | object x1 = arg1; | ||
2304 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"=.."))) | ||
2305 | { | ||
2306 | foreach (bool l3 in YP.unify(arg3, 2)) | ||
2307 | { | ||
2308 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.univ"))) | ||
2309 | { | ||
2310 | yield return true; | ||
2311 | yield break; | ||
2312 | } | ||
2313 | } | ||
2314 | } | ||
2315 | } | ||
2316 | { | ||
2317 | object x1 = arg1; | ||
2318 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"var"))) | ||
2319 | { | ||
2320 | foreach (bool l3 in YP.unify(arg3, 1)) | ||
2321 | { | ||
2322 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.var"))) | ||
2323 | { | ||
2324 | yield return true; | ||
2325 | yield break; | ||
2326 | } | ||
2327 | } | ||
2328 | } | ||
2329 | } | ||
2330 | { | ||
2331 | object x1 = arg1; | ||
2332 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"nonvar"))) | ||
2333 | { | ||
2334 | foreach (bool l3 in YP.unify(arg3, 1)) | ||
2335 | { | ||
2336 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.nonvar"))) | ||
2337 | { | ||
2338 | yield return true; | ||
2339 | yield break; | ||
2340 | } | ||
2341 | } | ||
2342 | } | ||
2343 | } | ||
2344 | { | ||
2345 | object x1 = arg1; | ||
2346 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"arg"))) | ||
2347 | { | ||
2348 | foreach (bool l3 in YP.unify(arg3, 3)) | ||
2349 | { | ||
2350 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.arg"))) | ||
2351 | { | ||
2352 | yield return true; | ||
2353 | yield break; | ||
2354 | } | ||
2355 | } | ||
2356 | } | ||
2357 | } | ||
2358 | { | ||
2359 | object x1 = arg1; | ||
2360 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"functor"))) | ||
2361 | { | ||
2362 | foreach (bool l3 in YP.unify(arg3, 3)) | ||
2363 | { | ||
2364 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.functor"))) | ||
2365 | { | ||
2366 | yield return true; | ||
2367 | yield break; | ||
2368 | } | ||
2369 | } | ||
2370 | } | ||
2371 | } | ||
2372 | { | ||
2373 | object x1 = arg1; | ||
2374 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"repeat"))) | ||
2375 | { | ||
2376 | foreach (bool l3 in YP.unify(arg3, 0)) | ||
2377 | { | ||
2378 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.repeat"))) | ||
2379 | { | ||
2380 | yield return true; | ||
2381 | yield break; | ||
2382 | } | ||
2383 | } | ||
2384 | } | ||
2385 | } | ||
2386 | { | ||
2387 | object x1 = arg1; | ||
2388 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"get_code"))) | ||
2389 | { | ||
2390 | foreach (bool l3 in YP.unify(arg3, 1)) | ||
2391 | { | ||
2392 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.get_code"))) | ||
2393 | { | ||
2394 | yield return true; | ||
2395 | yield break; | ||
2396 | } | ||
2397 | } | ||
2398 | } | ||
2399 | } | ||
2400 | { | ||
2401 | object x1 = arg1; | ||
2402 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"current_op"))) | ||
2403 | { | ||
2404 | foreach (bool l3 in YP.unify(arg3, 3)) | ||
2405 | { | ||
2406 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.current_op"))) | ||
2407 | { | ||
2408 | yield return true; | ||
2409 | yield break; | ||
2410 | } | ||
2411 | } | ||
2412 | } | ||
2413 | } | ||
2414 | { | ||
2415 | object x1 = arg1; | ||
2416 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"atom_length"))) | ||
2417 | { | ||
2418 | foreach (bool l3 in YP.unify(arg3, 2)) | ||
2419 | { | ||
2420 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.atom_length"))) | ||
2421 | { | ||
2422 | yield return true; | ||
2423 | yield break; | ||
2424 | } | ||
2425 | } | ||
2426 | } | ||
2427 | } | ||
2428 | { | ||
2429 | object x1 = arg1; | ||
2430 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"atom_concat"))) | ||
2431 | { | ||
2432 | foreach (bool l3 in YP.unify(arg3, 3)) | ||
2433 | { | ||
2434 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.atom_concat"))) | ||
2435 | { | ||
2436 | yield return true; | ||
2437 | yield break; | ||
2438 | } | ||
2439 | } | ||
2440 | } | ||
2441 | } | ||
2442 | { | ||
2443 | object x1 = arg1; | ||
2444 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"sub_atom"))) | ||
2445 | { | ||
2446 | foreach (bool l3 in YP.unify(arg3, 5)) | ||
2447 | { | ||
2448 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.sub_atom"))) | ||
2449 | { | ||
2450 | yield return true; | ||
2451 | yield break; | ||
2452 | } | ||
2453 | } | ||
2454 | } | ||
2455 | } | ||
2456 | { | ||
2457 | object x1 = arg1; | ||
2458 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"atom_codes"))) | ||
2459 | { | ||
2460 | foreach (bool l3 in YP.unify(arg3, 2)) | ||
2461 | { | ||
2462 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.atom_codes"))) | ||
2463 | { | ||
2464 | yield return true; | ||
2465 | yield break; | ||
2466 | } | ||
2467 | } | ||
2468 | } | ||
2469 | } | ||
2470 | { | ||
2471 | object x1 = arg1; | ||
2472 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"number_codes"))) | ||
2473 | { | ||
2474 | foreach (bool l3 in YP.unify(arg3, 2)) | ||
2475 | { | ||
2476 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.number_codes"))) | ||
2477 | { | ||
2478 | yield return true; | ||
2479 | yield break; | ||
2480 | } | ||
2481 | } | ||
2482 | } | ||
2483 | } | ||
2484 | { | ||
2485 | object x1 = arg1; | ||
2486 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"copy_term"))) | ||
2487 | { | ||
2488 | foreach (bool l3 in YP.unify(arg3, 2)) | ||
2489 | { | ||
2490 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.copy_term"))) | ||
2491 | { | ||
2492 | yield return true; | ||
2493 | yield break; | ||
2494 | } | ||
2495 | } | ||
2496 | } | ||
2497 | } | ||
2498 | { | ||
2499 | object x1 = arg1; | ||
2500 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"sort"))) | ||
2501 | { | ||
2502 | foreach (bool l3 in YP.unify(arg3, 2)) | ||
2503 | { | ||
2504 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.sort"))) | ||
2505 | { | ||
2506 | yield return true; | ||
2507 | yield break; | ||
2508 | } | ||
2509 | } | ||
2510 | } | ||
2511 | } | ||
2512 | { | ||
2513 | object x1 = arg1; | ||
2514 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"script_event"))) | ||
2515 | { | ||
2516 | foreach (bool l3 in YP.unify(arg3, 2)) | ||
2517 | { | ||
2518 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.script_event"))) | ||
2519 | { | ||
2520 | yield return true; | ||
2521 | yield break; | ||
2522 | } | ||
2523 | } | ||
2524 | } | ||
2525 | } | ||
2526 | { | ||
2527 | object x1 = arg1; | ||
2528 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"nl"))) | ||
2529 | { | ||
2530 | foreach (bool l3 in YP.unify(arg3, 0)) | ||
2531 | { | ||
2532 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.nl"))) | ||
2533 | { | ||
2534 | yield return true; | ||
2535 | yield break; | ||
2536 | } | ||
2537 | } | ||
2538 | } | ||
2539 | } | ||
2540 | { | ||
2541 | object x1 = arg1; | ||
2542 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"write"))) | ||
2543 | { | ||
2544 | foreach (bool l3 in YP.unify(arg3, 1)) | ||
2545 | { | ||
2546 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.write"))) | ||
2547 | { | ||
2548 | yield return true; | ||
2549 | yield break; | ||
2550 | } | ||
2551 | } | ||
2552 | } | ||
2553 | } | ||
2554 | { | ||
2555 | object x1 = arg1; | ||
2556 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"put_code"))) | ||
2557 | { | ||
2558 | foreach (bool l3 in YP.unify(arg3, 1)) | ||
2559 | { | ||
2560 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.put_code"))) | ||
2561 | { | ||
2562 | yield return true; | ||
2563 | yield break; | ||
2564 | } | ||
2565 | } | ||
2566 | } | ||
2567 | } | ||
2568 | { | ||
2569 | object x1 = arg1; | ||
2570 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"atom"))) | ||
2571 | { | ||
2572 | foreach (bool l3 in YP.unify(arg3, 1)) | ||
2573 | { | ||
2574 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.atom"))) | ||
2575 | { | ||
2576 | yield return true; | ||
2577 | yield break; | ||
2578 | } | ||
2579 | } | ||
2580 | } | ||
2581 | } | ||
2582 | { | ||
2583 | object x1 = arg1; | ||
2584 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"number"))) | ||
2585 | { | ||
2586 | foreach (bool l3 in YP.unify(arg3, 1)) | ||
2587 | { | ||
2588 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.number"))) | ||
2589 | { | ||
2590 | yield return true; | ||
2591 | yield break; | ||
2592 | } | ||
2593 | } | ||
2594 | } | ||
2595 | } | ||
2596 | { | ||
2597 | object x1 = arg1; | ||
2598 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"=="))) | ||
2599 | { | ||
2600 | foreach (bool l3 in YP.unify(arg3, 2)) | ||
2601 | { | ||
2602 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.termEqual"))) | ||
2603 | { | ||
2604 | yield return true; | ||
2605 | yield break; | ||
2606 | } | ||
2607 | } | ||
2608 | } | ||
2609 | } | ||
2610 | { | ||
2611 | object x1 = arg1; | ||
2612 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"\=="))) | ||
2613 | { | ||
2614 | foreach (bool l3 in YP.unify(arg3, 2)) | ||
2615 | { | ||
2616 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.termNotEqual"))) | ||
2617 | { | ||
2618 | yield return true; | ||
2619 | yield break; | ||
2620 | } | ||
2621 | } | ||
2622 | } | ||
2623 | } | ||
2624 | { | ||
2625 | object x1 = arg1; | ||
2626 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"@<"))) | ||
2627 | { | ||
2628 | foreach (bool l3 in YP.unify(arg3, 2)) | ||
2629 | { | ||
2630 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.termLessThan"))) | ||
2631 | { | ||
2632 | yield return true; | ||
2633 | yield break; | ||
2634 | } | ||
2635 | } | ||
2636 | } | ||
2637 | } | ||
2638 | { | ||
2639 | object x1 = arg1; | ||
2640 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"@=<"))) | ||
2641 | { | ||
2642 | foreach (bool l3 in YP.unify(arg3, 2)) | ||
2643 | { | ||
2644 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.termLessThanOrEqual"))) | ||
2645 | { | ||
2646 | yield return true; | ||
2647 | yield break; | ||
2648 | } | ||
2649 | } | ||
2650 | } | ||
2651 | } | ||
2652 | { | ||
2653 | object x1 = arg1; | ||
2654 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"@>"))) | ||
2655 | { | ||
2656 | foreach (bool l3 in YP.unify(arg3, 2)) | ||
2657 | { | ||
2658 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.termGreaterThan"))) | ||
2659 | { | ||
2660 | yield return true; | ||
2661 | yield break; | ||
2662 | } | ||
2663 | } | ||
2664 | } | ||
2665 | } | ||
2666 | { | ||
2667 | object x1 = arg1; | ||
2668 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"@>="))) | ||
2669 | { | ||
2670 | foreach (bool l3 in YP.unify(arg3, 2)) | ||
2671 | { | ||
2672 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.termGreaterThanOrEqual"))) | ||
2673 | { | ||
2674 | yield return true; | ||
2675 | yield break; | ||
2676 | } | ||
2677 | } | ||
2678 | } | ||
2679 | } | ||
2680 | { | ||
2681 | object x1 = arg1; | ||
2682 | foreach (bool l2 in YP.unify(arg2, Atom.a(@"throw"))) | ||
2683 | { | ||
2684 | foreach (bool l3 in YP.unify(arg3, 1)) | ||
2685 | { | ||
2686 | foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.throwException"))) | ||
2687 | { | ||
2688 | yield return true; | ||
2689 | yield break; | ||
2690 | } | ||
2691 | } | ||
2692 | } | ||
2693 | } | ||
2694 | { | ||
2695 | object State = arg1; | ||
2696 | object Arity = arg3; | ||
2697 | Variable Name = new Variable(); | ||
2698 | foreach (bool l2 in YP.unify(arg2, Name)) | ||
2699 | { | ||
2700 | foreach (bool l3 in YP.unify(arg4, Name)) | ||
2701 | { | ||
2702 | if (CompilerState.nameArityHasModule(State, Name, Arity, Atom.a(@""))) | ||
2703 | { | ||
2704 | yield return true; | ||
2705 | yield break; | ||
2706 | } | ||
2707 | } | ||
2708 | } | ||
2709 | } | ||
2710 | { | ||
2711 | object _State = arg1; | ||
2712 | object _Arity = arg3; | ||
2713 | Variable Name = new Variable(); | ||
2714 | foreach (bool l2 in YP.unify(arg2, Name)) | ||
2715 | { | ||
2716 | foreach (bool l3 in YP.unify(arg4, Name)) | ||
2717 | { | ||
2718 | foreach (bool l4 in Atom.module(Name, Atom.a(@""))) | ||
2719 | { | ||
2720 | yield return true; | ||
2721 | yield break; | ||
2722 | } | ||
2723 | } | ||
2724 | } | ||
2725 | } | ||
2726 | { | ||
2727 | object _State = arg1; | ||
2728 | object Name = arg2; | ||
2729 | object Arity = arg3; | ||
2730 | object x4 = arg4; | ||
2731 | foreach (bool l2 in Atom.module(Name, Atom.NIL)) | ||
2732 | { | ||
2733 | YP.throwException(new Functor2(@"error", new Functor2(@"type_error", Atom.a(@"callable"), new Functor2(@"/", Name, Arity)), Atom.a(@"Calls to dynamic predicates not supported"))); | ||
2734 | yield return true; | ||
2735 | yield break; | ||
2736 | } | ||
2737 | } | ||
2738 | { | ||
2739 | object _State = arg1; | ||
2740 | object Name = arg2; | ||
2741 | object Arity = arg3; | ||
2742 | object x4 = arg4; | ||
2743 | Variable Module = new Variable(); | ||
2744 | Variable Message = new Variable(); | ||
2745 | foreach (bool l2 in Atom.module(Name, Module)) | ||
2746 | { | ||
2747 | foreach (bool l3 in Atom.module(Name, Atom.NIL)) | ||
2748 | { | ||
2749 | foreach (bool l4 in YP.atom_concat(Atom.a(@"Not supporting calls to external module: "), Module, Message)) | ||
2750 | { | ||
2751 | YP.throwException(new Functor2(@"error", new Functor2(@"type_error", Atom.a(@"callable"), new Functor2(@"/", Name, Arity)), Message)); | ||
2752 | yield return true; | ||
2753 | yield break; | ||
2754 | } | ||
2755 | } | ||
2756 | } | ||
2757 | } | ||
2758 | } | ||
2759 | |||
2760 | public static IEnumerable<bool> compileTerm(object arg1, object arg2, object arg3) | ||
2761 | { | ||
2762 | { | ||
2763 | object Term = arg1; | ||
2764 | object State = arg2; | ||
2765 | Variable VariableName = new Variable(); | ||
2766 | foreach (bool l2 in YP.unify(arg3, new Functor1(@"var", VariableName))) | ||
2767 | { | ||
2768 | if (YP.var(Term)) | ||
2769 | { | ||
2770 | foreach (bool l4 in CompilerState.getVariableName(State, Term, VariableName)) | ||
2771 | { | ||
2772 | yield return true; | ||
2773 | yield break; | ||
2774 | } | ||
2775 | } | ||
2776 | } | ||
2777 | } | ||
2778 | { | ||
2779 | object _State = arg2; | ||
2780 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
2781 | { | ||
2782 | foreach (bool l3 in YP.unify(arg3, new Functor1(@"var", Atom.a(@"Atom.NIL")))) | ||
2783 | { | ||
2784 | yield return true; | ||
2785 | yield break; | ||
2786 | } | ||
2787 | } | ||
2788 | } | ||
2789 | { | ||
2790 | object Term = arg1; | ||
2791 | object State = arg2; | ||
2792 | object Code = arg3; | ||
2793 | Variable ModuleCode = new Variable(); | ||
2794 | if (YP.atom(Term)) | ||
2795 | { | ||
2796 | foreach (bool l3 in compileAtomModule(Term, 0, State, ModuleCode)) | ||
2797 | { | ||
2798 | 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))))) | ||
2799 | { | ||
2800 | yield return true; | ||
2801 | yield break; | ||
2802 | } | ||
2803 | goto cutIf1; | ||
2804 | } | ||
2805 | foreach (bool l3 in YP.unify(Code, new Functor2(@"call", Atom.a(@"Atom.a"), new ListPair(new Functor1(@"object", Term), Atom.NIL)))) | ||
2806 | { | ||
2807 | yield return true; | ||
2808 | yield break; | ||
2809 | } | ||
2810 | cutIf1: | ||
2811 | { } | ||
2812 | } | ||
2813 | } | ||
2814 | { | ||
2815 | object State = arg2; | ||
2816 | Variable First = new Variable(); | ||
2817 | Variable Rest = new Variable(); | ||
2818 | Variable Arg1 = new Variable(); | ||
2819 | Variable Arg2 = new Variable(); | ||
2820 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) | ||
2821 | { | ||
2822 | foreach (bool l3 in YP.unify(arg3, new Functor2(@"new", Atom.a(@"ListPair"), new ListPair(Arg1, new ListPair(Arg2, Atom.NIL))))) | ||
2823 | { | ||
2824 | foreach (bool l4 in compileTerm(First, State, Arg1)) | ||
2825 | { | ||
2826 | foreach (bool l5 in compileTerm(Rest, State, Arg2)) | ||
2827 | { | ||
2828 | yield return true; | ||
2829 | yield break; | ||
2830 | } | ||
2831 | } | ||
2832 | } | ||
2833 | } | ||
2834 | } | ||
2835 | { | ||
2836 | object Term = arg1; | ||
2837 | object State = arg2; | ||
2838 | object Result = arg3; | ||
2839 | Variable Name = new Variable(); | ||
2840 | Variable TermArgs = new Variable(); | ||
2841 | Variable x6 = new Variable(); | ||
2842 | Variable Arity = new Variable(); | ||
2843 | Variable ModuleCode = new Variable(); | ||
2844 | Variable NameCode = new Variable(); | ||
2845 | Variable X1 = new Variable(); | ||
2846 | Variable Arg1 = new Variable(); | ||
2847 | Variable X2 = new Variable(); | ||
2848 | Variable Arg2 = new Variable(); | ||
2849 | Variable X3 = new Variable(); | ||
2850 | Variable Arg3 = new Variable(); | ||
2851 | Variable Args = new Variable(); | ||
2852 | foreach (bool l2 in YP.univ(Term, new ListPair(Name, TermArgs))) | ||
2853 | { | ||
2854 | if (YP.termEqual(TermArgs, Atom.NIL)) | ||
2855 | { | ||
2856 | foreach (bool l4 in YP.unify(Result, new Functor1(@"object", Name))) | ||
2857 | { | ||
2858 | yield return true; | ||
2859 | yield break; | ||
2860 | } | ||
2861 | goto cutIf2; | ||
2862 | } | ||
2863 | foreach (bool l3 in YP.functor(Term, x6, Arity)) | ||
2864 | { | ||
2865 | foreach (bool l4 in compileAtomModule(Name, Arity, State, ModuleCode)) | ||
2866 | { | ||
2867 | 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))))) | ||
2868 | { | ||
2869 | foreach (bool l6 in YP.unify(TermArgs, new ListPair(X1, Atom.NIL))) | ||
2870 | { | ||
2871 | foreach (bool l7 in compileTerm(X1, State, Arg1)) | ||
2872 | { | ||
2873 | foreach (bool l8 in YP.unify(Result, new Functor2(@"new", Atom.a(@"Functor1"), new ListPair(NameCode, new ListPair(Arg1, Atom.NIL))))) | ||
2874 | { | ||
2875 | yield return true; | ||
2876 | yield break; | ||
2877 | } | ||
2878 | } | ||
2879 | goto cutIf4; | ||
2880 | } | ||
2881 | foreach (bool l6 in YP.unify(TermArgs, new ListPair(X1, new ListPair(X2, Atom.NIL)))) | ||
2882 | { | ||
2883 | foreach (bool l7 in compileTerm(X1, State, Arg1)) | ||
2884 | { | ||
2885 | foreach (bool l8 in compileTerm(X2, State, Arg2)) | ||
2886 | { | ||
2887 | foreach (bool l9 in YP.unify(Result, new Functor2(@"new", Atom.a(@"Functor2"), new ListPair(NameCode, new ListPair(Arg1, new ListPair(Arg2, Atom.NIL)))))) | ||
2888 | { | ||
2889 | yield return true; | ||
2890 | yield break; | ||
2891 | } | ||
2892 | } | ||
2893 | } | ||
2894 | goto cutIf5; | ||
2895 | } | ||
2896 | foreach (bool l6 in YP.unify(TermArgs, new ListPair(X1, new ListPair(X2, new ListPair(X3, Atom.NIL))))) | ||
2897 | { | ||
2898 | foreach (bool l7 in compileTerm(X1, State, Arg1)) | ||
2899 | { | ||
2900 | foreach (bool l8 in compileTerm(X2, State, Arg2)) | ||
2901 | { | ||
2902 | foreach (bool l9 in compileTerm(X3, State, Arg3)) | ||
2903 | { | ||
2904 | foreach (bool l10 in YP.unify(Result, new Functor2(@"new", Atom.a(@"Functor3"), new ListPair(NameCode, new ListPair(Arg1, new ListPair(Arg2, new ListPair(Arg3, Atom.NIL))))))) | ||
2905 | { | ||
2906 | yield return true; | ||
2907 | yield break; | ||
2908 | } | ||
2909 | } | ||
2910 | } | ||
2911 | } | ||
2912 | } | ||
2913 | foreach (bool l6 in maplist_compileTerm(TermArgs, State, Args)) | ||
2914 | { | ||
2915 | foreach (bool l7 in YP.unify(Result, new Functor2(@"new", Atom.a(@"Functor"), new ListPair(NameCode, new ListPair(new Functor1(@"objectArray", Args), Atom.NIL))))) | ||
2916 | { | ||
2917 | yield return true; | ||
2918 | yield break; | ||
2919 | } | ||
2920 | } | ||
2921 | cutIf5: | ||
2922 | cutIf4: | ||
2923 | { } | ||
2924 | } | ||
2925 | goto cutIf3; | ||
2926 | } | ||
2927 | foreach (bool l4 in YP.unify(NameCode, new Functor1(@"object", Name))) | ||
2928 | { | ||
2929 | foreach (bool l5 in YP.unify(TermArgs, new ListPair(X1, Atom.NIL))) | ||
2930 | { | ||
2931 | foreach (bool l6 in compileTerm(X1, State, Arg1)) | ||
2932 | { | ||
2933 | foreach (bool l7 in YP.unify(Result, new Functor2(@"new", Atom.a(@"Functor1"), new ListPair(NameCode, new ListPair(Arg1, Atom.NIL))))) | ||
2934 | { | ||
2935 | yield return true; | ||
2936 | yield break; | ||
2937 | } | ||
2938 | } | ||
2939 | goto cutIf6; | ||
2940 | } | ||
2941 | foreach (bool l5 in YP.unify(TermArgs, new ListPair(X1, new ListPair(X2, Atom.NIL)))) | ||
2942 | { | ||
2943 | foreach (bool l6 in compileTerm(X1, State, Arg1)) | ||
2944 | { | ||
2945 | foreach (bool l7 in compileTerm(X2, State, Arg2)) | ||
2946 | { | ||
2947 | foreach (bool l8 in YP.unify(Result, new Functor2(@"new", Atom.a(@"Functor2"), new ListPair(NameCode, new ListPair(Arg1, new ListPair(Arg2, Atom.NIL)))))) | ||
2948 | { | ||
2949 | yield return true; | ||
2950 | yield break; | ||
2951 | } | ||
2952 | } | ||
2953 | } | ||
2954 | goto cutIf7; | ||
2955 | } | ||
2956 | foreach (bool l5 in YP.unify(TermArgs, new ListPair(X1, new ListPair(X2, new ListPair(X3, Atom.NIL))))) | ||
2957 | { | ||
2958 | foreach (bool l6 in compileTerm(X1, State, Arg1)) | ||
2959 | { | ||
2960 | foreach (bool l7 in compileTerm(X2, State, Arg2)) | ||
2961 | { | ||
2962 | foreach (bool l8 in compileTerm(X3, State, Arg3)) | ||
2963 | { | ||
2964 | foreach (bool l9 in YP.unify(Result, new Functor2(@"new", Atom.a(@"Functor3"), new ListPair(NameCode, new ListPair(Arg1, new ListPair(Arg2, new ListPair(Arg3, Atom.NIL))))))) | ||
2965 | { | ||
2966 | yield return true; | ||
2967 | yield break; | ||
2968 | } | ||
2969 | } | ||
2970 | } | ||
2971 | } | ||
2972 | } | ||
2973 | foreach (bool l5 in maplist_compileTerm(TermArgs, State, Args)) | ||
2974 | { | ||
2975 | foreach (bool l6 in YP.unify(Result, new Functor2(@"new", Atom.a(@"Functor"), new ListPair(NameCode, new ListPair(new Functor1(@"objectArray", Args), Atom.NIL))))) | ||
2976 | { | ||
2977 | yield return true; | ||
2978 | yield break; | ||
2979 | } | ||
2980 | } | ||
2981 | cutIf7: | ||
2982 | cutIf6: | ||
2983 | { } | ||
2984 | } | ||
2985 | cutIf3: | ||
2986 | { } | ||
2987 | } | ||
2988 | cutIf2: | ||
2989 | { } | ||
2990 | } | ||
2991 | } | ||
2992 | } | ||
2993 | |||
2994 | public static IEnumerable<bool> compileAtomModule(object Name, object Arity, object State, object ModuleCode) | ||
2995 | { | ||
2996 | { | ||
2997 | if (CompilerState.nameArityHasModule(State, Name, Arity, Atom.a(@""))) | ||
2998 | { | ||
2999 | foreach (bool l3 in YP.unify(ModuleCode, new Functor2(@"call", Atom.a(@"Atom.a"), new ListPair(new Functor1(@"object", Atom.a(@"")), Atom.NIL)))) | ||
3000 | { | ||
3001 | yield return true; | ||
3002 | yield break; | ||
3003 | } | ||
3004 | } | ||
3005 | } | ||
3006 | } | ||
3007 | |||
3008 | public static IEnumerable<bool> maplist_compileTerm(object arg1, object arg2, object arg3) | ||
3009 | { | ||
3010 | { | ||
3011 | object _State = arg2; | ||
3012 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
3013 | { | ||
3014 | foreach (bool l3 in YP.unify(arg3, Atom.NIL)) | ||
3015 | { | ||
3016 | yield return true; | ||
3017 | yield break; | ||
3018 | } | ||
3019 | } | ||
3020 | } | ||
3021 | { | ||
3022 | object State = arg2; | ||
3023 | Variable First = new Variable(); | ||
3024 | Variable Rest = new Variable(); | ||
3025 | Variable FirstResult = new Variable(); | ||
3026 | Variable RestResults = new Variable(); | ||
3027 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) | ||
3028 | { | ||
3029 | foreach (bool l3 in YP.unify(arg3, new ListPair(FirstResult, RestResults))) | ||
3030 | { | ||
3031 | foreach (bool l4 in compileTerm(First, State, FirstResult)) | ||
3032 | { | ||
3033 | foreach (bool l5 in maplist_compileTerm(Rest, State, RestResults)) | ||
3034 | { | ||
3035 | yield return true; | ||
3036 | yield break; | ||
3037 | } | ||
3038 | } | ||
3039 | } | ||
3040 | } | ||
3041 | } | ||
3042 | } | ||
3043 | |||
3044 | public static IEnumerable<bool> compileExpression(object Term, object State, object Result) | ||
3045 | { | ||
3046 | { | ||
3047 | Variable Name = new Variable(); | ||
3048 | Variable TermArgs = new Variable(); | ||
3049 | Variable X1 = new Variable(); | ||
3050 | Variable FunctionName = new Variable(); | ||
3051 | Variable Arg1 = new Variable(); | ||
3052 | Variable x9 = new Variable(); | ||
3053 | Variable X2 = new Variable(); | ||
3054 | Variable Arg2 = new Variable(); | ||
3055 | if (YP.nonvar(Term)) | ||
3056 | { | ||
3057 | foreach (bool l3 in YP.univ(Term, new ListPair(Name, TermArgs))) | ||
3058 | { | ||
3059 | if (YP.atom(Name)) | ||
3060 | { | ||
3061 | foreach (bool l5 in YP.unify(TermArgs, new ListPair(X1, Atom.NIL))) | ||
3062 | { | ||
3063 | foreach (bool l6 in unaryFunction(Name, FunctionName)) | ||
3064 | { | ||
3065 | foreach (bool l7 in compileExpression(X1, State, Arg1)) | ||
3066 | { | ||
3067 | foreach (bool l8 in YP.unify(Result, new Functor2(@"call", FunctionName, new ListPair(Arg1, Atom.NIL)))) | ||
3068 | { | ||
3069 | yield return true; | ||
3070 | yield break; | ||
3071 | } | ||
3072 | } | ||
3073 | goto cutIf1; | ||
3074 | } | ||
3075 | } | ||
3076 | foreach (bool l5 in YP.unify(Term, new ListPair(x9, Atom.NIL))) | ||
3077 | { | ||
3078 | foreach (bool l6 in compileTerm(Term, State, Result)) | ||
3079 | { | ||
3080 | yield return true; | ||
3081 | yield break; | ||
3082 | } | ||
3083 | goto cutIf2; | ||
3084 | } | ||
3085 | foreach (bool l5 in YP.unify(TermArgs, new ListPair(X1, new ListPair(X2, Atom.NIL)))) | ||
3086 | { | ||
3087 | foreach (bool l6 in binaryFunction(Name, FunctionName)) | ||
3088 | { | ||
3089 | foreach (bool l7 in compileExpression(X1, State, Arg1)) | ||
3090 | { | ||
3091 | foreach (bool l8 in compileExpression(X2, State, Arg2)) | ||
3092 | { | ||
3093 | foreach (bool l9 in YP.unify(Result, new Functor2(@"call", FunctionName, new ListPair(Arg1, new ListPair(Arg2, Atom.NIL))))) | ||
3094 | { | ||
3095 | yield return true; | ||
3096 | yield break; | ||
3097 | } | ||
3098 | } | ||
3099 | } | ||
3100 | goto cutIf3; | ||
3101 | } | ||
3102 | } | ||
3103 | YP.throwException(new Functor2(@"error", new Functor2(@"type_error", Atom.a(@"evaluable"), Name), Atom.a(@"Not an expression function"))); | ||
3104 | yield return false; | ||
3105 | cutIf3: | ||
3106 | cutIf2: | ||
3107 | cutIf1: | ||
3108 | { } | ||
3109 | } | ||
3110 | } | ||
3111 | } | ||
3112 | } | ||
3113 | { | ||
3114 | foreach (bool l2 in compileTerm(Term, State, Result)) | ||
3115 | { | ||
3116 | yield return true; | ||
3117 | yield break; | ||
3118 | } | ||
3119 | } | ||
3120 | } | ||
3121 | |||
3122 | public static IEnumerable<bool> unaryFunction(object arg1, object arg2) | ||
3123 | { | ||
3124 | { | ||
3125 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"-"))) | ||
3126 | { | ||
3127 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.negate"))) | ||
3128 | { | ||
3129 | yield return true; | ||
3130 | yield break; | ||
3131 | } | ||
3132 | } | ||
3133 | } | ||
3134 | { | ||
3135 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"abs"))) | ||
3136 | { | ||
3137 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.abs"))) | ||
3138 | { | ||
3139 | yield return true; | ||
3140 | yield break; | ||
3141 | } | ||
3142 | } | ||
3143 | } | ||
3144 | { | ||
3145 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"sign"))) | ||
3146 | { | ||
3147 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.sign"))) | ||
3148 | { | ||
3149 | yield return true; | ||
3150 | yield break; | ||
3151 | } | ||
3152 | } | ||
3153 | } | ||
3154 | { | ||
3155 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"floor"))) | ||
3156 | { | ||
3157 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.floor"))) | ||
3158 | { | ||
3159 | yield return true; | ||
3160 | yield break; | ||
3161 | } | ||
3162 | } | ||
3163 | } | ||
3164 | { | ||
3165 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"truncate"))) | ||
3166 | { | ||
3167 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.truncate"))) | ||
3168 | { | ||
3169 | yield return true; | ||
3170 | yield break; | ||
3171 | } | ||
3172 | } | ||
3173 | } | ||
3174 | { | ||
3175 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"round"))) | ||
3176 | { | ||
3177 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.round"))) | ||
3178 | { | ||
3179 | yield return true; | ||
3180 | yield break; | ||
3181 | } | ||
3182 | } | ||
3183 | } | ||
3184 | { | ||
3185 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"floor"))) | ||
3186 | { | ||
3187 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.ceiling"))) | ||
3188 | { | ||
3189 | yield return true; | ||
3190 | yield break; | ||
3191 | } | ||
3192 | } | ||
3193 | } | ||
3194 | { | ||
3195 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"sin"))) | ||
3196 | { | ||
3197 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.sin"))) | ||
3198 | { | ||
3199 | yield return true; | ||
3200 | yield break; | ||
3201 | } | ||
3202 | } | ||
3203 | } | ||
3204 | { | ||
3205 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"cos"))) | ||
3206 | { | ||
3207 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.cos"))) | ||
3208 | { | ||
3209 | yield return true; | ||
3210 | yield break; | ||
3211 | } | ||
3212 | } | ||
3213 | } | ||
3214 | { | ||
3215 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"atan"))) | ||
3216 | { | ||
3217 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.atan"))) | ||
3218 | { | ||
3219 | yield return true; | ||
3220 | yield break; | ||
3221 | } | ||
3222 | } | ||
3223 | } | ||
3224 | { | ||
3225 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"exp"))) | ||
3226 | { | ||
3227 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.exp"))) | ||
3228 | { | ||
3229 | yield return true; | ||
3230 | yield break; | ||
3231 | } | ||
3232 | } | ||
3233 | } | ||
3234 | { | ||
3235 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"log"))) | ||
3236 | { | ||
3237 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.log"))) | ||
3238 | { | ||
3239 | yield return true; | ||
3240 | yield break; | ||
3241 | } | ||
3242 | } | ||
3243 | } | ||
3244 | { | ||
3245 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"sqrt"))) | ||
3246 | { | ||
3247 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.sqrt"))) | ||
3248 | { | ||
3249 | yield return true; | ||
3250 | yield break; | ||
3251 | } | ||
3252 | } | ||
3253 | } | ||
3254 | { | ||
3255 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"\"))) | ||
3256 | { | ||
3257 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.bitwiseComplement"))) | ||
3258 | { | ||
3259 | yield return true; | ||
3260 | yield break; | ||
3261 | } | ||
3262 | } | ||
3263 | } | ||
3264 | } | ||
3265 | |||
3266 | public static IEnumerable<bool> binaryFunction(object arg1, object arg2) | ||
3267 | { | ||
3268 | { | ||
3269 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"+"))) | ||
3270 | { | ||
3271 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.add"))) | ||
3272 | { | ||
3273 | yield return true; | ||
3274 | yield break; | ||
3275 | } | ||
3276 | } | ||
3277 | } | ||
3278 | { | ||
3279 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"-"))) | ||
3280 | { | ||
3281 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.subtract"))) | ||
3282 | { | ||
3283 | yield return true; | ||
3284 | yield break; | ||
3285 | } | ||
3286 | } | ||
3287 | } | ||
3288 | { | ||
3289 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"*"))) | ||
3290 | { | ||
3291 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.multiply"))) | ||
3292 | { | ||
3293 | yield return true; | ||
3294 | yield break; | ||
3295 | } | ||
3296 | } | ||
3297 | } | ||
3298 | { | ||
3299 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"/"))) | ||
3300 | { | ||
3301 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.divide"))) | ||
3302 | { | ||
3303 | yield return true; | ||
3304 | yield break; | ||
3305 | } | ||
3306 | } | ||
3307 | } | ||
3308 | { | ||
3309 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"//"))) | ||
3310 | { | ||
3311 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.intDivide"))) | ||
3312 | { | ||
3313 | yield return true; | ||
3314 | yield break; | ||
3315 | } | ||
3316 | } | ||
3317 | } | ||
3318 | { | ||
3319 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"mod"))) | ||
3320 | { | ||
3321 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.mod"))) | ||
3322 | { | ||
3323 | yield return true; | ||
3324 | yield break; | ||
3325 | } | ||
3326 | } | ||
3327 | } | ||
3328 | { | ||
3329 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"**"))) | ||
3330 | { | ||
3331 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.pow"))) | ||
3332 | { | ||
3333 | yield return true; | ||
3334 | yield break; | ||
3335 | } | ||
3336 | } | ||
3337 | } | ||
3338 | { | ||
3339 | foreach (bool l2 in YP.unify(arg1, Atom.a(@">>"))) | ||
3340 | { | ||
3341 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.bitwiseShiftRight"))) | ||
3342 | { | ||
3343 | yield return true; | ||
3344 | yield break; | ||
3345 | } | ||
3346 | } | ||
3347 | } | ||
3348 | { | ||
3349 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"<<"))) | ||
3350 | { | ||
3351 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.bitwiseShiftLeft"))) | ||
3352 | { | ||
3353 | yield return true; | ||
3354 | yield break; | ||
3355 | } | ||
3356 | } | ||
3357 | } | ||
3358 | { | ||
3359 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"/\"))) | ||
3360 | { | ||
3361 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.bitwiseAnd"))) | ||
3362 | { | ||
3363 | yield return true; | ||
3364 | yield break; | ||
3365 | } | ||
3366 | } | ||
3367 | } | ||
3368 | { | ||
3369 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"\/"))) | ||
3370 | { | ||
3371 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.bitwiseOr"))) | ||
3372 | { | ||
3373 | yield return true; | ||
3374 | yield break; | ||
3375 | } | ||
3376 | } | ||
3377 | } | ||
3378 | { | ||
3379 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"min"))) | ||
3380 | { | ||
3381 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.min"))) | ||
3382 | { | ||
3383 | yield return true; | ||
3384 | yield break; | ||
3385 | } | ||
3386 | } | ||
3387 | } | ||
3388 | { | ||
3389 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"max"))) | ||
3390 | { | ||
3391 | foreach (bool l3 in YP.unify(arg2, Atom.a(@"YP.max"))) | ||
3392 | { | ||
3393 | yield return true; | ||
3394 | yield break; | ||
3395 | } | ||
3396 | } | ||
3397 | } | ||
3398 | } | ||
3399 | |||
3400 | public static void convertFunctionCSharp(object arg1) | ||
3401 | { | ||
3402 | { | ||
3403 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"getDeclaringClass"))) | ||
3404 | { | ||
3405 | YP.write(Atom.a(@"class YPInnerClass {}")); | ||
3406 | YP.nl(); | ||
3407 | YP.write(Atom.a(@"static System.Type getDeclaringClass() { return typeof(YPInnerClass).DeclaringType; }")); | ||
3408 | YP.nl(); | ||
3409 | YP.nl(); | ||
3410 | return; | ||
3411 | } | ||
3412 | } | ||
3413 | { | ||
3414 | Variable ReturnType = new Variable(); | ||
3415 | Variable Name = new Variable(); | ||
3416 | Variable ArgList = new Variable(); | ||
3417 | Variable Body = new Variable(); | ||
3418 | Variable Level = new Variable(); | ||
3419 | foreach (bool l2 in YP.unify(arg1, new Functor(@"function", new object[] { ReturnType, Name, ArgList, Body }))) | ||
3420 | { | ||
3421 | YP.write(Atom.a(@"public static ")); | ||
3422 | YP.write(ReturnType); | ||
3423 | YP.write(Atom.a(@" ")); | ||
3424 | YP.write(Name); | ||
3425 | YP.write(Atom.a(@"(")); | ||
3426 | convertArgListCSharp(ArgList); | ||
3427 | YP.write(Atom.a(@") {")); | ||
3428 | YP.nl(); | ||
3429 | foreach (bool l3 in YP.unify(Level, 1)) | ||
3430 | { | ||
3431 | convertStatementListCSharp(Body, Level); | ||
3432 | YP.write(Atom.a(@"}")); | ||
3433 | YP.nl(); | ||
3434 | YP.nl(); | ||
3435 | return; | ||
3436 | } | ||
3437 | } | ||
3438 | } | ||
3439 | } | ||
3440 | |||
3441 | public static IEnumerable<bool> convertStatementListCSharp(object arg1, object x1, object x2) | ||
3442 | { | ||
3443 | { | ||
3444 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
3445 | { | ||
3446 | yield return true; | ||
3447 | yield break; | ||
3448 | } | ||
3449 | } | ||
3450 | } | ||
3451 | |||
3452 | public static void convertStatementListCSharp(object arg1, object Level) | ||
3453 | { | ||
3454 | { | ||
3455 | Variable Name = new Variable(); | ||
3456 | Variable Body = new Variable(); | ||
3457 | Variable RestStatements = new Variable(); | ||
3458 | Variable NewStatements = new Variable(); | ||
3459 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"breakableBlock", Name, Body), RestStatements))) | ||
3460 | { | ||
3461 | foreach (bool l3 in append(Body, new ListPair(new Functor1(@"label", Name), RestStatements), NewStatements)) | ||
3462 | { | ||
3463 | convertStatementListCSharp(NewStatements, Level); | ||
3464 | return; | ||
3465 | } | ||
3466 | } | ||
3467 | } | ||
3468 | { | ||
3469 | Variable Type = new Variable(); | ||
3470 | Variable Name = new Variable(); | ||
3471 | Variable Expression = new Variable(); | ||
3472 | Variable RestStatements = new Variable(); | ||
3473 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3(@"declare", Type, Name, Expression), RestStatements))) | ||
3474 | { | ||
3475 | convertIndentationCSharp(Level); | ||
3476 | YP.write(Type); | ||
3477 | YP.write(Atom.a(@" ")); | ||
3478 | YP.write(Name); | ||
3479 | YP.write(Atom.a(@" = ")); | ||
3480 | convertExpressionCSharp(Expression); | ||
3481 | YP.write(Atom.a(@";")); | ||
3482 | YP.nl(); | ||
3483 | convertStatementListCSharp(RestStatements, Level); | ||
3484 | return; | ||
3485 | } | ||
3486 | } | ||
3487 | { | ||
3488 | Variable Name = new Variable(); | ||
3489 | Variable Expression = new Variable(); | ||
3490 | Variable RestStatements = new Variable(); | ||
3491 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"assign", Name, Expression), RestStatements))) | ||
3492 | { | ||
3493 | convertIndentationCSharp(Level); | ||
3494 | YP.write(Name); | ||
3495 | YP.write(Atom.a(@" = ")); | ||
3496 | convertExpressionCSharp(Expression); | ||
3497 | YP.write(Atom.a(@";")); | ||
3498 | YP.nl(); | ||
3499 | convertStatementListCSharp(RestStatements, Level); | ||
3500 | return; | ||
3501 | } | ||
3502 | } | ||
3503 | { | ||
3504 | Variable RestStatements = new Variable(); | ||
3505 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"yieldtrue"), RestStatements))) | ||
3506 | { | ||
3507 | convertIndentationCSharp(Level); | ||
3508 | YP.write(Atom.a(@"yield return true;")); | ||
3509 | YP.nl(); | ||
3510 | convertStatementListCSharp(RestStatements, Level); | ||
3511 | return; | ||
3512 | } | ||
3513 | } | ||
3514 | { | ||
3515 | Variable RestStatements = new Variable(); | ||
3516 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"yieldfalse"), RestStatements))) | ||
3517 | { | ||
3518 | convertIndentationCSharp(Level); | ||
3519 | YP.write(Atom.a(@"yield return false;")); | ||
3520 | YP.nl(); | ||
3521 | convertStatementListCSharp(RestStatements, Level); | ||
3522 | return; | ||
3523 | } | ||
3524 | } | ||
3525 | { | ||
3526 | Variable RestStatements = new Variable(); | ||
3527 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"yieldbreak"), RestStatements))) | ||
3528 | { | ||
3529 | convertIndentationCSharp(Level); | ||
3530 | YP.write(Atom.a(@"yield break;")); | ||
3531 | YP.nl(); | ||
3532 | convertStatementListCSharp(RestStatements, Level); | ||
3533 | return; | ||
3534 | } | ||
3535 | } | ||
3536 | { | ||
3537 | Variable RestStatements = new Variable(); | ||
3538 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"return"), RestStatements))) | ||
3539 | { | ||
3540 | convertIndentationCSharp(Level); | ||
3541 | YP.write(Atom.a(@"return;")); | ||
3542 | YP.nl(); | ||
3543 | convertStatementListCSharp(RestStatements, Level); | ||
3544 | return; | ||
3545 | } | ||
3546 | } | ||
3547 | { | ||
3548 | Variable RestStatements = new Variable(); | ||
3549 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"returntrue"), RestStatements))) | ||
3550 | { | ||
3551 | convertIndentationCSharp(Level); | ||
3552 | YP.write(Atom.a(@"return true;")); | ||
3553 | YP.nl(); | ||
3554 | convertStatementListCSharp(RestStatements, Level); | ||
3555 | return; | ||
3556 | } | ||
3557 | } | ||
3558 | { | ||
3559 | Variable RestStatements = new Variable(); | ||
3560 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"returnfalse"), RestStatements))) | ||
3561 | { | ||
3562 | convertIndentationCSharp(Level); | ||
3563 | YP.write(Atom.a(@"return false;")); | ||
3564 | YP.nl(); | ||
3565 | convertStatementListCSharp(RestStatements, Level); | ||
3566 | return; | ||
3567 | } | ||
3568 | } | ||
3569 | { | ||
3570 | Variable Name = new Variable(); | ||
3571 | Variable RestStatements = new Variable(); | ||
3572 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1(@"label", Name), RestStatements))) | ||
3573 | { | ||
3574 | convertIndentationCSharp(Level); | ||
3575 | YP.write(Name); | ||
3576 | YP.write(Atom.a(@":")); | ||
3577 | YP.nl(); | ||
3578 | if (YP.termEqual(RestStatements, Atom.NIL)) | ||
3579 | { | ||
3580 | convertIndentationCSharp(Level); | ||
3581 | YP.write(Atom.a(@"{}")); | ||
3582 | YP.nl(); | ||
3583 | convertStatementListCSharp(RestStatements, Level); | ||
3584 | return; | ||
3585 | goto cutIf1; | ||
3586 | } | ||
3587 | convertStatementListCSharp(RestStatements, Level); | ||
3588 | return; | ||
3589 | cutIf1: | ||
3590 | { } | ||
3591 | } | ||
3592 | } | ||
3593 | { | ||
3594 | Variable Name = new Variable(); | ||
3595 | Variable RestStatements = new Variable(); | ||
3596 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1(@"breakBlock", Name), RestStatements))) | ||
3597 | { | ||
3598 | convertIndentationCSharp(Level); | ||
3599 | YP.write(Atom.a(@"goto ")); | ||
3600 | YP.write(Name); | ||
3601 | YP.write(Atom.a(@";")); | ||
3602 | YP.nl(); | ||
3603 | convertStatementListCSharp(RestStatements, Level); | ||
3604 | return; | ||
3605 | } | ||
3606 | } | ||
3607 | { | ||
3608 | Variable Name = new Variable(); | ||
3609 | Variable ArgList = new Variable(); | ||
3610 | Variable RestStatements = new Variable(); | ||
3611 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"call", Name, ArgList), RestStatements))) | ||
3612 | { | ||
3613 | convertIndentationCSharp(Level); | ||
3614 | YP.write(Name); | ||
3615 | YP.write(Atom.a(@"(")); | ||
3616 | convertArgListCSharp(ArgList); | ||
3617 | YP.write(Atom.a(@");")); | ||
3618 | YP.nl(); | ||
3619 | convertStatementListCSharp(RestStatements, Level); | ||
3620 | return; | ||
3621 | } | ||
3622 | } | ||
3623 | { | ||
3624 | Variable Obj = new Variable(); | ||
3625 | Variable Name = new Variable(); | ||
3626 | Variable ArgList = new Variable(); | ||
3627 | Variable RestStatements = new Variable(); | ||
3628 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3(@"callMember", new Functor1(@"var", Obj), Name, ArgList), RestStatements))) | ||
3629 | { | ||
3630 | convertIndentationCSharp(Level); | ||
3631 | YP.write(Obj); | ||
3632 | YP.write(Atom.a(@".")); | ||
3633 | YP.write(Name); | ||
3634 | YP.write(Atom.a(@"(")); | ||
3635 | convertArgListCSharp(ArgList); | ||
3636 | YP.write(Atom.a(@");")); | ||
3637 | YP.nl(); | ||
3638 | convertStatementListCSharp(RestStatements, Level); | ||
3639 | return; | ||
3640 | } | ||
3641 | } | ||
3642 | { | ||
3643 | Variable Body = new Variable(); | ||
3644 | Variable RestStatements = new Variable(); | ||
3645 | Variable NextLevel = new Variable(); | ||
3646 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1(@"blockScope", Body), RestStatements))) | ||
3647 | { | ||
3648 | convertIndentationCSharp(Level); | ||
3649 | YP.write(Atom.a(@"{")); | ||
3650 | YP.nl(); | ||
3651 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
3652 | { | ||
3653 | convertStatementListCSharp(Body, NextLevel); | ||
3654 | convertIndentationCSharp(Level); | ||
3655 | YP.write(Atom.a(@"}")); | ||
3656 | YP.nl(); | ||
3657 | convertStatementListCSharp(RestStatements, Level); | ||
3658 | return; | ||
3659 | } | ||
3660 | } | ||
3661 | } | ||
3662 | { | ||
3663 | Variable Expression = new Variable(); | ||
3664 | Variable Body = new Variable(); | ||
3665 | Variable RestStatements = new Variable(); | ||
3666 | Variable NextLevel = new Variable(); | ||
3667 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"if", Expression, Body), RestStatements))) | ||
3668 | { | ||
3669 | convertIndentationCSharp(Level); | ||
3670 | YP.write(Atom.a(@"if (")); | ||
3671 | convertExpressionCSharp(Expression); | ||
3672 | YP.write(Atom.a(@") {")); | ||
3673 | YP.nl(); | ||
3674 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
3675 | { | ||
3676 | convertStatementListCSharp(Body, NextLevel); | ||
3677 | convertIndentationCSharp(Level); | ||
3678 | YP.write(Atom.a(@"}")); | ||
3679 | YP.nl(); | ||
3680 | convertStatementListCSharp(RestStatements, Level); | ||
3681 | return; | ||
3682 | } | ||
3683 | } | ||
3684 | } | ||
3685 | { | ||
3686 | Variable Expression = new Variable(); | ||
3687 | Variable Body = new Variable(); | ||
3688 | Variable RestStatements = new Variable(); | ||
3689 | Variable NextLevel = new Variable(); | ||
3690 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"foreach", Expression, Body), RestStatements))) | ||
3691 | { | ||
3692 | convertIndentationCSharp(Level); | ||
3693 | YP.write(Atom.a(@"foreach (bool l")); | ||
3694 | YP.write(Level); | ||
3695 | YP.write(Atom.a(@" in ")); | ||
3696 | convertExpressionCSharp(Expression); | ||
3697 | YP.write(Atom.a(@") {")); | ||
3698 | YP.nl(); | ||
3699 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
3700 | { | ||
3701 | convertStatementListCSharp(Body, NextLevel); | ||
3702 | convertIndentationCSharp(Level); | ||
3703 | YP.write(Atom.a(@"}")); | ||
3704 | YP.nl(); | ||
3705 | convertStatementListCSharp(RestStatements, Level); | ||
3706 | return; | ||
3707 | } | ||
3708 | } | ||
3709 | } | ||
3710 | } | ||
3711 | |||
3712 | public static void convertIndentationCSharp(object Level) | ||
3713 | { | ||
3714 | { | ||
3715 | Variable N = new Variable(); | ||
3716 | foreach (bool l2 in YP.unify(N, YP.multiply(Level, 2))) | ||
3717 | { | ||
3718 | repeatWrite(Atom.a(@" "), N); | ||
3719 | return; | ||
3720 | } | ||
3721 | } | ||
3722 | } | ||
3723 | |||
3724 | public static void convertArgListCSharp(object arg1) | ||
3725 | { | ||
3726 | { | ||
3727 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
3728 | { | ||
3729 | return; | ||
3730 | } | ||
3731 | } | ||
3732 | { | ||
3733 | Variable Head = new Variable(); | ||
3734 | Variable Tail = new Variable(); | ||
3735 | foreach (bool l2 in YP.unify(arg1, new ListPair(Head, Tail))) | ||
3736 | { | ||
3737 | convertExpressionCSharp(Head); | ||
3738 | if (YP.termNotEqual(Tail, Atom.NIL)) | ||
3739 | { | ||
3740 | YP.write(Atom.a(@", ")); | ||
3741 | convertArgListCSharp(Tail); | ||
3742 | return; | ||
3743 | goto cutIf1; | ||
3744 | } | ||
3745 | convertArgListCSharp(Tail); | ||
3746 | return; | ||
3747 | cutIf1: | ||
3748 | { } | ||
3749 | } | ||
3750 | } | ||
3751 | } | ||
3752 | |||
3753 | public static void convertExpressionCSharp(object arg1) | ||
3754 | { | ||
3755 | { | ||
3756 | Variable X = new Variable(); | ||
3757 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"arg", X))) | ||
3758 | { | ||
3759 | YP.write(Atom.a(@"object ")); | ||
3760 | YP.write(X); | ||
3761 | return; | ||
3762 | } | ||
3763 | } | ||
3764 | { | ||
3765 | Variable Name = new Variable(); | ||
3766 | Variable ArgList = new Variable(); | ||
3767 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"call", Name, ArgList))) | ||
3768 | { | ||
3769 | YP.write(Name); | ||
3770 | YP.write(Atom.a(@"(")); | ||
3771 | convertArgListCSharp(ArgList); | ||
3772 | YP.write(Atom.a(@")")); | ||
3773 | return; | ||
3774 | } | ||
3775 | } | ||
3776 | { | ||
3777 | Variable Obj = new Variable(); | ||
3778 | Variable Name = new Variable(); | ||
3779 | Variable ArgList = new Variable(); | ||
3780 | foreach (bool l2 in YP.unify(arg1, new Functor3(@"callMember", new Functor1(@"var", Obj), Name, ArgList))) | ||
3781 | { | ||
3782 | YP.write(Obj); | ||
3783 | YP.write(Atom.a(@".")); | ||
3784 | YP.write(Name); | ||
3785 | YP.write(Atom.a(@"(")); | ||
3786 | convertArgListCSharp(ArgList); | ||
3787 | YP.write(Atom.a(@")")); | ||
3788 | return; | ||
3789 | } | ||
3790 | } | ||
3791 | { | ||
3792 | Variable Name = new Variable(); | ||
3793 | Variable ArgList = new Variable(); | ||
3794 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"new", Name, ArgList))) | ||
3795 | { | ||
3796 | YP.write(Atom.a(@"new ")); | ||
3797 | YP.write(Name); | ||
3798 | YP.write(Atom.a(@"(")); | ||
3799 | convertArgListCSharp(ArgList); | ||
3800 | YP.write(Atom.a(@")")); | ||
3801 | return; | ||
3802 | } | ||
3803 | } | ||
3804 | { | ||
3805 | Variable Name = new Variable(); | ||
3806 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"var", Name))) | ||
3807 | { | ||
3808 | YP.write(Name); | ||
3809 | return; | ||
3810 | } | ||
3811 | } | ||
3812 | { | ||
3813 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"null"))) | ||
3814 | { | ||
3815 | YP.write(Atom.a(@"null")); | ||
3816 | return; | ||
3817 | } | ||
3818 | } | ||
3819 | { | ||
3820 | Variable X = new Variable(); | ||
3821 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"not", X))) | ||
3822 | { | ||
3823 | YP.write(Atom.a(@"!(")); | ||
3824 | convertExpressionCSharp(X); | ||
3825 | YP.write(Atom.a(@")")); | ||
3826 | return; | ||
3827 | } | ||
3828 | } | ||
3829 | { | ||
3830 | Variable X = new Variable(); | ||
3831 | Variable Y = new Variable(); | ||
3832 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"and", X, Y))) | ||
3833 | { | ||
3834 | YP.write(Atom.a(@"(")); | ||
3835 | convertExpressionCSharp(X); | ||
3836 | YP.write(Atom.a(@") && (")); | ||
3837 | convertExpressionCSharp(Y); | ||
3838 | YP.write(Atom.a(@")")); | ||
3839 | return; | ||
3840 | } | ||
3841 | } | ||
3842 | { | ||
3843 | Variable ArgList = new Variable(); | ||
3844 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"objectArray", ArgList))) | ||
3845 | { | ||
3846 | YP.write(Atom.a(@"new object[] {")); | ||
3847 | convertArgListCSharp(ArgList); | ||
3848 | YP.write(Atom.a(@"}")); | ||
3849 | return; | ||
3850 | } | ||
3851 | } | ||
3852 | { | ||
3853 | Variable X = new Variable(); | ||
3854 | Variable Codes = new Variable(); | ||
3855 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"object", X))) | ||
3856 | { | ||
3857 | if (YP.atom(X)) | ||
3858 | { | ||
3859 | YP.write(Atom.a(@"@""")); | ||
3860 | foreach (bool l4 in YP.atom_codes(X, Codes)) | ||
3861 | { | ||
3862 | convertStringCodesCSharp(Codes); | ||
3863 | YP.write(Atom.a(@"""")); | ||
3864 | return; | ||
3865 | } | ||
3866 | } | ||
3867 | } | ||
3868 | } | ||
3869 | { | ||
3870 | Variable X = new Variable(); | ||
3871 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"object", X))) | ||
3872 | { | ||
3873 | YP.write(X); | ||
3874 | return; | ||
3875 | } | ||
3876 | } | ||
3877 | } | ||
3878 | |||
3879 | public static void convertStringCodesCSharp(object arg1) | ||
3880 | { | ||
3881 | { | ||
3882 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
3883 | { | ||
3884 | return; | ||
3885 | } | ||
3886 | } | ||
3887 | { | ||
3888 | Variable Code = new Variable(); | ||
3889 | Variable RestCodes = new Variable(); | ||
3890 | foreach (bool l2 in YP.unify(arg1, new ListPair(Code, RestCodes))) | ||
3891 | { | ||
3892 | if (YP.termEqual(Code, 34)) | ||
3893 | { | ||
3894 | YP.put_code(34); | ||
3895 | YP.put_code(Code); | ||
3896 | convertStringCodesCSharp(RestCodes); | ||
3897 | return; | ||
3898 | goto cutIf1; | ||
3899 | } | ||
3900 | YP.put_code(Code); | ||
3901 | convertStringCodesCSharp(RestCodes); | ||
3902 | return; | ||
3903 | cutIf1: | ||
3904 | { } | ||
3905 | } | ||
3906 | } | ||
3907 | } | ||
3908 | |||
3909 | public static void convertFunctionJavascript(object arg1) | ||
3910 | { | ||
3911 | { | ||
3912 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"getDeclaringClass"))) | ||
3913 | { | ||
3914 | YP.write(Atom.a(@"function getDeclaringClass() { return null; }")); | ||
3915 | YP.nl(); | ||
3916 | return; | ||
3917 | } | ||
3918 | } | ||
3919 | { | ||
3920 | Variable x1 = new Variable(); | ||
3921 | Variable Name = new Variable(); | ||
3922 | Variable ArgList = new Variable(); | ||
3923 | Variable Body = new Variable(); | ||
3924 | foreach (bool l2 in YP.unify(arg1, new Functor(@"function", new object[] { x1, Name, ArgList, Body }))) | ||
3925 | { | ||
3926 | YP.write(Atom.a(@"function ")); | ||
3927 | YP.write(Name); | ||
3928 | YP.write(Atom.a(@"(")); | ||
3929 | convertArgListJavascript(ArgList); | ||
3930 | YP.write(Atom.a(@") {")); | ||
3931 | YP.nl(); | ||
3932 | convertStatementListJavascript(Body, 1); | ||
3933 | YP.write(Atom.a(@"}")); | ||
3934 | YP.nl(); | ||
3935 | YP.nl(); | ||
3936 | return; | ||
3937 | } | ||
3938 | } | ||
3939 | } | ||
3940 | |||
3941 | public static void convertStatementListJavascript(object arg1, object arg2) | ||
3942 | { | ||
3943 | { | ||
3944 | object x1 = arg2; | ||
3945 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
3946 | { | ||
3947 | return; | ||
3948 | } | ||
3949 | } | ||
3950 | { | ||
3951 | object Level = arg2; | ||
3952 | Variable Name = new Variable(); | ||
3953 | Variable Body = new Variable(); | ||
3954 | Variable RestStatements = new Variable(); | ||
3955 | Variable NextLevel = new Variable(); | ||
3956 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"breakableBlock", Name, Body), RestStatements))) | ||
3957 | { | ||
3958 | convertIndentationJavascript(Level); | ||
3959 | YP.write(Name); | ||
3960 | YP.write(Atom.a(@":")); | ||
3961 | YP.nl(); | ||
3962 | convertIndentationJavascript(Level); | ||
3963 | YP.write(Atom.a(@"{")); | ||
3964 | YP.nl(); | ||
3965 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
3966 | { | ||
3967 | convertStatementListJavascript(Body, NextLevel); | ||
3968 | convertIndentationJavascript(Level); | ||
3969 | YP.write(Atom.a(@"}")); | ||
3970 | YP.nl(); | ||
3971 | convertStatementListJavascript(RestStatements, Level); | ||
3972 | return; | ||
3973 | } | ||
3974 | } | ||
3975 | } | ||
3976 | { | ||
3977 | object Level = arg2; | ||
3978 | Variable _Type = new Variable(); | ||
3979 | Variable Name = new Variable(); | ||
3980 | Variable Expression = new Variable(); | ||
3981 | Variable RestStatements = new Variable(); | ||
3982 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3(@"declare", _Type, Name, Expression), RestStatements))) | ||
3983 | { | ||
3984 | convertIndentationJavascript(Level); | ||
3985 | YP.write(Atom.a(@"var ")); | ||
3986 | YP.write(Name); | ||
3987 | YP.write(Atom.a(@" = ")); | ||
3988 | convertExpressionJavascript(Expression); | ||
3989 | YP.write(Atom.a(@";")); | ||
3990 | YP.nl(); | ||
3991 | convertStatementListJavascript(RestStatements, Level); | ||
3992 | return; | ||
3993 | } | ||
3994 | } | ||
3995 | { | ||
3996 | object Level = arg2; | ||
3997 | Variable Name = new Variable(); | ||
3998 | Variable Expression = new Variable(); | ||
3999 | Variable RestStatements = new Variable(); | ||
4000 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"assign", Name, Expression), RestStatements))) | ||
4001 | { | ||
4002 | convertIndentationJavascript(Level); | ||
4003 | YP.write(Name); | ||
4004 | YP.write(Atom.a(@" = ")); | ||
4005 | convertExpressionJavascript(Expression); | ||
4006 | YP.write(Atom.a(@";")); | ||
4007 | YP.nl(); | ||
4008 | convertStatementListJavascript(RestStatements, Level); | ||
4009 | return; | ||
4010 | } | ||
4011 | } | ||
4012 | { | ||
4013 | object Level = arg2; | ||
4014 | Variable RestStatements = new Variable(); | ||
4015 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"yieldtrue"), RestStatements))) | ||
4016 | { | ||
4017 | convertIndentationJavascript(Level); | ||
4018 | YP.write(Atom.a(@"yield true;")); | ||
4019 | YP.nl(); | ||
4020 | convertStatementListJavascript(RestStatements, Level); | ||
4021 | return; | ||
4022 | } | ||
4023 | } | ||
4024 | { | ||
4025 | object Level = arg2; | ||
4026 | Variable RestStatements = new Variable(); | ||
4027 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"yieldfalse"), RestStatements))) | ||
4028 | { | ||
4029 | convertIndentationJavascript(Level); | ||
4030 | YP.write(Atom.a(@"yield false;")); | ||
4031 | YP.nl(); | ||
4032 | convertStatementListJavascript(RestStatements, Level); | ||
4033 | return; | ||
4034 | } | ||
4035 | } | ||
4036 | { | ||
4037 | object Level = arg2; | ||
4038 | Variable RestStatements = new Variable(); | ||
4039 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"yieldbreak"), RestStatements))) | ||
4040 | { | ||
4041 | convertIndentationJavascript(Level); | ||
4042 | YP.write(Atom.a(@"return;")); | ||
4043 | YP.nl(); | ||
4044 | convertStatementListJavascript(RestStatements, Level); | ||
4045 | return; | ||
4046 | } | ||
4047 | } | ||
4048 | { | ||
4049 | object Level = arg2; | ||
4050 | Variable RestStatements = new Variable(); | ||
4051 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"return"), RestStatements))) | ||
4052 | { | ||
4053 | convertIndentationJavascript(Level); | ||
4054 | YP.write(Atom.a(@"return;")); | ||
4055 | YP.nl(); | ||
4056 | convertStatementListJavascript(RestStatements, Level); | ||
4057 | return; | ||
4058 | } | ||
4059 | } | ||
4060 | { | ||
4061 | object Level = arg2; | ||
4062 | Variable RestStatements = new Variable(); | ||
4063 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"returntrue"), RestStatements))) | ||
4064 | { | ||
4065 | convertIndentationJavascript(Level); | ||
4066 | YP.write(Atom.a(@"return true;")); | ||
4067 | YP.nl(); | ||
4068 | convertStatementListJavascript(RestStatements, Level); | ||
4069 | return; | ||
4070 | } | ||
4071 | } | ||
4072 | { | ||
4073 | object Level = arg2; | ||
4074 | Variable RestStatements = new Variable(); | ||
4075 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"returnfalse"), RestStatements))) | ||
4076 | { | ||
4077 | convertIndentationJavascript(Level); | ||
4078 | YP.write(Atom.a(@"return false;")); | ||
4079 | YP.nl(); | ||
4080 | convertStatementListJavascript(RestStatements, Level); | ||
4081 | return; | ||
4082 | } | ||
4083 | } | ||
4084 | { | ||
4085 | object Level = arg2; | ||
4086 | Variable Name = new Variable(); | ||
4087 | Variable RestStatements = new Variable(); | ||
4088 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1(@"breakBlock", Name), RestStatements))) | ||
4089 | { | ||
4090 | convertIndentationJavascript(Level); | ||
4091 | YP.write(Atom.a(@"break ")); | ||
4092 | YP.write(Name); | ||
4093 | YP.write(Atom.a(@";")); | ||
4094 | YP.nl(); | ||
4095 | convertStatementListJavascript(RestStatements, Level); | ||
4096 | return; | ||
4097 | } | ||
4098 | } | ||
4099 | { | ||
4100 | object Level = arg2; | ||
4101 | Variable Name = new Variable(); | ||
4102 | Variable ArgList = new Variable(); | ||
4103 | Variable RestStatements = new Variable(); | ||
4104 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"call", Name, ArgList), RestStatements))) | ||
4105 | { | ||
4106 | convertIndentationJavascript(Level); | ||
4107 | YP.write(Name); | ||
4108 | YP.write(Atom.a(@"(")); | ||
4109 | convertArgListJavascript(ArgList); | ||
4110 | YP.write(Atom.a(@");")); | ||
4111 | YP.nl(); | ||
4112 | convertStatementListJavascript(RestStatements, Level); | ||
4113 | return; | ||
4114 | } | ||
4115 | } | ||
4116 | { | ||
4117 | object Level = arg2; | ||
4118 | Variable Obj = new Variable(); | ||
4119 | Variable Name = new Variable(); | ||
4120 | Variable ArgList = new Variable(); | ||
4121 | Variable RestStatements = new Variable(); | ||
4122 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3(@"callMember", new Functor1(@"var", Obj), Name, ArgList), RestStatements))) | ||
4123 | { | ||
4124 | convertIndentationJavascript(Level); | ||
4125 | YP.write(Obj); | ||
4126 | YP.write(Atom.a(@".")); | ||
4127 | YP.write(Name); | ||
4128 | YP.write(Atom.a(@"(")); | ||
4129 | convertArgListJavascript(ArgList); | ||
4130 | YP.write(Atom.a(@");")); | ||
4131 | YP.nl(); | ||
4132 | convertStatementListJavascript(RestStatements, Level); | ||
4133 | return; | ||
4134 | } | ||
4135 | } | ||
4136 | { | ||
4137 | object Level = arg2; | ||
4138 | Variable Body = new Variable(); | ||
4139 | Variable RestStatements = new Variable(); | ||
4140 | Variable NextLevel = new Variable(); | ||
4141 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1(@"blockScope", Body), RestStatements))) | ||
4142 | { | ||
4143 | convertIndentationJavascript(Level); | ||
4144 | YP.write(Atom.a(@"{")); | ||
4145 | YP.nl(); | ||
4146 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
4147 | { | ||
4148 | convertStatementListJavascript(Body, NextLevel); | ||
4149 | convertIndentationJavascript(Level); | ||
4150 | YP.write(Atom.a(@"}")); | ||
4151 | YP.nl(); | ||
4152 | convertStatementListJavascript(RestStatements, Level); | ||
4153 | return; | ||
4154 | } | ||
4155 | } | ||
4156 | } | ||
4157 | { | ||
4158 | object Level = arg2; | ||
4159 | Variable Expression = new Variable(); | ||
4160 | Variable Body = new Variable(); | ||
4161 | Variable RestStatements = new Variable(); | ||
4162 | Variable NextLevel = new Variable(); | ||
4163 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"if", Expression, Body), RestStatements))) | ||
4164 | { | ||
4165 | convertIndentationJavascript(Level); | ||
4166 | YP.write(Atom.a(@"if (")); | ||
4167 | convertExpressionJavascript(Expression); | ||
4168 | YP.write(Atom.a(@") {")); | ||
4169 | YP.nl(); | ||
4170 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
4171 | { | ||
4172 | convertStatementListJavascript(Body, NextLevel); | ||
4173 | convertIndentationJavascript(Level); | ||
4174 | YP.write(Atom.a(@"}")); | ||
4175 | YP.nl(); | ||
4176 | convertStatementListJavascript(RestStatements, Level); | ||
4177 | return; | ||
4178 | } | ||
4179 | } | ||
4180 | } | ||
4181 | { | ||
4182 | object Level = arg2; | ||
4183 | Variable Expression = new Variable(); | ||
4184 | Variable Body = new Variable(); | ||
4185 | Variable RestStatements = new Variable(); | ||
4186 | Variable NextLevel = new Variable(); | ||
4187 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"foreach", Expression, Body), RestStatements))) | ||
4188 | { | ||
4189 | convertIndentationJavascript(Level); | ||
4190 | YP.write(Atom.a(@"for each (var l")); | ||
4191 | YP.write(Level); | ||
4192 | YP.write(Atom.a(@" in ")); | ||
4193 | convertExpressionJavascript(Expression); | ||
4194 | YP.write(Atom.a(@") {")); | ||
4195 | YP.nl(); | ||
4196 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
4197 | { | ||
4198 | convertStatementListJavascript(Body, NextLevel); | ||
4199 | convertIndentationJavascript(Level); | ||
4200 | YP.write(Atom.a(@"}")); | ||
4201 | YP.nl(); | ||
4202 | convertStatementListJavascript(RestStatements, Level); | ||
4203 | return; | ||
4204 | } | ||
4205 | } | ||
4206 | } | ||
4207 | } | ||
4208 | |||
4209 | public static void convertIndentationJavascript(object Level) | ||
4210 | { | ||
4211 | { | ||
4212 | Variable N = new Variable(); | ||
4213 | foreach (bool l2 in YP.unify(N, YP.multiply(Level, 2))) | ||
4214 | { | ||
4215 | repeatWrite(Atom.a(@" "), N); | ||
4216 | return; | ||
4217 | } | ||
4218 | } | ||
4219 | } | ||
4220 | |||
4221 | public static void convertArgListJavascript(object arg1) | ||
4222 | { | ||
4223 | { | ||
4224 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
4225 | { | ||
4226 | return; | ||
4227 | } | ||
4228 | } | ||
4229 | { | ||
4230 | Variable Head = new Variable(); | ||
4231 | Variable Tail = new Variable(); | ||
4232 | foreach (bool l2 in YP.unify(arg1, new ListPair(Head, Tail))) | ||
4233 | { | ||
4234 | convertExpressionJavascript(Head); | ||
4235 | if (YP.termNotEqual(Tail, Atom.NIL)) | ||
4236 | { | ||
4237 | YP.write(Atom.a(@", ")); | ||
4238 | convertArgListJavascript(Tail); | ||
4239 | return; | ||
4240 | goto cutIf1; | ||
4241 | } | ||
4242 | convertArgListJavascript(Tail); | ||
4243 | return; | ||
4244 | cutIf1: | ||
4245 | { } | ||
4246 | } | ||
4247 | } | ||
4248 | } | ||
4249 | |||
4250 | public static void convertExpressionJavascript(object arg1) | ||
4251 | { | ||
4252 | { | ||
4253 | Variable X = new Variable(); | ||
4254 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"arg", X))) | ||
4255 | { | ||
4256 | YP.write(X); | ||
4257 | return; | ||
4258 | } | ||
4259 | } | ||
4260 | { | ||
4261 | Variable Name = new Variable(); | ||
4262 | Variable ArgList = new Variable(); | ||
4263 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"call", Name, ArgList))) | ||
4264 | { | ||
4265 | YP.write(Name); | ||
4266 | YP.write(Atom.a(@"(")); | ||
4267 | convertArgListJavascript(ArgList); | ||
4268 | YP.write(Atom.a(@")")); | ||
4269 | return; | ||
4270 | } | ||
4271 | } | ||
4272 | { | ||
4273 | Variable Obj = new Variable(); | ||
4274 | Variable Name = new Variable(); | ||
4275 | Variable ArgList = new Variable(); | ||
4276 | foreach (bool l2 in YP.unify(arg1, new Functor3(@"callMember", new Functor1(@"var", Obj), Name, ArgList))) | ||
4277 | { | ||
4278 | YP.write(Obj); | ||
4279 | YP.write(Atom.a(@".")); | ||
4280 | YP.write(Name); | ||
4281 | YP.write(Atom.a(@"(")); | ||
4282 | convertArgListJavascript(ArgList); | ||
4283 | YP.write(Atom.a(@")")); | ||
4284 | return; | ||
4285 | } | ||
4286 | } | ||
4287 | { | ||
4288 | Variable Name = new Variable(); | ||
4289 | Variable ArgList = new Variable(); | ||
4290 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"new", Name, ArgList))) | ||
4291 | { | ||
4292 | YP.write(Atom.a(@"new ")); | ||
4293 | YP.write(Name); | ||
4294 | YP.write(Atom.a(@"(")); | ||
4295 | convertArgListJavascript(ArgList); | ||
4296 | YP.write(Atom.a(@")")); | ||
4297 | return; | ||
4298 | } | ||
4299 | } | ||
4300 | { | ||
4301 | Variable Name = new Variable(); | ||
4302 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"var", Name))) | ||
4303 | { | ||
4304 | YP.write(Name); | ||
4305 | return; | ||
4306 | } | ||
4307 | } | ||
4308 | { | ||
4309 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"null"))) | ||
4310 | { | ||
4311 | YP.write(Atom.a(@"null")); | ||
4312 | return; | ||
4313 | } | ||
4314 | } | ||
4315 | { | ||
4316 | Variable X = new Variable(); | ||
4317 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"not", X))) | ||
4318 | { | ||
4319 | YP.write(Atom.a(@"!(")); | ||
4320 | convertExpressionJavascript(X); | ||
4321 | YP.write(Atom.a(@")")); | ||
4322 | return; | ||
4323 | } | ||
4324 | } | ||
4325 | { | ||
4326 | Variable X = new Variable(); | ||
4327 | Variable Y = new Variable(); | ||
4328 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"and", X, Y))) | ||
4329 | { | ||
4330 | YP.write(Atom.a(@"(")); | ||
4331 | convertExpressionJavascript(X); | ||
4332 | YP.write(Atom.a(@") && (")); | ||
4333 | convertExpressionJavascript(Y); | ||
4334 | YP.write(Atom.a(@")")); | ||
4335 | return; | ||
4336 | } | ||
4337 | } | ||
4338 | { | ||
4339 | Variable ArgList = new Variable(); | ||
4340 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"objectArray", ArgList))) | ||
4341 | { | ||
4342 | YP.write(Atom.a(@"[")); | ||
4343 | convertArgListJavascript(ArgList); | ||
4344 | YP.write(Atom.a(@"]")); | ||
4345 | return; | ||
4346 | } | ||
4347 | } | ||
4348 | { | ||
4349 | Variable X = new Variable(); | ||
4350 | Variable Codes = new Variable(); | ||
4351 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"object", X))) | ||
4352 | { | ||
4353 | if (YP.atom(X)) | ||
4354 | { | ||
4355 | YP.write(Atom.a(@"""")); | ||
4356 | foreach (bool l4 in YP.atom_codes(X, Codes)) | ||
4357 | { | ||
4358 | convertStringCodesJavascript(Codes); | ||
4359 | YP.write(Atom.a(@"""")); | ||
4360 | return; | ||
4361 | } | ||
4362 | } | ||
4363 | } | ||
4364 | } | ||
4365 | { | ||
4366 | Variable X = new Variable(); | ||
4367 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"object", X))) | ||
4368 | { | ||
4369 | YP.write(X); | ||
4370 | return; | ||
4371 | } | ||
4372 | } | ||
4373 | } | ||
4374 | |||
4375 | public static void convertStringCodesJavascript(object arg1) | ||
4376 | { | ||
4377 | { | ||
4378 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
4379 | { | ||
4380 | return; | ||
4381 | } | ||
4382 | } | ||
4383 | { | ||
4384 | Variable Code = new Variable(); | ||
4385 | Variable RestCodes = new Variable(); | ||
4386 | foreach (bool l2 in YP.unify(arg1, new ListPair(Code, RestCodes))) | ||
4387 | { | ||
4388 | if (YP.termEqual(Code, 34)) | ||
4389 | { | ||
4390 | YP.put_code(92); | ||
4391 | YP.put_code(Code); | ||
4392 | convertStringCodesJavascript(RestCodes); | ||
4393 | return; | ||
4394 | goto cutIf1; | ||
4395 | } | ||
4396 | if (YP.termEqual(Code, 92)) | ||
4397 | { | ||
4398 | YP.put_code(92); | ||
4399 | YP.put_code(Code); | ||
4400 | convertStringCodesJavascript(RestCodes); | ||
4401 | return; | ||
4402 | goto cutIf1; | ||
4403 | } | ||
4404 | YP.put_code(Code); | ||
4405 | convertStringCodesJavascript(RestCodes); | ||
4406 | return; | ||
4407 | cutIf1: | ||
4408 | { } | ||
4409 | } | ||
4410 | } | ||
4411 | } | ||
4412 | |||
4413 | public static void convertFunctionPython(object arg1) | ||
4414 | { | ||
4415 | { | ||
4416 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"getDeclaringClass"))) | ||
4417 | { | ||
4418 | YP.write(Atom.a(@"def getDeclaringClass():")); | ||
4419 | YP.nl(); | ||
4420 | YP.write(Atom.a(@" return None")); | ||
4421 | YP.nl(); | ||
4422 | YP.nl(); | ||
4423 | return; | ||
4424 | } | ||
4425 | } | ||
4426 | { | ||
4427 | Variable x1 = new Variable(); | ||
4428 | Variable Name = new Variable(); | ||
4429 | Variable ArgList = new Variable(); | ||
4430 | Variable Body = new Variable(); | ||
4431 | Variable Level = new Variable(); | ||
4432 | Variable HasBreakableBlock = new Variable(); | ||
4433 | foreach (bool l2 in YP.unify(arg1, new Functor(@"function", new object[] { x1, Name, ArgList, Body }))) | ||
4434 | { | ||
4435 | YP.write(Atom.a(@"def ")); | ||
4436 | YP.write(Name); | ||
4437 | YP.write(Atom.a(@"(")); | ||
4438 | convertArgListPython(ArgList); | ||
4439 | YP.write(Atom.a(@"):")); | ||
4440 | YP.nl(); | ||
4441 | foreach (bool l3 in YP.unify(Level, 1)) | ||
4442 | { | ||
4443 | if (hasBreakableBlockPython(Body)) | ||
4444 | { | ||
4445 | foreach (bool l5 in YP.unify(HasBreakableBlock, 1)) | ||
4446 | { | ||
4447 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
4448 | { | ||
4449 | convertIndentationPython(Level); | ||
4450 | YP.write(Atom.a(@"doBreak = False")); | ||
4451 | YP.nl(); | ||
4452 | foreach (bool l7 in convertStatementListPython(Body, Level, HasBreakableBlock)) | ||
4453 | { | ||
4454 | YP.nl(); | ||
4455 | return; | ||
4456 | } | ||
4457 | goto cutIf2; | ||
4458 | } | ||
4459 | foreach (bool l6 in convertStatementListPython(Body, Level, HasBreakableBlock)) | ||
4460 | { | ||
4461 | YP.nl(); | ||
4462 | return; | ||
4463 | } | ||
4464 | cutIf2: | ||
4465 | { } | ||
4466 | } | ||
4467 | goto cutIf1; | ||
4468 | } | ||
4469 | foreach (bool l4 in YP.unify(HasBreakableBlock, 0)) | ||
4470 | { | ||
4471 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
4472 | { | ||
4473 | convertIndentationPython(Level); | ||
4474 | YP.write(Atom.a(@"doBreak = False")); | ||
4475 | YP.nl(); | ||
4476 | foreach (bool l6 in convertStatementListPython(Body, Level, HasBreakableBlock)) | ||
4477 | { | ||
4478 | YP.nl(); | ||
4479 | return; | ||
4480 | } | ||
4481 | goto cutIf3; | ||
4482 | } | ||
4483 | foreach (bool l5 in convertStatementListPython(Body, Level, HasBreakableBlock)) | ||
4484 | { | ||
4485 | YP.nl(); | ||
4486 | return; | ||
4487 | } | ||
4488 | cutIf3: | ||
4489 | { } | ||
4490 | } | ||
4491 | cutIf1: | ||
4492 | { } | ||
4493 | } | ||
4494 | } | ||
4495 | } | ||
4496 | } | ||
4497 | |||
4498 | public static bool hasBreakableBlockPython(object arg1) | ||
4499 | { | ||
4500 | { | ||
4501 | Variable _Name = new Variable(); | ||
4502 | Variable _Body = new Variable(); | ||
4503 | Variable _RestStatements = new Variable(); | ||
4504 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"breakableBlock", _Name, _Body), _RestStatements))) | ||
4505 | { | ||
4506 | return true; | ||
4507 | } | ||
4508 | } | ||
4509 | { | ||
4510 | Variable Body = new Variable(); | ||
4511 | Variable _RestStatements = new Variable(); | ||
4512 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1(@"blockScope", Body), _RestStatements))) | ||
4513 | { | ||
4514 | if (hasBreakableBlockPython(Body)) | ||
4515 | { | ||
4516 | return true; | ||
4517 | } | ||
4518 | } | ||
4519 | } | ||
4520 | { | ||
4521 | Variable _Expression = new Variable(); | ||
4522 | Variable Body = new Variable(); | ||
4523 | Variable _RestStatements = new Variable(); | ||
4524 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"if", _Expression, Body), _RestStatements))) | ||
4525 | { | ||
4526 | if (hasBreakableBlockPython(Body)) | ||
4527 | { | ||
4528 | return true; | ||
4529 | } | ||
4530 | } | ||
4531 | } | ||
4532 | { | ||
4533 | Variable _Expression = new Variable(); | ||
4534 | Variable Body = new Variable(); | ||
4535 | Variable _RestStatements = new Variable(); | ||
4536 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"foreach", _Expression, Body), _RestStatements))) | ||
4537 | { | ||
4538 | if (hasBreakableBlockPython(Body)) | ||
4539 | { | ||
4540 | return true; | ||
4541 | } | ||
4542 | } | ||
4543 | } | ||
4544 | { | ||
4545 | Variable x1 = new Variable(); | ||
4546 | Variable RestStatements = new Variable(); | ||
4547 | foreach (bool l2 in YP.unify(arg1, new ListPair(x1, RestStatements))) | ||
4548 | { | ||
4549 | if (hasBreakableBlockPython(RestStatements)) | ||
4550 | { | ||
4551 | return true; | ||
4552 | } | ||
4553 | } | ||
4554 | } | ||
4555 | return false; | ||
4556 | } | ||
4557 | |||
4558 | public static IEnumerable<bool> convertStatementListPython(object arg1, object arg2, object arg3) | ||
4559 | { | ||
4560 | { | ||
4561 | object x1 = arg2; | ||
4562 | object x2 = arg3; | ||
4563 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
4564 | { | ||
4565 | yield return true; | ||
4566 | yield break; | ||
4567 | } | ||
4568 | } | ||
4569 | { | ||
4570 | object Level = arg2; | ||
4571 | object HasBreakableBlock = arg3; | ||
4572 | Variable Name = new Variable(); | ||
4573 | Variable Body = new Variable(); | ||
4574 | Variable RestStatements = new Variable(); | ||
4575 | Variable NextLevel = new Variable(); | ||
4576 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"breakableBlock", Name, Body), RestStatements))) | ||
4577 | { | ||
4578 | convertIndentationPython(Level); | ||
4579 | YP.write(Name); | ||
4580 | YP.write(Atom.a(@" = False")); | ||
4581 | YP.nl(); | ||
4582 | convertIndentationPython(Level); | ||
4583 | YP.write(Atom.a(@"for _ in [1]:")); | ||
4584 | YP.nl(); | ||
4585 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
4586 | { | ||
4587 | foreach (bool l4 in convertStatementListPython(Body, NextLevel, HasBreakableBlock)) | ||
4588 | { | ||
4589 | convertIndentationPython(Level); | ||
4590 | YP.write(Atom.a(@"if ")); | ||
4591 | YP.write(Name); | ||
4592 | YP.write(Atom.a(@":")); | ||
4593 | YP.nl(); | ||
4594 | convertIndentationPython(NextLevel); | ||
4595 | YP.write(Atom.a(@"doBreak = False")); | ||
4596 | YP.nl(); | ||
4597 | convertIndentationPython(Level); | ||
4598 | YP.write(Atom.a(@"if doBreak:")); | ||
4599 | YP.nl(); | ||
4600 | convertIndentationPython(NextLevel); | ||
4601 | YP.write(Atom.a(@"break")); | ||
4602 | YP.nl(); | ||
4603 | foreach (bool l5 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4604 | { | ||
4605 | yield return true; | ||
4606 | yield break; | ||
4607 | } | ||
4608 | } | ||
4609 | } | ||
4610 | } | ||
4611 | } | ||
4612 | { | ||
4613 | object Level = arg2; | ||
4614 | object HasBreakableBlock = arg3; | ||
4615 | Variable _Type = new Variable(); | ||
4616 | Variable Name = new Variable(); | ||
4617 | Variable Expression = new Variable(); | ||
4618 | Variable RestStatements = new Variable(); | ||
4619 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3(@"declare", _Type, Name, Expression), RestStatements))) | ||
4620 | { | ||
4621 | convertIndentationPython(Level); | ||
4622 | YP.write(Name); | ||
4623 | YP.write(Atom.a(@" = ")); | ||
4624 | convertExpressionPython(Expression); | ||
4625 | YP.nl(); | ||
4626 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4627 | { | ||
4628 | yield return true; | ||
4629 | yield break; | ||
4630 | } | ||
4631 | } | ||
4632 | } | ||
4633 | { | ||
4634 | object Level = arg2; | ||
4635 | object HasBreakableBlock = arg3; | ||
4636 | Variable Name = new Variable(); | ||
4637 | Variable Expression = new Variable(); | ||
4638 | Variable RestStatements = new Variable(); | ||
4639 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"assign", Name, Expression), RestStatements))) | ||
4640 | { | ||
4641 | convertIndentationPython(Level); | ||
4642 | YP.write(Name); | ||
4643 | YP.write(Atom.a(@" = ")); | ||
4644 | convertExpressionPython(Expression); | ||
4645 | YP.nl(); | ||
4646 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4647 | { | ||
4648 | yield return true; | ||
4649 | yield break; | ||
4650 | } | ||
4651 | } | ||
4652 | } | ||
4653 | { | ||
4654 | object Level = arg2; | ||
4655 | object HasBreakableBlock = arg3; | ||
4656 | Variable RestStatements = new Variable(); | ||
4657 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"yieldtrue"), RestStatements))) | ||
4658 | { | ||
4659 | convertIndentationPython(Level); | ||
4660 | YP.write(Atom.a(@"yield True")); | ||
4661 | YP.nl(); | ||
4662 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4663 | { | ||
4664 | yield return true; | ||
4665 | yield break; | ||
4666 | } | ||
4667 | } | ||
4668 | } | ||
4669 | { | ||
4670 | object Level = arg2; | ||
4671 | object HasBreakableBlock = arg3; | ||
4672 | Variable RestStatements = new Variable(); | ||
4673 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"yieldfalse"), RestStatements))) | ||
4674 | { | ||
4675 | convertIndentationPython(Level); | ||
4676 | YP.write(Atom.a(@"yield False")); | ||
4677 | YP.nl(); | ||
4678 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4679 | { | ||
4680 | yield return true; | ||
4681 | yield break; | ||
4682 | } | ||
4683 | } | ||
4684 | } | ||
4685 | { | ||
4686 | object Level = arg2; | ||
4687 | object HasBreakableBlock = arg3; | ||
4688 | Variable RestStatements = new Variable(); | ||
4689 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"yieldbreak"), RestStatements))) | ||
4690 | { | ||
4691 | convertIndentationPython(Level); | ||
4692 | YP.write(Atom.a(@"return")); | ||
4693 | YP.nl(); | ||
4694 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4695 | { | ||
4696 | yield return true; | ||
4697 | yield break; | ||
4698 | } | ||
4699 | } | ||
4700 | } | ||
4701 | { | ||
4702 | object Level = arg2; | ||
4703 | object HasBreakableBlock = arg3; | ||
4704 | Variable RestStatements = new Variable(); | ||
4705 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"return"), RestStatements))) | ||
4706 | { | ||
4707 | convertIndentationPython(Level); | ||
4708 | YP.write(Atom.a(@"return")); | ||
4709 | YP.nl(); | ||
4710 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4711 | { | ||
4712 | yield return true; | ||
4713 | yield break; | ||
4714 | } | ||
4715 | } | ||
4716 | } | ||
4717 | { | ||
4718 | object Level = arg2; | ||
4719 | object HasBreakableBlock = arg3; | ||
4720 | Variable RestStatements = new Variable(); | ||
4721 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"returntrue"), RestStatements))) | ||
4722 | { | ||
4723 | convertIndentationPython(Level); | ||
4724 | YP.write(Atom.a(@"return True")); | ||
4725 | YP.nl(); | ||
4726 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4727 | { | ||
4728 | yield return true; | ||
4729 | yield break; | ||
4730 | } | ||
4731 | } | ||
4732 | } | ||
4733 | { | ||
4734 | object Level = arg2; | ||
4735 | object HasBreakableBlock = arg3; | ||
4736 | Variable RestStatements = new Variable(); | ||
4737 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(@"returnfalse"), RestStatements))) | ||
4738 | { | ||
4739 | convertIndentationPython(Level); | ||
4740 | YP.write(Atom.a(@"return False")); | ||
4741 | YP.nl(); | ||
4742 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4743 | { | ||
4744 | yield return true; | ||
4745 | yield break; | ||
4746 | } | ||
4747 | } | ||
4748 | } | ||
4749 | { | ||
4750 | object Level = arg2; | ||
4751 | object HasBreakableBlock = arg3; | ||
4752 | Variable Name = new Variable(); | ||
4753 | Variable RestStatements = new Variable(); | ||
4754 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1(@"breakBlock", Name), RestStatements))) | ||
4755 | { | ||
4756 | convertIndentationPython(Level); | ||
4757 | YP.write(Name); | ||
4758 | YP.write(Atom.a(@" = True")); | ||
4759 | YP.nl(); | ||
4760 | convertIndentationPython(Level); | ||
4761 | YP.write(Atom.a(@"doBreak = True")); | ||
4762 | YP.nl(); | ||
4763 | convertIndentationPython(Level); | ||
4764 | YP.write(Atom.a(@"break")); | ||
4765 | YP.nl(); | ||
4766 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4767 | { | ||
4768 | yield return true; | ||
4769 | yield break; | ||
4770 | } | ||
4771 | } | ||
4772 | } | ||
4773 | { | ||
4774 | object Level = arg2; | ||
4775 | object HasBreakableBlock = arg3; | ||
4776 | Variable Name = new Variable(); | ||
4777 | Variable ArgList = new Variable(); | ||
4778 | Variable RestStatements = new Variable(); | ||
4779 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"call", Name, ArgList), RestStatements))) | ||
4780 | { | ||
4781 | convertIndentationPython(Level); | ||
4782 | YP.write(Name); | ||
4783 | YP.write(Atom.a(@"(")); | ||
4784 | convertArgListPython(ArgList); | ||
4785 | YP.write(Atom.a(@")")); | ||
4786 | YP.nl(); | ||
4787 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4788 | { | ||
4789 | yield return true; | ||
4790 | yield break; | ||
4791 | } | ||
4792 | } | ||
4793 | } | ||
4794 | { | ||
4795 | object Level = arg2; | ||
4796 | object HasBreakableBlock = arg3; | ||
4797 | Variable Obj = new Variable(); | ||
4798 | Variable Name = new Variable(); | ||
4799 | Variable ArgList = new Variable(); | ||
4800 | Variable RestStatements = new Variable(); | ||
4801 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3(@"callMember", new Functor1(@"var", Obj), Name, ArgList), RestStatements))) | ||
4802 | { | ||
4803 | convertIndentationPython(Level); | ||
4804 | YP.write(Obj); | ||
4805 | YP.write(Atom.a(@".")); | ||
4806 | YP.write(Name); | ||
4807 | YP.write(Atom.a(@"(")); | ||
4808 | convertArgListPython(ArgList); | ||
4809 | YP.write(Atom.a(@")")); | ||
4810 | YP.nl(); | ||
4811 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4812 | { | ||
4813 | yield return true; | ||
4814 | yield break; | ||
4815 | } | ||
4816 | } | ||
4817 | } | ||
4818 | { | ||
4819 | object Level = arg2; | ||
4820 | object HasBreakableBlock = arg3; | ||
4821 | Variable Body = new Variable(); | ||
4822 | Variable RestStatements = new Variable(); | ||
4823 | Variable NextLevel = new Variable(); | ||
4824 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1(@"blockScope", Body), RestStatements))) | ||
4825 | { | ||
4826 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
4827 | { | ||
4828 | convertIndentationPython(Level); | ||
4829 | YP.write(Atom.a(@"for _ in [1]:")); | ||
4830 | YP.nl(); | ||
4831 | foreach (bool l4 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
4832 | { | ||
4833 | foreach (bool l5 in convertStatementListPython(Body, NextLevel, HasBreakableBlock)) | ||
4834 | { | ||
4835 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
4836 | { | ||
4837 | if (YP.greaterThan(Level, 1)) | ||
4838 | { | ||
4839 | convertIndentationPython(Level); | ||
4840 | YP.write(Atom.a(@"if doBreak:")); | ||
4841 | YP.nl(); | ||
4842 | convertIndentationPython(NextLevel); | ||
4843 | YP.write(Atom.a(@"break")); | ||
4844 | YP.nl(); | ||
4845 | foreach (bool l8 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4846 | { | ||
4847 | yield return true; | ||
4848 | yield break; | ||
4849 | } | ||
4850 | goto cutIf3; | ||
4851 | } | ||
4852 | foreach (bool l7 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4853 | { | ||
4854 | yield return true; | ||
4855 | yield break; | ||
4856 | } | ||
4857 | cutIf3: | ||
4858 | goto cutIf2; | ||
4859 | } | ||
4860 | foreach (bool l6 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4861 | { | ||
4862 | yield return true; | ||
4863 | yield break; | ||
4864 | } | ||
4865 | cutIf2: | ||
4866 | { } | ||
4867 | } | ||
4868 | } | ||
4869 | goto cutIf1; | ||
4870 | } | ||
4871 | foreach (bool l3 in YP.unify(NextLevel, Level)) | ||
4872 | { | ||
4873 | foreach (bool l4 in convertStatementListPython(Body, NextLevel, HasBreakableBlock)) | ||
4874 | { | ||
4875 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
4876 | { | ||
4877 | if (YP.greaterThan(Level, 1)) | ||
4878 | { | ||
4879 | convertIndentationPython(Level); | ||
4880 | YP.write(Atom.a(@"if doBreak:")); | ||
4881 | YP.nl(); | ||
4882 | convertIndentationPython(NextLevel); | ||
4883 | YP.write(Atom.a(@"break")); | ||
4884 | YP.nl(); | ||
4885 | foreach (bool l7 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4886 | { | ||
4887 | yield return true; | ||
4888 | yield break; | ||
4889 | } | ||
4890 | goto cutIf5; | ||
4891 | } | ||
4892 | foreach (bool l6 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4893 | { | ||
4894 | yield return true; | ||
4895 | yield break; | ||
4896 | } | ||
4897 | cutIf5: | ||
4898 | goto cutIf4; | ||
4899 | } | ||
4900 | foreach (bool l5 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4901 | { | ||
4902 | yield return true; | ||
4903 | yield break; | ||
4904 | } | ||
4905 | cutIf4: | ||
4906 | { } | ||
4907 | } | ||
4908 | } | ||
4909 | cutIf1: | ||
4910 | { } | ||
4911 | } | ||
4912 | } | ||
4913 | { | ||
4914 | object Level = arg2; | ||
4915 | object HasBreakableBlock = arg3; | ||
4916 | Variable Expression = new Variable(); | ||
4917 | Variable Body = new Variable(); | ||
4918 | Variable RestStatements = new Variable(); | ||
4919 | Variable NextLevel = new Variable(); | ||
4920 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"if", Expression, Body), RestStatements))) | ||
4921 | { | ||
4922 | convertIndentationPython(Level); | ||
4923 | YP.write(Atom.a(@"if ")); | ||
4924 | convertExpressionPython(Expression); | ||
4925 | YP.write(Atom.a(@":")); | ||
4926 | YP.nl(); | ||
4927 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
4928 | { | ||
4929 | foreach (bool l4 in convertStatementListPython(Body, NextLevel, HasBreakableBlock)) | ||
4930 | { | ||
4931 | foreach (bool l5 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4932 | { | ||
4933 | yield return true; | ||
4934 | yield break; | ||
4935 | } | ||
4936 | } | ||
4937 | } | ||
4938 | } | ||
4939 | } | ||
4940 | { | ||
4941 | object Level = arg2; | ||
4942 | object HasBreakableBlock = arg3; | ||
4943 | Variable Expression = new Variable(); | ||
4944 | Variable Body = new Variable(); | ||
4945 | Variable RestStatements = new Variable(); | ||
4946 | Variable NextLevel = new Variable(); | ||
4947 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2(@"foreach", Expression, Body), RestStatements))) | ||
4948 | { | ||
4949 | convertIndentationPython(Level); | ||
4950 | YP.write(Atom.a(@"for l")); | ||
4951 | YP.write(Level); | ||
4952 | YP.write(Atom.a(@" in ")); | ||
4953 | convertExpressionPython(Expression); | ||
4954 | YP.write(Atom.a(@":")); | ||
4955 | YP.nl(); | ||
4956 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
4957 | { | ||
4958 | foreach (bool l4 in convertStatementListPython(Body, NextLevel, HasBreakableBlock)) | ||
4959 | { | ||
4960 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
4961 | { | ||
4962 | convertIndentationPython(Level); | ||
4963 | YP.write(Atom.a(@"if doBreak:")); | ||
4964 | YP.nl(); | ||
4965 | convertIndentationPython(NextLevel); | ||
4966 | YP.write(Atom.a(@"break")); | ||
4967 | YP.nl(); | ||
4968 | foreach (bool l6 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4969 | { | ||
4970 | yield return true; | ||
4971 | yield break; | ||
4972 | } | ||
4973 | goto cutIf6; | ||
4974 | } | ||
4975 | foreach (bool l5 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
4976 | { | ||
4977 | yield return true; | ||
4978 | yield break; | ||
4979 | } | ||
4980 | cutIf6: | ||
4981 | { } | ||
4982 | } | ||
4983 | } | ||
4984 | } | ||
4985 | } | ||
4986 | } | ||
4987 | |||
4988 | public static void convertIndentationPython(object Level) | ||
4989 | { | ||
4990 | { | ||
4991 | Variable N = new Variable(); | ||
4992 | foreach (bool l2 in YP.unify(N, YP.multiply(Level, 2))) | ||
4993 | { | ||
4994 | repeatWrite(Atom.a(@" "), N); | ||
4995 | return; | ||
4996 | } | ||
4997 | } | ||
4998 | } | ||
4999 | |||
5000 | public static void convertArgListPython(object arg1) | ||
5001 | { | ||
5002 | { | ||
5003 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
5004 | { | ||
5005 | return; | ||
5006 | } | ||
5007 | } | ||
5008 | { | ||
5009 | Variable Head = new Variable(); | ||
5010 | Variable Tail = new Variable(); | ||
5011 | foreach (bool l2 in YP.unify(arg1, new ListPair(Head, Tail))) | ||
5012 | { | ||
5013 | convertExpressionPython(Head); | ||
5014 | if (YP.termNotEqual(Tail, Atom.NIL)) | ||
5015 | { | ||
5016 | YP.write(Atom.a(@", ")); | ||
5017 | convertArgListPython(Tail); | ||
5018 | return; | ||
5019 | goto cutIf1; | ||
5020 | } | ||
5021 | convertArgListPython(Tail); | ||
5022 | return; | ||
5023 | cutIf1: | ||
5024 | { } | ||
5025 | } | ||
5026 | } | ||
5027 | } | ||
5028 | |||
5029 | public static void convertExpressionPython(object arg1) | ||
5030 | { | ||
5031 | { | ||
5032 | Variable X = new Variable(); | ||
5033 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"arg", X))) | ||
5034 | { | ||
5035 | YP.write(X); | ||
5036 | return; | ||
5037 | } | ||
5038 | } | ||
5039 | { | ||
5040 | Variable Name = new Variable(); | ||
5041 | Variable ArgList = new Variable(); | ||
5042 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"call", Name, ArgList))) | ||
5043 | { | ||
5044 | YP.write(Name); | ||
5045 | YP.write(Atom.a(@"(")); | ||
5046 | convertArgListPython(ArgList); | ||
5047 | YP.write(Atom.a(@")")); | ||
5048 | return; | ||
5049 | } | ||
5050 | } | ||
5051 | { | ||
5052 | Variable Obj = new Variable(); | ||
5053 | Variable Name = new Variable(); | ||
5054 | Variable ArgList = new Variable(); | ||
5055 | foreach (bool l2 in YP.unify(arg1, new Functor3(@"callMember", new Functor1(@"var", Obj), Name, ArgList))) | ||
5056 | { | ||
5057 | YP.write(Obj); | ||
5058 | YP.write(Atom.a(@".")); | ||
5059 | YP.write(Name); | ||
5060 | YP.write(Atom.a(@"(")); | ||
5061 | convertArgListPython(ArgList); | ||
5062 | YP.write(Atom.a(@")")); | ||
5063 | return; | ||
5064 | } | ||
5065 | } | ||
5066 | { | ||
5067 | Variable Name = new Variable(); | ||
5068 | Variable ArgList = new Variable(); | ||
5069 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"new", Name, ArgList))) | ||
5070 | { | ||
5071 | YP.write(Name); | ||
5072 | YP.write(Atom.a(@"(")); | ||
5073 | convertArgListPython(ArgList); | ||
5074 | YP.write(Atom.a(@")")); | ||
5075 | return; | ||
5076 | } | ||
5077 | } | ||
5078 | { | ||
5079 | Variable Name = new Variable(); | ||
5080 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"var", Name))) | ||
5081 | { | ||
5082 | YP.write(Name); | ||
5083 | return; | ||
5084 | } | ||
5085 | } | ||
5086 | { | ||
5087 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"null"))) | ||
5088 | { | ||
5089 | YP.write(Atom.a(@"None")); | ||
5090 | return; | ||
5091 | } | ||
5092 | } | ||
5093 | { | ||
5094 | Variable X = new Variable(); | ||
5095 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"not", X))) | ||
5096 | { | ||
5097 | YP.write(Atom.a(@"not (")); | ||
5098 | convertExpressionPython(X); | ||
5099 | YP.write(Atom.a(@")")); | ||
5100 | return; | ||
5101 | } | ||
5102 | } | ||
5103 | { | ||
5104 | Variable X = new Variable(); | ||
5105 | Variable Y = new Variable(); | ||
5106 | foreach (bool l2 in YP.unify(arg1, new Functor2(@"and", X, Y))) | ||
5107 | { | ||
5108 | YP.write(Atom.a(@"(")); | ||
5109 | convertExpressionPython(X); | ||
5110 | YP.write(Atom.a(@") and (")); | ||
5111 | convertExpressionPython(Y); | ||
5112 | YP.write(Atom.a(@")")); | ||
5113 | return; | ||
5114 | } | ||
5115 | } | ||
5116 | { | ||
5117 | Variable ArgList = new Variable(); | ||
5118 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"objectArray", ArgList))) | ||
5119 | { | ||
5120 | YP.write(Atom.a(@"[")); | ||
5121 | convertArgListPython(ArgList); | ||
5122 | YP.write(Atom.a(@"]")); | ||
5123 | return; | ||
5124 | } | ||
5125 | } | ||
5126 | { | ||
5127 | Variable X = new Variable(); | ||
5128 | Variable Codes = new Variable(); | ||
5129 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"object", X))) | ||
5130 | { | ||
5131 | if (YP.atom(X)) | ||
5132 | { | ||
5133 | YP.write(Atom.a(@"""")); | ||
5134 | foreach (bool l4 in YP.atom_codes(X, Codes)) | ||
5135 | { | ||
5136 | convertStringCodesPython(Codes); | ||
5137 | YP.write(Atom.a(@"""")); | ||
5138 | return; | ||
5139 | } | ||
5140 | } | ||
5141 | } | ||
5142 | } | ||
5143 | { | ||
5144 | Variable X = new Variable(); | ||
5145 | foreach (bool l2 in YP.unify(arg1, new Functor1(@"object", X))) | ||
5146 | { | ||
5147 | YP.write(X); | ||
5148 | return; | ||
5149 | } | ||
5150 | } | ||
5151 | } | ||
5152 | |||
5153 | public static void convertStringCodesPython(object arg1) | ||
5154 | { | ||
5155 | { | ||
5156 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
5157 | { | ||
5158 | return; | ||
5159 | } | ||
5160 | } | ||
5161 | { | ||
5162 | Variable Code = new Variable(); | ||
5163 | Variable RestCodes = new Variable(); | ||
5164 | foreach (bool l2 in YP.unify(arg1, new ListPair(Code, RestCodes))) | ||
5165 | { | ||
5166 | if (YP.termEqual(Code, 34)) | ||
5167 | { | ||
5168 | YP.put_code(92); | ||
5169 | YP.put_code(Code); | ||
5170 | convertStringCodesPython(RestCodes); | ||
5171 | return; | ||
5172 | goto cutIf1; | ||
5173 | } | ||
5174 | if (YP.termEqual(Code, 92)) | ||
5175 | { | ||
5176 | YP.put_code(92); | ||
5177 | YP.put_code(Code); | ||
5178 | convertStringCodesPython(RestCodes); | ||
5179 | return; | ||
5180 | goto cutIf1; | ||
5181 | } | ||
5182 | YP.put_code(Code); | ||
5183 | convertStringCodesPython(RestCodes); | ||
5184 | return; | ||
5185 | cutIf1: | ||
5186 | { } | ||
5187 | } | ||
5188 | } | ||
5189 | } | ||
5190 | |||
5191 | public static IEnumerable<bool> member(object X, object arg2) | ||
5192 | { | ||
5193 | { | ||
5194 | Variable x2 = new Variable(); | ||
5195 | foreach (bool l2 in YP.unify(arg2, new ListPair(X, x2))) | ||
5196 | { | ||
5197 | yield return false; | ||
5198 | } | ||
5199 | } | ||
5200 | { | ||
5201 | Variable x2 = new Variable(); | ||
5202 | Variable Rest = new Variable(); | ||
5203 | foreach (bool l2 in YP.unify(arg2, new ListPair(x2, Rest))) | ||
5204 | { | ||
5205 | foreach (bool l3 in member(X, Rest)) | ||
5206 | { | ||
5207 | yield return false; | ||
5208 | } | ||
5209 | } | ||
5210 | } | ||
5211 | } | ||
5212 | |||
5213 | public static IEnumerable<bool> append(object arg1, object arg2, object arg3) | ||
5214 | { | ||
5215 | { | ||
5216 | Variable List = new Variable(); | ||
5217 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
5218 | { | ||
5219 | foreach (bool l3 in YP.unify(arg2, List)) | ||
5220 | { | ||
5221 | foreach (bool l4 in YP.unify(arg3, List)) | ||
5222 | { | ||
5223 | yield return false; | ||
5224 | } | ||
5225 | } | ||
5226 | } | ||
5227 | } | ||
5228 | { | ||
5229 | object List2 = arg2; | ||
5230 | Variable X = new Variable(); | ||
5231 | Variable List1 = new Variable(); | ||
5232 | Variable List12 = new Variable(); | ||
5233 | foreach (bool l2 in YP.unify(arg1, new ListPair(X, List1))) | ||
5234 | { | ||
5235 | foreach (bool l3 in YP.unify(arg3, new ListPair(X, List12))) | ||
5236 | { | ||
5237 | foreach (bool l4 in append(List1, List2, List12)) | ||
5238 | { | ||
5239 | yield return false; | ||
5240 | } | ||
5241 | } | ||
5242 | } | ||
5243 | } | ||
5244 | } | ||
5245 | |||
5246 | } | ||
5247 | } | ||