コード例 #1
0
def test_grammars():
    print("\n")
    a = load_grammar(gram_filename)
    grammar, all_symbols, env = a
    # print(all_symbols)
    g = closure_collection(grammar, all_symbols)
    for num in range(len(g)):
        clos = [i for i in g if i.label == num][0]
        print(clos.__repr__())
    _state_map = gen_syntax_table(grammar, all_symbols)
    args = ''.join(
        list(
            map(lambda x: '{:' + str(max(5,
                                         len(x.__str__()) + 2)) + 's}',
                all_symbols)))
    s = "{:10s}" + args
    head = [
        'state',
    ] + list(all_symbols)
    print(s.format(*head))
    for j, i in enumerate(_state_map):
        _state = [
            str(j),
        ] + i
        print(s.format(*_state))
コード例 #2
0
def test_productions():
    print("test productions\n\n")
    a = load_grammar(gram_filename)
    grammar, all_symbols, env = a
    for n, i in enumerate(grammar):
        body = ('{} ' * len(i.body)).format(*i.body)
        print(f"{n} {i.head} -> {body}")
コード例 #3
0
def test_productions():
    print("test productions\n\n")
    a = load_grammar(gram_filename)
    grammar, symbols, env = a
    print(symbols)
    for i in grammar:
        body = ('{} '*len(i.body)).format(*i.body)
        print(f"{i.head} -> {body}")
コード例 #4
0
def test_productions():
    print("test productions\n\n")
    a = load_grammar(gram_filename)
    grammar, all_symbols, env = a
    for i in grammar:
        body = ('{} ' * len(i.body)).format(*i.body)
        print(f"{i.head} -> {body}")
    g = closure_collection(grammar, all_symbols)
    print(g)
コード例 #5
0
def test_grammars():
    print("\n")
    a = load_grammar(gram_filename)
    grammar, all_symbols, env = a
    _state_map = gen_syntax_table(grammar, all_symbols)
    args = ''.join(list(map(lambda x: '{:'+str(max(5, len(x.__str__())+2))+'s}',
                            all_symbols)))
    s = "{:10s}" + args
    head = ['state', ] + list(all_symbols)
    print(s.format(*head))
    for j, i in enumerate(_state_map):
        _state = [str(j), ] + i
        print(s.format(*_state))
コード例 #6
0
def test_productions():
    print("test productions\n\n")
    a = load_grammar(gram_filename)
    grammar, all_symbols, env = a
    g = closure_collection(grammar, all_symbols)
    for num in range(len(g)):
        clos = [i for i in g if i.label == num][0]
        print(clos.__repr__())
    for n, i in enumerate(grammar):
        body = ('{} ' * len(i.body)).format(*i.body)
        # if isinstance()
        print(
            f"{n} {i.head} -> {body} {i.head.source if isinstance(i.head, Code) else ''}"
        )
コード例 #7
0
def test_grammars():
    print("\n")
    a = load_grammar(gram_filename)
    grammar, syms, env = a
    _state_map = gen_syntax_table(grammar, syms)
    s = "{:6s}" + ''.join(
        map(lambda x: '{:' + str(max(4, len(x))) + 's}', syms))
    head = [
        'state',
    ] + list(syms)
    print(s.format(*head))
    for j, i in enumerate(_state_map):
        _state = [
            str(j),
        ] + i
        print(s.format(*_state))