Example #1
0
        private void ParseElement(Production node, ProductionPatternElement elem)
        {
            var num = elem.MaxCount - 1;

            for (var i = 0; i <= num; i++)
            {
                var flag = i < elem.MinCount || this.IsNext(elem);
                if (!flag)
                {
                    break;
                }
                var flag2 = elem.IsToken();
                if (flag2)
                {
                    Node child = this.NextToken(elem.Id);
                    this.EnterNode(child);
                    this.AddNode(node, this.ExitNode(child));
                }
                else
                {
                    var child = this.ParsePattern(this.GetPattern(elem.Id));
                    this.AddNode(node, child);
                }
            }
        }
Example #2
0
        private void CheckElement(string name, ProductionPatternElement elem)
        {
            var flag = elem.IsProduction() && this.GetPattern(elem.Id) == null;

            if (flag)
            {
                throw new ParserCreationException(ParserCreationException.ErrorType.INVALID_PRODUCTION, name,
                                                  Conversions.ToString(Conversions.ToDouble("an undefined production pattern id (") +
                                                                       elem.Id + Conversions.ToDouble(") is referenced")));
            }
        }
Example #3
0
        public void AddElement(ProductionPatternElement elem, int min, int max)
        {
            var flag = elem.IsToken();

            if (flag)
            {
                this.AddToken(elem.Id, min, max);
            }
            else
            {
                this.AddProduction(elem.Id, min, max);
            }
        }
Example #4
0
        private string ToString(ProductionPatternElement elem)
        {
            var buffer = new StringBuilder();
            var min    = elem.MinCount;
            var max    = elem.MaxCount;
            var flag   = min == 0 && max == 1;

            if (flag)
            {
                buffer.Append("[");
            }
            var flag2 = elem.IsToken();

            buffer.Append(flag2 ? this.GetTokenDescription(elem.Id) : this.GetPattern(elem.Id).Name);
            var flag3 = min == 0 && max == 1;

            if (flag3)
            {
                buffer.Append("]");
            }
            else
            {
                var flag4 = min == 0 && max == 2147483647;
                if (flag4)
                {
                    buffer.Append("*");
                }
                else
                {
                    var flag5 = min == 1 && max == 2147483647;
                    if (flag5)
                    {
                        buffer.Append("+");
                    }
                    else
                    {
                        var flag6 = min != 1 || max != 1;
                        if (flag6)
                        {
                            buffer.Append("{");
                            buffer.Append(min);
                            buffer.Append(",");
                            buffer.Append(max);
                            buffer.Append("}");
                        }
                    }
                }
            }
            return(buffer.ToString());
        }
Example #5
0
        private bool IsNext(ProductionPatternElement elem)
        {
            var  set  = elem.LookAhead;
            var  flag = set != null;
            bool isNext;

            if (flag)
            {
                isNext = set.IsNext(this);
            }
            else
            {
                var flag2 = elem.IsToken();
                isNext = flag2 ? elem.IsMatch(this.PeekToken(0)) : this.IsNext(this.GetPattern(elem.Id));
            }
            return(isNext);
        }
Example #6
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 #7
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);
        }
Example #8
0
 public void AddElement(ProductionPatternElement elem)
 {
     this.elements.Add(elem);
 }