-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (32 loc) · 1.14 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
from optparse import OptionParser
from core.lexical import LexicalAutomata
from core.syntactic import SyntacticAutomata
from api.symbol_table import SymbolTable
def main():
options = read_commands()
symbol_table = SymbolTable(options)
tokens = LexicalAutomata(options, symbol_table).run()
SyntacticAutomata(options, tokens).run()
symbol_table.save()
def read_commands():
parser = OptionParser("%prog -f <input_file>")
parser.add_option("-f", dest="input", help="File to analyse")
parser.add_option("-o", dest="output", help="Directory in which to save output files")
(options, args) = parser.parse_args()
# Mostrar los ayuda si no se especifica el archivo a leer
if not options.input:
parser.print_help()
exit(0)
if not options.output:
options.output = ""
elif options.output[-1] != "/":
options.output += "/"
options = {
"input" : options.input,
"tokens": options.output + "tokens.txt",
"tables": options.output + "tables.txt",
"parse": options.output + "parse.txt"
}
return options
if __name__ == "__main__":
main()