Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.cyk() method of CFG class appears to be incorrect sometimes. #1

Open
BigTuna08 opened this issue Oct 6, 2021 · 1 comment
Open

Comments

@BigTuna08
Copy link

I'm not sure exactly what the problem is, here is an example, it is saying the null string is not accepted but it should be

Variables (V): {'B', 'A', 'S'}
Terminals (Σ): {'λ', '1', '0'}
Null character: λ
Start variable (S): S
Rules (R):
S -> 0S1B | ABA
A -> 1S00 | λ
B -> λ
11111 in grammer: False
1111 in grammer: False
1010101 in grammer: False
1100 in grammer: False
1010 in grammer: False
0 in grammer: False
1101 in grammer: False
0011 in grammer: True
λ in grammer: False
in grammer: False

Here is the code to replicate

from cfg import CFG

variables= {"A", "B", "S"}
terminals= {"0", "1", 'λ'}
null_char = 'λ'

symbols = variables.union(terminals)
symbols

test_strings = ["11111", "1111", "1010101", "1100", "1010", "0", "1101", "0011", 'λ', ""]

rules = [('S', 'ABA'), ('S', '0S1B'), ('A', 'λ'), ('A', '1S00'), ('B', 'λ')]

grammer = CFG(variables= variables,
terminals= terminals,
rules = set(rules),
start_variable = "S",
null_character = 'λ'
)

print(grammer)
for s in test_strings:
print(f"{s} in grammer: {grammer.cyk(s)}",)

@mahdavipanah
Copy link
Owner

mahdavipanah commented Oct 7, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants