public static void TestExpression(string expr, double expected) { var expression = new Parser(expr).Parse(); if (expression == null) { throw new Exception("Could not resolve types"); } var resolver = new SymbolRegistry <object>(); resolver.Add("Spend", DataType.Currency, x => 1); // Resolve symbols var decorator = new TypeDecoratorVisitor <object>(resolver, true); decorator.Visit(expression); // Check the types var checker = new TypeCheckerVisitor(); var type = (DataType)(checker.Visit(expression)); if (type == DataType.Unknown) { throw new Exception("Could not resolve types"); } //TWADS - it's busted jim // Run it! //var interpreter = new TreeInterpreter<object>(resolver); // var result = (double)interpreter.Evaluate(expression); //Assert.AreEqual(expected, result, 0.02, expr); }
protected void bindToKernel() { messageSendBinderRegistry = objectSpace.MessageSendBinderRegistry; symbolRegistry = objectSpace.SymbolRegistry; selfSymbol = objectSpace.SymbolRegistry.symbolFor(selfName); superSymbol = objectSpace.SymbolRegistry.symbolFor(superName); thisContextSymbol = objectSpace.SymbolRegistry.symbolFor(thisContextName); }
protected void bindToCompiler() { objectSpace = compiler.ObjectSpace; symbolRegistry = objectSpace.SymbolRegistry; }
public Evaluator(SymbolRegistry <T> symbols, T data) { Data = data; SymbolRegistry = symbols; }
public Evaluator(SymbolRegistry <T> symbols) { SymbolRegistry = symbols; }
///-- public ScriptAnalyzer(SymbolRegistry registry) { this.registry = registry; }
/// <summary> /// Creates a new instance of <c>ReflectionServiceIml</c>. /// </summary> public ReflectionService(IEnumerable <ServiceDescriptorProto> serviceDescriptors) { this.services = new List <string>(serviceDescriptors.Select((serviceDescriptor) => serviceDescriptor.Name)); this.symbolRegistry = SymbolRegistry.FromFiles(serviceDescriptors.Select((serviceDescriptor) => serviceDescriptor.File)); }
/// <summary> /// Creates a new instance of <c>ReflectionServiceIml</c>. /// </summary> public ReflectionService(IEnumerable <string> services, SymbolRegistry symbolRegistry) { this.services = new List <string>(services); this.symbolRegistry = symbolRegistry; }
public Parser(TokenRegistry tokens) { this.tokens = tokens; this.symbols = new SymbolRegistry(); this.ast = new AST.AST(); }
public TypeDecoratorVisitor(SymbolRegistry <T> symbols, bool throwOnError) { Symbols = symbols; ThrowOnError = throwOnError; }