示例#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))
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))
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))