Example #1
0
import sys
import os.path

if __name__ == '__main__':
    if len(sys.argv) == 1:
        print('No folder was specified. please enter a file or folder'
              'name in system args.')
    else:
        for i in range(1, len(sys.argv)):
            file_list = fp.directory_parser(sys.argv[i])
            dir_name = fp.get_dir_name(sys.argv[i])
            accumulated_code = []
            for path in file_list:
                try:
                    lines = fp.file_reader(path)
                    name = fp.name_extractor(path)
                    accumulated_code += vmp.init()
                    accumulated_code += vmp.translate(lines, name)
                except SyntaxError as e:
                    print("Error translating file:\n{0}"
                          "\nwith Error:\n{1}".format(path, e.msg))
                except IOError as e:
                    print("Error parsing file:\n{0}\nwith Error:\n{1}".format(
                        path, e.strerror))
            vm_path = file_list[0]
            if os.path.isdir(sys.argv[i]):
                dir_name += '.vm'
                dir_path = os.path.abspath(sys.argv[i])
                vm_path = os.path.sep.join([dir_path, dir_name])
            fp.file_writer(accumulated_code, vm_path)
Example #2
0
import file_parser as fp
import first_pass as first
import second_pass as second
import sys

if __name__ == '__main__':
    if len(sys.argv) == 1:
        print('No folder was specified. please enter a file or folder'
              'name in system args.')
    else:
        for i in range(1, len(sys.argv)):
            file_list = fp.directory_parser(sys.argv[i])
            for path in file_list:
                try:
                    lines = fp.file_reader(path)
                    clean_code, symbol_table = first.first_pass(lines)
                    assembled_code = second.second_pass(
                        clean_code, symbol_table)
                    fp.file_writer(assembled_code, path)
                except SyntaxError as e:
                    print("Error assembling file:\n{0}"
                          "\nwith Error:\n{1}".format(path, e.msg))
Example #3
0
import os.path
import sys
import file_parser as fp
import CompilationEngine as ce

if __name__ == '__main__':
    if len(sys.argv) == 1:
        print('No folder was specified. please enter a file or folder'
              'name in system args.')
    else:
        for i in range(1, len(sys.argv)):
            file_list = fp.directory_parser(sys.argv[i])
            dir_name = fp.get_dir_name(sys.argv[i])
            for path in file_list:
                try:
                    lines = fp.file_reader(path)
                    name = fp.name_extractor(path)
                    engine = ce.CompilationEngine(lines)
                    xml_path = file_list[0]
                    if os.path.isdir(sys.argv[i]):
                        name += '.xml'
                        dir_path = os.path.abspath(sys.argv[i])
                        xml_path = os.path.sep.join([dir_path, name])
                    fp.file_writer(engine.compile(), xml_path)
                except SyntaxError as e:
                    print("Error translating file:\n{0}"
                          "\nwith error:\n{1}".format(path, e))
                except IOError as e:
                    print("Error parsing file:\n{0}\nwith error:\n{1}".format(
                        path, e.strerror))
Example #4
0
import os.path
import sys
import file_parser as fp
import CompilationEngine as ce

if __name__ == '__main__':
    if len(sys.argv) == 1:
        print('No folder was specified. please enter a file or folder'
              'name in system args.')
    else:
        file_list = fp.directory_parser(sys.argv[1])
        dir_name = fp.get_dir_name(sys.argv[1])
        for path in file_list:
            try:
                lines = fp.file_reader(path)
                name = fp.name_extractor(path)
                engine = ce.CompilationEngine(lines)
                vm_path = file_list[0]
                if os.path.isdir(sys.argv[1]):
                    name += '.vm'
                    dir_path = os.path.abspath(sys.argv[1])
                    vm_path = os.path.sep.join([dir_path, name])
                fp.file_writer(engine.compile(), vm_path)
            except SyntaxError as e:
                print("Error translating file:\n{0}"
                      "\nwith error:\n{1}".format(path, e))
            except IOError as e:
                print("Error parsing file:\n{0}\nwith error:\n{1}".format(
                    path, e.strerror))