public LookAheadSet CreateFilter(LookAheadSet set) { LookAheadSet result = new LookAheadSet(_maxLength); // Handle special cases if (this.Size() <= 0 || set.Size() <= 0) { return(this); } // Create combinations for (int i = 0; i < _elements.Count; i++) { var first = (Sequence)_elements[i]; for (int j = 0; j < set._elements.Count; j++) { var second = (Sequence)set._elements[j]; if (first.StartsWith(second)) { result.Add(first.Subsequence(second.Length())); } } } return(result); }
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); }
public LookAheadSet CreateRepetitive() { LookAheadSet result = new LookAheadSet(_maxLength); for (int i = 0; i < _elements.Count; i++) { var seq = (Sequence)_elements[i]; if (seq.IsRepetitive()) { result.Add(seq); } else { result.Add(new Sequence(true, seq)); } } return(result); }
public LookAheadSet CreateIntersection(LookAheadSet set) { LookAheadSet result = new LookAheadSet(_maxLength); for (int i = 0; i < _elements.Count; i++) { var seq1 = (Sequence)_elements[i]; var seq2 = set.FindSequence(seq1); if (seq2 != null && seq1.IsRepetitive()) { result.Add(seq2); } else if (seq2 != null) { result.Add(seq1); } } return(result); }
public LookAheadSet CreateCombination(LookAheadSet set) { LookAheadSet result = new LookAheadSet(_maxLength); // Handle special cases if (this.Size() <= 0) { return(set); } else if (set.Size() <= 0) { return(this); } // Create combinations for (int i = 0; i < _elements.Count; i++) { var 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; j++) { var second = (Sequence)set._elements[j]; result.Add(first.Concat(_maxLength, second)); } } } return(result); }
public LookAheadSet CreateOverlaps(LookAheadSet set) { LookAheadSet result = new LookAheadSet(_maxLength); for (int i = 0; i < _elements.Count; i++) { var seq = (Sequence)_elements[i]; if (set.IsOverlap(seq)) { result.Add(seq); } } return(result); }
public LookAheadSet CreateNextSet(int token) { LookAheadSet result = new LookAheadSet(_maxLength - 1); for (int i = 0; i < _elements.Count; i++) { var seq = (Sequence)_elements[i]; var value = seq.GetToken(0); if (value != null && token == (int)value) { result.Add(seq.Subsequence(1)); } } return(result); }