예제 #1
0
        public static IEnumerable <CFunctionDefinition> getFunctionContents(CToken[] tokens)
        {
            foreach (CMatchedData matched in matchExpression(function_declarator, tokens))
            {
                MatchResult currResult = compound_statement.match(tokens, matched.startIndex + matched.numMatches);

                if (currResult.isMatch && currResult.numMatches > 0)
                {
                    string functionName;
                    int    i;

                    for (i = matched.startIndex; i < tokens.Length && tokens[i].tokenCode != "("; i++)
                    {
                        ;
                    }

                    functionName = tokens[i - 1].tokenCode;

                    yield return(new CFunctionDefinition(functionName,
                                                         new CParser().parseCompoundStatement(
                                                             new Queue <CMatchedData>(
                                                                 new CMatchedData[] {
                        new CMatchedData(tokens, matched.startIndex + matched.numMatches, currResult.numMatches)
                    }
                                                                 )
                                                             )
                                                         ));
                }
            }
        }
예제 #2
0
        public static IEnumerable <SFunctionDefinition> GetFunctionContents(PToken[] tokens)
        {
            foreach (var matched in MatchExpression(FunctionDeclarator, tokens))
            {
                var currResult = CompoundStatement.match(tokens, matched.StartIndex + matched.NumMatches);

                if (!currResult.IsMatch || currResult.NumMatches <= 0)
                {
                    continue;
                }
                int i;

                for (i = matched.StartIndex; i < tokens.Length && tokens[i].TokenCode != "("; i++)
                {
                    ;
                }

                var functionName = tokens[i - 1].TokenCode;

                yield return(new SFunctionDefinition(functionName,
                                                     new PParser().ParseCompoundStatement(
                                                         new Queue <PMatchedData>(
                                                             new[]
                {
                    new PMatchedData(tokens, matched.StartIndex + matched.NumMatches, currResult.NumMatches)
                }
                                                             )
                                                         )
                                                     ));
            }
        }
예제 #3
0
        public static IEnumerable <CMatchedData> matchExpression(IMatchable expression,
                                                                 CToken[] tokens, bool getFirstMatches = true, int startIndex = 0)
        {
            int         i;
            MatchResult currResult;

            for (i = startIndex; i < tokens.Length; i += getFirstMatches && currResult.isMatch ? currResult.numMatches : 1)
            {
                currResult = expression.match(tokens, i);

                if (currResult.isMatch && currResult.numMatches > 0)
                {
                    yield return(new CMatchedData(tokens, i, currResult.numMatches));
                }
            }
        }
예제 #4
0
        private static IEnumerable <PMatchedData> MatchExpression(IMatchable expression, PToken[] tokens,
                                                                  bool getFirstMatches = true, int startIndex = 0)
        {
            int         i;
            MatchResult currResult;

            for (i = startIndex;
                 i < tokens.Length;
                 i += getFirstMatches && currResult.IsMatch ? currResult.NumMatches : 1)
            {
                currResult = expression.match(tokens, i);

                if (!currResult.IsMatch || currResult.NumMatches <= 0)
                {
                    continue;
                }
                yield return(new PMatchedData(tokens, i, currResult.NumMatches));
            }
        }
예제 #5
0
        private MatchResult matchNext(CToken[] tokens, int startIndex, IMatchable currSequence, int numRepeat)
        {
            MatchResult currResult    = currSequence.match(tokens, startIndex);
            int         nextNumRepeat = this.greedyMatch ? numRepeat - 1 : numRepeat + 1;

            if (!currResult.matchComplete)
            {
                return(new MatchResult(currResult.numMatches, false,
                                       (tokensArr, tokensStartIndex) => matchNext(tokensArr, tokensStartIndex, currResult, numRepeat)));
            }

            if (nextNumRepeat < this.repeatLowerBound || nextNumRepeat > this.repeatUpperBound)
            {
                return(currResult);
            }

            return(new MatchResult(currResult.numMatches, currResult.isMatch, false,
                                   (tokensArr, tokensStartIndex) => matchNext(tokensArr, tokensStartIndex,
                                                                              getRepeatSequence(nextNumRepeat), nextNumRepeat)));
        }
예제 #6
0
        private MatchResult MatchNext(PToken[] tokens, int startIndex, IMatchable currSequence, int numRepeat)
        {
            var currResult    = currSequence.match(tokens, startIndex);
            var nextNumRepeat = _greedyMatch ? numRepeat - 1 : numRepeat + 1;

            if (!currResult.MatchComplete)
            {
                return(new MatchResult(currResult.NumMatches, false,
                                       (tokensArr, tokensStartIndex) => MatchNext(tokensArr, tokensStartIndex, currResult, numRepeat)));
            }

            if (nextNumRepeat < _repeatLowerBound || nextNumRepeat > RepeatUpperBound)
            {
                return(currResult);
            }

            return(new MatchResult(currResult.NumMatches, currResult.IsMatch, false,
                                   (tokensArr, tokensStartIndex) => MatchNext(tokensArr, tokensStartIndex,
                                                                              GetRepeatSequence(nextNumRepeat), nextNumRepeat)));
        }