コード例 #1
0
 public void CheckResult_BlockNode_Throw()
 {
     var node = new BlockSyntacticNode(
         MockRepository.GenerateStub<IBlock>(),
         Enumerable.Empty<ISyntacticNode>());
     var translator = new Translator(Enumerable.Empty<ISyntaxRewriter>());
     translator.CheckResult(node);
 }
コード例 #2
0
 public void CheckResult_TermNode_DoesNotThrow()
 {
     var node = new TermSyntacticNode(
         MockRepository.GenerateStub<ITerm>(),
         Enumerable.Empty<ISyntacticNode>());
     var translator = new Translator(Enumerable.Empty<ISyntaxRewriter>());
     Assert.DoesNotThrow(() => translator.CheckResult(node));
 }
コード例 #3
0
 public void TranslateAndCheck_Expressiion_DoesNotThrow(string text)
 {
     var lexical = new LexicalAnalyzer(StandardProcessorBuilder.LexicalRules);
     var syntactic = new SyntacticAnalyzer(StandardProcessorBuilder.SyntacticRules);
     var translator = new Translator(StandardProcessorBuilder.TranslateRules);
     Assert.DoesNotThrow(
         () =>
         {
             var tokens = lexical.Parse(text);
             var tree = syntactic.Parse(tokens, StandardProcessorBuilder.SyntacticTarget);
             var result = translator.Translate(tree);
             translator.CheckResult(result);
         });
 }
コード例 #4
0
        public void Resolve_UnresolverIdentifier_Throw(string text)
        {
            var lexical = new LexicalAnalyzer(StandardProcessorBuilder.LexicalRules);
            var syntactic = new SyntacticAnalyzer(StandardProcessorBuilder.SyntacticRules);
            var translator = new Translator(StandardProcessorBuilder.TranslateRules);
            var linkedLibraryFactory = new StaticLinkedLibraryFactory(typeof(StandardProcessorBuilder.LinkedMath));
            var linker = new Linker(StandardProcessorBuilder.LinkerRules, linkedLibraryFactory.CreateLinkedLibrary());

            var tokens = lexical.Parse(text);
            var tree = syntactic.Parse(tokens, StandardProcessorBuilder.SyntacticTarget);
            var translatedTree = translator.Translate(tree);
            translator.CheckResult(translatedTree);
            linker.Resolve(translatedTree);

        }
コード例 #5
0
        public void Compile_Expressiion_RightResult(string text, double value)
        {
            var linkedLibraryFactory = new StaticLinkedLibraryFactory(typeof(StandardProcessorBuilder.LinkedMath));

            var lexical = new LexicalAnalyzer(StandardProcessorBuilder.LexicalRules);
            var syntactic = new SyntacticAnalyzer(StandardProcessorBuilder.SyntacticRules);
            var translator = new Translator(StandardProcessorBuilder.TranslateRules);
            var linker = new Linker(StandardProcessorBuilder.LinkerRules, 
                linkedLibraryFactory.CreateLinkedLibrary());
            var tokens = lexical.Parse(text);
            var tree = syntactic.Parse(tokens, StandardProcessorBuilder.SyntacticTarget);
            var translatedTree = translator.Translate(tree);
            translator.CheckResult(translatedTree);
            var linkedTree = linker.Resolve(translatedTree);
            linker.CheckResult(linkedTree);
            var compilator = new Compiler();
            var lambda = compilator.CreateExpression(linkedTree);
            var result = lambda.Compile()();
            Assert.That(result, Is.EqualTo(value).Within(1e-1));
        }