Пример #1
0
        private EbnfTerm VisitTermNode(IInternalTreeNode node)
        {
            EbnfFactor factor = null;
            EbnfTerm   term   = null;

            for (int c = 0; c < node.Children.Count; c++)
            {
                var child = node.Children[c];
                switch (child.NodeType)
                {
                case TreeNodeType.Internal:
                    var internalNode = child as IInternalTreeNode;
                    var symbolValue  = internalNode.Symbol.Value;
                    if (EbnfGrammar.Factor == symbolValue)
                    {
                        factor = VisitFactorNode(internalNode);
                    }
                    else if (EbnfGrammar.Term == symbolValue)
                    {
                        term = VisitTermNode(internalNode);
                    }
                    break;

                case TreeNodeType.Token:
                    break;
                }
            }
            if (term == null)
            {
                return(new EbnfTerm(factor));
            }
            return(new EbnfTermConcatenation(factor, term));
        }
Пример #2
0
        private EbnfExpression VisitExpressionNode(IInternalTreeNode node)
        {
            EbnfTerm       term       = null;
            EbnfExpression expression = null;

            for (int c = 0; c < node.Children.Count; c++)
            {
                var child = node.Children[c];
                switch (child.NodeType)
                {
                case TreeNodeType.Internal:
                    var internalNode = child as IInternalTreeNode;
                    var symbolValue  = internalNode.Symbol.Value;
                    if (EbnfGrammar.Term == symbolValue)
                    {
                        term = VisitTermNode(internalNode);
                    }
                    else if (EbnfGrammar.Expression == symbolValue)
                    {
                        expression = VisitExpressionNode(internalNode);
                    }
                    break;

                case TreeNodeType.Token:
                    break;
                }
            }
            if (expression == null)
            {
                return(new EbnfExpression(term));
            }
            return(new EbnfExpressionAlteration(term, expression));
        }
Пример #3
0
 public EbnfExpressionAlteration(
     EbnfTerm term,
     EbnfExpression expression)
     : base(term)
 {
     Expression = expression;
     _hashCode  = ComputeHashCode();
 }
Пример #4
0
        IEnumerable <ProductionModel> Term(EbnfTerm term, ProductionModel currentProduction)
        {
            foreach (var production in Factor(term.Factor, currentProduction))
            {
                yield return(production);
            }

            if (term.NodeType != EbnfNodeType.EbnfTermConcatenation)
            {
                yield break;
            }

            var concatenation = term as EbnfTermConcatenation;

            foreach (var production in Term(concatenation.Term, currentProduction))
            {
                yield return(production);
            }
        }
Пример #5
0
 public EbnfExpression(EbnfTerm term)
 {
     Term      = term;
     _hashCode = ComputeHashCode();
 }
Пример #6
0
 public EbnfTermConcatenation(EbnfFactor factor, EbnfTerm term)
     : base(factor)
 {
     Term      = term;
     _hashCode = ComputeHashCode();
 }
Пример #7
0
        IEnumerable<ProductionModel> Term(EbnfTerm term, ProductionModel currentProduction)
        {
            foreach (var production in Factor(term.Factor, currentProduction))
                yield return production;

            if (term.NodeType != EbnfNodeType.EbnfTermConcatenation)
                yield break;

            var concatenation = term as EbnfTermConcatenation;
            foreach(var production in Term(concatenation.Term, currentProduction))
                yield return production;
        }
Пример #8
0
 public EbnfTermConcatenation(EbnfFactor factor, EbnfTerm term)
     : base(factor)
 {
     Term = term;
     _hashCode = ComputeHashCode();
 }