Skip to content

Commit

Permalink
* add input/output directory
Browse files Browse the repository at this point in the history
* update readme
  • Loading branch information
Hagar-Usama committed Jun 6, 2020
1 parent 7c13f00 commit e727072
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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))


Expand All @@ -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:
Expand Down
Binary file modified modules/__pycache__/lexical_aux.cpython-37.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion modules/lexical_aux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
42 changes: 42 additions & 0 deletions outputs/lexemes.txt
Original file line number Diff line number Diff line change
@@ -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
6 changes: 0 additions & 6 deletions tokens.txt → outputs/tokens.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
'id'
'assign'
'num'
'id'
'assign'
'floatNum'
'id'
'assign'
'num'
'while'
'id'
'relop'
Expand Down

0 comments on commit e727072

Please sign in to comment.