def __init__(self, tokenize, grammar, table='YappyTab', no_table=1,
tabletype=LALRtable, noconflicts=1, expect=0, **args):
"""@param tokenize: same as for L{Lexer}
@param grammar: if a string C{parse_grammar} is called
@param table: and no_table, tabletype same as for L{LRparser}
@param args: dictionary where:
- key C{tmpdir} is the directory where the parse table used by the Yappy Grammar is stored;
- key C{usrdir} is the directory where the user tables are stored
- key C{nosemrules} if 1 semantic actions are not applied"""
self.lex = Lexer(tokenize)
operators = None
if self.lex.__dict__.has_key("operators"):
operators = self.lex.operators
if type(grammar) is StringType:
grammar = self.parse_grammar(grammar, {'locals': locals()}, args)
if args.has_key('usrdir') and os.path.isdir(args['usrdir']):
table = string.rstrip(args['usrdir']) + '/' + table
if os.path.dirname(table) == "" or os.path.exists(os.path.dirname(table)):
LRparser.__init__(self, grammar,table, no_table, tabletype, operators, noconflicts, expect, **args)
else:
sys.stderr.write("Directory %s do not exist\n" % table)
sys.exit()
if (self.Log.noconflicts):
if ((self.Log.conflicts.has_key('sr') and len(self.Log.conflicts['sr']) !=
self.Log.expect)):
print "LR conflicts: number %s value %s" % (len(self.Log.conflicts['sr']), self.Log.conflicts)
print """If it is Ok, set expect to the number of conflicts and build table again"""
elif self.Log.conflicts.has_key('rr'):
print "LR conflicts rr : number %s value %s" % (len(self.Log.conflicts['rr']), self.Log.conflicts['rr'])
评论列表
文章目录