1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 10:07:45 +03:00
mal/cs/step1_read_print.cs
2015-01-09 16:16:46 -06:00

55 lines
1.5 KiB
C#

using System;
using System.IO;
using Mal;
using MalVal = Mal.types.MalVal;
namespace Mal {
class step1_read_print {
// read
static MalVal READ(string str) {
return reader.read_str(str);
}
// eval
static MalVal EVAL(MalVal ast, string env) {
return ast;
}
// print
static string PRINT(MalVal exp) {
return printer._pr_str(exp, true);
}
// repl
static void Main(string[] args) {
Func<string, MalVal> RE = (string str) => EVAL(READ(str), "");
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;
}
try {
Console.WriteLine(PRINT(RE(line)));
} catch (Mal.types.MalContinue) {
continue;
} catch (Exception e) {
Console.WriteLine("Error: " + e.Message);
Console.WriteLine(e.StackTrace);
continue;
}
}
}
}
}