Exemplo n.º 1
0
        private EbnfBlockLexerRule VisitLexerRuleNode(IInternalTreeNode node)
        {
            EbnfQualifiedIdentifier qualifiedIdentifier = null;
            EbnfLexerRuleExpression expression          = null;

            for (int c = 0; c < node.Children.Count; c++)
            {
                var child = node.Children[c];
                if (child.NodeType != TreeNodeType.Internal)
                {
                    continue;
                }
                var internalNode = child as IInternalTreeNode;
                var symbolValue  = internalNode.Symbol.Value;
                if (EbnfGrammar.QualifiedIdentifier == symbolValue)
                {
                    qualifiedIdentifier = VisitQualifiedIdentifierNode(internalNode);
                }
                else if (EbnfGrammar.LexerRuleExpression == symbolValue)
                {
                    expression = VisitLexerRuleExpressionNode(internalNode);
                }
            }
            return(new EbnfBlockLexerRule(
                       new EbnfLexerRule(qualifiedIdentifier, expression)));
        }
Exemplo n.º 2
0
        private EbnfLexerRuleExpression VisitLexerRuleExpressionNode(IInternalTreeNode node)
        {
            EbnfLexerRuleTerm       term       = null;
            EbnfLexerRuleExpression expression = null;

            for (int c = 0; c < node.Children.Count; c++)
            {
                var child = node.Children[c];
                if (child.NodeType != TreeNodeType.Internal)
                {
                    continue;
                }
                var internalNode = child as IInternalTreeNode;
                var symbolValue  = internalNode.Symbol.Value;
                if (EbnfGrammar.LexerRuleTerm == symbolValue)
                {
                    term = VisitLexerRuleTermNode(internalNode);
                }
                if (EbnfGrammar.LexerRuleExpression == symbolValue)
                {
                    expression = VisitLexerRuleExpressionNode(internalNode);
                }
            }

            if (expression == null)
            {
                return(new EbnfLexerRuleExpression(term));
            }
            return(new EbnfLexerRuleExpressionAlteration(term, expression));
        }
Exemplo n.º 3
0
        private bool TryRecognizeSimpleLiteralExpression(
            FullyQualifiedName fullyQualifiedName,
            EbnfLexerRuleExpression ebnfLexerRule,
            out ILexerRule lexerRule)
        {
            lexerRule = null;

            if (ebnfLexerRule.NodeType != EbnfNodeType.EbnfLexerRuleExpression)
            {
                return(false);
            }

            var term = ebnfLexerRule.Term;

            if (term.NodeType != EbnfNodeType.EbnfLexerRuleTerm)
            {
                return(false);
            }

            var factor = term.Factor;

            if (factor.NodeType != EbnfNodeType.EbnfLexerRuleFactorLiteral)
            {
                return(false);
            }

            var literal = factor as EbnfLexerRuleFactorLiteral;

            lexerRule = new StringLiteralLexerRule(
                literal.Value,
                new TokenType(fullyQualifiedName.FullName));

            return(true);
        }
Exemplo n.º 4
0
        INfa LexerRuleExpression(EbnfLexerRuleExpression expression)
        {
            var nfa = LexerRuleTerm(expression.Term);

            if (expression.NodeType == EbnfNodeType.EbnfLexerRuleExpressionAlteration)
            {
                var alteration    = expression as EbnfLexerRuleExpressionAlteration;
                var alterationNfa = LexerRuleExpression(alteration);
                nfa = nfa.Union(alterationNfa);
            }
            return(nfa);
        }
Exemplo n.º 5
0
        private ILexerRule LexerRuleExpression(
            FullyQualifiedName fullyQualifiedName,
            EbnfLexerRuleExpression ebnfLexerRule)
        {
            ILexerRule lexerRule = null;

            if (TryRecognizeSimpleLiteralExpression(fullyQualifiedName, ebnfLexerRule, out lexerRule))
            {
                return(lexerRule);
            }

            var nfa = LexerRuleExpression(ebnfLexerRule);
            var dfa = _nfaToDfaAlgorithm.Transform(nfa);

            return(new DfaLexerRule(dfa, fullyQualifiedName.FullName));
        }
Exemplo n.º 6
0
 public EbnfLexerRule(EbnfQualifiedIdentifier qualifiedIdentifier, EbnfLexerRuleExpression expression)
 {
     QualifiedIdentifier = qualifiedIdentifier;
     Expression          = expression;
     _hashCode           = ComputeHashCode();
 }
Exemplo n.º 7
0
 public EbnfLexerRuleExpressionAlteration(EbnfLexerRuleTerm term, EbnfLexerRuleExpression expression)
     : base(term)
 {
     Expression = expression;
     _hashCode = ComputeHashCode();
 }
Exemplo n.º 8
0
 public EbnfLexerRuleExpressionAlteration(EbnfLexerRuleTerm term, EbnfLexerRuleExpression expression)
     : base(term)
 {
     Expression = expression;
     _hashCode  = ComputeHashCode();
 }
Exemplo n.º 9
0
 public EbnfLexerRule(EbnfQualifiedIdentifier qualifiedIdentifier, EbnfLexerRuleExpression expression)
 {
     QualifiedIdentifier = qualifiedIdentifier;
     Expression = expression;
     _hashCode = ComputeHashCode();
 }