-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparser.py
executable file
·21 lines (17 loc) · 1 KB
/
parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python3
import argparse
import earley
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Sentence parser: \
returns if given sentences are part of the \
language described in given grammar file.')
parser.add_argument('grammar', help='path to file containing the grammar to be used')
parser.add_argument('-v', '--verbose', action='store_true', help='print parsing steps')
args = parser.parse_args()
initial, variables, terminals, rules = earley.read_file(args.grammar)
string = input('Frase a ser reconhecida (string vazia termina a execução): ')
while string != '':
print('\n\'' + string + '\' faz parte da linguagem.\n'
if earley.earley(initial, variables, rules, string, args.verbose)
else '\n\'' + string + '\' não reconhecida como parte da linguagem.\n')
string = input('Frase a ser reconhecida: ')