1

I'm in an undergraduate class where we're studying formal grammars right now. I asked my teacher if there was any known set of rules for creating context free grammars that

1) Was guaranteed to produce an unambiguous grammar. 2) Allows for the creation of any possible unambiguous grammar.

I am well aware that determining whether a grammar is ambiguous is undecidable. I'm not sure if the above stated idea is reducible to that, but after fiddling around with it a bit, I couldn't think of a method for making such a reduction. That said I'm really no expert at reductions or grammars. I tried googling for a while, but I only found pages about undecidability. Does anyone know?

sync
  • 75
  • 6
  • Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. – Ken White Feb 13 '15 at 02:45
  • @Ken If I just asked for an answer would that be better? – sync Feb 13 '15 at 03:08
  • I'm not convinced that "Does anyone know?" is better than your previous question. The obvious answers to that are 1) *Yes, someone knows.*, 2) *No, no one knows*, or 3) *Possibly someone knows*. Which one of those would be acceptable to you as an answer? If it's *None of the above*, you need to restate your question. – Ken White Feb 13 '15 at 03:39

1 Answers1

0

I think you know enough to work this out to a satisfactory conclusion on your own.

Consider a set of rules which I claim will satisfy your constraints: they will accept only unambiguous grammars, and they will accept all unambiguous grammars. That is, a grammar G is unambiguous if, and only if, it follows the rules.

Now, to be useful, my set of rules must be such that it's possible to tell by looking at a grammar whether it obeys the rules or not. That is, there must be an effective procedure for determining the truth, for any grammar G, of the proposition "G follows the rules."

You may be able now to see where this is headed. If you don't, give yourself a minute; it may come to you.

Assume I have such a set of rules. If my description is correct, we now have an effective procedure for determining whether a grammar follows the rules. And we know that iff the grammar follows the rules, then the grammar is unambiguous. My rules now sound a lot like a claim to have an effective procedure for determining whether a grammar is unambiguous. The decidability result you mention says that there is no such effective procedure.

So you can know, without examination, that my set of rules does not satisfy all three constraints. Either my rules do allow some ambiguous grammars (violating your first constraint), or my rules reject some unambiguous grammar (violating your second constraint), or there is no effective procedure for determining whether a grammar obeys my rules or not (violating our intuitive understanding of "a set of rules").


[Addendum]

If we relax the constraint on the set of rules to allow rules to count as useful even if they do not always terminate, then I think that the answer is probably 'yes', on the general principle that for any program one can formulate a theorem true if and only if the program terminates, and for any theorem, one can construct a program which will terminate iff the theorem is true. (This has a name, but I'm blanking on it at the moment.)

Goedel's Completeness Theorem established that there is an algorithm which will generate (given enough time) any theorem of a logical system; the hitch is that it's not guaranteed to terminate, so that after any given period of time we may be unable to tell whether we are dealing with a true statement which will be recognized eventually, or a false statement for which the algorithm may not terminate.

That said, I do not know that the rules in question would be anything other than a statement, in logical form, of the definition of ambiguity (or its absence) in a grammar. The simplest way to construct such a device would be to generate all possible grammars, in order of ascending length, and for each grammar undertake the proof, one step at a time, each grammar taking turns with the others. (If we work on one grammar until we have a result, we may never get to the next grammar, so we have to perform a sort of round-robin, much like the simple algorithm for generating all sentences from a grammar by generating all derivations.)

I hope this helps.

C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65
  • Thank you for this answer. Yet this is not quite what I'm trying to get at here. What if there was a procedure for creating an infinite set of grammars and thus would not run in constant time (i.e. it doesn't satisfy your "to be useful" requirement)? Could there exist such an algorithm that we could be certain would, at the limit, create all unambiguous grammars and no others? – sync Feb 13 '15 at 03:15
  • Thanks for the in-depth addendum-it's still a little bit short of an answer, but it's got me thinking about methods to ensure that all grammars will be covered, though not necessarily in finite time. – sync Feb 13 '15 at 05:06
  • You can enumerate all pairs of positive integers by zigzagging the plane: (1,1),(1,2),(2,1),(1,3),(2,2),(3,1),(1,4)... That's what you do to enumerate halting turing machines, or unambiguous grammars: enumerate the pairs (length of TM/grammar, number of steps to test). Since there are a finite number of descriptions with any given length, this will eventually generate every halting TM/unambiguous grammar, but there is no way of telling when so it won't work as a decision procedure. Just enumerating TMs by length isn't quite good enough. – rici Feb 13 '15 at 07:05