-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_parser.py
More file actions
36 lines (31 loc) · 1.56 KB
/
test_parser.py
File metadata and controls
36 lines (31 loc) · 1.56 KB
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
from glob import glob
from compiler import run
from os import mkdir, chdir, path
for file in glob('D:/University/Compiler Design/Project/Parser_Tests/*/input.txt'):
# for file in glob('/Users/fereshtah/Desktop/term 8/compiler/Project/Compiler-Project/Scanner_Tests/*/input.txt'):
file = file.replace('\\', '/')
folder = file.split('/')[-2]
input_path = 'D:/University/Compiler Design/Project/Parser_Tests/' + folder
# input_path = '/Users/fereshtah/Desktop/term 8/compiler/Project/Compiler-Project/Scanner_Tests/' + folder
chdir(input_path)
if not path.exists(input_path + '/output'):
mkdir('output')
run(input_path)
print('Test ' + folder + ':')
with open(input_path + '/parse_tree.txt', 'r') as f:
test_tokens = f.read().replace(' ', '').replace('\t', '').replace('\n', '').lower()
with open(input_path + '/output/parse_tree.txt', 'r') as f:
our_tokens = f.read().replace(' ', '').replace('\t', '').replace('\n', '').lower()
if test_tokens == our_tokens:
print('Test Parse Tree: PASS')
else:
print('Test Parse Tree: FAIL')
with open(input_path + '/syntax_errors.txt', 'r') as f:
test_symbol_table = f.read().replace(' ', '').replace('\t', '').replace('\n', '').lower()
with open(input_path + '/output/syntax_errors.txt', 'r') as f:
our_symbol_table = f.read().replace(' ', '').replace('\t', '').replace('\n', '').lower()
if test_symbol_table == our_symbol_table:
print('Test Syntax Errors: PASS')
else:
print('Test Syntax Errors: FAIL')
print()