static void Main(string[] args) { IContext context = new Context(); Parser parser = new Parser(System.Console.In); context.DefineVariable("write"); context.SetValue("write", new WriteFunction()); context.DefineVariable("writeln"); context.SetValue("writeln", new WriteLineFunction()); context.DefineVariable("Object"); context.SetValue("Object", new ObjectFunction(context)); Console.WriteLine("AjScript 0.1 (JavaScript-like Interpreter in C#)"); for (ICommand cmd = parser.ParseCommand(); cmd != null; cmd = parser.ParseCommand()) cmd.Execute(context); }
private void EvaluateCommands(string text) { Parser parser = new Parser(text); for (ICommand cmd = parser.ParseCommand(); cmd != null; cmd = parser.ParseCommand()) cmd.Execute(this.context); }
private object EvaluateFile(string filename) { Parser parser = new Parser(new StreamReader(filename)); for (ICommand cmd = parser.ParseCommand(); cmd != null; cmd = parser.ParseCommand()) cmd.Execute(this.context); return this.context.GetValue("result"); }