2023-11-16 21:40:35 +01:00
|
|
|
import sys
|
2023-11-19 17:38:19 +01:00
|
|
|
|
2023-11-19 19:01:41 +01:00
|
|
|
def write_answer(answer, row):
|
2023-11-16 21:40:35 +01:00
|
|
|
with open(output_file, 'a') as file:
|
2023-11-19 19:01:41 +01:00
|
|
|
file.write(answer+' '+row)
|
2023-11-16 21:40:35 +01:00
|
|
|
|
|
|
|
def line_checking(row, position):
|
2023-11-19 17:38:19 +01:00
|
|
|
stack = [(row, position)]
|
2023-11-19 19:01:41 +01:00
|
|
|
help_row, help_position=row,position
|
2023-11-19 17:38:19 +01:00
|
|
|
while stack:
|
|
|
|
help_row, help_position = stack.pop()
|
2023-11-19 19:01:41 +01:00
|
|
|
if help_row == '':
|
|
|
|
help_row = '\n'
|
2023-11-19 17:38:19 +01:00
|
|
|
next_character_array = find_next_position(help_position, help_row[0])
|
|
|
|
if next_character_array:
|
|
|
|
for element_in_next_position_array in next_character_array:
|
|
|
|
stack.append((help_row[1:], element_in_next_position_array))
|
2023-11-16 21:40:35 +01:00
|
|
|
|
2023-11-19 19:01:41 +01:00
|
|
|
# if help_row == '\n':
|
|
|
|
# if help_position in what_is_the_ended_positions():
|
|
|
|
# return True
|
|
|
|
# else:
|
|
|
|
# return False
|
|
|
|
if help_row == '\n':
|
|
|
|
if help_position in what_is_the_ended_positions():
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
# return False
|
2023-11-16 21:40:35 +01:00
|
|
|
|
|
|
|
def find_next_position(position, character):
|
|
|
|
with open(used_table, 'r') as readed_used_table:
|
|
|
|
take_all_possible_positions = []
|
|
|
|
for row_used_table in readed_used_table:
|
2023-11-19 19:01:41 +01:00
|
|
|
line = row_used_table.strip().split('\t')
|
2023-11-16 21:40:35 +01:00
|
|
|
if len(line) != 1:
|
|
|
|
|
2023-11-19 19:01:41 +01:00
|
|
|
if position == line[0] and character == line[2] or position == line[0] and line[2] == '<eps>':
|
|
|
|
take_all_possible_positions.append(line[1])
|
2023-11-16 21:40:35 +01:00
|
|
|
return take_all_possible_positions
|
2023-11-19 17:38:19 +01:00
|
|
|
|
2023-11-16 21:40:35 +01:00
|
|
|
def what_is_the_ended_positions():
|
|
|
|
array = []
|
|
|
|
with open(used_table, 'r') as file:
|
|
|
|
for row in file:
|
|
|
|
line = row.strip().split('\t')
|
2023-11-19 17:38:19 +01:00
|
|
|
if len(line) == 1:
|
2023-11-16 21:40:35 +01:00
|
|
|
array += line
|
|
|
|
return array
|
2023-11-19 17:38:19 +01:00
|
|
|
|
2023-11-19 19:05:52 +01:00
|
|
|
# used_table = 'simple1.arg'
|
|
|
|
# input_file = 'simple1.in'
|
|
|
|
# output_file = 'simple1.out'
|
|
|
|
used_table = sys.argv[1]
|
|
|
|
input_file = sys.argv[2]
|
|
|
|
output_file = sys.argv[3]
|
2023-11-16 21:40:35 +01:00
|
|
|
with open(output_file, 'w') as readed_output_file:
|
|
|
|
with open(input_file, 'r') as readed_input_file:
|
|
|
|
for row_input_file in readed_input_file:
|
2023-11-19 17:38:19 +01:00
|
|
|
if line_checking(row_input_file, '0'):
|
2023-11-19 19:01:41 +01:00
|
|
|
write_answer('TRUE', row_input_file)
|
2023-11-16 21:40:35 +01:00
|
|
|
else:
|
2023-11-19 19:01:41 +01:00
|
|
|
write_answer('FALSE', row_input_file)
|