-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
53 lines (38 loc) · 1.37 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import re
import sys
from src.structures import gen_foret
from src.parser import parse_grammar, parse_program
from src.scanner import scan_g0, scan_gpl
from src.analyzer import analyze_g0, analyze_gpl
from src.interpreter import exec_code
import src.global_variables as global_variables
if __name__ == '__main__':
if len(sys.argv) == 1:
print("Usage: dumas <path/to/file.dumas> <optional: grammar_name>")
sys.exit(1)
global_variables.init()
gen_foret()
parse_grammar(sys.argv[2] if len(sys.argv) == 3 else None)
global_variables.scanned, global_variables.grammar = scan_g0(
global_variables.grammar)
result = analyze_g0(global_variables.A[0])
if not result:
print("Grammar is not correct")
sys.exit(1)
parse_program(sys.argv[1] if len(sys.argv) >=
2 else './examples/variables.dumas')
global_variables.scanned, global_variables.program = scan_gpl(
global_variables.program)
result = analyze_gpl(global_variables.A[5])
result = result and global_variables.scanned == None and len(
global_variables.program) == 0
if not result:
print("Program is not correct")
sys.exit(1)
# print(global_variables.pcode)
exec_code()
"""
from src.debugger import imprim_arbre
imprim_arbre(global_variables.A[5])
# print(f'Grammaire correcte? {result}')
"""