How to determine if a context-free grammar describes a regular language?

旧时模样 提交于 2021-02-19 07:56:05

问题


Given an arbitrary context-free grammar, how can I check whether it describes a regular language?

I'm not looking for exam "tricks". I'm looking for a foolproof mechanical test that I can code.

If it helps, here's an example of a CFG that I might receive as an input. Specifically, notice that the answer must be much more complicated than just looking for left- or right-recursion, since the presence of another type of recursion does not automatically imply the grammar is irregular.

S: A B C D X
A: A a
A:
B: b B
B:
C: c C c
C: c
D: D d D
D: d
X: x Y
X:
Y: y X
Y:

回答1:


There is no such mechanical procedure because the problem of determining whether a CFG defines a regular language is undecidable.

This result is a simple application of Greibach's Thereom.



来源:https://stackoverflow.com/questions/31643381/how-to-determine-if-a-context-free-grammar-describes-a-regular-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!