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_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}")
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}")
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)
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_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 ''}" )
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))