Пример #1
0
        public Grammar Generate(IEbnfDefinition ebnf)
        {
            var grammarModel = new GrammarModel();

            Definition(ebnf, grammarModel);
            return(grammarModel.ToGrammar());
        }
Пример #2
0
 public override void Visit(IInternalTreeNode node)
 {
     if (node.Is(EbnfGrammar.Definition))
     {
         Definition = VisitDefinitionNode(node);
     }
 }
Пример #3
0
        private void Definition(IEbnfDefinition definition, GrammarModel grammarModel)
        {
            Block(definition.Block, grammarModel);

            if (definition is EbnfDefinitionConcatenation definitionConcatenation)
            {
                Definition(definitionConcatenation.Definition, grammarModel);
            }
        }
Пример #4
0
        private IEbnfDefinition VisitDefinitionNode(IInternalTreeNode node)
        {
            IEbnfBlock      block      = null;
            IEbnfDefinition definition = null;

            foreach (var internalNode in node.Children.OfType <IInternalTreeNode>())
            {
                if (internalNode.Is(EbnfGrammar.Block))
                {
                    block = VisitBlockNode(internalNode);
                }
                else if (internalNode.Is(EbnfGrammar.Definition))
                {
                    definition = VisitDefinitionNode(internalNode);
                }
            }

            if (definition == null)
            {
                return(new EbnfDefinitionSimple(block));
            }

            return(new EbnfDefinitionConcatenation(block, definition));
        }
Пример #5
0
 public EbnfDefinitionConcatenation(IEbnfBlock block, IEbnfDefinition definition)
 {
     Block      = block;
     Definition = definition;
 }
Пример #6
0
        private static Grammar GenerateGrammar(IEbnfDefinition definition)
        {
            var generator = new EbnfGrammarGenerator();

            return(generator.Generate(definition));
        }