public void Rules_SomeList_Same() { var rules = new[] { MockRepository.GenerateStub<IBlock>(), MockRepository.GenerateStub<IBlock>() }; var analyzer = new SyntacticAnalyzer(rules); Assert.That(analyzer.Rules, Is.SameAs(rules)); }
public void Rewrite_SpecialExpression2_TargetNodeCount() { var lexical = new LexicalAnalyzer(AnalyzerFacade.LexicalRules); var syntactic = new SyntacticAnalyzer(AnalyzerFacade.SyntacticRules); var translator = new Translator(AnalyzerFacade.TranslateRules); const string text = "(((-1+1+3+pi)))"; var tokens = lexical.Parse(text); var tree = syntactic.Parse(tokens, BlockOf<ExpressionBlock>()); var root = translator.Rewrite(tree); Assert.That(root.Nodes.Count(), Is.EqualTo(2)); }
public void Rewrite_Expressiion_DoesNotThrow(string text) { var lexical = new LexicalAnalyzer(AnalyzerFacade.LexicalRules); var syntactic = new SyntacticAnalyzer(AnalyzerFacade.SyntacticRules); var translator = new Translator(AnalyzerFacade.TranslateRules); Assert.DoesNotThrow( () => { var tokens = lexical.Parse(text); var tree = syntactic.Parse(tokens, BlockOf<ExpressionBlock>()); translator.Rewrite(tree); }); }
public void Translate_SpecialExpression2_TargetNodeCount() { var lexical = new LexicalAnalyzer(StandardProcessorBuilder.LexicalRules); var syntactic = new SyntacticAnalyzer(StandardProcessorBuilder.SyntacticRules); var translator = new Translator(StandardProcessorBuilder.TranslateRules); const string text = "(((-1+1+3+pi)))"; var tokens = lexical.Parse(text); var tree = syntactic.Parse(tokens, StandardProcessorBuilder.SyntacticTarget); var result = translator.Translate(tree); Assert.That(result.Nodes.Count(), Is.EqualTo(2)); }
public void Parse_EmptyNodeTypes_SingleIterate() { var iterate = new SyntacticParseIterateResult( Enumerable.Empty<ISyntacticNode>(), Enumerable.Empty<ISyntacticNodeType>(), Enumerable.Empty<TokenSyntacticNode>()); var rules = Enumerable.Empty<IBlock>(); var analyzer = new SyntacticAnalyzer(rules); var result = analyzer.Parse(iterate).ToArray(); Assert.That(result.Count(),Is.EqualTo(1)); Assert.That(result.First(), Is.EqualTo(iterate)); }
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); }); }
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); }
public void Translate_SumOfProduct_SumTerm() { var lexical = new LexicalAnalyzer(StandardProcessorBuilder.LexicalRules); var syntactic = new SyntacticAnalyzer(StandardProcessorBuilder.SyntacticRules); var translator = new Translator(StandardProcessorBuilder.TranslateRules); const string text = "2*3+3*4.7"; var tokens = lexical.Parse(text); var tree = syntactic.Parse(tokens, StandardProcessorBuilder.SyntacticTarget); var result = translator.Translate(tree); var termNode = (TermSyntacticNode) result; Assert.That(termNode.Term, Is.TypeOf<BinaryOperatorTerm>()); var operatorTerm = (BinaryOperatorTerm) termNode.Term; Assert.That(operatorTerm.Operator, Is.TypeOf<PlusOperator>()); }
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)); }
public void GivenIHaveStandardLexicalAnSyntacticAnalyzers() { LexicalAnalyzer = new LexicalAnalyzer(StandardProcessorBuilder.LexicalRules); SyntacticAnalyzer = new SyntacticAnalyzer(StandardProcessorBuilder.SyntacticRules); }
public void Rules_Empty_Empty() { var rules = Enumerable.Empty<IBlock>(); var analyzer = new SyntacticAnalyzer(rules); Assert.That(analyzer.Rules, Is.SameAs(rules)); }
public void Rules_Null_Null() { var analyzer = new SyntacticAnalyzer(null); Assert.That(analyzer.Rules, Is.Null); }
public void GivenIHaveStandardLexicalAnSyntacticAnalyzers() { LexicalAnalyzer = new LexicalAnalyzer(AnalyzerFacade.LexicalRules); SyntacticAnalyzer = new SyntacticAnalyzer(AnalyzerFacade.SyntacticRules); }