Ejemplo n.º 1
0
        private LookAheadSet FindLookAhead(ProductionPatternElement elem,
                                           int length,
                                           int dummy,
                                           CallStack stack,
                                           LookAheadSet filter)
        {
            LookAheadSet result;

            if (elem.IsToken())
            {
                result = new LookAheadSet(length);
                result.Add(elem.Id);
            }
            else
            {
                var pattern = GetPattern(elem.Id);
                result = FindLookAhead(pattern, length, stack, filter);
                if (stack.Contains(pattern.Name))
                {
                    result = result.CreateRepetitive();
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
 private void ParseElement(Production node,
                           ProductionPatternElement elem)
 {
     for (int i = 0; i < elem.MaxCount; i++)
     {
         if (i < elem.MinCount || IsNext(elem))
         {
             Node child;
             if (elem.IsToken())
             {
                 child = NextToken(elem.Id);
                 EnterNode(child);
                 AddNode(node, ExitNode(child));
             }
             else
             {
                 child = ParsePattern(GetPattern(elem.Id));
                 AddNode(node, child);
             }
         }
         else
         {
             break;
         }
     }
 }
 public void AddElement(ProductionPatternElement elem,
                        int min,
                        int max)
 {
     if (elem.IsToken())
     {
         AddToken(elem.Id, min, max);
     }
     else
     {
         AddProduction(elem.Id, min, max);
     }
 }
Ejemplo n.º 4
0
        private bool IsNext(ProductionPatternElement elem)
        {
            LookAheadSet set = elem.LookAhead;

            if (set != null)
            {
                return(set.IsNext(this));
            }
            else if (elem.IsToken())
            {
                return(elem.IsMatch(PeekToken(0)));
            }
            else
            {
                return(IsNext(GetPattern(elem.Id)));
            }
        }
Ejemplo n.º 5
0
        private string ToString(ProductionPatternElement elem)
        {
            StringBuilder buffer = new StringBuilder();
            int           min    = elem.MinCount;
            int           max    = elem.MaxCount;

            if (min == 0 && max == 1)
            {
                buffer.Append("[");
            }
            if (elem.IsToken())
            {
                buffer.Append(GetTokenDescription(elem.Id));
            }
            else
            {
                buffer.Append(GetPattern(elem.Id).Name);
            }
            if (min == 0 && max == 1)
            {
                buffer.Append("]");
            }
            else if (min == 0 && max == Int32.MaxValue)
            {
                buffer.Append("*");
            }
            else if (min == 1 && max == Int32.MaxValue)
            {
                buffer.Append("+");
            }
            else if (min != 1 || max != 1)
            {
                buffer.Append("{");
                buffer.Append(min);
                buffer.Append(",");
                buffer.Append(max);
                buffer.Append("}");
            }
            return(buffer.ToString());
        }