Beispiel #1
0
def uniqueness(A):
    """Uniqueness of complement:
        
              A u B = Universal   and    A n B = Empty

           => A = complement B  and vice versa

       Involution:
            
              A = complement(complement(A))
    """
    global count

    B = difference(DFA.Universal(), A)
    # => A u B = Universal   and    A n B = Empty
    assert identity(union([A, B]), DFA.Universal())
    assert identity(intersection([A, B]), DFA.Empty())

    # Uniqueness of complement
    assert identity(A, complement(B))
    assert identity(B, complement(A))

    # Involution/Double Complement
    assert identity(A, complement(complement(A)))
    assert identity(B, complement(complement(B)))
    count += 1
Beispiel #2
0
def domination(A):
    global count
    first  = union([A, DFA.Universal()])
    assert identity(first, DFA.Universal())

    first  = intersection([A, DFA.Empty()]) 
    assert identity(first, DFA.Empty())

    count += 1
Beispiel #3
0
def complement_laws(A):
    global count
    first = union([A.clone(), complement(A.clone())])
    assert identity(first, DFA.Universal())

    first = intersection([A.clone(), complement(A.clone())])
    assert identity(first, DFA.Empty())

    count += 1
Beispiel #4
0
def identity_vs_empty_and_universal(A):
    global count
    count += 1
    # if count != 3: return
    first = union([A.clone(), DFA.Empty()])
    assert identity(first, A.clone())

    first = intersection([A.clone(), DFA.Universal()])
    assert identity(first, A)
Beispiel #5
0
def unary_checks(Q, operation):
    Q_plus = beautifier.do(repeat.do(Q))
    Q_star = beautifier.do(repeat.do(Q, min_repetition_n=0))

    Q_is_Q_star = identity.do(Q, Q_star)
    Q_is_Q_plus = identity.do(Q, Q_plus)

    # \Cut{Q Q} = \Nothing
    y = operation(Q, Q)
    assert y.is_Nothing()

    # if Q != Q+: \CutBegin{Q+ Q} = Q*
    if not Q_is_Q_plus:
        y = operation(Q_plus, Q)
        assert identity.do(y, Q_star)

    # if Q != Q*: \CutBegin{Q* Q} = Q*
    if not Q_is_Q_star:
        y = operation(Q_star, Q)
        assert identity.do(y, Q_star)

    # \Cut{Q \Nothing} = Q
    y = operation(Q, DFA.Nothing())
    assert identity.do(y, Q)

    # \Cut{\Nothing Q} = \Nothing
    y = operation(DFA.Nothing(), Q)
    assert y.is_Nothing()

    # \Cut{Q \Universal} = \Nothing
    y = operation(Q, DFA.Universal())
    assert y.is_Nothing()

    # NOT: \Cut{\Universal Q} = \Universal
    if not Q_is_Q_star and not Q_is_Q_plus:
        y = operation(Q, DFA.Universal())
        assert y.is_Nothing()

    return Q_star, Q_plus
Beispiel #6
0
from quex.engine.state_machine.check.identity import do as identity
from quex.engine.state_machine.check.superset import do as superset
from quex.engine.state_machine.core import DFA

import quex.input.regular_expression.engine as regex
import quex.engine.state_machine.TEST_help.many_shapes as shapes

shapes.set_unique_transition_f()


def dfa(Str):
    return regex.do(Str, {}, AllowNothingIsNecessaryF=True).extract_sm()


__dfa_list = [
    DFA.Universal(),  # Matches all lexemes
    DFA.Empty(),  # Matches the lexeme of zero length
    #
    dfa('a'),
    dfa('ab'),
    dfa('a(b?)'),
    dfa('ab|abcd'),
    # "Branches"
    dfa('12|AB'),
    dfa('x(12|AB)'),
    dfa('(12|AB)x'),
    dfa('x(12|AB)x'),
    dfa('x(1?2|A?B)x'),
    dfa('x(1?2?|A?B?)x'),
    # "Loops"
    dfa('A+'),
Beispiel #7
0
elif "Loops" in sys.argv:
    test('A+')
    test('A(B*)')
    test('A((BC)*)')
    test('((A+)B+)C+')
    test('(ABC|BC|C)+')

elif "BranchesLoops" in sys.argv:
    test('(AB|XY)+')
    test('(AB|XY)((DE|FG)*)')
    test('(((AB|XY)+)(DE|FG)+)(HI|JK)+')
    test('((AB|XY)(DE|FG)(HI|JK)|(DE|FG)(HI|JK)|(HI|JK))+')

elif "Misc" in sys.argv:
    test('((((((((p+)r)+i)+)n)+t)+e)+r)+')
    test('(printer|rinter|inter|nter|ter|er|r)+')
    test('(p?r?i?n?t?e?r|rinter|inter|nter|ter|er|r)+')
    test(
        '(((((((((p+)r)+i)+)p)+r)+i)+n)+|(priprin|riprin|iprin|prin|rin|in|n)+)x?'
    )

elif "Special" in sys.argv:
    test(DFA.Empty())
    test(DFA.Universal())
    sm = DFA.Universal()
    sm.get_init_state().set_acceptance(True)
    sm = beautifier.do(sm)
    test(sm)
else:
    test('a|ab')
Beispiel #8
0
def anything_containing(Q):
    tmp = sequentialize.do([DFA.Universal(), Q, DFA.Universal()])
    return beautifier.do(tmp)
Beispiel #9
0
def anything_ending_with(Q):
    tmp = sequentialize.do([DFA.Universal(), Q])
    return beautifier.do(tmp)
Beispiel #10
0
def anything_beginning_with(Q):
    tmp = sequentialize.do([Q, DFA.Universal()])
    return beautifier.do(tmp)
def least_and_greatest(A):
    global count
    assert superset(A, DFA.Empty())
    assert superset(DFA.Universal(), A)

    count += 1
Beispiel #12
0
def snap_universal(stream, PatternDict):
    return DFA.Universal()