public void EbnfGrammarGeneratorShouldCreateGrammarForMultipleProductions()
 {
     // S = 'a';
     // S = 'b';
     var definition = new EbnfDefinitionConcatenation(
         new EbnfBlockRule(
             new EbnfRule(
                 new EbnfQualifiedIdentifier("S"),
                 new EbnfExpression(
                     new EbnfTerm(
                         new EbnfFactorLiteral("a"))))),
         new EbnfDefinition(
             new EbnfBlockRule(
                 new EbnfRule(
                     new EbnfQualifiedIdentifier("S"),
                     new EbnfExpression(
                         new EbnfTerm(
                             new EbnfFactorLiteral("b")))))));
     var grammar = GenerateGrammar(definition);
     Assert.IsNotNull(grammar);
     Assert.IsNotNull(grammar.Start);
     Assert.AreEqual(2, grammar.Productions.Count);
 }
Exemple #2
0
 public void EbnfParserShouldParseMultipleRules()
 {
     var expected = new EbnfDefinitionConcatenation(
         new EbnfBlockRule(
             new EbnfRule(
                 new EbnfQualifiedIdentifier("S"),
                 new EbnfExpression(
                     new EbnfTermConcatenation(
                         new EbnfFactorIdentifier(
                             new EbnfQualifiedIdentifier("A")),
                         new EbnfTerm(
                             new EbnfFactorIdentifier(
                                 new EbnfQualifiedIdentifier("B"))))))),
         new EbnfDefinitionConcatenation(
             new EbnfBlockRule(
                 new EbnfRule(
                     new EbnfQualifiedIdentifier("A"),
                     new EbnfExpression(
                         new EbnfTerm(
                             new EbnfFactorLiteral("a"))))),
             new EbnfDefinition(
                 new EbnfBlockRule(
                     new EbnfRule(
                         new EbnfQualifiedIdentifier(
                             "B"),
                         new EbnfExpression(
                             new EbnfTerm(
                                 new EbnfFactorLiteral("b"))))))));
     var actual = Parse(@"
         S = A B;
         A = 'a';
         B = 'b';
     ");
     Assert.AreEqual(expected, actual);
 }