示例#1
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):
            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"
        if decafparser.from_file(infile):
			print "No syntax errors found."
			# after parsing using the attribute grammar, print each
			# class from the generated list of decaf classes
			for c in classes:
				c.printClass()
        else:
            print "Failure: there were errors."
示例#3
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."
示例#4
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"
        if decafparser.from_file(infile):
            print "No syntax errors found."
        else:
            print "Failure: there were errors."
示例#5
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"
        if decafparser.from_file(infile):
			print "No syntax errors found."
			# after parsing using the attribute grammar
			# and producing the AST we perform type checking
			# Note that we need a completed AST in order to properly
			# perform type checking so this compilation phase
			# is distinct
			for c in classes:
				c.typeCheck()

			# print each class from the generated list of decaf classes
			for c in classes:
				c.printClass()
        else:
            print "Failure: there were errors."