Exemple #1
0
        private EbnfBlockRule VisitRuleNode(IInternalTreeNode node)
        {
            EbnfQualifiedIdentifier qualifiedIdentifier = 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.QualifiedIdentifier == symbolValue)
                    {
                        qualifiedIdentifier = VisitQualifiedIdentifierNode(internalNode);
                    }
                    else if (EbnfGrammar.Expression == symbolValue)
                    {
                        expression = VisitExpressionNode(internalNode);
                    }
                    break;

                case TreeNodeType.Token:
                    break;
                }
            }
            return(new EbnfBlockRule(
                       new EbnfRule(qualifiedIdentifier, expression)));
        }
Exemple #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));
        }
Exemple #3
0
 public EbnfExpressionAlteration(
     EbnfTerm term,
     EbnfExpression expression)
     : base(term)
 {
     Expression = expression;
     _hashCode  = ComputeHashCode();
 }
Exemple #4
0
        IEnumerable <ProductionModel> Expression(EbnfExpression expression, ProductionModel currentProduction)
        {
            foreach (var production in Term(expression.Term, currentProduction))
            {
                yield return(production);
            }

            if (expression.NodeType != EbnfNodeType.EbnfExpressionAlteration)
            {
                yield break;
            }

            var expressionAlteration = expression as EbnfExpressionAlteration;

            currentProduction.Lambda();

            foreach (var production in Expression(expressionAlteration.Expression, currentProduction))
            {
                yield return(production);
            }
        }
Exemple #5
0
 public EbnfFactorGrouping(EbnfExpression expression)
 {
     Expression = expression;
     _hashCode  = ComputeHashCode();
 }
Exemple #6
0
 public EbnfFactorOptional(EbnfExpression expression)
 {
     Expression = expression;
     _hashCode  = ComputeHashCode();
 }
Exemple #7
0
 public EbnfFactorRepetition(EbnfExpression expression)
 {
     Expression = expression;
     _hashCode  = ComputeHashCode();
 }
Exemple #8
0
 public EbnfRule(EbnfQualifiedIdentifier qualifiedIdentifier, EbnfExpression expression)
 {
     QualifiedIdentifier = qualifiedIdentifier;
     Expression          = expression;
     _hashCode           = ComputeHashCode();
 }