From: handa Date: Fri, 17 Jul 2009 13:09:10 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04d20a4293c7fb0db73511e9e6009cf4d4d2a9bd;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/MExpression.cs b/MExpression.cs new file mode 100644 index 0000000..3c43747 --- /dev/null +++ b/MExpression.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using M17N; +using M17N.Core; + +namespace M17N.Core +{ + public delegate object MEvaluator (MExpression args); + + public class MFunction + { + internal readonly MSymbol name; + internal readonly MEvaluator evaluator; + public static Dictionary CommonTable + = new Dictionary (); + + public MFunction (MSymbol name, MEvaluator evaluator) + { + this.evaluator = evaluator; + CommonTable[name] = this; + } + + public MFunction (MSymbol name, MEvaluator evaluator, + Dictionary dict) + { + this.evaluator = evaluator; + dict[name] = this; + } + + public object Call (MExpression args) + { + return evaluator (args); + } + + private object plus (MExpression args) + { + int n = 0; + foreach (MExpression expr in args) + n += expr.Eval (bindings); + return n; + } + + private object multiply (MExpression args) + { + int n = 1; + foreach (MExpression expr in args) + n *= expr.Eval (bindings); + return n; + } + +#if false + if (key == Mminus) + { + int n = - Plist.Eval (env); + foreach (MPlist plist in Plist.next) + n -= plist.Eval (env); + return n; + } + if (key == Mslash) + { + int n = Plist.Eval (env); + foreach (MPlist plist in Plist.next) + n /= plist.Eval (env); + return n; + } + if (key == Mpercent) + { + return Plist.Eval (env) % Plist.next.Eval (env); + } + if (key == Mlogior) + { + return Plist.Eval (env) | Plist.next.Eval (env); + } + if (key == Mlogand) + { + return Plist.Eval (env) & Plist.next.Eval (env); + } + if (key == Mlshift) + { + return Plist.Eval (env) << Plist.next.Eval (env); + } + if (key == Mrshift) + { + return Plist.Eval (env) >> Plist.next.Eval (env); + } + if (key == Mset) + { + MSymbol var = (MSymbol) Plist.val; + + } +#endif + } + + public class MBindings : MPlist + { + public MBindings () : base () { } + + public new MBindings Push (MSymbol variable, object value) + { + base.Push (variable, value); + } + + public override string ToString () + { + string str = "("; + foreach (MBindings b in this) + { + if (b != this) + str += ", "; + str += b.key + " = " + b.val; + } + return str + ")"; + } + } + + public class MExpression : MPlist + { + public MExpression () : base () { } + + public MExpression Append (MFunction func, MExpression args) + { + base.Add (op, (MPlist) args); + return this; + } + + public object Eval () + { + + + } + } +} \ No newline at end of file diff --git a/MPlist.cs b/MPlist.cs index 480c9d2..0535d86 100644 --- a/MPlist.cs +++ b/MPlist.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using System.IO; using M17N; using M17N.Core; @@ -8,25 +9,36 @@ namespace M17N.Core { public class MPlist : IEnumerable { - public MSymbol Key; - public object Val; + public MSymbol key; + public object val; private MPlist next; + public MSymbol Key { get { return key; } } + public object Val { get { return val; } } + public MPlist Next { get { return next; } } + + private static List wf_keys; + + static MPlist () + { + wf_keys = new List (); + wf_keys.Add (MSymbol.symbol); + wf_keys.Add (MSymbol.mtext); + wf_keys.Add (MSymbol.plist); + wf_keys.Add (MSymbol.integer); + } + public MPlist () { - Key = MSymbol.nil; - Val = null; + key = MSymbol.nil; + val = null; } public MPlist (FileStream stream) { MStreamReader reader = new MStreamReader (stream); - MSymbol key; - object val; bool result = reader.ReadElement (out key, out val); - Key = key; - Val = val; if (result) next = new MPlist (reader); } @@ -34,12 +46,8 @@ namespace M17N.Core public MPlist (FileStream stream, int count) { MStreamReader reader = new MStreamReader (stream); - MSymbol key; - object val; bool result = reader.ReadElement (out key, out val); - Key = key; - Val = val; if (result && --count > 0) next = new MPlist (reader, count); else @@ -49,20 +57,21 @@ namespace M17N.Core public MPlist (FileStream stream, MSymbol target, MSymbol stop) { MStreamReader reader = new MStreamReader (stream); - MSymbol key; - object val; bool result; - Key = MSymbol.nil; - Val = null; + key = MSymbol.nil; + val = null; while (true) { - result = reader.ReadElement (out key, out val); + MSymbol this_key; + object this_val; + + result = reader.ReadElement (out this_key, out this_val); if (! result) return; - if (key == MSymbol.plist) + if (this_key == MSymbol.plist) { - MPlist plist = (MPlist) val; + MPlist plist = (MPlist) this_val; if (plist.IsSymbol) { @@ -70,8 +79,8 @@ namespace M17N.Core return; if (plist.Symbol == target) { - Key = target; - Val = val; + key = target; + val = this_val; next = new MPlist (); return; } @@ -82,24 +91,16 @@ namespace M17N.Core internal MPlist (MStreamReader reader) { - MSymbol key; - object val; bool result = reader.ReadElement (out key, out val); - Key = key; - Val = val; if (result) next = new MPlist (reader); } private MPlist (MStreamReader reader, int count) { - MSymbol key; - object val; bool result = reader.ReadElement (out key, out val); - Key = key; - Val = val; if (result && --count > 0) next = new MPlist (reader, count); else @@ -108,20 +109,21 @@ namespace M17N.Core private MPlist (MStreamReader reader, MSymbol target, MSymbol stop) { - MSymbol key; - object val; bool result; - Key = MSymbol.nil; - Val = null; + key = MSymbol.nil; + val = null; while (true) { - result = reader.ReadElement (out key, out val); + MSymbol this_key; + object this_val; + + result = reader.ReadElement (out this_key, out this_val); if (! result) return; - if (key == MSymbol.plist) + if (this_key == MSymbol.plist) { - MPlist plist = (MPlist) val; + MPlist plist = (MPlist) this_val; if (plist.IsSymbol) { @@ -129,8 +131,8 @@ namespace M17N.Core return; if (plist.Symbol == target) { - Key = target; - Val = val; + key = target; + val = this_val; next = new MPlist (); return; } @@ -139,24 +141,23 @@ namespace M17N.Core } } - private MPlist (MSymbol key, object val) + protected MPlist (MSymbol key, object val) { - Key = key; - Val = val; + this.key = key; + this.val = val; } public bool IsEmpty { get { return next == null; } } - public MPlist Next { get { return next; } } internal bool IsSymbol { get { return Key == MSymbol.symbol; } } internal bool IsMText { get { return Key == MSymbol.mtext; } } internal bool IsPlist { get { return Key == MSymbol.plist; } } internal bool IsInteger { get { return Key == MSymbol.integer; } } - internal MSymbol Symbol { get { return (MSymbol) Val; } } - internal MText Text { get { return (MText) Val; } } - internal MPlist Plist { get { return (MPlist) Val; } } - internal int Integer { get { return (int) Val; } } + internal MSymbol Symbol { get { return (MSymbol) val; } } + internal MText Text { get { return (MText) val; } } + internal MPlist Plist { get { return (MPlist) val; } } + internal int Integer { get { return (int) val; } } public int Count { @@ -174,7 +175,7 @@ namespace M17N.Core MPlist plist = new MPlist (), pl = plist; for (MPlist p = this; p.next != null; p = p.next) - pl = pl.Add (p.Key, p.Val); + pl = pl.Add (p.key, p.val); return plist; } @@ -186,15 +187,12 @@ namespace M17N.Core { if (p != this) str += " "; - if (p.Key != MSymbol.symbol - && p.Key != MSymbol.integer - && p.Key != MSymbol.plist - && p.Key != MSymbol.mtext) - str += p.Key + ":"; - if (p.Key == MSymbol.mtext) - str += "\"" + p.Val + "\""; + if (! wf_keys.Contains (p.key)) + str += p.key + ":"; + if (p.key == MSymbol.mtext) + str += "\"" + p.val + "\""; else - str += p.Val; + str += p.val; } return str + ")"; } @@ -204,7 +202,7 @@ namespace M17N.Core MPlist p; for (p = this; ! p.IsEmpty; p = p.next) - if (p.Key == key) + if (p.key == key) break; return p; } @@ -218,7 +216,7 @@ namespace M17N.Core public object Get (MSymbol key) { - return find (key).Val; + return find (key).val; } internal MPlist Assq (MSymbol key) @@ -251,7 +249,7 @@ namespace M17N.Core if (IsEmpty) Push (key, val); else - Val = val; + this.val = val; return this; } @@ -272,11 +270,11 @@ namespace M17N.Core public MPlist Push (MSymbol key, object val) { - MPlist p = new MPlist (Key, Val); + MPlist p = new MPlist (this.key, this.val); p.next = this.next; - Key = key; - Val = val; + this.key = key; + this.val = val; next = p; return this; } @@ -288,22 +286,22 @@ namespace M17N.Core public object Pop (out MSymbol key) { - key = Key; + key = this.key; if (IsEmpty) return null; - object val = Val; + object this_val = val; - Key = next.Key; - Val = next.Val; + this.key = next.key; + this.val = next.val; next = next.next; - return val; + return this_val; } public object Pop () { - MSymbol key; - return Pop (out key); + MSymbol temp; + return Pop (out temp); } public MPlist Add (MSymbol key, object val) @@ -316,8 +314,8 @@ namespace M17N.Core public MPlist Clear () { - Key = MSymbol.nil; - Val = null; + key = MSymbol.nil; + val = null; next = null; return this; } diff --git a/Makefile b/Makefile index 6c9114f..1148bd8 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ CS=gmcs M17N_SRC = M17N.cs CORE_SRC = MSymbol.cs MPlist.cs MCharTable.cs MText.cs MDatabase.cs +INPUT_SRC = MInputMethod.cs EXAMPLE = symbol.exe plist.exe chartab.exe text.exe textprop.exe database.exe TEST = rearsticky.exe frontsticky.exe \ sensitive.exe frontsensitive.exe rearsensitive.exe @@ -14,6 +15,9 @@ M17N.dll: ${M17N_SRC} M17NCore.dll: M17N.dll ${CORE_SRC} $(CS) -out:$@ -t:library -r:M17N.dll ${CORE_SRC} +M17NInput.dll: M17N.dll M17NCore.dll ${INPUT_SRC} + $(CS) -out:$@ -t:library -r:M17N.dll -r:M17NCore.dll ${INPUT_SRC} + %.exe: %.cs M17NCore.dll $(CS) -codepage:65001 -r:M17N.dll -r:M17NCore $< @@ -22,3 +26,6 @@ clean: temp.exe: temp.cs $(CS) temp.cs + +expr.exe: M17N.dll M17NCore.dll MExpression.cs expr.cs + $(CS) -out:$@ -t:library -r:M17N.dll -r:M17NCore.dll MExpression.cs expr.cs diff --git a/expr.cs b/expr.cs new file mode 100644 index 0000000..1d4af26 --- /dev/null +++ b/expr.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using M17N; +using M17N.Core; + +public class Test +{ + public static void Main() + { + } +}