*** 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 (MExpression[] args, MExpression.Domain domain)
12   {
13     MText preedit = (MText) domain.GetValue (Mpreedit);
14     object val = args[0].Val;
15
16     if (val is int)
17       preedit.Cat ((int) val);
18     else
19       preedit.Cat ((MText) val);
20     return val;
21   }
22
23   public static void Main()
24   {
25     MExpression.Domain domain = new MExpression.Domain (null);
26
27     domain.Defun ("insert", insert, 1, 1, false);
28     domain.Bind (MSymbol.Of ("X"), 10);
29     domain.Bind (Mpreedit, new MText ("PREEDIT TEXT"));
30
31     MExpression expr;
32     using (FileStream stream = new FileStream ("eval.txt", FileMode.Open))
33       {
34         expr = new MExpression (new MPlist (stream), domain);
35       }
36     Console.WriteLine (domain);
37     Console.Write (expr);
38     Console.WriteLine ("  => " + expr.Eval (domain));
39     Console.WriteLine (domain);
40   }
41 }