aboutsummaryrefslogtreecommitdiff
path: root/cs/step0_repl.cs
blob: 68cac944823e2a3964dca7e1f02376dbebad815f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.IO;
using Mal;

namespace Mal {
    class step0_repl {
        // read
        static string READ(string str) {
            return str;
        }

        // eval
        static string EVAL(string ast, string env) {
            return ast;
        }

        // print
        static string PRINT(string exp) {
            return exp;
        }

        // repl
        static string RE(string env, string str) {
            return EVAL(READ(str), env);
        }

        static void Main(string[] args) {
            if (args.Length > 0 && args[0] == "--raw") {
                Mal.readline.mode = Mal.readline.Mode.Raw;
            }

            // repl loop
            while (true) {
                string line;
                try {
                    line = Mal.readline.Readline("user> ");
                    if (line == null) { break; }
                    if (line == "") { continue; }
                } catch (IOException e) {
                    Console.WriteLine("IOException: " + e.Message);
                    break;
                }
                Console.WriteLine(PRINT(RE(null, line)));
            }
        }
    }
}