Esempio n. 1
0
def main():
    import pasparser
    import sys
    from errors import subscribe_errors
    lexer = paslex.make_lexer()
    parser = pasparser.make_parser()
    with subscribe_errors(lambda msg: sys.stdout.write(msg+"\n")):
        program = parser.parse(open(sys.argv[1]).read())
        check_program(program)
Esempio n. 2
0
    if (len(sys.argv) < 2 or len(sys.argv) > 3):
        show_usage(sys.argv[0])
        raise SystemExit(1)
    elif (re.match(r'.*\.pas', sys.argv[-1])):
        try:
            filename =  sys.argv[-1]
            outname = os.path.splitext(filename)[0] + '.s'

            file = open(filename)
            data = file.read()
            file.close()

            if ("-lex" in sys.argv):
                paslex.run_lexer(data)
            else:
                parser = pasparser.make_parser()
                clear_errors()
                try:
                    with subscribe_errors(lambda msg: sys.stdout.write(msg+"\n")):
                        root_ast = parser.parse(data)
                        check.check_program(root_ast);
                    errors = errors_reported();
                    if errors == 0:
                        if ("-ast" in sys.argv):
                            # dump_class_tree(root_ast)
                            dot = DotVisitor()
                            dot.generic_visit(root_ast)
                            print dot
                        # Generate code
                        outfile = open(outname, "w")
                        mpasgen.generate(outfile, root_ast)
Esempio n. 3
0
    if (len(sys.argv) < 2 or len(sys.argv) > 3):
        show_usage(sys.argv[0])
        raise SystemExit(1)
    elif (re.match(r'.*\.pas', sys.argv[-1])):
        try:
            filename = sys.argv[-1]
            outname = os.path.splitext(filename)[0] + '.s'

            file = open(filename)
            data = file.read()
            file.close()

            if ("-lex" in sys.argv):
                paslex.run_lexer(data)
            else:
                parser = pasparser.make_parser()
                clear_errors()
                try:
                    with subscribe_errors(
                            lambda msg: sys.stdout.write(msg + "\n")):
                        root_ast = parser.parse(data)
                        check.check_program(root_ast)
                    errors = errors_reported()
                    if errors == 0:
                        if ("-ast" in sys.argv):
                            # dump_class_tree(root_ast)
                            dot = DotVisitor()
                            dot.generic_visit(root_ast)
                            print dot
                        # Generate code
                        outfile = open(outname, "w")