+ private Xex.Term parse_cond (MPlist plist)
+ {
+ Xex.Term[] args = new Xex.Term[plist.Count];
+
+ for (int i = 0; ! plist.IsEmpty; i++, plist = plist.next)
+ {
+ if (! plist.IsPlist)
+ throw new Exception ("Invalid cond args: " + plist);
+ MPlist p = plist.Plist;
+ List<Xex.Term> arg = new List<Xex.Term> (parse_action (p));
+ args[i] = new Xex.Term (arg);
+ }
+ return new Xex.Term (domain, (Xex.Symbol) Mcond.Name, args);
+ }
+
+ private Xex.Term[] parse_action (MPlist plist)
+ {
+ Xex.Term[] terms = new Xex.Term[plist.Count];
+
+ for (int i = 0; ! plist.IsEmpty; i++, plist = plist.next)
+ {
+ if (plist.IsSymbol)
+ terms[i] = new Xex.Term ((Xex.Symbol) plist.Symbol.Name);
+ else if (plist.IsMText)
+ terms[i] = new Xex.Term ((string) plist.Text);
+ else if (plist.IsInteger)
+ terms[i] = new Xex.Term (plist.Integer);
+ else if (plist.IsPlist)
+ {
+ MPlist p = plist.Plist;
+ if (! p.IsSymbol)
+ throw new Exception ("Invalid action: " + p);
+ MSymbol name = p.Symbol;
+ p = p.next;
+ if (name == Mcond)
+ terms[i] = parse_cond (p);
+ else if (name == Mset || name == Madd || name == Msub
+ || name == Mmul || name == Mdiv)
+ {
+ if (! p.IsSymbol)
+ throw new Exception ("Invalid action: " + p);
+ Xex.Symbol varname = p.Symbol.Name;
+ terms[i] = new Xex.Term (domain, (Xex.Symbol) name.Name,
+ varname, parse_action (p.next));
+ }
+ else
+ terms[i] = new Xex.Term (domain, (Xex.Symbol) name.Name,
+ parse_action (p));
+ }
+ else
+ throw new Exception ("Invalid action: " + plist);
+ }
+ return terms;
+ }
+
+