3

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:
user541686
  • 205,094
  • 128
  • 528
  • 886

1 Answers1

5

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.

rici
  • 234,347
  • 28
  • 237
  • 341
  • 2
    That was painful to read :) I most definitely did *not* see it coming. Thanks though! – user541686 Jul 27 '15 at 04:42
  • 1
    By the way, if you know whether there is a more restricted superset of regular grammars whose regularity can be determined, then that might be nice to add to the answer. – user541686 Jul 27 '15 at 04:46