Skip to content

Commit 90ce4aa

Browse files
authored
Merge pull request #17 from viabzalov/master
Corrected mistake in grammar_to_cnf
2 parents d9d395d + 542a9b1 commit 90ce4aa

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

tools/grammar_to_cnf/grammar_to_cnf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ def to_txt(cfg):
113113
variables, productions, terminals = '', '', ''
114114

115115
for var in cfg.variables:
116-
variables += f'{var.value} '
116+
if var not in cfg.variables:
117+
variables += f'{var.value} '
117118
for ter in cfg.terminals:
118119
terminals += f'{ter.value} '
119120
for pr in cfg.productions:
@@ -122,7 +123,7 @@ def to_txt(cfg):
122123
for sym in pr.body:
123124
productions += f'{sym.value} '
124125
productions += '\n'
125-
return f'{variables}\n{terminals}\n{productions}'
126+
return f'{cfg.start_symbol} {variables}\n{terminals}\n{productions}'
126127

127128

128129
def main():

0 commit comments

Comments
 (0)