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); }
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; } } }
private void CheckElement(string name, ProductionPatternElement elem) { if (elem.IsProduction() && GetPattern(elem.Id) == null) { throw new ParserCreationException( ParserCreationException.ErrorType.INVALID_PRODUCTION, name, "an undefined production pattern id (" + elem.Id + ") is referenced"); } }
public void AddElement(ProductionPatternElement elem, int min, int max) { if (elem.IsToken()) { AddToken(elem.Id, min, max); } else { AddProduction(elem.Id, min, max); } }
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))); } }
private LookAheadSet FindLookAhead(ProductionPatternElement elem, int length, CallStack stack, LookAheadSet filter) { // Find initial element look-ahead var first = FindLookAhead(elem, length, 0, stack, filter); var result = new LookAheadSet(length); result.AddAll(first); if (filter == null || !filter.IsOverlap(result)) { return(result); } // Handle element repetitions if (elem.MaxCount == Int32.MaxValue) { first = first.CreateRepetitive(); } var max = elem.MaxCount; if (length < max) { max = length; } for (int i = 1; i < max; i++) { first = first.CreateOverlaps(filter); if (first.Size() <= 0 || first.GetMinLength() >= length) { break; } var follow = FindLookAhead(elem, length, 0, stack, filter.CreateFilter(first)); first = first.CreateCombination(follow); result.AddAll(first); } return(result); }
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()); }
public void AddElement(ProductionPatternElement elem) { _elements.Add(elem); }