2014-04-07 07:13:14 +04:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using Mal;
|
|
|
|
using MalVal = Mal.types.MalVal;
|
|
|
|
|
|
|
|
namespace Mal {
|
2014-04-07 09:17:13 +04:00
|
|
|
class step1_read_print {
|
2014-04-07 07:13:14 +04:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2014-04-19 22:04:09 +04:00
|
|
|
// repl
|
2014-04-07 07:13:14 +04:00
|
|
|
static void Main(string[] args) {
|
2014-11-16 05:38:50 +03:00
|
|
|
Func<string, MalVal> RE = (string str) => EVAL(READ(str), "");
|
|
|
|
|
2014-04-07 07:13:14 +04:00
|
|
|
if (args.Length > 0 && args[0] == "--raw") {
|
|
|
|
Mal.readline.mode = Mal.readline.Mode.Raw;
|
|
|
|
}
|
2014-11-16 05:38:50 +03:00
|
|
|
|
|
|
|
// repl loop
|
2014-04-07 07:13:14 +04:00
|
|
|
while (true) {
|
|
|
|
string line;
|
|
|
|
try {
|
2014-11-16 05:38:50 +03:00
|
|
|
line = Mal.readline.Readline("user> ");
|
2014-04-07 07:13:14 +04:00
|
|
|
if (line == null) { break; }
|
2014-11-16 05:38:50 +03:00
|
|
|
if (line == "") { continue; }
|
2014-04-07 07:13:14 +04:00
|
|
|
} catch (IOException e) {
|
|
|
|
Console.WriteLine("IOException: " + e.Message);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
try {
|
2014-11-16 05:38:50 +03:00
|
|
|
Console.WriteLine(PRINT(RE(line)));
|
2014-04-07 07:13:14 +04:00
|
|
|
} catch (Mal.types.MalContinue) {
|
|
|
|
continue;
|
2014-04-17 08:57:50 +04:00
|
|
|
} catch (Exception e) {
|
2014-04-07 07:13:14 +04:00
|
|
|
Console.WriteLine("Error: " + e.Message);
|
2014-04-17 08:57:50 +04:00
|
|
|
Console.WriteLine(e.StackTrace);
|
2014-04-07 07:13:14 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|