source.process.announce()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 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