Commit | Line | Data |
---|---|---|
53beaa0a JM |
1 | using System; |
2 | using System.IO; | |
3 | using Mal; | |
4 | using MalVal = Mal.types.MalVal; | |
5 | ||
6 | namespace Mal { | |
afdf531e | 7 | class step1_read_print { |
53beaa0a JM |
8 | // read |
9 | static MalVal READ(string str) { | |
10 | return reader.read_str(str); | |
11 | } | |
12 | ||
13 | // eval | |
14 | static MalVal EVAL(MalVal ast, string env) { | |
15 | return ast; | |
16 | } | |
17 | ||
18 | ||
19 | static string PRINT(MalVal exp) { | |
20 | return printer._pr_str(exp, true); | |
21 | } | |
22 | ||
86b689f3 | 23 | // repl |
53beaa0a JM |
24 | static MalVal RE(string env, string str) { |
25 | return EVAL(READ(str), env); | |
26 | } | |
27 | ||
28 | static void Main(string[] args) { | |
29 | string prompt = "user> "; | |
30 | ||
31 | if (args.Length > 0 && args[0] == "--raw") { | |
32 | Mal.readline.mode = Mal.readline.Mode.Raw; | |
33 | } | |
53beaa0a JM |
34 | while (true) { |
35 | string line; | |
36 | try { | |
37 | line = Mal.readline.Readline(prompt); | |
38 | if (line == null) { break; } | |
39 | } catch (IOException e) { | |
40 | Console.WriteLine("IOException: " + e.Message); | |
41 | break; | |
42 | } | |
43 | try { | |
44 | Console.WriteLine(PRINT(RE(null, line))); | |
45 | } catch (Mal.types.MalContinue) { | |
46 | continue; | |
8cb5cda4 | 47 | } catch (Exception e) { |
53beaa0a | 48 | Console.WriteLine("Error: " + e.Message); |
8cb5cda4 | 49 | Console.WriteLine(e.StackTrace); |
53beaa0a | 50 | continue; |
53beaa0a JM |
51 | } |
52 | } | |
53 | } | |
54 | } | |
55 | } |