def TESTDFA( STRING , ttt, DFA, Rulelist, DOREDUCTIONS = 1): ttt.STRING = STRING #ttt.List = kjParser.LexList(LD0, ttt.STRING) ttt.Stream = kjParser.LexStringWalker( ttt.STRING, LD0 ) ttt.Stack = {-1:0}# Walkers.SimpleStack() ttt.ParseObj = kjParser.ParserObj( Rulelist, \ ttt.Stream, DFA, ttt.Stack,DOREDUCTIONS) ttt.RESULT = ttt.ParseObj.GO() #ttt.Stack.Dump(10) return ttt.RESULT
def hackDoParse(String, Context=None, DoReductions=1): import sys, kjParser try: # construct the ParserObj # add a newline to front to avoid problem with leading comment #String = "\n%s\n" % String Stream = pylexstringwalker(String, pyg.LexD) Stack = [] # {-1:0} #Walkers.SimpleStack() ParseOb = kjParser.ParserObj( pyg.RuleL, Stream, pyg.DFA, Stack, \ DoReductions, Context ) # do the parse ParseResult = ParseOb.GO() # return final result of reduction and the context return (ParseResult[1], Context) #return kjParser.Grammar.DoParse(pyg, String, Context, DoReductions) except: ### for testing!! t, v = sys.exc_type, sys.exc_value v = ("near line", pyg.LexD.lineno, v) raise t, v