Пример #1
0
def main():
    lexer = adalex.make_lexer()
    tokens = adalex.tokens
    parser = adaparse.make_parser()
    fpath = sys.argv[1] #input file path
    global filepath
    filepath = fpath
    program = parser.parse(open(fpath).read())
    cwd = os.getcwd() #gettign the current working directory
    slash, dot = fpath.rfind('/'), fpath.rfind('.')
    gfilename = fpath[slash+1:dot] # getting the input canonical file name stripping of the rest

    # Check the program
    typechecker = typecheck.typecheck()
    initialize_types(typechecker)
    env = typechecker.check_goal_symbol(program)

    if typechecker.get_error_count() > 0:
        print "Fix the type errors and compile again"
        sys.exit(0)
    # If no errors occurred, generate code
    code = generate_code(program)
    gen_file = cwd + "/assembly/" + gfilename + ".asm" #forming the output file name
    try:
        fd = open(gen_file, "w")
        fd.write(code)
        fd.flush()
        fd.close()
    except IOError:
        print "folder cannot be created"
    print "Done"
    # Emit the code sequence
    JumpGenerator().visit(code)
Пример #2
0
def main():
  global DEBUG
  if(len(sys.argv) > 2):
    DEBUG = 1
  fileName = sys.argv[1]
  f = open(fileName, 'r')
  lexer = adalex.make_lexer()
  tokens = adalex.tokens
  parser = adaparse.make_parser()
  tree = parser.parse(f.read())
  typechecker = typecheck()
  typechecker.check_goal_symbol(tree)