コード例 #1
0
ファイル: LookAheadSet.cs プロジェクト: jblacker/Flee
        public LookAheadSet CreateIntersection(LookAheadSet set)
        {
            var result = new LookAheadSet(this.maxLength);
            var num    = this.elements.Count - 1;

            for (var i = 0; i <= num; i++)
            {
                var seq  = (Sequence)this.elements[i];
                var seq2 = set.FindSequence(seq);
                var flag = seq2 != null && seq.IsRepetitive();
                if (flag)
                {
                    result.Add(seq2);
                }
                else
                {
                    var flag2 = seq2 != null;
                    if (flag2)
                    {
                        result.Add(seq);
                    }
                }
            }
            return(result);
        }
コード例 #2
0
ファイル: LookAheadSet.cs プロジェクト: jblacker/Flee
        public LookAheadSet CreateFilter(LookAheadSet set)
        {
            var          result = new LookAheadSet(this.maxLength);
            var          flag   = this.Size() <= 0 || set.Size() <= 0;
            LookAheadSet createFilter;

            if (flag)
            {
                createFilter = this;
            }
            else
            {
                var num = this.elements.Count - 1;
                for (var i = 0; i <= num; i++)
                {
                    var first = (Sequence)this.elements[i];
                    var num2  = set.elements.Count - 1;
                    for (var j = 0; j <= num2; j++)
                    {
                        var second = (Sequence)set.elements[j];
                        var flag2  = first.StartsWith(second);
                        if (flag2)
                        {
                            result.Add(first.Subsequence(second.Length()));
                        }
                    }
                }
                createFilter = result;
            }
            return(createFilter);
        }
コード例 #3
0
ファイル: LookAheadSet.cs プロジェクト: jblacker/Flee
        public void RemoveAll(LookAheadSet set)
        {
            var num = set.elements.Count - 1;

            for (var i = 0; i <= num; i++)
            {
                this.Remove((Sequence)set.elements[i]);
            }
        }
コード例 #4
0
        private LookAheadSet FindConflicts(string pattern, string location, LookAheadSet set1, LookAheadSet set2)
        {
            var result = set1.CreateIntersection(set2);
            var flag   = result.IsRepetitive();

            if (flag)
            {
                this.ThrowAmbiguityException(pattern, location, result);
            }
            return(result);
        }
コード例 #5
0
        private void ThrowAmbiguityException(string pattern, string location, LookAheadSet set)
        {
            var list     = new ArrayList();
            var initials = set.GetInitialTokens();
            var num      = initials.Length - 1;

            for (var i = 0; i <= num; i++)
            {
                list.Add(this.GetTokenDescription(initials[i]));
            }
            throw new ParserCreationException(ParserCreationException.ErrorType.INHERENT_AMBIGUITY, pattern, location, list);
        }
コード例 #6
0
ファイル: LookAheadSet.cs プロジェクト: jblacker/Flee
        public LookAheadSet CreateRepetitive()
        {
            var result = new LookAheadSet(this.maxLength);
            var num    = this.elements.Count - 1;

            for (var i = 0; i <= num; i++)
            {
                var seq  = (Sequence)this.elements[i];
                var flag = seq.IsRepetitive();
                result.Add(flag ? seq : new Sequence(true, seq));
            }
            return(result);
        }
コード例 #7
0
ファイル: LookAheadSet.cs プロジェクト: jblacker/Flee
        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);
        }
