def __init__(self, nid, simple_segments, reachables): self.nid = nid self.table = {} self.simple_segments = simple_segments for i, L in enumerate(simple_segments): s = L[0] if is_token(s): self.table[s] = i else: self.table[s] = i for rx in reachables[s]: self.table[rx] = i
def fold_segment(segment): res = [] for item in segment[::-1]: if type(item) == int: if res: if type(res[0]) == int: res = [item, res] else: res = [item]+res else: res.append(item) else: S = [] for r in item: if is_token(r): S.append([r]) else: S.append([r, res]) res = S return res
def fold_segment(segment): res = [] for item in segment[::-1]: if type(item) == int: if res: if type(res[0]) == int: res = [item, res] else: res = [item] + res else: res.append(item) else: S = [] for r in item: if is_token(r): S.append([r]) else: S.append([r, res]) res = S return res