yappy_parser.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:FAdo 作者: Glavin001 项目源码 文件源码
def __init__(self, no_table=1, table='yappypar.tab', tabletype=LR1table, **args):
        grammar = grules([
            ("G -> RULE G", self.GRule),
            ("G -> []", EmptySemRule),
            ("RULE -> ID rulesym MULTI ruleend", self.RULERule),
            ("MULTI -> RHS rulesep MULTI", self.MULTIRule),
            ("MULTI -> RHS", self.MULTIRule),
            ("RHS -> []", EmptySemRule),  #RHS->OPSEM not allowed; epsilon-rule
            ("RHS -> RH OPSEM", self.RHSRule),
            ("RH -> ID RH", self.RHRule),
            ("RH -> ID", self.RHRule),
            ("OPSEM -> []", self.OPSEMRule),
            #      ("OPSEM -> semsym ID csemsym",self.OPSEMRule),#OPSEM->OP not allowed
            #      ("OPSEM -> semsym ID OP csemsym",self.OPSEMRule),
            ("OPSEM -> IDS", self.OPSEMRule1),
            ("OPSEM -> IDS OP", self.OPSEMRule1),
            ("OP -> opsym OPV", self.OPRule),
            ("OPV ->  ID  ID ", self.OPVRule)
        ])

        tokenize = [
            ("\{\{.*\}\}", lambda x: ("IDS", string.strip(x[2:-2]))),
            ("\s+", ""),
            ("->", lambda x: ("rulesym", x)),
            ("\|", lambda x: ("rulesep", x)),
            (";", lambda x: ("ruleend", x)),
            #        ("}}",lambda x: ("csemsym",x)),
            #        ("{{",lambda x: ("semsym",x)),
            ("//", lambda x: ("opsym", x)),
            (".*", lambda x: ("ID", x))]
        if args.has_key('tmpdir'):
            args1 = {'usrdir': string.rstrip(args['tmpdir'], '/')}
        else:
            args1 = {}
        Yappy.__init__(self, tokenize, grammar, table, no_table, **args1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号