Example #1
0
        private LookAheadSet FindLookAhead(ProductionPatternElement elem, int length, CallStack stack, LookAheadSet filter)
        {
            var first  = this.FindLookAhead(elem, length, 0, stack, filter);
            var result = new LookAheadSet(length);

            result.AddAll(first);
            var          flag = filter == null || !filter.IsOverlap(result);
            LookAheadSet findLookAhead;

            if (flag)
            {
                findLookAhead = result;
            }
            else
            {
                var flag2 = elem.MaxCount == 2147483647;
                if (flag2)
                {
                    first = first.CreateRepetitive();
                }
                var max   = elem.MaxCount;
                var flag3 = length < max;
                if (flag3)
                {
                    max = length;
                }
                var num = max - 1;
                for (var i = 1; i <= num; i++)
                {
                    first = first.CreateOverlaps(filter);
                    var flag4 = first.Size() <= 0 || first.GetMinLength() >= length;
                    if (flag4)
                    {
                        break;
                    }
                    var follow = this.FindLookAhead(elem, length, 0, stack, filter.CreateFilter(first));
                    first = first.CreateCombination(follow);
                    result.AddAll(first);
                }
                findLookAhead = result;
            }
            return(findLookAhead);
        }
Example #2
0
        public LookAheadSet CreateCombination(LookAheadSet set)
        {
            var          result = new LookAheadSet(this.maxLength);
            var          flag   = this.Size() <= 0;
            LookAheadSet createCombination;

            if (flag)
            {
                createCombination = set;
            }
            else
            {
                var flag2 = set.Size() <= 0;
                if (flag2)
                {
                    createCombination = this;
                }
                else
                {
                    var num = this.elements.Count - 1;
                    for (var i = 0; i <= num; i++)
                    {
                        var first = (Sequence)this.elements[i];
                        var flag3 = first.Length() >= this.maxLength;
                        if (flag3)
                        {
                            result.Add(first);
                        }
                        else
                        {
                            var flag4 = first.Length() <= 0;
                            if (flag4)
                            {
                                result.AddAll(set);
                            }
                            else
                            {
                                var num2 = set.elements.Count - 1;
                                for (var j = 0; j <= num2; j++)
                                {
                                    var second = (Sequence)set.elements[j];
                                    result.Add(first.Concat(this.maxLength, second));
                                }
                            }
                        }
                    }
                    createCombination = result;
                }
            }
            return(createCombination);
        }
Example #3
0
        private LookAheadSet FindLookAhead(ProductionPattern pattern, int length, CallStack stack, LookAheadSet filter)
        {
            var flag = stack.Contains(pattern.Name, length);

            if (flag)
            {
                throw new ParserCreationException(ParserCreationException.ErrorType.INFINITE_LOOP, pattern.Name, null);
            }
            stack.Push(pattern.Name, length);
            var result = new LookAheadSet(length);
            var num    = pattern.Count - 1;

            for (var i = 0; i <= num; i++)
            {
                var temp = this.FindLookAhead(pattern[i], length, 0, stack, filter);
                result.AddAll(temp);
            }
            stack.Pop();
            return(result);
        }
Example #4
0
        private LookAheadSet FindConflicts(ProductionPattern pattern, int maxLength)
        {
            var result = new LookAheadSet(maxLength);
            var num    = pattern.Count - 1;

            for (var i = 0; i <= num; i++)
            {
                var set  = pattern[i].LookAheadSet;
                var num2 = i - 1;
                for (var j = 0; j <= num2; j++)
                {
                    var set2 = pattern[j].LookAheadSet;
                    result.AddAll(set.CreateIntersection(set2));
                }
            }
            var flag = result.IsRepetitive();

            if (flag)
            {
                this.ThrowAmbiguityException(pattern.Name, null, result);
            }
            return(result);
        }
Example #5
0
        private LookAheadSet FindUnion(ProductionPattern pattern)
        {
            var          length = 0;
            var          num    = pattern.Count - 1;
            LookAheadSet result;

            for (var i = 0; i <= num; i++)
            {
                result = pattern[i].LookAheadSet;
                var flag = result.GetMaxLength() > length;
                if (flag)
                {
                    length = result.GetMaxLength();
                }
            }
            result = new LookAheadSet(length);
            var num2 = pattern.Count - 1;

            for (var i = 0; i <= num2; i++)
            {
                result.AddAll(pattern[i].LookAheadSet);
            }
            return(result);
        }
Example #6
0
        private void CalculateLookAhead(ProductionPattern pattern)
        {
            var previous = new LookAheadSet(0);
            var length   = 1;
            var stack    = new CallStack();

            stack.Push(pattern.Name, 1);
            var result       = new LookAheadSet(1);
            var alternatives = new LookAheadSet[pattern.Count - 1 + 1];
            var num          = pattern.Count - 1;

            for (var i = 0; i <= num; i++)
            {
                var alt = pattern[i];
                alternatives[i]  = this.FindLookAhead(alt, 1, 0, stack, null);
                alt.LookAheadSet = alternatives[i];
                result.AddAll(alternatives[i]);
            }
            var flag = pattern.LookAhead == null;

            if (flag)
            {
                pattern.LookAhead = result;
            }
            var conflicts = this.FindConflicts(pattern, 1);

            while (conflicts.Size() > 0)
            {
                length++;
                stack.Clear();
                stack.Push(pattern.Name, length);
                conflicts.AddAll(previous);
                var num2 = pattern.Count - 1;
                for (var i = 0; i <= num2; i++)
                {
                    var alt   = pattern[i];
                    var flag2 = alternatives[i].Intersects(conflicts);
                    if (flag2)
                    {
                        alternatives[i]  = this.FindLookAhead(alt, length, 0, stack, conflicts);
                        alt.LookAheadSet = alternatives[i];
                    }
                    var flag3 = alternatives[i].Intersects(conflicts);
                    if (flag3)
                    {
                        var flag4 = pattern.DefaultAlternative == null;
                        if (flag4)
                        {
                            pattern.DefaultAlternative = alt;
                        }
                        else
                        {
                            // ReSharper disable once PossibleUnintendedReferenceComparison
                            var flag5 = pattern.DefaultAlternative != alt;
                            if (flag5)
                            {
                                result = alternatives[i].CreateIntersection(conflicts);
                                this.ThrowAmbiguityException(pattern.Name, null, result);
                            }
                        }
                    }
                }
                previous  = conflicts;
                conflicts = this.FindConflicts(pattern, length);
            }
            var num3 = pattern.Count - 1;

            for (var i = 0; i <= num3; i++)
            {
                this.CalculateLookAhead(pattern[i], 0);
            }
        }