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);
        }
Esempio n. 2
0
 protected void bindToKernel()
 {
     messageSendBinderRegistry = objectSpace.MessageSendBinderRegistry;
     symbolRegistry            = objectSpace.SymbolRegistry;
     selfSymbol        = objectSpace.SymbolRegistry.symbolFor(selfName);
     superSymbol       = objectSpace.SymbolRegistry.symbolFor(superName);
     thisContextSymbol = objectSpace.SymbolRegistry.symbolFor(thisContextName);
 }
Esempio n. 3
0
 protected void bindToCompiler()
 {
     objectSpace    = compiler.ObjectSpace;
     symbolRegistry = objectSpace.SymbolRegistry;
 }
Esempio n. 4
0
 public Evaluator(SymbolRegistry <T> symbols, T data)
 {
     Data           = data;
     SymbolRegistry = symbols;
 }
Esempio n. 5
0
 public Evaluator(SymbolRegistry <T> symbols)
 {
     SymbolRegistry = symbols;
 }
Esempio n. 6
0
 ///--
 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;
 }
Esempio n. 9
0
 public Parser(TokenRegistry tokens)
 {
     this.tokens  = tokens;
     this.symbols = new SymbolRegistry();
     this.ast     = new AST.AST();
 }
Esempio n. 10
0
 public TypeDecoratorVisitor(SymbolRegistry <T> symbols, bool throwOnError)
 {
     Symbols      = symbols;
     ThrowOnError = throwOnError;
 }