Total Complexity | 6 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from source.analyzer import analyzer |
||
2 | from source.assembler import assembler |
||
3 | from source.cleaner import cleaner |
||
4 | from source.compile import compiler |
||
5 | from source.io_library import source_reader |
||
6 | from source.precompile import precompile |
||
7 | |||
8 | |||
9 | def process(input_file: str, output_file: str, mode: str): |
||
10 | source = source_reader(input_file) |
||
11 | source = cleaner(source) |
||
12 | analyze(source) |
||
13 | symbols_address = precompile(source) |
||
14 | obj_dict = assembler(source, symbols_address) |
||
15 | compiler(obj_dict, output_file, mode) |
||
16 | print('\n Program compiled successfully!\n') |
||
17 | |||
18 | |||
19 | def analyze(source: str): |
||
20 | declaration = set() |
||
21 | usage = set() |
||
22 | error_counter = 0 |
||
23 | line_number = 1 |
||
24 | lines = source.split('\n') |
||
25 | |||
26 | for line in lines: |
||
27 | declaration, usage, err_c = analyzer(line, declaration, usage, line_number) |
||
28 | error_counter += err_c |
||
29 | line_number += 1 |
||
30 | |||
31 | if error_counter != 0: |
||
32 | announce(error_counter) |
||
33 | else: |
||
34 | if declaration != usage: |
||
35 | announce(1) |
||
36 | |||
37 | |||
38 | def announce(error_counter: int): |
||
39 | print("Compiler found {} errors\nCompile FAILED\n".format(error_counter)) |
||
40 | exit(2) |
||
41 |