private static void RunFile(string path, List <string> includeDirs) { var text = File.ReadAllText(path); var env = new Squirrel.Environment(); INode result; try { result = Interpret(text, ref env, includeDirs); } catch (TokenizerException e) { Console.WriteLine(e.Message); return; } catch (ParserException e) { Console.WriteLine(e.Message); return; } if (!result.Equals(Evaluator.Null)) { Console.WriteLine(result); } }
private static INode Interpret(string text, ref Squirrel.Environment env, List <string> includeDirs) { var tokenizer = new Tokenizer(text); var parser = new Parser(tokenizer.Tokenize()); var evaluator = new Evaluator(parser.Parse(), includeDirs); return(evaluator.Evaluate(ref env)); }
private static void RunInteractiveConsole(List <string> includeDirs) { var env = new Squirrel.Environment(); const string prompt = ">>> "; Console.WriteLine("Press ^D to quit. Use an underscore ('_') to refer to the last output."); while (true) { Console.Write(prompt); var line = Console.ReadLine(); if (line == null) { break; } if (string.IsNullOrWhiteSpace(line)) { continue; } INode result; try { result = Interpret(line, ref env, includeDirs); } catch (TokenizerException e) { Console.WriteLine(e.Message); continue; } catch (ParserException e) { Console.WriteLine(e.Message); continue; } if (!result.Equals(Evaluator.Null)) { Console.WriteLine(result); } if (result.GetType() != typeof(ErrorNode)) { env.Put("_", result); } } }