source.process   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 6

3 Functions

Rating   Name   Duplication   Size   Complexity  
A announce() 0 3 1
A process() 0 8 1
A analyze() 0 17 4
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