Ejemplo n.º 1
0
def closure_lr1(items, firsts):
    closure = ContainerSet(*items)
    changed = True
    while changed:
        new_items = ContainerSet()
        for item in closure:
            new_items.extend(expand(item, firsts))
        changed = closure.update(new_items)
    return compress(closure)
Ejemplo n.º 2
0
    def ClosureLR1(items, firsts):
        closure = ContainerSet(*items)

        changed = True
        while changed:
            changed = False

            new_items = ContainerSet()
            for item in closure:
                new_items.extend(LR1Parser.Expand(item, firsts))

            changed = closure.update(new_items)

        return LR1Parser.Compress(closure)
Ejemplo n.º 3
0
def closure_lr1(items, firsts):
    closure = ContainerSet(*items)

    changed = True
    while changed:
        changed = False

        new_items = ContainerSet()
        # Your code here!!!
        for x in closure:
            new_items.extend(expand(x, firsts))

        changed = closure.update(new_items)

    return compress(closure)
Ejemplo n.º 4
0
def closure_lr1(items, firsts, with_lookaheads=True):
    closure = ContainerSet(*items)

    changed = True
    while changed:
        changed = False

        new_items = ContainerSet()
        # Your code here!!!
        for item in closure:
            new_items.extend(expand(item, firsts))

        changed = closure.update(new_items)
    if with_lookaheads:
        return compress(closure)
    else:
        return closure
Ejemplo n.º 5
0
def closure_lr0(items):
    closure = ContainerSet(*items)

    pending = list(items)
    while pending:
        current = pending.pop()
        symbol = current.NextSymbol

        if current.IsReduceItem or symbol.IsTerminal:
            continue

        new_items = [
            Item(p, 0) for p in symbol.productions if Item(p, 0) not in closure
        ]
        pending += new_items
        closure.extend(new_items)
    return frozenset(closure)