def generate(modelica_model, trace=False): "The modelica model" input_stream = antlr4.InputStream(modelica_model) lexer = ModelicaLexer(input_stream) stream = antlr4.CommonTokenStream(lexer) parser = ModelicaParser(stream) tree = parser.stored_definition() # print(tree.toStringTree(recog=parser)) sympyPrinter = SympyPrinter(parser, trace) walker = antlr4.ParseTreeWalker() walker.walk(sympyPrinter, tree) return sympyPrinter.result
def main(argv): #pylint: disable=unused-argument "The main function" parser = argparse.ArgumentParser() parser.add_argument('src') parser.add_argument('out') parser.add_argument('-t', '--trace', action='store_true') parser.set_defaults(trace=False) args = parser.parse_args(argv) text = antlr4.FileStream(args.src) lexer = ModelicaLexer(text) stream = antlr4.CommonTokenStream(lexer) parser = ModelicaParser(stream) tree = parser.stored_definition() # print(tree.toStringTree(recog=parser)) sympyPrinter = SympyPrinter(parser, args.trace) walker = antlr4.ParseTreeWalker() walker.walk(sympyPrinter, tree) with open(args.out, 'w') as f: f.write(sympyPrinter.result)