Esempio n. 1
0
        private bool TryRecognizeSimpleLiteralExpression(
            FullyQualifiedName fullyQualifiedName,
            PdlLexerRuleExpression ebnfLexerRule,
            out ILexerRule lexerRule)
        {
            lexerRule = null;

            if (ebnfLexerRule.NodeType != PdlNodeType.PdlLexerRuleExpression)
            {
                return(false);
            }

            var term = ebnfLexerRule.Term;

            if (term.NodeType != PdlNodeType.PdlLexerRuleTerm)
            {
                return(false);
            }

            var factor = term.Factor;

            if (factor.NodeType != PdlNodeType.PdlLexerRuleFactorLiteral)
            {
                return(false);
            }

            var literal = factor as PdlLexerRuleFactorLiteral;

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

            return(true);
        }
Esempio n. 2
0
        private PdlLexerRuleExpression VisitLexerRuleExpressionNode(IInternalTreeNode node)
        {
            PdlLexerRuleTerm       term       = null;
            PdlLexerRuleExpression 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 (PdlGrammar.LexerRuleTerm == symbolValue)
                {
                    term = VisitLexerRuleTermNode(internalNode);
                }
                if (PdlGrammar.LexerRuleExpression == symbolValue)
                {
                    expression = VisitLexerRuleExpressionNode(internalNode);
                }
            }

            if (expression is null)
            {
                return(new PdlLexerRuleExpression(term));
            }
            return(new PdlLexerRuleExpressionAlteration(term, expression));
        }
Esempio n. 3
0
        private PdlBlockLexerRule VisitLexerRuleNode(IInternalTreeNode node)
        {
            PdlQualifiedIdentifier qualifiedIdentifier = null;
            PdlLexerRuleExpression 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 (PdlGrammar.QualifiedIdentifier == symbolValue)
                {
                    qualifiedIdentifier = VisitQualifiedIdentifierNode(internalNode);
                }
                else if (PdlGrammar.LexerRuleExpression == symbolValue)
                {
                    expression = VisitLexerRuleExpressionNode(internalNode);
                }
            }
            return(new PdlBlockLexerRule(
                       new PdlLexerRule(qualifiedIdentifier, expression)));
        }
Esempio n. 4
0
        INfa LexerRuleExpression(PdlLexerRuleExpression expression)
        {
            var nfa = LexerRuleTerm(expression.Term);

            if (expression.NodeType == PdlNodeType.PdlLexerRuleExpressionAlteration)
            {
                var alteration    = expression as PdlLexerRuleExpressionAlteration;
                var alterationNfa = LexerRuleExpression(alteration);
                nfa = nfa.Union(alterationNfa);
            }
            return(nfa);
        }
Esempio n. 5
0
        private ILexerRule LexerRuleExpression(
            FullyQualifiedName fullyQualifiedName,
            PdlLexerRuleExpression ebnfLexerRule)
        {
            if (TryRecognizeSimpleLiteralExpression(fullyQualifiedName, ebnfLexerRule, out ILexerRule lexerRule))
            {
                return(lexerRule);
            }

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

            return(new DfaLexerRule(dfa, fullyQualifiedName.FullName));
        }
Esempio n. 6
0
 public PdlLexerRule(PdlQualifiedIdentifier qualifiedIdentifier, PdlLexerRuleExpression expression)
 {
     QualifiedIdentifier = qualifiedIdentifier;
     Expression          = expression;
     _hashCode           = ComputeHashCode();
 }
 public PdlLexerRuleExpressionAlteration(PdlLexerRuleTerm term, PdlLexerRuleExpression expression)
     : base(term)
 {
     Expression = expression;
     _hashCode  = ComputeHashCode();
 }