コード例 #8
0
ファイル: LookAheadSet.cs プロジェクト: jblacker/Flee
        public bool Intersects(LookAheadSet set)
        {
            var num = this.elements.Count - 1;

            for (var i = 0; i <= num; i++)
            {
                var flag = set.Contains((Sequence)this.elements[i]);
                if (flag)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #9
0
ファイル: LookAheadSet.cs プロジェクト: jblacker/Flee
        public bool IsOverlap(LookAheadSet set)
        {
            var num = this.elements.Count - 1;

            for (var i = 0; i <= num; i++)
            {
                var flag = set.IsOverlap((Sequence)this.elements[i]);
                if (flag)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #10
0
ファイル: LookAheadSet.cs プロジェクト: jblacker/Flee
        public LookAheadSet CreateOverlaps(LookAheadSet set)
        {
            var result = new LookAheadSet(this.maxLength);
            var num    = this.elements.Count - 1;

            for (var i = 0; i <= num; i++)
            {
                var seq  = (Sequence)this.elements[i];
                var flag = set.IsOverlap(seq);
                if (flag)
                {
                    result.Add(seq);
                }
            }
            return(result);
        }
コード例 #11
0
ファイル: LookAheadSet.cs プロジェクト: jblacker/Flee
        public LookAheadSet CreateNextSet(int token)
        {
            var result = new LookAheadSet(this.maxLength - 1);
            var num    = this.elements.Count - 1;

            for (var i = 0; i <= num; i++)
            {
                var seq   = (Sequence)this.elements[i];
                var value = RuntimeHelpers.GetObjectValue(seq.GetToken(0));
                var flag  = value != null && token == Conversions.ToInteger(value);
                if (flag)
                {
                    result.Add(seq.Subsequence(1));
                }
            }
            return(result);
        }
コード例 #12
0
        private LookAheadSet FindLookAhead(ProductionPatternAlternative alt, int length, int pos, CallStack stack, LookAheadSet filter)
        {
            var          flag = length <= 0 || pos >= alt.Count;
            LookAheadSet findLookAhead;

            if (flag)
            {
                findLookAhead = new LookAheadSet(0);
            }
            else
            {
                var first = this.FindLookAhead(alt[pos], length, stack, filter);
                var flag2 = alt[pos].MinCount == 0;
                if (flag2)
                {
                    first.AddEmpty();
                }
                var flag3 = filter == null;
                if (flag3)
                {
                    length -= first.GetMinLength();
                    var flag4 = length > 0;
                    if (flag4)
                    {
                        var follow = this.FindLookAhead(alt, length, pos + 1, stack, null);
                        first = first.CreateCombination(follow);
                    }
                }
                else
                {
                    var flag5 = filter.IsOverlap(first);
                    if (flag5)
                    {
                        var overlaps = first.CreateOverlaps(filter);
                        length -= overlaps.GetMinLength();
                        filter  = filter.CreateFilter(overlaps);
                        var follow = this.FindLookAhead(alt, length, pos + 1, stack, filter);
                        first.RemoveAll(overlaps);
                        first.AddAll(overlaps.CreateCombination(follow));
                    }
                }
                findLookAhead = first;
            }
            return(findLookAhead);
        }
コード例 #13
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);
        }
コード例 #14
0
        private void CalculateLookAhead(ProductionPatternAlternative alt, int pos)
        {
            var previous = new LookAheadSet(0);
            var length   = 1;
            var flag     = pos >= alt.Count;

            if (!flag)
            {
                var pattern = alt.Pattern;
                var elem    = alt[pos];
                var flag2   = elem.MinCount == elem.MaxCount;
                if (flag2)
                {
                    this.CalculateLookAhead(alt, pos + 1);
                }
                else
                {
                    var first     = this.FindLookAhead(elem, 1, new CallStack(), null);
                    var follow    = this.FindLookAhead(alt, 1, pos + 1, new CallStack(), null);
                    var location  = "at position " + Conversions.ToString(pos + 1);
                    var conflicts = this.FindConflicts(pattern.Name, location, first, follow);
                    while (conflicts.Size() > 0)
                    {
                        length++;
                        conflicts.AddAll(previous);
                        first          = this.FindLookAhead(elem, length, new CallStack(), conflicts);
                        follow         = this.FindLookAhead(alt, length, pos + 1, new CallStack(), conflicts);
                        first          = first.CreateCombination(follow);
                        elem.LookAhead = first;
                        var flag3 = first.Intersects(conflicts);
                        if (flag3)
                        {
                            first = first.CreateIntersection(conflicts);
                            this.ThrowAmbiguityException(pattern.Name, location, first);
                        }
                        previous  = conflicts;
                        conflicts = this.FindConflicts(pattern.Name, location, first, follow);
                    }
                    this.CalculateLookAhead(alt, pos + 1);
                }
            }
        }
コード例 #15
0
        private void ThrowParseException(LookAheadSet set)
        {
            var list = new List <string>();

            while (set.IsNext(this, 1))
            {
                set = set.CreateNextSet(this.NextToken().Id);
            }
            var initials = set.GetInitialTokens();
            var num      = initials.Length - 1;

            for (var i = 0; i <= num; i++)
            {
                list.Add(this.GetTokenDescription(initials[i]));
            }
            var token = this.NextToken();

            throw new ParseException(ParseException.ErrorType.UnexpectedToken, token.ToShortString(), list, token.StartLine,
                                     token.StartColumn);
        }
コード例 #16
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);
        }
コード例 #17
0
        // ReSharper disable once UnusedParameter.Local
        private LookAheadSet FindLookAhead(ProductionPatternElement elem, int length, int dummy, CallStack stack, LookAheadSet filter)
        {
            var          flag = elem.IsToken();
            LookAheadSet result;

            if (flag)
            {
                result = new LookAheadSet(length);
                result.Add(elem.Id);
            }
            else
            {
                var pattern = this.GetPattern(elem.Id);
                result = this.FindLookAhead(pattern, length, stack, filter);
                var flag2 = stack.Contains(pattern.Name);
                if (flag2)
                {
                    result = result.CreateRepetitive();
                }
            }
            return(result);
        }
コード例 #18
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);
        }
コード例 #19
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);
        }
コード例 #20
0
ファイル: LookAheadSet.cs プロジェクト: jblacker/Flee
 public LookAheadSet(int maxLength, LookAheadSet set)
     : this(maxLength)
 {
     this.AddAll(set);
 }
コード例 #21
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);
            }
        }