def main(): import sys, PgenParser, pprint, DFAParser # ____________________________________________________________ # Generate a test parser grammarST = PgenParser.parseFile("Grammar") pgenObj = PyPgen() grammarObj = pgenObj(grammarST) if "-py" in sys.argv: print "# %s" % ("_" * 70) print "# This was automatically generated by PyPgen." print "# Hack at your own risk." print print "grammarObj =", pprint.pprint(grammarObj) if "-i" in sys.argv: # __________________________________________________ # Parse some input if len(sys.argv) > 1: inputFile = sys.argv[1] fileObj = open(inputFile) else: inputFile = "<stdin>" fileObj = sys.stdin tokenizer = StdTokenizer.StdTokenizer().tokenize(fileObj) parseTree = DFAParser.parsetok(tokenizer, grammarObj, 257) fileObj.close() # __________________________________________________ # Show the result if __BASIL__: from basil.visuals.TreeBox import showTree showTree(parseTree).mainloop() else: pprint.pprint(parseTree)
def _doParse (source, start): """_doParse() Ignore the function behind the curtain! Even if it is kinda like the CPython PyParser_SimpleParseString() (I think.) """ global pygrammar tokenizer = PyTokenizer.PyTokenizer().tokenizeString(source) return STType(DFAParser.parsetok(tokenizer, pygrammar, start))