static void Main(string[] args) { var interpreter = new AphidInterpreter(); interpreter.Interpret("add = @(x, y) x + y;"); var x = interpreter.CallFunction("add", 3, 7).Value; Console.WriteLine(x); }
static void Main(string[] args) { if (args.Length != 1) { DisplayDirections(); } else if (!File.Exists(args[0])) { Console.WriteLine("Could not find {0}", args[0]); Environment.Exit(1); } var code = File.ReadAllText(args[0]); EnvironmentLibrary.SetEnvArgs(true); var interpreter = new AphidInterpreter(); try { interpreter.Interpret(code); } catch (AphidParserException exception) { Console.WriteLine(ParserErrorMessage.Create(code, exception)); } catch (AphidRuntimeException exception) { Console.WriteLine("Unexpected runtime exception\r\n\r\n{0}\r\n", exception.Message); } }
private AphidObject Execute(string script) { script = PrefixScript(script); var interpreter = new AphidInterpreter(); interpreter.Loader.SearchPaths.Add(Path.Combine(Environment.CurrentDirectory, "Library")); interpreter.Interpret(script); return interpreter.GetReturnValue(); }
static void Main(string[] args) { var interpreter = new AphidInterpreter(); interpreter.Interpret(@" #'Std'; print('Hello, world'); "); }
static void Main(string[] args) { var interpreter = new AphidInterpreter(); interpreter.CurrentScope.Add("x", new AphidObject("foo")); interpreter.Interpret(@" #'Std'; print(x); "); }
static void Main(string[] args) { var interpreter = new AphidInterpreter(); interpreter.Interpret(@" #'Std'; ret { name: 'My Widget', location: { x: 10, y: 20 } }; "); var widget = interpreter.GetReturnValue().ConvertTo<Widget>(); Console.WriteLine(widget); widget.Location.X = 40; var aphidWidget = AphidObject.ConvertFrom(widget); interpreter.CurrentScope.Add("w", aphidWidget); interpreter.Interpret(@"printf('New X value: {0}', w.location.x);"); }
static void Main(string[] args) { var interpreter = new AphidInterpreter(); interpreter.Interpret(@" #'Std'; add = @(x, y) x + y; print(add(3, 7)); "); }
static void Main(string[] args) { var interpreter = new AphidInterpreter(); interpreter.Interpret(@" #'Std'; call = @(func) func(); foo = @() print('foo() called'); call(foo); "); }
static void Main(string[] args) { var interprer = new AphidInterpreter(); interprer.Loader.LoadModule(Assembly.GetExecutingAssembly()); interprer.Interpret(@" #'Std'; ##'InteropFunctionSample.AphidMath'; print(math.add(3, 7)); "); }
public void LoadScript(string scriptFile) { var f = FindScriptFile(scriptFile); if (f != null) { _interpreter.Interpret(File.ReadAllText(f)); } else { throw new AphidRuntimeException("Cannot find script {0}", scriptFile); } }
public AphidObject Deserialize(string obj) { var lexer = new AphidObjectLexer(obj); var tokens = lexer.GetTokens(); tokens.Add(new AphidToken(AphidTokenType.EndOfStatement, null, 0)); var ast = new AphidParser(tokens).Parse(); if (ast.Count != 1) { throw new AphidRuntimeException("Invalid Aphid object string: {0}", obj); } ast[0] = new UnaryOperatorExpression(AphidTokenType.retKeyword, ast[0]); var objInterpreter = new AphidInterpreter(); objInterpreter.Interpret(ast); return objInterpreter.GetReturnValue(); }
public void LoadScript(string scriptFile) { var f = FindScriptFile(scriptFile); if (f != null) { if (f.Contains(Path.DirectorySeparatorChar)) { var dir = Path.GetFullPath(Path.GetDirectoryName(f)); if (!_searchPaths.Contains(dir)) { _searchPaths.Add(dir); } } _interpreter.Interpret(File.ReadAllText(f)); } else { throw new AphidRuntimeException("Cannot find script {0}", scriptFile); } }
static void Main(string[] args) { var interpreter = new AphidInterpreter(); interpreter.Interpret("x = 'foo';"); Console.WriteLine(interpreter.CurrentScope["x"].Value); }
private static object Eval(AphidInterpreter interpreter, string code) { interpreter.EnterChildScope(); interpreter.Interpret(code); var retVal = interpreter.GetReturnValue(); interpreter.LeaveChildScope(); return retVal; }
static void RunTest(PerfTest test, int iterations) { var interpreter = new AphidInterpreter(); if (test.Prologue != null) { interpreter.Interpret(test.Prologue); } var ast = new AphidParser(new AphidLexer(test.Body).GetTokens()).Parse(); for (int i = 0; i < iterations; i++) { interpreter.Interpret(ast); } }