예제 #1
0
파일: decafc.py 프로젝트: ClavinSBU/CSE304
def main(argv=None):
    if argv is None:
        argv = sys.argv

    # parse command line options
    try:
        try:
            opts, args = getopt.getopt(argv[1:], "h", ["help"])
        except getopt.error, msg:
            raise Usage(msg)
        for o, a in opts:
            if o in ("-h", "--help"):
                print __doc__
                return 0
        if (len(args) != 1):
            raise Usage("A single file name argument is required")
        fullfilename = args[0]
        if (fullfilename.endswith('.decaf')):
            (filename, s, e) = fullfilename.rpartition('.')
        else:
            filename = fullfilename
        infile = filename + ".decaf"
        ast.initialize_ast()
        if decafparser.from_file(infile):
            typecheck.check_classes(ast.classtable)
            if not typecheck.error_flag:
                # AST OK. Print and exit
                codegen.generate_code(ast.classtable)
                print machine
                return 0
        print "Failure: there were errors."
예제 #2
0
def main(argv=None):
    if argv is None:
        argv = sys.argv
        
    # parse command line options
    try:
        try:
            opts, args = getopt.getopt(argv[1:], "h", ["help"])
        except getopt.error, msg:
            raise Usage(msg)
        for o,a in opts:
            if o in ("-h", "--help"):
                print __doc__
                return 0
        if (len(args) != 1):
            raise Usage("A single file name argument is required")
        fullfilename = args[0]
        if (fullfilename.endswith('.decaf')):
            (filename,s,e) = fullfilename.rpartition('.')
        else:
            filename=fullfilename
        infile = filename + ".decaf"
        ast.initialize_ast()
        if decafparser.from_file(infile):
            if typechecker.main():
                ast.print_ast()
        else:
            print "Failure: there were errors."