{
public class Xex
{
- public struct Name
+ public struct Name : IEquatable<Name>
{
private static NameTable nt = new NameTable ();
name = nt.Add (str);
}
- public Name (XmlAttribute attr)
- {
- name = nt.Add (attr.Value);
- }
-
- public Name (XmlNode node)
- {
- name = node.Name;
- }
-
public static implicit operator Name (string str)
{
return new Name (str);
}
- public static implicit operator Name (XmlAttribute attr)
- {
- return new Name (attr);
- }
-
- public static implicit operator Name (XmlNode node)
- {
- return new Name (node);
- }
-
public static implicit operator string (Name name)
{
return name.name;
return (object) n1.name == (object) n2.name;
}
- public static bool operator== (Name n1, string n2)
- {
- return (object) n1.name == (object) n2;
- }
-
- public static bool operator== (string n1, Name n2)
+ public static bool operator!= (Name n1, Name n2)
{
- return (object) n1 == (object) n2.name;
+ return (object) n1.name != (object) n2.name;
}
- public static bool operator!= (Name n1, Name n2)
+ public static bool operator== (Name n1, string n2)
{
- return (object) n1.name != (object) n2.name;
+ return (object) n1.name == (object) n2;
}
public static bool operator!= (Name n1, string n2)
return (object) n1.name != (object) n2;
}
- public static bool operator!= (string n1, Name n2)
- {
- return (object) n1 != (object) n2.name;
- }
+ public bool Equals (Name name)
+ {
+ Console.WriteLine ("Equals ({0}, {1})", this, name);
+ bool result = Object.ReferenceEquals (this.name, name.name);
+ Console.WriteLine (result);
+ return result;
+ }
- public override bool Equals (object other)
+ public override bool Equals (object obj)
{
- Console.WriteLine ("Equals (object)");
- return Object.ReferenceEquals (this, other);
+ Console.WriteLine ("Equals ({0}, {1})", this, obj);
+ bool result = Object.ReferenceEquals (this.name, obj);
+ Console.WriteLine (result);
+ return result;
}
public override int GetHashCode ()
}
public static NameTable Table { get { return nt; } }
+
+ public override string ToString () { return name; }
}
+ private static Name Nexpr = "expr";
+ private static Name Nargs = "args";
+
private static Name Ninteger = "integer";
private static Name Nstring = "string";
private static Name Nboolean = "boolean";
XmlNodeList body = node.ChildNodes;
int idx = 0;
- if (body[0].Name == "args")
+ if (Nargs == body[0].Name)
{
XmlNodeList args = body[0].ChildNodes;
if (this.args == null)
}
}
+#if false
internal class ThrowException : Exception
{
Name tag;
this.value = value;
}
}
+#endif
public class Domain
{
internal Domain () { }
- public Domain (object context) : this (basic, context) { }
+ public Domain (object context) : this (basic, context)
+ {
+ Console.WriteLine (basic);
+ }
public Domain (Domain parent, object context)
{
public void Defun (XmlNode node)
{
- Name name = node.Attributes["id"];
+ Name name = node.Attributes["id"].Value;
Function func;
if (functions.TryGetValue (name, out func))
str += ") (variabls";
foreach (KeyValuePair<Name, Variable> kv in variables)
str += " " + kv.Key;
- str += " " + bindings;
+ str += ")";
+ if (bindings != null)
+ str += " " + bindings;
if (context != null)
str += " (" + context + ")";
str += ">";
basic.Defun ("||", or, 1, -1, false);
basic.Defun ("not", not, 1, 1, false);
basic.Defun ("!", not, 1, 1, false);
+ basic.Defun ("add", add, 2, -1, false);
basic.Defun ("+", add, 2, -1, false);
+ basic.Defun ("mul", mul, 2, -1, false);
basic.Defun ("*", mul, 2, -1, false);
+ basic.Defun ("sub", sub, 1, -1, false);
basic.Defun ("-", sub, 1, -1, false);
+ basic.Defun ("div", div, 2, -1, false);
basic.Defun ("/", div, 2, -1, false);
+ basic.Defun ("mod", mod, 2, 2, false);
basic.Defun ("%", mod, 2, 2, false);
+ basic.Defun ("logior", logior, 2, -1, false);
basic.Defun ("|", logior, 2, -1, false);
+ basic.Defun ("logand", logand, 2, -1, false);
basic.Defun ("&", logand, 2, -1, false);
+ basic.Defun ("add-set", add_set, 2, -1, true);
basic.Defun ("+=", add_set, 2, -1, true);
+ basic.Defun ("mul-set", mul_set, 2, -1, true);
basic.Defun ("*=", mul_set, 2, -1, true);
+ basic.Defun ("sub-set", sub_set, 2, -1, true);
basic.Defun ("-=", sub_set, 2, -1, true);
+ basic.Defun ("div-set", div_set, 2, -1, true);
basic.Defun ("/=", div_set, 2, -1, true);
+ basic.Defun ("mod-set", mod_set, 2, 2, true);
basic.Defun ("%=", mod_set, 2, 2, true);
+ basic.Defun ("logior-set", logior_set, 2, -1, true);
basic.Defun ("|=", logior_set, 2, -1, true);
+ basic.Defun ("logand-set", logand_set, 2, -1, true);
basic.Defun ("&=", logand_set, 2, -1, true);
+ basic.Defun ("lsh", lsh, 2, 2, false);
basic.Defun ("<<", lsh, 2, 2, false);
+ basic.Defun ("rsh", rsh, 2, 2, false);
basic.Defun (">>", rsh, 2, 2, false);
+ basic.Defun ("lsh-set", lsh_set, 2, 2, true);
basic.Defun ("<<=", lsh_set, 2, 2, true);
+ basic.Defun ("rsh-set", rsh_set, 2, 2, true);
basic.Defun (">>=", rsh_set, 2, 2, true);
+ basic.Defun ("eq", eq, 2, -1, false);
basic.Defun ("==", eq, 2, -1, false);
+ basic.Defun ("noteq", noteq, 2, 2, false);
basic.Defun ("!=", noteq, 2, 2, false);
+ basic.Defun ("lt", less_than, 2, -1, false);
basic.Defun ("<", less_than, 2, -1, false);
+ basic.Defun ("le", less_eq, 2, -1, false);
basic.Defun ("<=", less_eq, 2, -1, false);
+ basic.Defun ("gt", greater_than, 2, -1, false);
basic.Defun (">", greater_than, 2, -1, false);
+ basic.Defun ("ge", greater_eq, 2, -1, false);
basic.Defun (">=", greater_eq, 2, -1, false);
basic.Defun ("progn", progn_clause, 0, -1, true);
+ basic.Defun ("expr", progn_clause, 0, -1, true);
basic.Defun ("if", if_clause, 2, -1, true);
basic.Defun ("when", when_clause, 1, -1, true);
basic.Defun ("while", while_clause, 1, -1, true);
return xex;
}
- // EXPR = SYMBOL | MTEXT | INTEGER | FUNCALL | PROGN
- // FUNCALL = '(' SYMBOL EXPR* ')'
- // PROGN = '(' EXPR * ')'
- public Xex (XmlNode node, Domain domain)
+ private void Setup (XmlNode node, Domain domain)
{
Name name = node.Name;
}
}
+ public Xex (string url, Domain domain)
+ {
+ XmlDocument doc = new XmlDocument (Name.Table);
+ XmlNode node;
+
+ using (XmlTextReader reader = new XmlTextReader (url, Name.Table))
+ {
+ do {
+ reader.Read ();
+ } while (reader.NodeType != XmlNodeType.None
+ && (reader.NodeType != XmlNodeType.Element
+ || (object) Nexpr != (object) reader.Name));
+ if (reader.NodeType != XmlNodeType.None)
+ throw new Exception ("Node <expr> not found");
+ Console.WriteLine (doc.ReadNode (reader).OuterXml);
+ node = doc.ReadNode (reader);
+ Console.WriteLine ("node read:" + node.OuterXml);
+ }
+
+ Setup (node, domain);
+ }
+
+
+ // EXPR = SYMBOL | MTEXT | INTEGER | FUNCALL | PROGN
+ // FUNCALL = '(' SYMBOL EXPR* ')'
+ // PROGN = '(' EXPR * ')'
+ public Xex (XmlNode node, Domain domain)
+ {
+ Setup (node, domain);
+ }
+
private int parse_integer (string str)
{
int len = str.Length;