예제 #1
0
        //*
        // * Creates a new look-ahead set filter. The filter will contain
        // * all sequences from this set, possibly left trimmed by each one
        // * of the sequences in the specified set.
        // *
        // * @param set the look-ahead set to trim with
        // *
        // * @return a new look-ahead set filter
        //

        public LookAheadSet CreateFilter(LookAheadSet @set)
        {
            LookAheadSet result = new LookAheadSet(maxLength);
            Sequence     first  = default(Sequence);
            Sequence     second = default(Sequence);

            // Handle special cases
            if (this.Size() <= 0 || @set.Size() <= 0)
            {
                return(this);
            }
            for (int i = 0; i <= elements.Count - 1; i++)
            {
                // Create combinations
                first = (Sequence)elements[i];
                for (int j = 0; j <= @set.elements.Count - 1; j++)
                {
                    second = (Sequence)@set.elements[j];
                    if (first.StartsWith(second))
                    {
                        result.Add(first.Subsequence(second.Length()));
                    }
                }
            }
            return(result);
        }
예제 #2
0
        //*
        // * Creates a new identical look-ahead set, except for the
        // * repeat flag being set in each token sequence.
        // *
        // * @return a new repetitive look-ahead set
        //

        public LookAheadSet CreateRepetitive()
        {
            LookAheadSet result = new LookAheadSet(maxLength);
            Sequence     seq    = default(Sequence);

            for (int i = 0; i <= elements.Count - 1; i++)
            {
                seq = (Sequence)elements[i];
                if (seq.IsRepetitive())
                {
                    result.Add(seq);
                }
                else
                {
                    result.Add(new Sequence(true, seq));
                }
            }
            return(result);
        }
예제 #3
0
        //*
        // * Creates a new look-ahead set that is the intersection of
        // * this set with another set. The token sequences in the net
        // * set will only have the repeat flag set if it was set in
        // * both the identical token sequences.
        // *
        // * @param set the set to intersect with
        // *
        // * @return a new look-ahead set containing the intersection
        //

        public LookAheadSet CreateIntersection(LookAheadSet @set)
        {
            LookAheadSet result = new LookAheadSet(maxLength);
            Sequence     seq1   = default(Sequence);
            Sequence     seq2   = default(Sequence);

            for (int i = 0; i <= elements.Count - 1; i++)
            {
                seq1 = (Sequence)elements[i];
                seq2 = @set.FindSequence(seq1);
                if (seq2 != null && seq1.IsRepetitive())
                {
                    result.Add(seq2);
                }
                else if (seq2 != null)
                {
                    result.Add(seq1);
                }
            }
            return(result);
        }
예제 #4
0
        //*
        // * Creates a new look-ahead set that is the combination of
        // * this set with another set. The combination is created by
        // * creating new token sequences that consist of appending all
        // * elements from the specified set onto all elements in this
        // * set. This is sometimes referred to as the cartesian
        // * product.
        // *
        // * @param set the set to combine with
        // *
        // * @return a new look-ahead set containing the combination
        //

        public LookAheadSet CreateCombination(LookAheadSet @set)
        {
            LookAheadSet result = new LookAheadSet(maxLength);
            Sequence     first  = default(Sequence);
            Sequence     second = default(Sequence);

            // Handle special cases
            if (this.Size() <= 0)
            {
                return(@set);
            }
            else if (@set.Size() <= 0)
            {
                return(this);
            }
            for (int i = 0; i <= elements.Count - 1; i++)
            {
                // Create combinations
                first = (Sequence)elements[i];
                if (first.Length() >= maxLength)
                {
                    result.Add(first);
                }
                else if (first.Length() <= 0)
                {
                    result.AddAll(@set);
                }
                else
                {
                    for (int j = 0; j <= @set.elements.Count - 1; j++)
                    {
                        second = (Sequence)@set.elements[j];
                        result.Add(first.Concat(maxLength, second));
                    }
                }
            }
            return(result);
        }
예제 #5
0
        //*
        // * Creates a new look-ahead set with overlaps from another. All
        // * token sequences in this set that overlaps with the other set
        // * will be added to the new look-ahead set.
        // *
        // * @param set the look-ahead set to check with
        // *
        // * @return a new look-ahead set containing the overlaps
        //

        public LookAheadSet CreateOverlaps(LookAheadSet @set)
        {
            LookAheadSet result = new LookAheadSet(maxLength);
            Sequence     seq    = default(Sequence);

            for (int i = 0; i <= elements.Count - 1; i++)
            {
                seq = (Sequence)elements[i];
                if (@set.IsOverlap(seq))
                {
                    result.Add(seq);
                }
            }
            return(result);
        }
예제 #6
0
        //*
        // * Creates a new look-ahead set that is the result of reading
        // * the specified token. The new look-ahead set will contain
        // * the rest of all the token sequences that started with the
        // * specified token.
        // *
        // * @param token the token to read
        // *
        // * @return a new look-ahead set containing the remaining tokens
        //

        public LookAheadSet CreateNextSet(int token)
        {
            LookAheadSet result = new LookAheadSet(maxLength - 1);
            Sequence     seq    = default(Sequence);
            object       value  = null;

            for (int i = 0; i <= elements.Count - 1; i++)
            {
                seq   = (Sequence)elements[i];
                value = seq.GetToken(0);
                if (value != null && token == (int)value)
                {
                    result.Add(seq.Subsequence(1));
                }
            }
            return(result);
        }