def antrl_parse(input_stream, debug): lexer = CalcLexer(input_stream) token_stream = CommonTokenStream(lexer) parser = CalcParser(token_stream) print "### PARSING ###" tree = parser.calcfile() if debug: lisp_tree_str = tree.toStringTree(recog=parser) print(lisp_tree_str) return tree
def convert(input_stream): lexer = CalcLexer(input_stream) token_stream = CommonTokenStream(lexer) parser = CalcParser(token_stream) tree = parser.calcfile() lisp_tree_str = tree.toStringTree(recog=parser) print(lisp_tree_str) walker = ParseTreeWalker() listner = CalcListener() walker.walk(listner, tree) root = etree.XML('<?xml version="1.0" ?>' + listner.output) print "##ParseTreeWalker##" pretty_print(root) resolve_vars(root, use_tke='-tps' not in sys.argv) assign_ids(root) accumulations(root) difference(root) multiplications(root) multicopy_accumulation(root) # print "## RESOLVE VARS ##" # pretty_print(root) section = root.xpath('/CALC/Section/@val')[0] root = xslt(root, 'xslt/calc2script.xsl') print "## calc2script ##" pretty_print(root) clean_temps(root) # print "## CleanTemps ##" # pretty_print(root) root = xslt(root, 'xslt/calc2script2.xsl') print "## calc2script2 ##" pretty_print(root) text = xslt_text(root, 'xslt/calc2script3.xsl') print "## calc2script3 ##" print text return text