Example #1
0
        private PdlTerm VisitTermNode(IInternalTreeNode node)
        {
            PdlFactor factor = null;
            PdlTerm   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 (PdlGrammar.Factor == symbolValue)
                    {
                        factor = VisitFactorNode(internalNode);
                    }
                    else if (PdlGrammar.Term == symbolValue)
                    {
                        term = VisitTermNode(internalNode);
                    }
                    break;

                case TreeNodeType.Token:
                    break;
                }
            }
            if (term is null)
            {
                return(new PdlTerm(factor));
            }
            return(new PdlTermConcatenation(factor, term));
        }
Example #2
0
        private PdlExpression VisitExpressionNode(IInternalTreeNode node)
        {
            PdlTerm       term       = null;
            PdlExpression 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 (PdlGrammar.Term == symbolValue)
                    {
                        term = VisitTermNode(internalNode);
                    }
                    else if (PdlGrammar.Expression == symbolValue)
                    {
                        expression = VisitExpressionNode(internalNode);
                    }
                    break;

                case TreeNodeType.Token:
                    break;
                }
            }
            if (expression is null)
            {
                return(new PdlExpression(term));
            }
            return(new PdlExpressionAlteration(term, expression));
        }
Example #3
0
 public PdlExpressionAlteration(
     PdlTerm term,
     PdlExpression expression)
     : base(term)
 {
     Expression = expression;
     _hashCode  = ComputeHashCode();
 }
        IEnumerable <ProductionModel> Term(PdlTerm term, ProductionModel currentProduction)
        {
            foreach (var production in Factor(term.Factor, currentProduction))
            {
                yield return(production);
            }

            if (term.NodeType != PdlNodeType.PdlTermConcatenation)
            {
                yield break;
            }

            var concatenation = term as PdlTermConcatenation;

            foreach (var production in Term(concatenation.Term, currentProduction))
            {
                yield return(production);
            }
        }
Example #5
0
 public PdlTermConcatenation(PdlFactor factor, PdlTerm term)
     : base(factor)
 {
     Term      = term;
     _hashCode = ComputeHashCode();
 }
Example #6
0
 public PdlExpression(PdlTerm term)
 {
     Term      = term;
     _hashCode = ComputeHashCode();
 }