diff --git a/README.md b/README.md index b72bc08..8dd84bd 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ I am proud of my original work. It is not the best. Yet, it is mine. And that is * [x] consider module file to add your modules in * [x] replace state names with smaller unique names * [x] add arguments (argparse) -* [ ] consider add directory for input and directory for output +* [x] consider add directory for input and directory for output * [ ] add DFA table to Lexical (from lexical_aux) * [ ] add Lexical to modules and run from main * [x] report diff --git a/lexemes.txt b/inputs/lexemes.txt similarity index 100% rename from lexemes.txt rename to inputs/lexemes.txt diff --git a/lexical.txt b/inputs/lexical.txt similarity index 100% rename from lexical.txt rename to inputs/lexical.txt diff --git a/lexical1.txt b/inputs/lexical1.txt similarity index 100% rename from lexical1.txt rename to inputs/lexical1.txt diff --git a/lexical2.txt b/inputs/lexical2.txt similarity index 100% rename from lexical2.txt rename to inputs/lexical2.txt diff --git a/lexical3.txt b/inputs/lexical3.txt similarity index 100% rename from lexical3.txt rename to inputs/lexical3.txt diff --git a/program.txt b/inputs/program.txt similarity index 100% rename from program.txt rename to inputs/program.txt diff --git a/program1.txt b/inputs/program1.txt similarity index 100% rename from program1.txt rename to inputs/program1.txt diff --git a/program2.txt b/inputs/program2.txt similarity index 100% rename from program2.txt rename to inputs/program2.txt diff --git a/program3.txt b/inputs/program3.txt similarity index 100% rename from program3.txt rename to inputs/program3.txt diff --git a/main.py b/main.py index 42bb1f5..0146b83 100644 --- a/main.py +++ b/main.py @@ -34,8 +34,8 @@ def main(): ## get directory for lexical and program cd = get_current_directory() lex_file = lexical_file - lex_path = cd + '/' + lex_file - program_path = cd + '/' + program_file + lex_path = cd + '/' + 'inputs' +'/' + lex_file + program_path = cd + '/' + 'inputs' +'/' + program_file ## build full dfa lx = Lexical() @@ -104,7 +104,7 @@ def main(): print("") print_blue(list_to_str(accepted_tokens)) - lexeme_path = cd + '/' + 'lexemes.txt' + lexeme_path = cd + '/' + 'outputs'+ '/' + 'lexemes.txt' write_file(lexeme_path, list_to_str(accepted_tokens)) @@ -114,7 +114,7 @@ def main(): print("*.*. Stream of Tokens .*.*") print_yellow(symbol_table) - output_path = cd + '/' + 'tokens.txt' + output_path = cd + '/' + 'outputs' + '/' + 'tokens.txt' quote_tokens = [] for i in symbol_table: diff --git a/modules/__pycache__/lexical_aux.cpython-37.pyc b/modules/__pycache__/lexical_aux.cpython-37.pyc index bbbf8a0..53a7b7c 100644 Binary files a/modules/__pycache__/lexical_aux.cpython-37.pyc and b/modules/__pycache__/lexical_aux.cpython-37.pyc differ diff --git a/modules/lexical_aux.py b/modules/lexical_aux.py index 6f2ec11..10decfc 100644 --- a/modules/lexical_aux.py +++ b/modules/lexical_aux.py @@ -12,7 +12,8 @@ def get_current_directory(): def write_file(path_file, output_list): - with open(path_file, 'w') as filehandle: + os.makedirs(os.path.dirname(path_file), exist_ok=True) + with open(path_file, 'w+') as filehandle: for listitem in output_list: filehandle.write('%s\n' % listitem) diff --git a/outputs/lexemes.txt b/outputs/lexemes.txt new file mode 100644 index 0000000..1da81cc --- /dev/null +++ b/outputs/lexemes.txt @@ -0,0 +1,42 @@ +program +example +var +sum +count +integer +begin +pass +:= +0 +while +pass +<> +10 +do +begin +pass +:= +pass ++ +1 +read +if +mnt +<= +0 +then +count +:= +count ++ +1.234 +else +sum +:= +sum ++ +mnt +end +write +count +end diff --git a/tokens.txt b/outputs/tokens.txt similarity index 86% rename from tokens.txt rename to outputs/tokens.txt index 4189a61..fb55002 100644 --- a/tokens.txt +++ b/outputs/tokens.txt @@ -8,12 +8,6 @@ 'id' 'assign' 'num' -'id' -'assign' -'floatNum' -'id' -'assign' -'num' 'while' 'id' 'relop'