The problem is the implementation of an algorithm that generates all the lines of length l and r from a given context free grammar G .. p>
I came up with a simple approach: run BFS on the grammar graph, remembering the states. But it doesnβt work by some recursive rules:
(1) S -> 0 | SSS | Ξ»
I can't just limit the maximum line length because the rules can contain Ξ» (empty lines), so non-terminals can reduce the final line length. (for example, work (1) with l = 1 , r = 2 will only output 0 in my implementation)
I also tried to limit the maximum number of rules applied, but this is also obviously wrong.
How can I limit or change my algorithm, so it will never go into an infinite loop and will work correctly?
source share