from algos import create_dfa, globals_holder from atn_creation import rule from datastructure import atn # LL(3) grammar # S ::= A $ # A ::= a b c d? # | a b e d+ r = rule('A') rs = rule('S').ele('A').ele('eof') print rs r.ele('a').ele('b').ele('c').opt('d') r.alt().ele('a').ele('b').ele('e').kc('d') print r globals_holder.a_net = atn() r.merge_to_atn(globals_holder.a_net) rs.merge_to_atn(globals_holder.a_net) d_s = create_dfa(rs.get_start_state(globals_holder.a_net)) d_net = create_dfa(r.get_start_state(globals_holder.a_net)) globals_holder.a_net.to_png('A') d_s.to_png("S_dfa") d_net.to_png('A_dfa')
# S ::= A eof # A ::= E a # | E b # E ::= c E d # | e ra = rule("A") rs = rule("S").ele("A").ele("eof") print rs re = rule("E") ra.ele("E").ele("a") ra.alt().ele("E").ele("b") print ra re.ele("c").ele("E").ele("d") re.alt().ele("e") print re globals_holder.a_net = atn() rs.merge_to_atn(globals_holder.a_net) ra.merge_to_atn(globals_holder.a_net) re.merge_to_atn(globals_holder.a_net) d_a = create_dfa(ra.get_start_state(globals_holder.a_net)) globals_holder.a_net.to_png("A") d_a.to_png("A_dfa")
class globals_holder(object): a_net = atn() def __init__(self): pass