예제 #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
파일: EbnfTerm.cs 프로젝트: DinkDev/Pliant
 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();
 }