*** empty log message ***
[m17n/m17n-lib-cs.git] / expr.cs
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 using M17N;
5 using M17N.Core;
6
7 public class Test
8 {
9   static MSymbol Mpreedit = MSymbol.Of ("preedit");
10
11   public static object insert (object[] args, MPlist bindings)
12   {
13     object arg = ((MExpression) args[0]).Eval (bindings);
14     MPlist slot = bindings.Find (Mpreedit);
15     MText preedit = (MText) slot.val;
16
17     if (arg is int)
18       preedit.Cat ((int) arg);
19     else
20       preedit.Cat ((MText) arg);
21     return arg;
22   }
23
24   public static void Main()
25   {
26     MExpression expr;
27     MPlist bindings = new MPlist ();
28     MExpression.FunctionTable func_table = new MExpression.FunctionTable ();
29
30     MExpression.Defun (func_table, "insert", new MExpression.Evaluator (insert),
31                        1, 1, typeof (MExpression));
32     bindings.Add (MSymbol.Of ("X"), 10);
33     bindings.Add (Mpreedit, new MText ("PREEDIT TEXT"));
34
35     using (FileStream stream = new FileStream ("eval.txt", FileMode.Open))
36       {
37         expr = new MExpression (new MPlist (stream), func_table);
38       }
39     Console.WriteLine (bindings);
40     expr.PrettyPrint ();
41     Console.WriteLine ("\n  => " + expr.Eval (bindings));
42     Console.WriteLine (bindings);
43   }
44 }